1 | /* $NetBSD: netbsd32_exec.h,v 1.32 2014/10/24 21:07:55 christos Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 1998, 2001 Matthew R. Green |
5 | * All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. |
27 | */ |
28 | |
29 | #ifndef _NETBSD32_EXEC_H_ |
30 | #define _NETBSD32_EXEC_H_ |
31 | |
32 | #include <compat/netbsd32/netbsd32.h> |
33 | |
34 | #ifdef EXEC_AOUT |
35 | #include <sys/exec_aout.h> |
36 | #endif |
37 | |
38 | /* from <sys/exec_aout.h> */ |
39 | /* |
40 | * Header prepended to each a.out file. |
41 | * only manipulate the a_midmag field via the |
42 | * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below. |
43 | */ |
44 | struct netbsd32_exec { |
45 | netbsd32_u_long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */ |
46 | netbsd32_u_long a_text; /* text segment size */ |
47 | netbsd32_u_long a_data; /* initialized data size */ |
48 | netbsd32_u_long a_bss; /* uninitialized data size */ |
49 | netbsd32_u_long a_syms; /* symbol table size */ |
50 | netbsd32_u_long a_entry; /* entry point */ |
51 | netbsd32_u_long a_trsize; /* text relocation size */ |
52 | netbsd32_u_long a_drsize; /* data relocation size */ |
53 | }; |
54 | |
55 | extern struct emul emul_netbsd32; |
56 | |
57 | #ifdef EXEC_AOUT |
58 | int netbsd32_exec_aout_prep_zmagic(struct lwp *, struct exec_package *); |
59 | int netbsd32_exec_aout_prep_nmagic(struct lwp *, struct exec_package *); |
60 | int netbsd32_exec_aout_prep_omagic(struct lwp *, struct exec_package *); |
61 | int exec_netbsd32_makecmds(struct lwp *, struct exec_package *); |
62 | #endif |
63 | #ifdef EXEC_ELF32 |
64 | int netbsd32_elf32_probe(struct lwp *, struct exec_package *, void *, |
65 | char *, vaddr_t *); |
66 | int netbsd32_elf32_probe_noteless(struct lwp *, struct exec_package *, |
67 | void *, char *, vaddr_t *); |
68 | int netbsd32_elf32_copyargs(struct lwp *, struct exec_package *, |
69 | struct ps_strings *, char **, void *); |
70 | #endif /* EXEC_ELF32 */ |
71 | |
72 | static __inline int netbsd32_copyargs(struct lwp *, struct exec_package *, |
73 | struct ps_strings *, char **, void *); |
74 | |
75 | void netbsd32_setregs (struct lwp *, struct exec_package *, vaddr_t stack); |
76 | int netbsd32_sigreturn (struct proc *, void *, register_t *); |
77 | void netbsd32_sendsig (const ksiginfo_t *, const sigset_t *); |
78 | |
79 | extern char netbsd32_esigcode[], netbsd32_sigcode[]; |
80 | |
81 | /* |
82 | * We need to copy out all pointers as 32-bit values. |
83 | */ |
84 | static __inline int |
85 | netbsd32_copyargs(struct lwp *l, struct exec_package *pack, |
86 | struct ps_strings *arginfo, char **stackp, void *argp) |
87 | { |
88 | u_int32_t *cpp = (u_int32_t *)*stackp; |
89 | netbsd32_pointer_t dp; |
90 | u_int32_t nullp = 0; |
91 | char *sp; |
92 | size_t len; |
93 | int argc = arginfo->ps_nargvstr; |
94 | int envc = arginfo->ps_nenvstr; |
95 | int error; |
96 | |
97 | NETBSD32PTR32(dp, cpp + |
98 | 1 + /* int argc */ |
99 | argc + /* char *argv[] */ |
100 | 1 + /* \0 */ |
101 | envc + /* char *env[] */ |
102 | 1 + /* \0 */ |
103 | /* XXX auxinfo multiplied by ptr size? */ |
104 | pack->ep_esch->es_arglen); /* auxinfo */ |
105 | sp = argp; |
106 | |
107 | if ((error = copyout(&argc, cpp++, sizeof(argc))) != 0) |
108 | return error; |
109 | |
110 | /* XXX don't copy them out, remap them! */ |
111 | /* remember location of argv for later */ |
112 | arginfo->ps_argvstr = (char **)(u_long)cpp; |
113 | |
114 | for (; --argc >= 0; sp += len, NETBSD32PTR32PLUS(dp, len)) { |
115 | if ((error = copyout(&dp, cpp++, sizeof(dp))) != 0) |
116 | return error; |
117 | if ((error = copyoutstr(sp, NETBSD32PTR64(dp), |
118 | ARG_MAX, &len)) != 0) |
119 | return error; |
120 | } |
121 | if ((error = copyout(&nullp, cpp++, sizeof(nullp))) != 0) |
122 | return error; |
123 | |
124 | /* remember location of envp for later */ |
125 | arginfo->ps_envstr = (char **)(u_long)cpp; |
126 | |
127 | for (; --envc >= 0; sp += len, NETBSD32PTR32PLUS(dp, len)) { |
128 | if ((error = copyout(&dp, cpp++, sizeof(dp))) != 0) |
129 | return error; |
130 | if ((error = copyoutstr(sp, NETBSD32PTR64(dp), |
131 | ARG_MAX, &len)) != 0) |
132 | return error; |
133 | } |
134 | if ((error = copyout(&nullp, cpp++, sizeof(nullp))) != 0) |
135 | return error; |
136 | |
137 | *stackp = (char *)cpp; |
138 | return 0; |
139 | } |
140 | |
141 | #endif /* !_NETBSD32_EXEC_H_ */ |
142 | |