Skip to content

Commit d786856

Browse files
committed
Rework __linux_syscall
The way variadic functions are handled on macOS differs between x86/x86-64 and ARM64. See the following for more details: https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code#Dont-Redeclare-a-Function-to-Have-Variable-Parameters
1 parent f6e9f91 commit d786856

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

darling/src/libsystem_kernel/emulation/linux/base.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,47 @@ long __unknown_syscall_machdep(int nr, ...)
1818
}
1919

2020
VISIBLE
21-
int __linux_syscall(int nr, long a1, long a2, long a3, long a4, long a5, long a6)
21+
int __linux_syscall_6args(int nr, long a1, long a2, long a3, long a4, long a5, long a6)
2222
{
2323
return linux_syscall(a1, a2, a3, a4, a5, a6, nr);
2424
}
2525

26+
VISIBLE
27+
int __linux_syscall_noargs(int nr)
28+
{
29+
return __linux_syscall_6args(nr, 0, 0, 0, 0, 0, 0);
30+
}
31+
32+
VISIBLE
33+
int __linux_syscall_1arg(int nr, long a1)
34+
{
35+
return __linux_syscall_6args(nr, a1, 0, 0, 0, 0, 0);
36+
}
37+
38+
VISIBLE
39+
int __linux_syscall_2args(int nr, long a1, long a2)
40+
{
41+
return __linux_syscall_6args(nr, a1, a2, 0, 0, 0, 0);
42+
}
43+
44+
VISIBLE
45+
int __linux_syscall_3args(int nr, long a1, long a2, long a3)
46+
{
47+
return __linux_syscall_6args(nr, a1, a2, a3, 0, 0, 0);
48+
}
49+
50+
VISIBLE
51+
int __linux_syscall_4args(int nr, long a1, long a2, long a3, long a4)
52+
{
53+
return __linux_syscall_6args(nr, a1, a2, a3, a4, 0, 0);
54+
}
55+
56+
VISIBLE
57+
int __linux_syscall_5args(int nr, long a1, long a2, long a3, long a4, long a5)
58+
{
59+
return __linux_syscall_6args(nr, a1, a2, a3, a4, a5, 0);
60+
}
61+
2662
#ifdef __TESTING
2763
void _start()
2864
{

darling/src/libsystem_kernel/emulation/linux/base.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ long linux_syscall(long a1, long a2, long a3, long a4, long a5, long a6, int nr)
2121

2222
#ifndef BUILDING_BASE_C
2323

24-
VISIBLE
25-
int __linux_syscall(int nr, ...);
24+
VISIBLE int __linux_syscall_noargs(int);
25+
VISIBLE int __linux_syscall_1arg(int,long);
26+
VISIBLE int __linux_syscall_2args(int,long,long);
27+
VISIBLE int __linux_syscall_3args(int,long,long,long);
28+
VISIBLE int __linux_syscall_4args(int,long,long,long,long);
29+
VISIBLE int __linux_syscall_5args(int,long,long,long,long,long);
30+
VISIBLE int __linux_syscall_6args(int,long,long,long,long,long,long);
2631

2732
#endif /* BUILDING_BASE_C */
2833

libsyscall/os/tsd.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
#ifdef DARLING
5656
#include <darling/emulation/linux-syscalls.h>
57+
#include <darling/emulation/base.h>
5758
#endif
5859

5960
extern void _thread_set_tsd_base(void *tsd_base);
@@ -63,10 +64,8 @@ static __inline__ unsigned int
6364
_os_cpu_number(void)
6465
{
6566
#ifdef DARLING
66-
extern int __linux_syscall(int nr, ...);
67-
6867
unsigned int cpu_num = 0;
69-
int status = __linux_syscall(__NR_getcpu, &cpu_num, 0, 0, 0, 0, 0);
68+
int status = __linux_syscall_3args(__NR_getcpu, (long)&cpu_num, 0, 0);
7069
// should we even check? i don't think it's possible for it to fail with these arguments
7170
if (status < 0) {
7271
return 0; // i guess?

0 commit comments

Comments
 (0)