Implement _os_cpu_number on top of Linux getcpu

This commit is contained in:
Ariel Abreu 2020-09-27 21:37:56 -04:00
parent f5a965c8ac
commit 7a07bbe6e5
No known key found for this signature in database
GPG Key ID: ECF8C2B9E8AD3E6B
7 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1 @@
../../../../../../../../../../src/kernel/emulation/linux/linux-syscalls/linux-arm64.h

View File

@ -0,0 +1 @@
../../../../../../../../../../src/kernel/emulation/linux/linux-syscalls/linux-generic.h

View File

@ -0,0 +1 @@
../../../../../../../../../../src/kernel/emulation/linux/linux-syscalls/linux.h

View File

@ -0,0 +1 @@
../../../../../../../../../../src/kernel/emulation/linux/linux-syscalls/linux-x86.h

View File

@ -0,0 +1 @@
../../../../../../../../../../src/kernel/emulation/linux/linux-syscalls/linux-x86_64.h

View File

@ -17,6 +17,7 @@ long __unknown_syscall_machdep(int nr, ...)
return -ENOSYS;
}
VISIBLE
int __linux_syscall(int nr, long a1, long a2, long a3, long a4, long a5, long a6)
{
return linux_syscall(a1, a2, a3, a4, a5, a6, nr);

View File

@ -52,12 +52,28 @@
#include <arm/arch.h>
#endif
#ifdef DARLING
#include <darling/emulation/linux-syscalls.h>
#endif
extern void _thread_set_tsd_base(void *tsd_base);
__attribute__((always_inline))
static __inline__ unsigned int
_os_cpu_number(void)
{
#ifdef DARLING
extern int __linux_syscall(int nr, ...);
unsigned int cpu_num = 0;
int status = __linux_syscall(__NR_getcpu, &cpu_num, 0, 0, 0, 0, 0);
// should we even check? i don't think it's possible for it to fail with these arguments
if (status < 0) {
return 0; // i guess?
}
return cpu_num;
#else // !DARLING
#if defined(__arm__)
uintptr_t p;
__asm__("mrc p15, 0, %[p], c13, c0, 3" : [p] "=&r" (p));
@ -73,6 +89,7 @@ _os_cpu_number(void)
#else
#error _os_cpu_number not implemented on this architecture
#endif
#endif // !DARLING
}
#if defined(__i386__) || defined(__x86_64__)