LibC: Implement sched_getcpu

This commit is contained in:
Bananymous 2026-04-02 15:39:36 +03:00
parent e01e35713b
commit dd2bbe4588
2 changed files with 20 additions and 0 deletions

View File

@ -28,6 +28,8 @@ int sched_setparam(pid_t pid, const struct sched_param* param);
int sched_setscheduler(pid_t pid, int, const struct sched_param* param); int sched_setscheduler(pid_t pid, int, const struct sched_param* param);
int sched_yield(void); int sched_yield(void);
int sched_getcpu(void);
__END_DECLS __END_DECLS
#endif #endif

View File

@ -2,6 +2,10 @@
#include <sys/syscall.h> #include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#include <kernel/API/SharedPage.h>
extern volatile Kernel::API::SharedPage* g_shared_page;
int sched_get_priority_max(int policy) int sched_get_priority_max(int policy)
{ {
(void)policy; (void)policy;
@ -18,3 +22,17 @@ int sched_yield(void)
{ {
return syscall(SYS_YIELD); return syscall(SYS_YIELD);
} }
int sched_getcpu(void)
{
if (g_shared_page == nullptr)
return -1;
uint8_t cpu;
#if defined(__x86_64__)
asm volatile("movb %%gs:0, %0" : "=r"(cpu));
#elif defined(__i686__)
asm volatile("movb %%fs:0, %0" : "=q"(cpu));
#endif
return cpu;
}