Skip to content

Commit

Permalink
Make Sure Error Code Is Positive & Update Notes
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriousTommy committed Jun 15, 2024
1 parent 0ff8532 commit a48bb97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions gen/bsdsyscalls/SYS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 %%\
Expand All @@ -487,6 +492,7 @@ pseudo: ;\
b.cc 2f %%\
ARM64_STACK_PROLOG %%\
PUSH_FRAME %%\
neg x0, x0 %%\
bl _##cerror %%\
POP_FRAME %%\
ARM64_STACK_EPILOG %%\
Expand Down
10 changes: 8 additions & 2 deletions libsyscall/custom/SYS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 %%\
Expand All @@ -487,6 +492,7 @@ pseudo: ;\
b.cc 2f %%\
ARM64_STACK_PROLOG %%\
PUSH_FRAME %%\
neg x0, x0 %%\
bl _##cerror %%\
POP_FRAME %%\
ARM64_STACK_EPILOG %%\
Expand Down

0 comments on commit a48bb97

Please sign in to comment.