Chris Dearman | 645d031 | 2014-02-05 18:51:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame^] | 29 | #include <private/bionic_asm.h> |
Chris Dearman | 645d031 | 2014-02-05 18:51:43 -0800 | [diff] [blame] | 30 | #include <linux/errno.h> |
| 31 | #include <linux/sched.h> |
| 32 | |
| 33 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 34 | FRAMESZ = MKFSIZ(NARGSAVE,0) |
| 35 | FRAME_ARG = 0*REGSZ |
| 36 | FRAME_FN = 1*REGSZ |
| 37 | #else |
| 38 | FRAMESZ = MKFSIZ(0,3) |
| 39 | FRAME_GP = FRAMESZ-1*REGSZ |
| 40 | FRAME_ARG = FRAMESZ-2*REGSZ |
| 41 | FRAME_FN = FRAMESZ-3*REGSZ |
| 42 | #endif |
| 43 | |
| 44 | // pid_t __bionic_clone(int flags, void* child_stack, pid_t* parent_tid, void* tls, pid_t* child_tid, int (*fn)(void*), void* arg); |
Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame^] | 45 | LEAF(__bionic_clone, FRAMESZ) |
Chris Dearman | 645d031 | 2014-02-05 18:51:43 -0800 | [diff] [blame] | 46 | PTR_SUBU sp, FRAMESZ # allocate stack frame |
| 47 | SETUP_GP64(FRAME_GP,__bionic_clone) |
| 48 | SAVE_GP(FRAME_GP) |
| 49 | |
| 50 | # set up child stack |
| 51 | PTR_SUBU a1,FRAMESZ |
| 52 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 53 | PTR_L t0,FRAMESZ+5*REGSZ(sp) # fn |
| 54 | PRL_L t1,FRAMESZ+6*REGSZ(sp) # arg |
| 55 | PTR_S t0,FRAME_FN(a1) # fn |
| 56 | PTR_S t1,FRAME_ARG(a1) # arg |
| 57 | #else |
| 58 | PTR_L t0,FRAME_GP(sp) # copy gp to child stack |
| 59 | PTR_S t0,FRAME_GP(a1) |
| 60 | PTR_S a5,FRAME_FN(a1) # fn |
| 61 | PTR_S a6,FRAME_ARG(a1) # arg |
| 62 | # endif |
| 63 | |
| 64 | # remainder of arguments are correct for clone system call |
| 65 | LI v0,__NR_clone |
| 66 | syscall |
| 67 | |
| 68 | move a0,v0 |
| 69 | bnez a3,.L__error_bc |
| 70 | |
| 71 | beqz v0,.L__thread_start_bc |
| 72 | |
| 73 | RESTORE_GP64 |
| 74 | PTR_ADDU sp,FRAMESZ |
| 75 | j ra |
| 76 | |
| 77 | .L__thread_start_bc: |
| 78 | # void __bionic_clone_entry(int (*func)(void*), void *arg) |
| 79 | PTR_L a0,FRAME_FN(sp) # fn |
| 80 | PTR_L a1,FRAME_ARG(sp) # arg |
| 81 | LA t9,__bionic_clone_entry |
| 82 | RESTORE_GP64 |
| 83 | /* |
| 84 | * For O32 etc the child stack must have space for a0..a3 to be stored |
| 85 | * For N64 etc, the child stack can be restored to the original value |
| 86 | */ |
| 87 | #if !((_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)) |
| 88 | PTR_ADDU sp,FRAMESZ |
| 89 | #endif |
| 90 | j t9 |
| 91 | |
| 92 | .L__error_bc: |
| 93 | LA t9,__set_errno |
| 94 | RESTORE_GP64 |
| 95 | PTR_ADDU sp,FRAMESZ |
| 96 | j t9 |
| 97 | END(__bionic_clone) |