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