OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [i386/] [clone.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Copyright (C) 1996,1997,98,99,2000,02,03 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
3
   Contributed by Richard Henderson (rth@tamu.edu)
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
/* clone() is even more special than fork() as it mucks with stacks
21
   and invokes a function in the right context after its all over.
22
 
23
   Hacked up for uClibc by Erik Andersen 
24
*/
25
 
26
#define _ERRNO_H        1
27
#include 
28
#include 
29
 
30
/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
31
             pid_t *ptid, struct user_desc *tls, pid_t *ctid); */
32
 
33
#define LINKAGE     4
34
#define PTR_SIZE    4
35
#define PARMS       LINKAGE        /* no space for saved regs */
36
#define FUNC        PARMS
37
#define STACK       FUNC+4
38
#define FLAGS       STACK+PTR_SIZE
39
#define ARG         FLAGS+4
40
#define PTID        ARG+PTR_SIZE
41
#define TLS         PTID+PTR_SIZE
42
#define CTID        TLS+PTR_SIZE
43
 
44
#define __NR_clone        120
45
#define __NR_exit         1
46
 
47
.text
48
.type clone,@function;
49
.weak clone ; clone = __clone
50
 
51
.type __clone,@function;
52
.globl __clone;
53
 
54
__clone:
55
        /* Sanity check arguments.  */
56
        movl    $-EINVAL,%eax
57
 
58
        /* no NULL function pointers */
59
        movl    FUNC(%esp),%ecx
60
        jecxz   .Lclone_error
61
 
62
        /* no NULL stack pointers */
63
        movl    STACK(%esp),%ecx
64
        jecxz   .Lclone_error
65
 
66
        /* Insert the argument onto the new stack.  Make sure the new
67
           thread is started with an alignment of (mod 16).  */
68
        andl    $0xfffffff0, %ecx
69
        subl    $24,%ecx
70
        movl    ARG(%esp),%eax          /* no negative argument counts */
71
        movl    %eax,12(%ecx)
72
 
73
        /* Save the function pointer as the zeroth argument.
74
           It will be popped off in the child in the ebx frobbing below.  */
75
        movl    FUNC(%esp),%eax
76
        movl    %eax,8(%ecx)
77
        /* Don't leak any information.  */
78
        movl    $0,4(%ecx)
79
        movl    $0,(%ecx)
80
 
81
        /* Do the system call */
82
        pushl   %ebx
83
        pushl   %esi
84
        pushl   %edi
85
        movl    TLS+12(%esp),%esi
86
        movl    PTID+12(%esp),%edx
87
        movl    FLAGS+12(%esp),%ebx
88
        movl    CTID+12(%esp),%edi
89
        movl    $__NR_clone,%eax
90
        int     $0x80
91
        popl    %edi
92
        popl    %esi
93
        popl    %ebx
94
 
95
        test    %eax,%eax
96
        jl      .Lclone_error
97
        jz      .Lthread_start
98
 
99
.Lpseudo_end:
100
        ret
101
 
102
.Lthread_start:
103
        subl    %ebp,%ebp       /* terminate the stack frame */
104
        call    *%ebx
105
#ifdef __PIC__
106
        call    .Lhere
107
.Lhere:
108
        popl    %ebx
109
        addl    $_GLOBAL_OFFSET_TABLE_+[.-.Lhere], %ebx
110
#endif
111
        movl    %eax, %ebx
112
        movl    $__NR_exit, %eax
113
        int     $0x80
114
 
115
#ifdef __PIC__
116
 
117
.Lthere:
118
        movl    (%esp), %ebx
119
        ret
120
 
121
.Lclone_error:
122
        pushl %ebx
123
        call .Lthere
124
        addl $_GLOBAL_OFFSET_TABLE_, %ebx
125
        xorl %edx, %edx
126
        subl %eax, %edx
127
        pushl %edx
128
        call __errno_location@PLT
129
        popl %ecx
130
        popl %ebx
131
        movl %ecx, (%eax)
132
        orl $-1, %eax
133
        jmp .Lpseudo_end
134
 
135
#else   /* __PIC__ */
136
 
137
.Lclone_error:
138
        negl    %eax
139
        pushl   %eax
140
        call    __errno_location
141
        popl    %ecx
142
        movl    %ecx, (%eax)
143
        xorl    %eax, %eax
144
        decl    %eax
145
 
146
#endif
147
 
148
.size __clone,.-__clone
149
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.