-
-#include "SYS.h"
-
-#if defined(__ppc__) || defined(__ppc64__)
-
-/* We use mode-independent "g" opcodes such as "srgi". These expand
- * into word operations when targeting __ppc__, and into doubleword
- * operations when targeting __ppc64__.
- */
-#include <architecture/ppc/mode_independent_asm.h>
-
-MI_ENTRY_POINT(___fork)
- MI_PUSH_STACK_FRAME
-
- MI_CALL_EXTERNAL(__cthread_fork_prepare)
-
- li r0,SYS_fork
- sc // do the fork
- b Lbotch // error return
-
- cmpwi r4,0 // parent (r4==0) or child (r4==1) ?
- beq Lparent // parent, since r4==0
-
-
-/* Here if we are the child. */
-
-#if defined(__DYNAMIC__)
- .cstring
-LC3:
- .ascii "__dyld_fork_child\0"
- .text
- .align 2
- mflr r0
- bcl 20,31,1f
-1: mflr r3
- mtlr r0
- addis r3,r3,ha16(LC3-1b)
- addi r3,r3,lo16(LC3-1b)
- addi r4,r1,SF_LOCAL1
- bl __dyld_func_lookup
- lg r3,SF_LOCAL1(r1)
- mtspr ctr,r3
- bctrl
-#endif
-
- li r9,0
- MI_GET_ADDRESS(r8,__current_pid)
- stw r9,0(r8) // clear cached pid in child
-
- MI_CALL_EXTERNAL(__cthread_fork_child)
-
- li r3,0 // flag for "we are the child"
- b Lreturn
-
-
-/* Here if we are the parent, with:
- * r3 = child's pid
+
+/*
+ * All of the asm stubs in this file have been adjusted so the pre/post
+ * fork handlers and dyld fixup are done in C inside Libc. As such, Libc
+ * expects the __fork asm to fix up the return code to be -1, 0 or pid
+ * and errno if needed.