1 /* $NetBSD: irix_exec_elf32.c,v 1.15 2008/04/28 20:23:41 martin Exp $ */
4 * Copyright (c) 2001 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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_exec_elf32.c,v 1.15 2008/04/28 20:23:41 martin Exp $");
36 #define ELFSIZE 32 /* XXX should die */
39 #include "opt_execfmt.h"
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/syslimits.h>
48 #include <sys/exec_elf.h>
49 #include <sys/errno.h>
50 #include <sys/namei.h> /* Used for irix_load_addr */
51 #include <sys/vnode.h> /* Used for irix_load_addr */
53 #include <machine/vmparam.h>
55 #include <uvm/uvm_extern.h>
57 #include <compat/common/compat_util.h>
59 #include <compat/irix/irix_exec.h>
63 * IRIX o32 ABI probe function
66 ELFNAME2(irix
,probe_o32
)(struct lwp
*l
, struct exec_package
*epp
, void *eh
,
67 char *itp
, vaddr_t
*pos
)
72 printf("irix_probe_o32()\n");
74 if ((((Elf_Ehdr
*)epp
->ep_hdr
)->e_flags
& IRIX_EF_IRIX_ABI_MASK
) !=
79 /* o32 binaries use /lib/libc.so.1 */
80 if (strncmp(itp
, "/lib/libc.so", 12) &&
81 strncmp(itp
, "/usr/lib/libc.so", 16))
83 if ((error
= emul_find_interp(l
, epp
, itp
)))
88 printf("irix_probe_o32: returning 0\n");
89 printf("epp->ep_vm_minaddr = 0x%lx\n", epp
->ep_vm_minaddr
);
91 epp
->ep_vm_minaddr
= epp
->ep_vm_minaddr
& ~0xfUL
;
92 l
->l_proc
->p_md
.md_abi
= _MIPS_BSD_API_O32
;
97 * IRIX n32 ABI probe function
100 ELFNAME2(irix
,probe_n32
)(struct lwp
*l
, struct exec_package
*epp
, void *eh
,
101 char *itp
, vaddr_t
*pos
)
106 printf("irix_probe_n32()\n");
108 if ((((Elf_Ehdr
*)epp
->ep_hdr
)->e_flags
& IRIX_EF_IRIX_ABI_MASK
) !=
113 /* n32 binaries use /lib32/libc.so.1 */
114 if (strncmp(itp
, "/lib32/libc.so", 14) &&
115 strncmp(itp
, "/usr/lib32/libc.so", 18))
117 if ((error
= emul_find_interp(l
, epp
, itp
)))
121 printf("irix_probe_n32: returning 0\n");
122 printf("epp->ep_vm_minaddr = 0x%lx\n", epp
->ep_vm_minaddr
);
124 epp
->ep_vm_minaddr
= epp
->ep_vm_minaddr
& ~0xfUL
;
125 l
->l_proc
->p_md
.md_abi
= _MIPS_BSD_API_N32
;
128 #endif /* ELFSIZE == 32 */
132 * IRIX n64 ABI probe function
135 irix_elf64_probe_n64(struct lwp
*l
, struct exec_package
*epp
, void *eh
,
136 char *itp
, vaddr_t
*pos
)
141 printf("irix_probe_n64()\n");
143 if ((((Elf_Ehdr
*)epp
->ep_hdr
)->e_flags
& IRIX_EF_IRIX_ABI_MASK
) !=
148 /* n32 binaries use /lib64/libc.so.1 */
149 if (strncmp(itp
, "/lib64/libc.so", 14) &&
150 strncmp(itp
, "/usr/lib64/libc.so", 18))
152 if ((error
= emul_find_interp(l
, epp
, itp
)))
156 printf("irix_probe_n32: returning 0\n");
157 printf("epp->ep_vm_minaddr = 0x%lx\n", epp
->ep_vm_minaddr
);
159 epp
->ep_vm_minaddr
= epp
->ep_vm_minaddr
& ~0xfUL
;
160 l
->l_proc
->p_md
.md_abi
= _MIPS_BSD_API_N32
;
163 #endif /* ELFSIZE == 64 */
166 ELFNAME2(irix
,copyargs
)(l
, pack
, arginfo
, stackp
, argp
)
168 struct exec_package
*pack
;
169 struct ps_strings
*arginfo
;
173 char **cpp
, *dp
, *sp
;
177 AuxInfo ai
[IRIX_ELF_AUX_ENTRIES
], *a
;
182 * IRIX seems to expect argc and **argv to be aligned on a
183 * 16 bytes boundary. It seems there is no other way of
184 * getting **argv aligned than duplicating and customizing
185 * the code that sets up the stack in copyargs():
188 printf("%s(): *stackp = %p\n", __func__
, *stackp
);
191 * This is borrowed from sys/kern/kern_exec.c:copyargs()
193 cpp
= (char **)*stackp
;
195 argc
= arginfo
->ps_nargvstr
;
196 envc
= arginfo
->ps_nenvstr
;
197 if ((error
= copyout(&argc
, cpp
++, sizeof(argc
))) != 0)
200 dp
= (char *) (cpp
+ argc
+ envc
+ 2 + pack
->ep_esch
->es_arglen
);
202 /* Align **argv on a 16 bytes boundary */
203 dp
= (char *)(((unsigned long)dp
+ 0xf) & ~0xfUL
);
207 arginfo
->ps_argvstr
= cpp
; /* remember location of argv for later */
209 for (; --argc
>= 0; sp
+= len
, dp
+= len
) {
211 printf("irix_elf32_copyargs(): argc = %d, cpp = %p, dp = %p\n", (int)argc
, cpp
, dp
);
213 if ((error
= copyout(&dp
, cpp
++, sizeof(dp
))) != 0 ||
214 (error
= copyoutstr(sp
, dp
, ARG_MAX
, &len
)) != 0)
218 if ((error
= copyout(&nullp
, cpp
++, sizeof(nullp
))) != 0)
221 arginfo
->ps_envstr
= cpp
; /* remember location of envp for later */
223 for (; --envc
>= 0; sp
+= len
, dp
+= len
)
224 if ((error
= copyout(&dp
, cpp
++, sizeof(dp
))) != 0 ||
225 (error
= copyoutstr(sp
, dp
, ARG_MAX
, &len
)) != 0)
228 if ((error
= copyout(&nullp
, cpp
++, sizeof(nullp
))) != 0)
231 *stackp
= (char *)cpp
;
234 * This is borrowed from sys/kern/exec_elf32.c:elf32_copyargs
239 * Push extra arguments on the stack needed by dynamically
242 if ((ap
= (struct elf_args
*)pack
->ep_emul_arg
)) {
245 a
->a_v
= ap
->arg_phaddr
;
248 a
->a_type
= AT_PHENT
;
249 a
->a_v
= ap
->arg_phentsize
;
252 a
->a_type
= AT_PHNUM
;
253 a
->a_v
= ap
->arg_phnum
;
256 a
->a_type
= AT_ENTRY
;
257 a
->a_v
= ap
->arg_entry
;
261 a
->a_v
= ap
->arg_interp
;
264 a
->a_type
= AT_PAGESZ
;
268 free((char *)ap
, M_TEMP
);
269 pack
->ep_emul_arg
= NULL
;
276 len
= (a
- ai
) * sizeof(AuxInfo
);
277 if ((error
= copyout(ai
, *stackp
, len
)) != 0)
279 /* *stackp += len; */
281 printf("*stackp = %p\n", *stackp
);