Skip to content

Commit 91d7d50

Browse files
committed
Make Sure Error Code Is Positive & Update Notes
1 parent 0ff8532 commit 91d7d50

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

gen/bsdsyscalls/SYS.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,13 @@ pseudo: ;\
476476
*/
477477

478478
#ifdef DARLING
479-
// In addition to changing the macro to use __darling_handle_svc instead of the
480-
// syscall (svc) instruction, We are also setting the carry flag as well.
479+
// Changes compared to Apple's implementation:
480+
// * Replace `svc` instruction by calling `__darling_handle_svc` (as a
481+
// consequence, an additional `PUSH_FRAME` and `POP_FRAME` has been
482+
// added)
483+
// * Set the carry flag, by using the `cmn` instruction.
484+
// * Convert the negative error code into a positive error code before
485+
// calling `cerror` (errno must be a positive integer).
481486
#define DO_SYSCALL(num, cerror) \
482487
mov x16, #(num) %%\
483488
PUSH_FRAME %%\
@@ -487,6 +492,7 @@ pseudo: ;\
487492
b.cc 2f %%\
488493
ARM64_STACK_PROLOG %%\
489494
PUSH_FRAME %%\
495+
neg x0, x0 %%\
490496
bl _##cerror %%\
491497
POP_FRAME %%\
492498
ARM64_STACK_EPILOG %%\

libsyscall/custom/SYS.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,13 @@ pseudo: ;\
476476
*/
477477

478478
#ifdef DARLING
479-
// In addition to changing the macro to use __darling_handle_svc instead of the
480-
// syscall (svc) instruction, We are also setting the carry flag as well.
479+
// Changes compared to Apple's implementation:
480+
// * Replace `svc` instruction by calling `__darling_handle_svc` (as a
481+
// consequence, an additional `PUSH_FRAME` and `POP_FRAME` has been
482+
// added)
483+
// * Set the carry flag, by using the `cmn` instruction.
484+
// * Convert the negative error code into a positive error code before
485+
// calling `cerror` (errno must be a positive integer).
481486
#define DO_SYSCALL(num, cerror) \
482487
mov x16, #(num) %%\
483488
PUSH_FRAME %%\
@@ -487,6 +492,7 @@ pseudo: ;\
487492
b.cc 2f %%\
488493
ARM64_STACK_PROLOG %%\
489494
PUSH_FRAME %%\
495+
neg x0, x0 %%\
490496
bl _##cerror %%\
491497
POP_FRAME %%\
492498
ARM64_STACK_EPILOG %%\

0 commit comments

Comments
 (0)