src/os/unix/rfork_thread.S - nginx-1.7.10

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #include <sys/syscall.h>
  6. #include <machine/asm.h>

  7. /*
  8. * rfork_thread(3) - rfork_thread(flags, stack, func, arg);
  9. */

  10. #define        KERNCALL        int $0x80

  11. ENTRY(rfork_thread)
  12.         push        %ebp
  13.         mov        %esp, %ebp
  14.         push        %esi

  15.         mov        12(%ebp), %esi        # the thread stack address

  16.         sub        $4, %esi
  17.         mov        20(%ebp), %eax        # the thread argument
  18.         mov        %eax, (%esi)

  19.         sub        $4, %esi
  20.         mov        16(%ebp), %eax        # the thread start address
  21.         mov        %eax, (%esi)

  22.         push        8(%ebp)                # rfork(2) flags
  23.         push        $0
  24.         mov        $SYS_rfork, %eax
  25.         KERNCALL
  26.         jc        error

  27.         cmp        $0, %edx
  28.         jne        child

  29. parent:
  30.         add        $8, %esp
  31.         pop        %esi
  32.         leave
  33.         ret

  34. child:
  35.         mov        %esi, %esp
  36.         pop        %eax
  37.         call        *%eax                # call a thread start address ...
  38.         add        $4, %esp

  39.         push        %eax
  40.         push        $0
  41.         mov        $SYS_exit, %eax        # ... and exit(2) after a thread would return
  42.         KERNCALL

  43. error:
  44.         add        $8, %esp
  45.         pop        %esi
  46.         leave
  47.         PIC_PROLOGUE

  48.         /* libc's cerror: jmp  PIC_PLT(HIDENAME(cerror)) */

  49.         push        %eax
  50.         call        PIC_PLT(CNAME(__error))
  51.         pop        %ecx
  52.         PIC_EPILOGUE
  53.         mov        %ecx, (%eax)
  54.         mov        $-1, %eax
  55.         mov        $-1, %edx
  56.         ret