From a48bb9744960a1af98ec9a10b1ddd0106c1389de Mon Sep 17 00:00:00 2001 From: "Thomas A." Date: Sat, 15 Jun 2024 11:22:31 -0700 Subject: [PATCH] Make Sure Error Code Is Positive & Update Notes --- gen/bsdsyscalls/SYS.h | 10 ++++++++-- libsyscall/custom/SYS.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gen/bsdsyscalls/SYS.h b/gen/bsdsyscalls/SYS.h index 47dfcf3..3ccc122 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..3ccc122 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 %%\