diff --git a/gen/bsdsyscalls/SYS.h b/gen/bsdsyscalls/SYS.h index 47dfcf3..1f9974b 100644 --- a/gen/bsdsyscalls/SYS.h +++ b/gen/bsdsyscalls/SYS.h @@ -476,8 +476,13 @@ pseudo: ;\ */ #ifdef DARLING -// In addition to changing the macro to use __darling_handle_svc instead of the -// syscall (svc) instruction, We are also setting the carry flag as well. +// Changes compared to Apple's implementation: +// * Replace `svc` instruction by calling `__darling_handle_svc` (as a +// consequence, an additional `PUSH_FRAME` and `POP_FRAME` has been +// added) +// * Set the carry flag, by using the `cmn` instruction. +// * Convert the negative error code into a positive error code before +// calling `cerror` (errno must be a positive integer). #define DO_SYSCALL(num, cerror) \ mov x16, #(num) %%\ PUSH_FRAME %%\ @@ -487,6 +492,7 @@ pseudo: ;\ b.cc 2f %%\ ARM64_STACK_PROLOG %%\ PUSH_FRAME %%\ + neg x0, x0 %%\ bl _##cerror %%\ POP_FRAME %%\ ARM64_STACK_EPILOG %%\ diff --git a/libsyscall/custom/SYS.h b/libsyscall/custom/SYS.h index 47dfcf3..1f9974b 100644 --- a/libsyscall/custom/SYS.h +++ b/libsyscall/custom/SYS.h @@ -476,8 +476,13 @@ pseudo: ;\ */ #ifdef DARLING -// In addition to changing the macro to use __darling_handle_svc instead of the -// syscall (svc) instruction, We are also setting the carry flag as well. +// Changes compared to Apple's implementation: +// * Replace `svc` instruction by calling `__darling_handle_svc` (as a +// consequence, an additional `PUSH_FRAME` and `POP_FRAME` has been +// added) +// * Set the carry flag, by using the `cmn` instruction. +// * Convert the negative error code into a positive error code before +// calling `cerror` (errno must be a positive integer). #define DO_SYSCALL(num, cerror) \ mov x16, #(num) %%\ PUSH_FRAME %%\ @@ -487,6 +492,7 @@ pseudo: ;\ b.cc 2f %%\ ARM64_STACK_PROLOG %%\ PUSH_FRAME %%\ + neg x0, x0 %%\ bl _##cerror %%\ POP_FRAME %%\ ARM64_STACK_EPILOG %%\