1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/* $OpenBSD: ldasm.S,v 1.7 2003/07/09 21:01:10 drahn Exp $ */
/*
* Copyright (c) 2002 Dale Rahn
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#define DL_DATA_SIZE (16*4)
#include <sys/syscall.h>
#include <machine/asm.h>
.text
.align 4
.globl _dl_start
.type _dl_start,@function
_dl_start:
movl %esp,%eax # save stack pointer for _rtld
pushl %ebx # save ps_strings
subl $DL_DATA_SIZE,%esp # allocate dl_data
pushl $0 # push 0 for dynamicp (unused on i386)
movl %esp,%ebx
movl %ebx,%edi # save dl_data arg for dl_boot
pushl %ebx # push dl_data for dl_boot_bind
mov %eax, %esi # save stack for dl_boot
pushl %eax # load saved SP for dl_boot_bind
call _dl_boot_bind@PLT # _dl_boot_bind(sp,dl_data)
pushl %edi # push saved dl_data
movl %edi,%ebp
movl (7*4)(%ebp),%eax
pushl %eax # push loff from dl_data
movl %esi,%ebp
movl $4,%eax
imull 0(%ebp),%eax
addl $8,%eax
addl %ebp,%eax
push %eax # push envp
leal 4(%ebp),%eax
push %eax # push argv
call _dl_boot@PLT # _dl_boot(argv,envp,loff,dl_data)
addl $5*4,%esp # pop args
addl $DL_DATA_SIZE,%esp # return dl_data
popl %ebx # %ebx = ps_strings - XXXDSR
popl %edx # %edx = cleanup - XXXDSR
popl %ecx # %ecx = obj_main - XXXDSR
jmp *%eax
.section ".text"
.align 4
.global _dl_close
.type _dl_close,@function
_dl_close:
mov $SYS_close, %eax
int $0x80
jb 1f
ret
.section ".text"
.align 4
.global _dl_exit
.type _dl_exit,@function
_dl_exit:
mov $SYS_exit, %eax
int $0x80
ret
.section ".text"
.align 4
.global _dl_issetugid
.type _dl_issetugid,@function
_dl_issetugid:
mov $SYS_issetugid, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl__syscall
.type _dl__syscall,@function
_dl__syscall:
mov $SYS___syscall, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_munmap
.type _dl_munmap,@function
_dl_munmap:
mov $SYS_munmap, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_mprotect
.type _dl_mprotect,@function
_dl_mprotect:
mov $SYS_mprotect, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_open
.type _dl_open,@function
_dl_open:
mov $SYS_open, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_read
.type _dl_read,@function
_dl_read:
mov $SYS_read, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_write
.type _dl_write,@function
_dl_write:
mov $SYS_write, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_stat
.type _dl_stat,@function
_dl_stat:
mov $SYS_stat, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_fstat
.type _dl_fstat,@function
_dl_fstat:
mov $SYS_fstat, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_fcntl
.type _dl_fcntl,@function
_dl_fcntl:
mov $SYS_fcntl, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_sysctl
.type _dl_sysctl,@function
_dl_sysctl:
mov $SYS___sysctl, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
.section ".text"
.align 4
.global _dl_getdirentries
.type _dl_getdirentries,@function
_dl_getdirentries:
mov $SYS_getdirentries, %eax
int $0x80
jb 1f /* error: result = -errno */
ret
1:
/* error: result = -errno; - handled here. */
neg %eax
ret
/* _dl_sigprocmask: does not handle NULL new set */
.section ".text"
.align 4
.global _dl_sigprocmask
.type _dl_sigprocmask,@function
_dl_sigprocmask:
movl 8(%esp), %ecx
movl (%ecx),%ecx
movl %ecx,8(%esp) # to new mask arg
mov $SYS_sigprocmask, %eax
int $0x80
jb 1f /* error: result = -errno */
movl 12(%esp),%ecx # fetch old mask requested
testl %ecx,%ecx # test if old mask requested
jz 2f
movl %eax,(%ecx) # store old mask
xorl %eax,%eax
2: ret
1: /* error: result = -errno; - handled here. */
neg %eax
ret
.align 4
.global _dl_bind_start
.type _dl_bind_start,@function
_dl_bind_start:
pushf # save registers
pushl %eax
pushl %ecx
pushl %edx
pushl %ebx
pushl %ebp
pushl %esi
pushl %edi
pushl %ds
pushl %es
pushl 44(%esp) # Copy of reloff
pushl 44(%esp) # Copy of obj
call _dl_bind@PLT # Call the binder
addl $8,%esp # pop binder args
movl %eax,44(%esp) # Store function to be called in obj
popl %es # restore registers
popl %ds
popl %edi
popl %esi
popl %ebp
popl %ebx
popl %edx
popl %ecx
popl %eax
popf
leal 4(%esp),%esp # Discard reloff, do not change eflags
ret
|