linux_exec_elf32.c revision 1.75 1 1.75 christos /* $NetBSD: linux_exec_elf32.c,v 1.75 2006/10/12 01:30:48 christos Exp $ */
2 1.29 christos
3 1.29 christos /*-
4 1.51 manu * Copyright (c) 1995, 1998, 2000, 2001 The NetBSD Foundation, Inc.
5 1.29 christos * All rights reserved.
6 1.29 christos *
7 1.29 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.51 manu * by Christos Zoulas, Frank van der Linden, Eric Haszlakiewicz and
9 1.51 manu * Emmanuel Dreyfus.
10 1.29 christos *
11 1.29 christos * Redistribution and use in source and binary forms, with or without
12 1.29 christos * modification, are permitted provided that the following conditions
13 1.29 christos * are met:
14 1.29 christos * 1. Redistributions of source code must retain the above copyright
15 1.29 christos * notice, this list of conditions and the following disclaimer.
16 1.29 christos * 2. Redistributions in binary form must reproduce the above copyright
17 1.29 christos * notice, this list of conditions and the following disclaimer in the
18 1.29 christos * documentation and/or other materials provided with the distribution.
19 1.29 christos * 3. All advertising materials mentioning features or use of this software
20 1.29 christos * must display the following acknowledgement:
21 1.31 erh * This product includes software developed by the NetBSD
22 1.31 erh * Foundation, Inc. and its contributors.
23 1.29 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.29 christos * contributors may be used to endorse or promote products derived
25 1.29 christos * from this software without specific prior written permission.
26 1.29 christos *
27 1.29 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.29 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.29 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.29 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.29 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.29 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.29 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.29 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.29 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.29 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.29 christos * POSSIBILITY OF SUCH DAMAGE.
38 1.29 christos */
39 1.1 fvdl
40 1.1 fvdl /*
41 1.7 fvdl * based on exec_aout.c, sunos_exec.c and svr4_exec.c
42 1.1 fvdl */
43 1.54 lukem
44 1.54 lukem #include <sys/cdefs.h>
45 1.75 christos __KERNEL_RCSID(0, "$NetBSD: linux_exec_elf32.c,v 1.75 2006/10/12 01:30:48 christos Exp $");
46 1.1 fvdl
47 1.31 erh #ifndef ELFSIZE
48 1.58 christos /* XXX should die */
49 1.58 christos #define ELFSIZE 32
50 1.31 erh #endif
51 1.17 cgd
52 1.1 fvdl #include <sys/param.h>
53 1.1 fvdl #include <sys/systm.h>
54 1.1 fvdl #include <sys/kernel.h>
55 1.1 fvdl #include <sys/proc.h>
56 1.1 fvdl #include <sys/malloc.h>
57 1.1 fvdl #include <sys/namei.h>
58 1.1 fvdl #include <sys/vnode.h>
59 1.13 christos #include <sys/mount.h>
60 1.25 christos #include <sys/exec.h>
61 1.8 fvdl #include <sys/exec_elf.h>
62 1.59 jdolecek #include <sys/stat.h>
63 1.72 elad #include <sys/kauth.h>
64 1.1 fvdl
65 1.1 fvdl #include <sys/mman.h>
66 1.61 thorpej #include <sys/sa.h>
67 1.13 christos #include <sys/syscallargs.h>
68 1.1 fvdl
69 1.1 fvdl #include <machine/cpu.h>
70 1.1 fvdl #include <machine/reg.h>
71 1.1 fvdl
72 1.32 christos #include <compat/linux/common/linux_types.h>
73 1.32 christos #include <compat/linux/common/linux_signal.h>
74 1.32 christos #include <compat/linux/common/linux_util.h>
75 1.32 christos #include <compat/linux/common/linux_exec.h>
76 1.32 christos #include <compat/linux/common/linux_machdep.h>
77 1.32 christos
78 1.32 christos #include <compat/linux/linux_syscallargs.h>
79 1.4 christos #include <compat/linux/linux_syscall.h>
80 1.31 erh
81 1.56 christos #ifdef DEBUG_LINUX
82 1.56 christos #define DPRINTF(a) uprintf a
83 1.56 christos #else
84 1.56 christos #define DPRINTF(a)
85 1.56 christos #endif
86 1.56 christos
87 1.51 manu #ifdef LINUX_ATEXIT_SIGNATURE
88 1.51 manu /*
89 1.51 manu * On the PowerPC, statically linked Linux binaries are not recognized
90 1.51 manu * by linux_signature nor by linux_gcc_signature. Fortunately, thoses
91 1.51 manu * binaries features a __libc_atexit ELF section. We therefore assume we
92 1.51 manu * have a Linux binary if we find this section.
93 1.51 manu */
94 1.71 manu int
95 1.70 christos ELFNAME2(linux,atexit_signature)(l, epp, eh)
96 1.70 christos struct lwp *l;
97 1.51 manu struct exec_package *epp;
98 1.51 manu Elf_Ehdr *eh;
99 1.51 manu {
100 1.51 manu size_t shsize;
101 1.65 chs int strndx;
102 1.51 manu size_t i;
103 1.51 manu static const char signature[] = "__libc_atexit";
104 1.65 chs char *strtable = NULL;
105 1.51 manu Elf_Shdr *sh;
106 1.67 perry
107 1.51 manu int error;
108 1.51 manu
109 1.52 christos /*
110 1.67 perry * load the section header table
111 1.52 christos */
112 1.51 manu shsize = eh->e_shnum * sizeof(Elf_Shdr);
113 1.51 manu sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK);
114 1.70 christos error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize);
115 1.51 manu if (error)
116 1.51 manu goto out;
117 1.51 manu
118 1.67 perry /*
119 1.52 christos * Now let's find the string table. If it does not exists, give up.
120 1.52 christos */
121 1.51 manu strndx = (int)(eh->e_shstrndx);
122 1.52 christos if (strndx == SHN_UNDEF) {
123 1.51 manu error = ENOEXEC;
124 1.51 manu goto out;
125 1.51 manu }
126 1.51 manu
127 1.52 christos /*
128 1.52 christos * strndx is the index in section header table of the string table
129 1.52 christos * section get the whole string table in strtable, and then we get access to the names
130 1.52 christos * s->sh_name is the offset of the section name in strtable.
131 1.52 christos */
132 1.51 manu strtable = malloc(sh[strndx].sh_size, M_TEMP, M_WAITOK);
133 1.70 christos error = exec_read_from(l, epp->ep_vp, sh[strndx].sh_offset, strtable,
134 1.52 christos sh[strndx].sh_size);
135 1.51 manu if (error)
136 1.51 manu goto out;
137 1.51 manu
138 1.51 manu for (i = 0; i < eh->e_shnum; i++) {
139 1.51 manu Elf_Shdr *s = &sh[i];
140 1.67 perry if (!memcmp((void*)(&(strtable[s->sh_name])), signature,
141 1.51 manu sizeof(signature))) {
142 1.56 christos DPRINTF(("linux_atexit_sig=%s\n",
143 1.56 christos &(strtable[s->sh_name])));
144 1.51 manu error = 0;
145 1.51 manu goto out;
146 1.51 manu }
147 1.51 manu }
148 1.51 manu error = ENOEXEC;
149 1.51 manu
150 1.51 manu out:
151 1.51 manu free(sh, M_TEMP);
152 1.65 chs if (strtable)
153 1.65 chs free(strtable, M_TEMP);
154 1.51 manu return (error);
155 1.51 manu }
156 1.51 manu #endif
157 1.4 christos
158 1.31 erh #ifdef LINUX_GCC_SIGNATURE
159 1.14 christos /*
160 1.14 christos * Take advantage of the fact that all the linux binaries are compiled
161 1.14 christos * with gcc, and gcc sticks in the comment field a signature. Note that
162 1.14 christos * on SVR4 binaries, the gcc signature will follow the OS name signature,
163 1.14 christos * that will not be a problem. We don't bother to read in the string table,
164 1.14 christos * but we check all the progbits headers.
165 1.31 erh *
166 1.31 erh * XXX This only works in the i386. On the alpha (at least)
167 1.31 erh * XXX we have the same gcc signature which incorrectly identifies
168 1.31 erh * XXX NetBSD binaries as Linux.
169 1.14 christos */
170 1.71 manu int
171 1.70 christos ELFNAME2(linux,gcc_signature)(l, epp, eh)
172 1.70 christos struct lwp *l;
173 1.14 christos struct exec_package *epp;
174 1.31 erh Elf_Ehdr *eh;
175 1.14 christos {
176 1.50 mycroft size_t shsize;
177 1.14 christos size_t i;
178 1.14 christos static const char signature[] = "\0GCC: (GNU) ";
179 1.69 christos char tbuf[sizeof(signature) - 1];
180 1.31 erh Elf_Shdr *sh;
181 1.14 christos int error;
182 1.14 christos
183 1.50 mycroft shsize = eh->e_shnum * sizeof(Elf_Shdr);
184 1.31 erh sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK);
185 1.70 christos error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize);
186 1.50 mycroft if (error)
187 1.14 christos goto out;
188 1.14 christos
189 1.14 christos for (i = 0; i < eh->e_shnum; i++) {
190 1.31 erh Elf_Shdr *s = &sh[i];
191 1.14 christos
192 1.14 christos /*
193 1.14 christos * Identify candidates for the comment header;
194 1.15 christos * Header cannot have a load address, or flags and
195 1.14 christos * it must be large enough.
196 1.14 christos */
197 1.43 kleink if (s->sh_type != SHT_PROGBITS ||
198 1.14 christos s->sh_addr != 0 ||
199 1.14 christos s->sh_flags != 0 ||
200 1.14 christos s->sh_size < sizeof(signature) - 1)
201 1.14 christos continue;
202 1.14 christos
203 1.70 christos error = exec_read_from(l, epp->ep_vp, s->sh_offset, tbuf,
204 1.52 christos sizeof(signature) - 1);
205 1.50 mycroft if (error)
206 1.50 mycroft continue;
207 1.14 christos
208 1.15 christos /*
209 1.15 christos * error is 0, if the signatures match we are done.
210 1.15 christos */
211 1.69 christos DPRINTF(("linux_gcc_sig: sig=%s\n", tbuf));
212 1.69 christos if (!memcmp(tbuf, signature, sizeof(signature) - 1)) {
213 1.50 mycroft error = 0;
214 1.14 christos goto out;
215 1.50 mycroft }
216 1.14 christos }
217 1.50 mycroft error = ENOEXEC;
218 1.14 christos
219 1.14 christos out:
220 1.14 christos free(sh, M_TEMP);
221 1.50 mycroft return (error);
222 1.14 christos }
223 1.31 erh #endif
224 1.31 erh
225 1.74 manu #ifdef LINUX_DEBUGLINK_SIGNATURE
226 1.74 manu /*
227 1.74 manu * Look for a .gnu_debuglink, specific to x86_64 interpeter
228 1.74 manu */
229 1.74 manu int
230 1.74 manu ELFNAME2(linux,debuglink_signature)(l, epp, eh)
231 1.74 manu struct lwp *l;
232 1.74 manu struct exec_package *epp;
233 1.74 manu Elf_Ehdr *eh;
234 1.74 manu {
235 1.74 manu size_t shsize;
236 1.74 manu int strndx;
237 1.74 manu size_t i;
238 1.74 manu static const char signature[] = ".gnu_debuglink";
239 1.74 manu char *strtable = NULL;
240 1.74 manu Elf_Shdr *sh;
241 1.74 manu
242 1.74 manu int error;
243 1.74 manu
244 1.74 manu /*
245 1.74 manu * load the section header table
246 1.74 manu */
247 1.74 manu shsize = eh->e_shnum * sizeof(Elf_Shdr);
248 1.74 manu sh = (Elf_Shdr *) malloc(shsize, M_TEMP, M_WAITOK);
249 1.74 manu error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize);
250 1.74 manu if (error)
251 1.74 manu goto out;
252 1.74 manu
253 1.74 manu /*
254 1.74 manu * Now let's find the string table. If it does not exists, give up.
255 1.74 manu */
256 1.74 manu strndx = (int)(eh->e_shstrndx);
257 1.74 manu if (strndx == SHN_UNDEF) {
258 1.74 manu error = ENOEXEC;
259 1.74 manu goto out;
260 1.74 manu }
261 1.74 manu
262 1.74 manu /*
263 1.74 manu * strndx is the index in section header table of the string table
264 1.74 manu * section get the whole string table in strtable, and then we get access to the names
265 1.74 manu * s->sh_name is the offset of the section name in strtable.
266 1.74 manu */
267 1.74 manu strtable = malloc(sh[strndx].sh_size, M_TEMP, M_WAITOK);
268 1.74 manu error = exec_read_from(l, epp->ep_vp, sh[strndx].sh_offset, strtable,
269 1.74 manu sh[strndx].sh_size);
270 1.74 manu if (error)
271 1.74 manu goto out;
272 1.74 manu
273 1.74 manu for (i = 0; i < eh->e_shnum; i++) {
274 1.74 manu Elf_Shdr *s = &sh[i];
275 1.74 manu
276 1.74 manu if (!memcmp((void*)(&(strtable[s->sh_name])), signature,
277 1.74 manu sizeof(signature))) {
278 1.74 manu DPRINTF(("linux_debuglink_sig=%s\n",
279 1.74 manu &(strtable[s->sh_name])));
280 1.74 manu error = 0;
281 1.74 manu goto out;
282 1.74 manu }
283 1.74 manu }
284 1.74 manu error = ENOEXEC;
285 1.74 manu
286 1.74 manu out:
287 1.74 manu free(sh, M_TEMP);
288 1.74 manu if (strtable)
289 1.74 manu free(strtable, M_TEMP);
290 1.74 manu return (error);
291 1.74 manu }
292 1.74 manu #endif
293 1.74 manu
294 1.71 manu int
295 1.70 christos ELFNAME2(linux,signature)(l, epp, eh, itp)
296 1.70 christos struct lwp *l;
297 1.31 erh struct exec_package *epp;
298 1.31 erh Elf_Ehdr *eh;
299 1.50 mycroft char *itp;
300 1.31 erh {
301 1.31 erh size_t i;
302 1.31 erh Elf_Phdr *ph;
303 1.31 erh size_t phsize;
304 1.50 mycroft int error;
305 1.57 christos static const char linux[] = "Linux";
306 1.57 christos
307 1.57 christos if (eh->e_ident[EI_OSABI] == 3 ||
308 1.57 christos memcmp(&eh->e_ident[EI_ABIVERSION], linux, sizeof(linux)) == 0)
309 1.57 christos return 0;
310 1.31 erh
311 1.31 erh phsize = eh->e_phnum * sizeof(Elf_Phdr);
312 1.31 erh ph = (Elf_Phdr *)malloc(phsize, M_TEMP, M_WAITOK);
313 1.70 christos error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize);
314 1.50 mycroft if (error)
315 1.50 mycroft goto out;
316 1.31 erh
317 1.31 erh for (i = 0; i < eh->e_phnum; i++) {
318 1.31 erh Elf_Phdr *ephp = &ph[i];
319 1.50 mycroft Elf_Nhdr *np;
320 1.50 mycroft u_int32_t *abi;
321 1.31 erh
322 1.50 mycroft if (ephp->p_type != PT_NOTE ||
323 1.50 mycroft ephp->p_filesz > 1024 ||
324 1.50 mycroft ephp->p_filesz < sizeof(Elf_Nhdr) + 20)
325 1.31 erh continue;
326 1.31 erh
327 1.50 mycroft np = (Elf_Nhdr *)malloc(ephp->p_filesz, M_TEMP, M_WAITOK);
328 1.70 christos error = exec_read_from(l, epp->ep_vp, ephp->p_offset, np,
329 1.52 christos ephp->p_filesz);
330 1.50 mycroft if (error)
331 1.50 mycroft goto next;
332 1.50 mycroft
333 1.50 mycroft if (np->n_type != ELF_NOTE_TYPE_ABI_TAG ||
334 1.50 mycroft np->n_namesz != ELF_NOTE_ABI_NAMESZ ||
335 1.50 mycroft np->n_descsz != ELF_NOTE_ABI_DESCSZ ||
336 1.50 mycroft memcmp((caddr_t)(np + 1), ELF_NOTE_ABI_NAME,
337 1.50 mycroft ELF_NOTE_ABI_NAMESZ))
338 1.50 mycroft goto next;
339 1.50 mycroft
340 1.50 mycroft /* Make sure the OS is Linux. */
341 1.50 mycroft abi = (u_int32_t *)((caddr_t)np + sizeof(Elf_Nhdr) +
342 1.50 mycroft np->n_namesz);
343 1.50 mycroft if (abi[0] == ELF_NOTE_ABI_OS_LINUX)
344 1.50 mycroft error = 0;
345 1.50 mycroft else
346 1.40 erh error = ENOEXEC;
347 1.50 mycroft free(np, M_TEMP);
348 1.50 mycroft goto out;
349 1.31 erh
350 1.50 mycroft next:
351 1.50 mycroft free(np, M_TEMP);
352 1.50 mycroft continue;
353 1.50 mycroft }
354 1.31 erh
355 1.50 mycroft /* Check for certain intepreter names. */
356 1.66 drochner if (itp) {
357 1.50 mycroft if (!strncmp(itp, "/lib/ld-linux", 13) ||
358 1.68 manu #if (ELFSIZE == 64)
359 1.68 manu !strncmp(itp, "/lib64/ld-linux", 15) ||
360 1.68 manu #endif
361 1.50 mycroft !strncmp(itp, "/lib/ld.so.", 11))
362 1.50 mycroft error = 0;
363 1.50 mycroft else
364 1.50 mycroft error = ENOEXEC;
365 1.50 mycroft goto out;
366 1.31 erh }
367 1.31 erh
368 1.31 erh error = ENOEXEC;
369 1.50 mycroft out:
370 1.31 erh free(ph, M_TEMP);
371 1.50 mycroft return (error);
372 1.31 erh }
373 1.14 christos
374 1.8 fvdl int
375 1.75 christos ELFNAME2(linux,probe)(struct lwp *l, struct exec_package *epp, void *eh,
376 1.75 christos char *itp, vaddr_t *pos __unused)
377 1.6 fvdl {
378 1.8 fvdl int error;
379 1.14 christos
380 1.70 christos if (((error = ELFNAME2(linux,signature)(l, epp, eh, itp)) != 0) &&
381 1.51 manu #ifdef LINUX_GCC_SIGNATURE
382 1.70 christos ((error = ELFNAME2(linux,gcc_signature)(l, epp, eh)) != 0) &&
383 1.53 manu #endif
384 1.51 manu #ifdef LINUX_ATEXIT_SIGNATURE
385 1.70 christos ((error = ELFNAME2(linux,atexit_signature)(l, epp, eh)) != 0) &&
386 1.53 manu #endif
387 1.74 manu #ifdef LINUX_DEBUGLINK_SIGNATURE
388 1.74 manu ((error = ELFNAME2(linux,debuglink_signature)(l, epp, eh)) != 0) &&
389 1.74 manu #endif
390 1.74 manu 1) {
391 1.74 manu DPRINTF(("linux_probe: returning %d\n", error));
392 1.51 manu return error;
393 1.74 manu }
394 1.6 fvdl
395 1.66 drochner if (itp) {
396 1.70 christos if ((error = emul_find_interp(l, epp->ep_esch->es_emul->e_path,
397 1.60 jdolecek itp)))
398 1.60 jdolecek return (error);
399 1.6 fvdl }
400 1.56 christos DPRINTF(("linux_probe: returning 0\n"));
401 1.6 fvdl return 0;
402 1.6 fvdl }
403 1.6 fvdl
404 1.59 jdolecek #ifndef LINUX_MACHDEP_ELF_COPYARGS
405 1.59 jdolecek /*
406 1.59 jdolecek * Copy arguments onto the stack in the normal way, but add some
407 1.59 jdolecek * extra information in case of dynamic binding.
408 1.59 jdolecek */
409 1.59 jdolecek int
410 1.70 christos ELFNAME2(linux,copyargs)(struct lwp *l, struct exec_package *pack,
411 1.59 jdolecek struct ps_strings *arginfo, char **stackp, void *argp)
412 1.59 jdolecek {
413 1.59 jdolecek size_t len;
414 1.59 jdolecek AuxInfo ai[LINUX_ELF_AUX_ENTRIES], *a;
415 1.59 jdolecek struct elf_args *ap;
416 1.59 jdolecek int error;
417 1.59 jdolecek struct vattr *vap;
418 1.59 jdolecek
419 1.70 christos if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0)
420 1.59 jdolecek return error;
421 1.59 jdolecek
422 1.59 jdolecek a = ai;
423 1.59 jdolecek
424 1.59 jdolecek /*
425 1.59 jdolecek * Push extra arguments used by glibc on the stack.
426 1.59 jdolecek */
427 1.59 jdolecek
428 1.59 jdolecek a->a_type = AT_PAGESZ;
429 1.59 jdolecek a->a_v = PAGE_SIZE;
430 1.59 jdolecek a++;
431 1.59 jdolecek
432 1.59 jdolecek if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
433 1.59 jdolecek
434 1.59 jdolecek a->a_type = AT_PHDR;
435 1.59 jdolecek a->a_v = ap->arg_phaddr;
436 1.59 jdolecek a++;
437 1.59 jdolecek
438 1.59 jdolecek a->a_type = AT_PHENT;
439 1.59 jdolecek a->a_v = ap->arg_phentsize;
440 1.59 jdolecek a++;
441 1.59 jdolecek
442 1.59 jdolecek a->a_type = AT_PHNUM;
443 1.59 jdolecek a->a_v = ap->arg_phnum;
444 1.59 jdolecek a++;
445 1.59 jdolecek
446 1.59 jdolecek a->a_type = AT_BASE;
447 1.59 jdolecek a->a_v = ap->arg_interp;
448 1.59 jdolecek a++;
449 1.59 jdolecek
450 1.59 jdolecek a->a_type = AT_FLAGS;
451 1.59 jdolecek a->a_v = 0;
452 1.59 jdolecek a++;
453 1.59 jdolecek
454 1.59 jdolecek a->a_type = AT_ENTRY;
455 1.59 jdolecek a->a_v = ap->arg_entry;
456 1.59 jdolecek a++;
457 1.59 jdolecek
458 1.59 jdolecek free(pack->ep_emul_arg, M_TEMP);
459 1.59 jdolecek pack->ep_emul_arg = NULL;
460 1.59 jdolecek }
461 1.59 jdolecek
462 1.59 jdolecek /* Linux-specific items */
463 1.59 jdolecek a->a_type = LINUX_AT_CLKTCK;
464 1.59 jdolecek a->a_v = hz;
465 1.59 jdolecek a++;
466 1.59 jdolecek
467 1.59 jdolecek vap = pack->ep_vap;
468 1.59 jdolecek
469 1.59 jdolecek a->a_type = LINUX_AT_UID;
470 1.73 ad a->a_v = kauth_cred_getuid(l->l_cred);
471 1.59 jdolecek a++;
472 1.59 jdolecek
473 1.59 jdolecek a->a_type = LINUX_AT_EUID;
474 1.59 jdolecek if (vap->va_mode & S_ISUID)
475 1.59 jdolecek a->a_v = vap->va_uid;
476 1.59 jdolecek else
477 1.73 ad a->a_v = kauth_cred_geteuid(l->l_cred);
478 1.59 jdolecek a++;
479 1.59 jdolecek
480 1.59 jdolecek a->a_type = LINUX_AT_GID;
481 1.73 ad a->a_v = kauth_cred_getgid(l->l_cred);
482 1.59 jdolecek a++;
483 1.59 jdolecek
484 1.59 jdolecek a->a_type = LINUX_AT_EGID;
485 1.59 jdolecek if (vap->va_mode & S_ISGID)
486 1.59 jdolecek a->a_v = vap->va_gid;
487 1.59 jdolecek else
488 1.73 ad a->a_v = kauth_cred_getegid(l->l_cred);
489 1.59 jdolecek a++;
490 1.59 jdolecek
491 1.59 jdolecek a->a_type = AT_NULL;
492 1.59 jdolecek a->a_v = 0;
493 1.59 jdolecek a++;
494 1.59 jdolecek
495 1.59 jdolecek len = (a - ai) * sizeof(AuxInfo);
496 1.59 jdolecek if ((error = copyout(ai, *stackp, len)) != 0)
497 1.59 jdolecek return error;
498 1.59 jdolecek *stackp += len;
499 1.59 jdolecek
500 1.59 jdolecek return 0;
501 1.59 jdolecek }
502 1.59 jdolecek #endif /* !LINUX_MACHDEP_ELF_COPYARGS */
503