From ee93463c64cdd88f0dda7083d92ec5aebba113ec Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sat, 11 Oct 2025 21:54:06 +0200 Subject: [PATCH] Add rand() syscall --- kernel/syscall/randcrypto.c | 8 ++++++++ kernel/syscall/randcrypto.h | 8 ++++++++ kernel/syscall/syscall.c | 2 ++ share/sysdefs/syscall.h | 1 + 4 files changed, 19 insertions(+) create mode 100644 kernel/syscall/randcrypto.c create mode 100644 kernel/syscall/randcrypto.h diff --git a/kernel/syscall/randcrypto.c b/kernel/syscall/randcrypto.c new file mode 100644 index 0000000..28c7bb6 --- /dev/null +++ b/kernel/syscall/randcrypto.c @@ -0,0 +1,8 @@ +#include +#include +#include "hal/hal.h" +#include "syscall.h" + +int32_t SYSCALL0(sys_rand) { + return hal_randnum(); +} diff --git a/kernel/syscall/randcrypto.h b/kernel/syscall/randcrypto.h new file mode 100644 index 0000000..a4e42dd --- /dev/null +++ b/kernel/syscall/randcrypto.h @@ -0,0 +1,8 @@ +#ifndef SYSCALL_RANDCRYPTO_H_ +#define SYSCALL_RANDCRYPTO_H_ + +#include "syscall.h" + +int32_t SYSCALL0(sys_rand); + +#endif // SYSCALL_RANDCRYPTO_H_ diff --git a/kernel/syscall/syscall.c b/kernel/syscall/syscall.c index 479c961..a82be02 100644 --- a/kernel/syscall/syscall.c +++ b/kernel/syscall/syscall.c @@ -9,6 +9,7 @@ #include "mman.h" #include "sched.h" #include "devctl.h" +#include "randcrypto.h" int32_t SYSCALL1(sys_debugprint, string) { char *p = (char *)string; @@ -25,4 +26,5 @@ SyscallFn SYSCALL_TABLE[SYSCALLS_MAX] = { [SYS_MMAN_UNMAP] = &sys_mman_unmap, [SYS_SCHEDRELEASE] = &sys_schedrelease, [SYS_DEVCTL] = &sys_devctl, + [SYS_RAND] = &sys_rand, }; diff --git a/share/sysdefs/syscall.h b/share/sysdefs/syscall.h index 89286fa..597c46d 100644 --- a/share/sysdefs/syscall.h +++ b/share/sysdefs/syscall.h @@ -9,5 +9,6 @@ #define SYS_MMAN_UNMAP 6 #define SYS_SCHEDRELEASE 7 #define SYS_DEVCTL 8 +#define SYS_RAND 9 #endif // SHARE_HDRS_SYSCALL_H_