mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
Add kore_platform_random_uint32().
This commit is contained in:
parent
7b48959c32
commit
4ecd6d5603
@ -803,6 +803,7 @@ void kore_platform_schedule_read(int, void *);
|
||||
void kore_platform_schedule_write(int, void *);
|
||||
void kore_platform_event_schedule(int, int, int, void *);
|
||||
void kore_platform_worker_setcpu(struct kore_worker *);
|
||||
u_int32_t kore_platform_random_uint32(void);
|
||||
|
||||
#if defined(KORE_USE_PLATFORM_SENDFILE)
|
||||
int kore_platform_sendfile(struct connection *, struct netbuf *);
|
||||
|
@ -298,6 +298,12 @@ kore_platform_sandbox(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
kore_platform_random_uint32(void)
|
||||
{
|
||||
return (arc4random());
|
||||
}
|
||||
|
||||
#if defined(KORE_USE_PLATFORM_PLEDGE)
|
||||
void
|
||||
kore_platform_pledge(void)
|
||||
|
16
src/linux.c
16
src/linux.c
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/random.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/syscall.h>
|
||||
@ -262,3 +263,18 @@ kore_platform_sandbox(void)
|
||||
{
|
||||
kore_seccomp_enable();
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
kore_platform_random_uint32(void)
|
||||
{
|
||||
ssize_t ret;
|
||||
u_int32_t val;
|
||||
|
||||
if ((ret = getrandom(&val, sizeof(val), 0)) == -1)
|
||||
fatalx("getrandom(): %s", errno_s);
|
||||
|
||||
if ((size_t)ret != sizeof(val))
|
||||
fatalx("getrandom() %zd != %zu", ret, sizeof(val));
|
||||
|
||||
return (val);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user