Skip to content

Commit 542043e

Browse files
committed
Fixup Code That Calls __darling_handle_svc
* If not already done, add code to save and restore `fp` & `lr`. * Update code that wasn't changed to call `__darling_handle_svc` * Rework changes made to the macros.
1 parent d370896 commit 542043e

File tree

7 files changed

+67
-12
lines changed

7 files changed

+67
-12
lines changed

gen/bsdsyscalls/SYS.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,31 @@ pseudo: ;\
475475
* TBD
476476
*/
477477

478+
#ifdef DARLING
478479
#define DO_SYSCALL(num, cerror) \
479480
mov x16, #(num) %%\
480-
#ifdef DARLING %%\
481+
PUSH_FRAME %%\
481482
bl __darling_handle_svc %%\
482-
#else %%\
483+
POP_FRAME %%\
484+
b.cc 2f %%\
485+
ARM64_STACK_PROLOG %%\
486+
PUSH_FRAME %%\
487+
bl _##cerror %%\
488+
POP_FRAME %%\
489+
ARM64_STACK_EPILOG %%\
490+
2:
491+
#else
492+
#define DO_SYSCALL(num, cerror) \
493+
mov x16, #(num) %%\
483494
svc #SWI_SYSCALL %%\
484-
#endif %%\
485495
b.cc 2f %%\
486496
ARM64_STACK_PROLOG %%\
487497
PUSH_FRAME %%\
488498
bl _##cerror %%\
489499
POP_FRAME %%\
490500
ARM64_STACK_EPILOG %%\
491501
2:
502+
#endif
492503

493504
#define MI_GET_ADDRESS(reg,var) \
494505
adrp reg, var@page %%\

gen/bsdsyscalls/___vfork.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ Ltry_set_vfork:
232232
// ARM sets r1 to 1 here. I don't see why.
233233
mov w16, #SYS_vfork // Set syscall code
234234
#ifdef DARLING
235+
PUSH_FRAME
235236
bl __darling_handle_svc
237+
POP_FRAME
236238
#else
237239
svc #SWI_SYSCALL
238240
#endif

libsyscall/custom/SYS.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,31 @@ pseudo: ;\
475475
* TBD
476476
*/
477477

478+
#ifdef DARLING
478479
#define DO_SYSCALL(num, cerror) \
479480
mov x16, #(num) %%\
480-
#ifdef DARLING %%\
481+
PUSH_FRAME %%\
481482
bl __darling_handle_svc %%\
482-
#else %%\
483+
POP_FRAME %%\
484+
b.cc 2f %%\
485+
ARM64_STACK_PROLOG %%\
486+
PUSH_FRAME %%\
487+
bl _##cerror %%\
488+
POP_FRAME %%\
489+
ARM64_STACK_EPILOG %%\
490+
2:
491+
#else
492+
#define DO_SYSCALL(num, cerror) \
493+
mov x16, #(num) %%\
483494
svc #SWI_SYSCALL %%\
484-
#endif %%\
485495
b.cc 2f %%\
486496
ARM64_STACK_PROLOG %%\
487497
PUSH_FRAME %%\
488498
bl _##cerror %%\
489499
POP_FRAME %%\
490500
ARM64_STACK_EPILOG %%\
491501
2:
502+
#endif
492503

493504
#define MI_GET_ADDRESS(reg,var) \
494505
adrp reg, var@page %%\

libsyscall/custom/__fork.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ MI_ENTRY_POINT(___fork)
154154
PUSH_FRAME
155155
// ARM moves a 1 in to r1 here, but I can't see why.
156156
mov x16, #SYS_fork // Syscall code
157+
#ifdef DARLING
158+
bl __darling_handle_svc
159+
#else
157160
svc #SWI_SYSCALL // Trap to kernel
161+
#endif
158162
b.cs Lbotch // Carry bit indicates failure
159163
cbz x1, Lparent // x1 == 0 indicates that we are the parent
160164

libsyscall/custom/__vfork.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ Ltry_set_vfork:
231231

232232
// ARM sets r1 to 1 here. I don't see why.
233233
mov w16, #SYS_vfork // Set syscall code
234+
#ifdef DARLING
235+
PUSH_FRAME
236+
bl __darling_handle_svc
237+
POP_FRAME
238+
#else
234239
svc #SWI_SYSCALL
240+
#endif
235241
b.cs Lbotch
236242
cbz w1, Lparent
237243

libsyscall/custom/custom.S

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,22 @@ __thread_set_tsd_base:
137137
.align 2
138138
.globl __thread_set_tsd_base
139139
__thread_set_tsd_base:
140+
#ifdef DARLING
141+
stp fp, lr, [sp, #-16]!
142+
mov fp, sp
143+
140144
mov x3, #2
141145
mov x16, #0x80000000
142-
#ifdef DARLING
143146
bl __darling_handle_svc
147+
148+
ldp fp, lr, [sp], #16
149+
ret
144150
#else
151+
mov x3, #2
152+
mov x16, #0x80000000
145153
svc #SWI_SYSCALL
146-
#endif
147154
ret
155+
#endif
148156

149157
#else
150158
#error unknown architecture

osfmk/mach/arm/syscall_sw.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,32 @@
106106
#elif defined(__arm64__)
107107

108108
#include <mach/machine/vm_param.h>
109+
#ifdef DARLING
110+
// For PUSH_FRAME & POP_FRAME
111+
#include <mach/arm64/asm.h>
112+
#endif
109113

114+
#ifdef DARLING
115+
#define kernel_trap(trap_name, trap_number, num_args) \
116+
.globl _##trap_name %% \
117+
.text %% \
118+
.align 2 %% \
119+
_##trap_name: %% \
120+
PUSH_FRAME %% \
121+
mov x16, #(trap_number) %% \
122+
bl __darling_handle_svc %% \
123+
POP_FRAME %% \
124+
ret
125+
#else
110126
#define kernel_trap(trap_name, trap_number, num_args) \
111127
.globl _##trap_name %% \
112128
.text %% \
113129
.align 2 %% \
114130
_##trap_name: %% \
115131
mov x16, #(trap_number) %% \
116-
#ifdef DARLING %% \
117-
bl __darling_handle_svc %% \
118-
#else %% \
119132
svc #SWI_SYSCALL %% \
133+
ret
120134
#endif
121-
ret
122135

123136
#else
124137
#error Unsupported architecture

0 commit comments

Comments
 (0)