4 * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1996 Christopher G. Demetriou
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. The name of the author may not be used to endorse or promote products
45 * derived from this software without specific prior written permission
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 #include <sys/cdefs.h>
60 __KERNEL_RCSID(1, "$NetBSD$");
64 #endif /* _KERNEL_OPT */
66 #include <sys/param.h>
68 #include <sys/malloc.h>
70 #include <sys/namei.h>
71 #include <sys/vnode.h>
73 #include <sys/exec_elf.h>
74 #include <sys/syscall.h>
75 #include <sys/signalvar.h>
76 #include <sys/mount.h>
78 #include <sys/kauth.h>
79 #include <sys/bitops.h>
82 #include <machine/reg.h>
84 #include <compat/common/compat_util.h>
88 extern struct emul emul_netbsd
;
90 #define elf_check_header ELFNAME(check_header)
91 #define elf_copyargs ELFNAME(copyargs)
92 #define elf_load_file ELFNAME(load_file)
93 #define elf_load_psection ELFNAME(load_psection)
94 #define exec_elf_makecmds ELFNAME2(exec,makecmds)
95 #define netbsd_elf_signature ELFNAME2(netbsd,signature)
96 #define netbsd_elf_probe ELFNAME2(netbsd,probe)
97 #define coredump ELFNAMEEND(coredump)
99 int elf_load_file(struct lwp
*, struct exec_package
*, char *,
100 struct exec_vmcmd_set
*, u_long
*, struct elf_args
*, Elf_Addr
*);
101 void elf_load_psection(struct exec_vmcmd_set
*, struct vnode
*,
102 const Elf_Phdr
*, Elf_Addr
*, u_long
*, int *, int);
104 int netbsd_elf_signature(struct lwp
*, struct exec_package
*, Elf_Ehdr
*);
105 int netbsd_elf_probe(struct lwp
*, struct exec_package
*, void *, char *,
108 /* round up and down to page boundaries. */
109 #define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
110 #define ELF_TRUNC(a, b) ((a) & ~((b) - 1))
116 * We don't move this code in kern_pax.c because it is compiled twice.
119 pax_aslr_elf(struct lwp
*l
, struct exec_package
*epp
, Elf_Ehdr
*eh
,
122 size_t pax_align
= 0, pax_offset
, i
;
125 if (!pax_aslr_active(l
))
129 * find align XXX: not all sections might have the same
132 for (i
= 0; i
< eh
->e_phnum
; i
++)
133 if (ph
[i
].p_type
== PT_LOAD
) {
134 pax_align
= ph
[i
].p_align
;
143 uprintf("r=0x%x a=0x%x p=0x%x Delta=0x%lx\n", r
,
144 ilog2(pax_align
), PGSHIFT
, PAX_ASLR_DELTA(r
,
145 ilog2(pax_align
), PAX_ASLR_DELTA_EXEC_LEN
));
147 pax_offset
= ELF_TRUNC(PAX_ASLR_DELTA(r
,
148 ilog2(pax_align
), PAX_ASLR_DELTA_EXEC_LEN
), pax_align
);
150 for (i
= 0; i
< eh
->e_phnum
; i
++)
151 ph
[i
].p_vaddr
+= pax_offset
;
152 eh
->e_entry
+= pax_offset
;
154 uprintf("pax offset=0x%zx entry=0x%llx\n",
155 pax_offset
, (unsigned long long)eh
->e_entry
);
158 #endif /* PAX_ASLR */
161 * Copy arguments onto the stack in the normal way, but add some
162 * extra information in case of dynamic binding.
165 elf_copyargs(struct lwp
*l
, struct exec_package
*pack
,
166 struct ps_strings
*arginfo
, char **stackp
, void *argp
)
169 AuxInfo ai
[ELF_AUX_ENTRIES
], *a
, *execname
;
173 if ((error
= copyargs(l
, pack
, arginfo
, stackp
, argp
)) != 0)
180 * Push extra arguments on the stack needed by dynamically
183 if ((ap
= (struct elf_args
*)pack
->ep_emul_arg
)) {
184 struct vattr
*vap
= pack
->ep_vap
;
187 a
->a_v
= ap
->arg_phaddr
;
190 a
->a_type
= AT_PHENT
;
191 a
->a_v
= ap
->arg_phentsize
;
194 a
->a_type
= AT_PHNUM
;
195 a
->a_v
= ap
->arg_phnum
;
198 a
->a_type
= AT_PAGESZ
;
203 a
->a_v
= ap
->arg_interp
;
206 a
->a_type
= AT_FLAGS
;
210 a
->a_type
= AT_ENTRY
;
211 a
->a_v
= ap
->arg_entry
;
215 if (vap
->va_mode
& S_ISUID
)
216 a
->a_v
= vap
->va_uid
;
218 a
->a_v
= kauth_cred_geteuid(l
->l_cred
);
222 a
->a_v
= kauth_cred_getuid(l
->l_cred
);
226 if (vap
->va_mode
& S_ISGID
)
227 a
->a_v
= vap
->va_gid
;
229 a
->a_v
= kauth_cred_getegid(l
->l_cred
);
233 a
->a_v
= kauth_cred_getgid(l
->l_cred
);
238 a
->a_type
= AT_SUN_EXECNAME
;
243 pack
->ep_emul_arg
= NULL
;
250 vlen
= (a
- ai
) * sizeof(AuxInfo
);
253 char *path
= pack
->ep_path
;
254 execname
->a_v
= (uintptr_t)(*stackp
+ vlen
);
255 len
= strlen(path
) + 1;
256 if ((error
= copyout(path
, (*stackp
+ vlen
), len
)) != 0)
262 if ((error
= copyout(ai
, *stackp
, vlen
)) != 0)
264 *stackp
+= vlen
+ len
;
270 * elf_check_header():
272 * Check header for validity; return 0 of ok ENOEXEC if error
275 elf_check_header(Elf_Ehdr
*eh
, int type
)
278 if (memcmp(eh
->e_ident
, ELFMAG
, SELFMAG
) != 0 ||
279 eh
->e_ident
[EI_CLASS
] != ELFCLASS
)
282 switch (eh
->e_machine
) {
284 ELFDEFNNAME(MACHDEP_ID_CASES
)
290 if (ELF_EHDR_FLAGS_OK(eh
) == 0)
293 if (eh
->e_type
!= type
)
296 if (eh
->e_shnum
> 32768 || eh
->e_phnum
> 128)
303 * elf_load_psection():
305 * Load a psection at the appropriate address
308 elf_load_psection(struct exec_vmcmd_set
*vcset
, struct vnode
*vp
,
309 const Elf_Phdr
*ph
, Elf_Addr
*addr
, u_long
*size
, int *prot
, int flags
)
311 u_long msize
, psize
, rm
, rf
;
315 * If the user specified an address, then we load there.
317 if (*addr
== ELFDEFNNAME(NO_ADDR
))
320 if (ph
->p_align
> 1) {
322 * Make sure we are virtually aligned as we are supposed to be.
324 diff
= ph
->p_vaddr
- ELF_TRUNC(ph
->p_vaddr
, ph
->p_align
);
325 KASSERT(*addr
- diff
== ELF_TRUNC(*addr
, ph
->p_align
));
327 * But make sure to not map any pages before the start of the
328 * psection by limiting the difference to within a page.
334 *prot
|= (ph
->p_flags
& PF_R
) ? VM_PROT_READ
: 0;
335 *prot
|= (ph
->p_flags
& PF_W
) ? VM_PROT_WRITE
: 0;
336 *prot
|= (ph
->p_flags
& PF_X
) ? VM_PROT_EXECUTE
: 0;
339 * Adjust everything so it all starts on a page boundary.
342 offset
= ph
->p_offset
- diff
;
343 *size
= ph
->p_filesz
+ diff
;
344 msize
= ph
->p_memsz
+ diff
;
346 if (ph
->p_align
>= PAGE_SIZE
) {
347 if ((ph
->p_flags
& PF_W
) != 0) {
349 * Because the pagedvn pager can't handle zero fill
350 * of the last data page if it's not page aligned we
351 * map the last page readvn.
353 psize
= trunc_page(*size
);
355 psize
= round_page(*size
);
362 NEW_VMCMD2(vcset
, ph
->p_align
< PAGE_SIZE
?
363 vmcmd_map_readvn
: vmcmd_map_pagedvn
, psize
, *addr
, vp
,
364 offset
, *prot
, flags
);
365 flags
&= VMCMD_RELATIVE
;
368 NEW_VMCMD2(vcset
, vmcmd_map_readvn
, *size
- psize
,
369 *addr
+ psize
, vp
, offset
+ psize
, *prot
, flags
);
373 * Check if we need to extend the size of the segment (does
374 * bss extend page the next page boundary)?
376 rm
= round_page(*addr
+ msize
);
377 rf
= round_page(*addr
+ *size
);
380 NEW_VMCMD2(vcset
, vmcmd_map_zero
, rm
- rf
, rf
, NULLVP
,
381 0, *prot
, flags
& VMCMD_RELATIVE
);
389 * Load a file (interpreter/library) pointed to by path
390 * [stolen from coff_load_shlib()]. Made slightly generic
391 * so it might be used externally.
394 elf_load_file(struct lwp
*l
, struct exec_package
*epp
, char *path
,
395 struct exec_vmcmd_set
*vcset
, u_long
*entryoff
, struct elf_args
*ap
,
404 const Elf_Phdr
*base_ph
;
405 const Elf_Phdr
*last_ph
;
407 Elf_Addr addr
= *last
;
415 * 3. map text, data, and bss out of it using VM_*
419 error
= emul_find_interp(l
, epp
, path
);
424 /* We'll tidy this ourselves - otherwise we have locking issues */
425 epp
->ep_interp
= NULL
;
426 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
429 * Similarly, if it's not marked as executable, or it's not a regular
430 * file, we don't allow it to be used.
432 if (vp
->v_type
!= VREG
) {
436 if ((error
= VOP_ACCESS(vp
, VEXEC
, l
->l_cred
)) != 0)
440 if ((error
= VOP_GETATTR(vp
, &attr
, l
->l_cred
)) != 0)
444 * Check mount point. Though we're not trying to exec this binary,
445 * we will be executing code from it, so if the mount point
446 * disallows execution or set-id-ness, we punt or kill the set-id.
448 if (vp
->v_mount
->mnt_flag
& MNT_NOEXEC
) {
452 if (vp
->v_mount
->mnt_flag
& MNT_NOSUID
)
453 epp
->ep_vap
->va_mode
&= ~(S_ISUID
| S_ISGID
);
455 #ifdef notyet /* XXX cgd 960926 */
456 XXX cgd
960926: (maybe
) VOP_OPEN
it (and VOP_CLOSE in copyargs
?)
459 error
= vn_marktext(vp
);
465 if ((error
= exec_read_from(l
, vp
, 0, &eh
, sizeof(eh
))) != 0)
468 if ((error
= elf_check_header(&eh
, ET_DYN
)) != 0)
471 if (eh
.e_phnum
> MAXPHNUM
|| eh
.e_phnum
== 0) {
476 phsize
= eh
.e_phnum
* sizeof(Elf_Phdr
);
477 ph
= kmem_alloc(phsize
, KM_SLEEP
);
479 if ((error
= exec_read_from(l
, vp
, eh
.e_phoff
, ph
, phsize
)) != 0)
482 #ifdef ELF_INTERP_NON_RELOCATABLE
484 * Evil hack: Only MIPS should be non-relocatable, and the
485 * psections should have a high address (typically 0x5ffe0000).
486 * If it's now relocatable, it should be linked at 0 and the
487 * psections should have zeros in the upper part of the address.
488 * Otherwise, force the load at the linked address.
490 if (*last
== ELF_LINK_ADDR
&& (ph
->p_vaddr
& 0xffff0000) == 0)
491 *last
= ELFDEFNNAME(NO_ADDR
);
495 * If no position to load the interpreter was set by a probe
496 * function, pick the same address that a non-fixed mmap(0, ..)
497 * would (i.e. something safely out of the way).
499 if (*last
== ELFDEFNNAME(NO_ADDR
)) {
502 * Find the start and ending addresses of the psections to
503 * be loaded. This will give us the size.
505 for (i
= 0, ph0
= ph
, base_ph
= NULL
; i
< eh
.e_phnum
;
507 if (ph0
->p_type
== PT_LOAD
) {
508 u_long psize
= ph0
->p_vaddr
+ ph0
->p_memsz
;
516 if (base_ph
== NULL
) {
522 * Now compute the size and load address.
524 addr
= (*epp
->ep_esch
->es_emul
->e_vm_default_addr
)(p
,
526 round_page(limit
) - trunc_page(base_ph
->p_vaddr
));
528 addr
= *last
; /* may be ELF_LINK_ADDR */
531 * Load all the necessary sections
533 for (i
= 0, ph0
= ph
, base_ph
= NULL
, last_ph
= NULL
;
534 i
< eh
.e_phnum
; i
++, ph0
++) {
535 switch (ph0
->p_type
) {
541 if (base_ph
== NULL
) {
543 * First encountered psection is always the
544 * base psection. Make sure it's aligned
545 * properly (align down for topdown and align
546 * upwards for not topdown).
550 if (addr
== ELF_LINK_ADDR
)
552 if (p
->p_vmspace
->vm_map
.flags
& VM_MAP_TOPDOWN
)
553 addr
= ELF_TRUNC(addr
, ph0
->p_align
);
555 addr
= ELF_ROUND(addr
, ph0
->p_align
);
557 u_long limit
= round_page(last_ph
->p_vaddr
559 u_long base
= trunc_page(ph0
->p_vaddr
);
562 * If there is a gap in between the psections,
563 * map it as inaccessible so nothing else
564 * mmap'ed will be placed there.
567 NEW_VMCMD2(vcset
, vmcmd_map_zero
,
569 limit
- base_ph
->p_vaddr
, NULLVP
,
570 0, VM_PROT_NONE
, VMCMD_RELATIVE
);
573 addr
= ph0
->p_vaddr
- base_ph
->p_vaddr
;
574 flags
= VMCMD_RELATIVE
;
577 elf_load_psection(vcset
, vp
, &ph
[i
], &addr
,
578 &size
, &prot
, flags
);
580 * If entry is within this psection then this
581 * must contain the .text section. *entryoff is
582 * relative to the base psection.
584 if (eh
.e_entry
>= ph0
->p_vaddr
&&
585 eh
.e_entry
< (ph0
->p_vaddr
+ size
)) {
586 *entryoff
= eh
.e_entry
- base_ph
->p_vaddr
;
604 kmem_free(ph
, phsize
);
606 * This value is ignored if TOPDOWN.
617 kmem_free(ph
, phsize
);
618 #ifdef notyet /* XXX cgd 960926 */
626 * exec_elf_makecmds(): Prepare an Elf binary's exec package
628 * First, set of the various offsets/lengths in the exec package.
630 * Then, mark the text image busy (so it can be demand paged) or error
631 * out if this is not possible. Finally, set up vmcmds for the
632 * text, data, bss, and stack segments.
635 exec_elf_makecmds(struct lwp
*l
, struct exec_package
*epp
)
637 Elf_Ehdr
*eh
= epp
->ep_hdr
;
639 Elf_Addr phdr
= 0, pos
= 0;
646 if (epp
->ep_hdrvalid
< sizeof(Elf_Ehdr
))
649 is_dyn
= elf_check_header(eh
, ET_DYN
) == 0;
651 * XXX allow for executing shared objects. It seems silly
652 * but other ELF-based systems allow it as well.
654 if (elf_check_header(eh
, ET_EXEC
) != 0 && !is_dyn
)
657 if (eh
->e_phnum
> MAXPHNUM
|| eh
->e_phnum
== 0)
660 error
= vn_marktext(epp
->ep_vp
);
665 * Allocate space to hold all the program headers, and read them
669 phsize
= eh
->e_phnum
* sizeof(Elf_Phdr
);
670 ph
= kmem_alloc(phsize
, KM_SLEEP
);
672 if ((error
= exec_read_from(l
, epp
->ep_vp
, eh
->e_phoff
, ph
, phsize
)) !=
676 epp
->ep_taddr
= epp
->ep_tsize
= ELFDEFNNAME(NO_ADDR
);
677 epp
->ep_daddr
= epp
->ep_dsize
= ELFDEFNNAME(NO_ADDR
);
679 for (i
= 0; i
< eh
->e_phnum
; i
++) {
681 if (pp
->p_type
== PT_INTERP
) {
682 if (pp
->p_filesz
>= MAXPATHLEN
) {
686 interp
= PNBUF_GET();
688 if ((error
= exec_read_from(l
, epp
->ep_vp
,
689 pp
->p_offset
, interp
, pp
->p_filesz
)) != 0)
696 * On the same architecture, we may be emulating different systems.
697 * See which one will accept this executable.
699 * Probe functions would normally see if the interpreter (if any)
700 * exists. Emulation packages may possibly replace the interpreter in
701 * interp[] with a changed path (/emul/xxx/<path>).
703 pos
= ELFDEFNNAME(NO_ADDR
);
704 if (epp
->ep_esch
->u
.elf_probe_func
) {
705 vaddr_t startp
= (vaddr_t
)pos
;
707 error
= (*epp
->ep_esch
->u
.elf_probe_func
)(l
, epp
, eh
, interp
,
711 pos
= (Elf_Addr
)startp
;
714 #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
715 p
->p_pax
= epp
->ep_pax_flags
;
716 #endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
720 pax_aslr_elf(l
, epp
, eh
, ph
);
721 #endif /* PAX_ASLR */
724 * Load all the necessary sections
726 for (i
= nload
= 0; i
< eh
->e_phnum
; i
++) {
727 Elf_Addr addr
= ELFDEFNNAME(NO_ADDR
);
733 switch (ph
[i
].p_type
) {
737 * Can handle only 2 sections: text and data
743 elf_load_psection(&epp
->ep_vmcmds
, epp
->ep_vp
,
744 &ph
[i
], &addr
, &size
, &prot
, VMCMD_FIXED
);
747 * Decide whether it's text or data by looking
748 * at the entry point.
750 if (eh
->e_entry
>= addr
&&
751 eh
->e_entry
< (addr
+ size
)) {
752 epp
->ep_taddr
= addr
;
753 epp
->ep_tsize
= size
;
754 if (epp
->ep_daddr
== ELFDEFNNAME(NO_ADDR
)) {
755 epp
->ep_daddr
= addr
;
756 epp
->ep_dsize
= size
;
759 epp
->ep_daddr
= addr
;
760 epp
->ep_dsize
= size
;
765 /* SCO has these sections. */
767 /* Already did this one. */
773 /* Note address of program headers (in text segment) */
779 * Not fatal; we don't need to understand everything.
786 * Check if we found a dynamically linked binary and arrange to load
791 int j
= epp
->ep_vmcmds
.evs_used
;
792 u_long interp_offset
;
794 ap
= (struct elf_args
*)malloc(sizeof(struct elf_args
),
796 if ((error
= elf_load_file(l
, epp
, interp
,
797 &epp
->ep_vmcmds
, &interp_offset
, ap
, &pos
)) != 0) {
801 ap
->arg_interp
= epp
->ep_vmcmds
.evs_cmds
[j
].ev_addr
;
802 epp
->ep_entry
= ap
->arg_interp
+ interp_offset
;
803 ap
->arg_phaddr
= phdr
;
805 ap
->arg_phentsize
= eh
->e_phentsize
;
806 ap
->arg_phnum
= eh
->e_phnum
;
807 ap
->arg_entry
= eh
->e_entry
;
809 epp
->ep_emul_arg
= ap
;
813 epp
->ep_entry
= eh
->e_entry
;
815 #ifdef ELF_MAP_PAGE_ZERO
816 /* Dell SVR4 maps page zero, yeuch! */
817 NEW_VMCMD(&epp
->ep_vmcmds
, vmcmd_map_readvn
, PAGE_SIZE
, 0,
818 epp
->ep_vp
, 0, VM_PROT_READ
);
820 kmem_free(ph
, phsize
);
821 return (*epp
->ep_esch
->es_setup_stack
)(l
, epp
);
826 kmem_free(ph
, phsize
);
827 kill_vmcmds(&epp
->ep_vmcmds
);
832 netbsd_elf_signature(struct lwp
*l
, struct exec_package
*epp
,
842 epp
->ep_pax_flags
= 0;
843 if (eh
->e_phnum
> MAXPHNUM
|| eh
->e_phnum
== 0)
846 phsize
= eh
->e_phnum
* sizeof(Elf_Phdr
);
847 ph
= kmem_alloc(phsize
, KM_SLEEP
);
848 error
= exec_read_from(l
, epp
->ep_vp
, eh
->e_phoff
, ph
, phsize
);
852 for (i
= 0; i
< eh
->e_phnum
; i
++) {
853 Elf_Phdr
*ephp
= &ph
[i
];
856 if (ephp
->p_type
!= PT_NOTE
||
857 ephp
->p_filesz
> 1024 ||
858 ephp
->p_filesz
< sizeof(Elf_Nhdr
) + ELF_NOTE_NETBSD_NAMESZ
)
861 np
= kmem_alloc(ephp
->p_filesz
, KM_SLEEP
);
862 error
= exec_read_from(l
, epp
->ep_vp
, ephp
->p_offset
, np
,
867 ndata
= (char *)(np
+ 1);
868 switch (np
->n_type
) {
869 case ELF_NOTE_TYPE_NETBSD_TAG
:
870 if (np
->n_namesz
!= ELF_NOTE_NETBSD_NAMESZ
||
871 np
->n_descsz
!= ELF_NOTE_NETBSD_DESCSZ
||
872 memcmp(ndata
, ELF_NOTE_NETBSD_NAME
,
873 ELF_NOTE_NETBSD_NAMESZ
))
878 case ELF_NOTE_TYPE_PAX_TAG
:
879 if (np
->n_namesz
!= ELF_NOTE_PAX_NAMESZ
||
880 np
->n_descsz
!= ELF_NOTE_PAX_DESCSZ
||
881 memcmp(ndata
, ELF_NOTE_PAX_NAME
,
882 ELF_NOTE_PAX_NAMESZ
))
884 (void)memcpy(&epp
->ep_pax_flags
,
885 ndata
+ ELF_NOTE_PAX_NAMESZ
,
886 sizeof(epp
->ep_pax_flags
));
894 kmem_free(np
, ephp
->p_filesz
);
898 error
= isnetbsd
? 0 : ENOEXEC
;
900 kmem_free(ph
, phsize
);
905 netbsd_elf_probe(struct lwp
*l
, struct exec_package
*epp
, void *eh
, char *itp
,
910 if ((error
= netbsd_elf_signature(l
, epp
, eh
)) != 0)
912 #ifdef ELF_MD_PROBE_FUNC
913 if ((error
= ELF_MD_PROBE_FUNC(l
, epp
, eh
, itp
, pos
)) != 0)
915 #elif defined(ELF_INTERP_NON_RELOCATABLE)
916 *pos
= ELF_LINK_ADDR
;