X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/6d2010ae8f7a6078e10b361c6962983bab233e0f..d26ffc64f583ab2d29df48f13518685602bc8832:/libsyscall/custom/__fork.s diff --git a/libsyscall/custom/__fork.s b/libsyscall/custom/__fork.s index 2de3a9a28..dc517a1a2 100644 --- a/libsyscall/custom/__fork.s +++ b/libsyscall/custom/__fork.s @@ -55,7 +55,7 @@ LEAF(___fork, 0) UNIX_SYSCALL_TRAP // do the system call jnc L1 // jump if CF==0 - CALL_EXTERN(cerror) + CALL_EXTERN(tramp_cerror) movl $-1,%eax addl $28, %esp // restore the stack ret @@ -81,7 +81,8 @@ LEAF(___fork, 0) UNIX_SYSCALL_TRAP // do the system call jnc L1 // jump if CF==0 - CALL_EXTERN(cerror) + movq %rax, %rdi + CALL_EXTERN(_cerror) movq $-1, %rax addq $24, %rsp // restore the stack ret @@ -99,6 +100,59 @@ L2: addq $24, %rsp // restore the stack ret +#elif defined(__arm__) + +MI_ENTRY_POINT(___fork) + stmfd sp!, {r4, r7, lr} + add r7, sp, #4 + + mov r1, #1 // prime results + mov r12, #SYS_fork + swi #SWI_SYSCALL // make the syscall + bcs Lbotch // error? + + cmp r1, #0 // parent (r1=0) or child(r1=1) + beq Lparent + + //child here... + MI_GET_ADDRESS(r3, __current_pid) + mov r0, #0 + str r0, [r3] // clear cached pid in child + ldmfd sp!, {r4, r7, pc} + +Lbotch: + MI_CALL_EXTERNAL(_cerror) // jump here on error + mov r0,#-1 // set the error + // fall thru +Lparent: + ldmfd sp!, {r4, r7, pc} // pop and return + +#elif defined(__arm64__) + +#include + +MI_ENTRY_POINT(___fork) + PUSH_FRAME + // ARM moves a 1 in to r1 here, but I can't see why. + mov x16, #SYS_fork // Syscall code + svc #SWI_SYSCALL // Trap to kernel + b.cs Lbotch // Carry bit indicates failure + cbz x1, Lparent // x1 == 0 indicates that we are the parent + + // Child + MI_GET_ADDRESS(x9, __current_pid) // Get address of cached "current pid" + mov w0, #0 + str w0, [x9] // Clear cached current pid + POP_FRAME // And done + ret + +Lbotch: + MI_CALL_EXTERNAL(_cerror) // Handle error + mov w0, #-1 // Return value is -1 +Lparent: + POP_FRAME // Return + ret + #else #error Unsupported architecture #endif