Annotation of sys/compat/hpux/hppa/hpux_exec.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: hpux_exec.c,v 1.3 2005/12/30 19:46:53 miod Exp $ */
2:
3: /*
4: * Copyright (c) 2004 Michael Shalayeff. All rights reserved.
5: * Copyright (c) 1995, 1997 Jason R. Thorpe. All rights reserved.
6: * Copyright (c) 1993, 1994 Christopher G. Demetriou
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * This product includes software developed by Christopher G. Demetriou.
18: * 4. The name of the author may not be used to endorse or promote products
19: * derived from this software without specific prior written permission
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31: */
32:
33: /*
34: * Glue for exec'ing HP-UX executables and the HP-UX execv() system call.
35: * Based on sys/kern/exec_aout.c
36: */
37:
38: #include <sys/param.h>
39: #include <sys/systm.h>
40: #include <sys/kernel.h>
41: #include <sys/proc.h>
42: #include <sys/malloc.h>
43: #include <sys/mount.h>
44: #include <sys/namei.h>
45: #include <sys/user.h>
46: #include <sys/vnode.h>
47: #include <sys/mman.h>
48: #include <sys/stat.h>
49:
50: #include <uvm/uvm_extern.h>
51:
52: #include <machine/cpu.h>
53: #include <machine/reg.h>
54:
55: #include <sys/syscallargs.h>
56:
57: #include <compat/hpux/hpux.h>
58: #include <compat/hpux/hpux_util.h>
59: #include <compat/hpux/hppa/hpux_syscall.h>
60: #include <compat/hpux/hppa/hpux_syscallargs.h>
61:
62: #include <machine/hpux_machdep.h>
63:
64: const char hpux_emul_path[] = "/emul/hpux";
65: extern char hpux_sigcode[], hpux_esigcode[];
66: extern struct sysent hpux_sysent[];
67: #ifdef SYSCALL_DEBUG
68: extern char *hpux_syscallnames[];
69: #endif
70: extern int bsdtohpuxerrnomap[];
71:
72: int exec_hpux_som_nmagic(struct proc *, struct exec_package *);
73: int exec_hpux_som_zmagic(struct proc *, struct exec_package *);
74: int exec_hpux_som_omagic(struct proc *, struct exec_package *);
75:
76: struct emul emul_hpux = {
77: "hpux",
78: bsdtohpuxerrnomap,
79: hpux_sendsig,
80: HPUX_SYS_syscall,
81: HPUX_SYS_MAXSYSCALL,
82: hpux_sysent,
83: #ifdef SYSCALL_DEBUG
84: hpux_syscallnames,
85: #else
86: NULL,
87: #endif
88: 0,
89: copyargs,
90: hpux_setregs,
91: NULL,
92: hpux_sigcode,
93: hpux_esigcode,
94: };
95:
96: int
97: exec_hpux_makecmds(p, epp)
98: struct proc *p;
99: struct exec_package *epp;
100: {
101: struct som_exec *som_ep = epp->ep_hdr;
102: short sysid, magic;
103: int error = ENOEXEC;
104:
105: sysid = HPUX_SYSID(som_ep);
106: if (sysid != MID_HPUX800 && sysid != MID_HPPA11 && sysid != MID_HPPA20)
107: return (error);
108:
109: /* XXX read in the aux header if it was not following the som header */
110: if (sysid != MID_HPUX && (!(som_ep->som_version == HPUX_SOM_V0 ||
111: som_ep->som_version == HPUX_SOM_V1) ||
112: som_ep->som_auxhdr + sizeof(struct som_aux) > epp->ep_hdrvalid)) {
113: return (error);
114: }
115:
116: /*
117: * HP-UX is a 4k page size system, and executables assume
118: * this.
119: */
120: if (PAGE_SIZE != HPUX_LDPGSZ)
121: return (error);
122:
123: magic = HPUX_MAGIC(som_ep);
124: switch (magic) {
125: case OMAGIC:
126: error = exec_hpux_som_omagic(p, epp);
127: break;
128:
129: case NMAGIC:
130: error = exec_hpux_som_nmagic(p, epp);
131: break;
132:
133: case ZMAGIC:
134: error = exec_hpux_som_zmagic(p, epp);
135: break;
136: }
137:
138: if (error == 0) {
139: /* set up our emulation information */
140: epp->ep_emul = &emul_hpux;
141: } else
142: kill_vmcmds(&epp->ep_vmcmds);
143:
144: return (error);
145: }
146:
147: int
148: exec_hpux_som_nmagic(struct proc *p, struct exec_package *epp)
149: {
150: struct som_exec *execp = epp->ep_hdr;
151: struct som_aux *auxp = epp->ep_hdr + execp->som_auxhdr;
152:
153: epp->ep_taddr = auxp->som_tmem;
154: epp->ep_tsize = auxp->som_tsize;
155: epp->ep_daddr = auxp->som_dmem;
156: epp->ep_dsize = auxp->som_dsize + auxp->som_bsize;
157: epp->ep_entry = auxp->som_entry;
158:
159: /* set up command for text segment */
160: NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, epp->ep_tsize,
161: epp->ep_taddr, epp->ep_vp, auxp->som_tfile,
162: VM_PROT_READ|VM_PROT_EXECUTE);
163:
164: /* set up command for data segment */
165: NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, auxp->som_dsize,
166: epp->ep_daddr, epp->ep_vp, auxp->som_dfile,
167: VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
168:
169: /* set up command for bss segment */
170: if (auxp->som_bsize > 0)
171: NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, auxp->som_bsize,
172: epp->ep_daddr + auxp->som_dsize,
173: NULLVP, 0, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE);
174:
175: return (exec_setup_stack(p, epp));
176: }
177:
178: int
179: exec_hpux_som_zmagic(struct proc *p, struct exec_package *epp)
180: {
181:
182: return (exec_setup_stack(p, epp));
183: }
184:
185: int
186: exec_hpux_som_omagic(struct proc *p, struct exec_package *epp)
187: {
188:
189: return (exec_setup_stack(p, epp));
190: }
191:
192: /*
193: * The HP-UX execv(2) system call.
194: *
195: * Just check the alternate emulation path, and pass it on to the NetBSD
196: * execve().
197: */
198: int
199: hpux_sys_execv(p, v, retval)
200: struct proc *p;
201: void *v;
202: register_t *retval;
203: {
204: struct hpux_sys_execv_args /* {
205: syscallarg(char *) path;
206: syscallarg(char **) argv;
207: } */ *uap = v;
208: struct sys_execve_args ap;
209: caddr_t sg;
210:
211: sg = stackgap_init(p->p_emul);
212: HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
213:
214: SCARG(&ap, path) = SCARG(uap, path);
215: SCARG(&ap, argp) = SCARG(uap, argp);
216: SCARG(&ap, envp) = NULL;
217:
218: return sys_execve(p, &ap, retval);
219: }
220:
221: int
222: hpux_sys_execve(p, v, retval)
223: struct proc *p;
224: void *v;
225: register_t *retval;
226: {
227: struct hpux_sys_execve_args /* {
228: syscallarg(char *) path;
229: syscallarg(char **) argv;
230: syscallarg(char **) envp;
231: } */ *uap = v;
232: struct sys_execve_args ap;
233: caddr_t sg;
234:
235: sg = stackgap_init(p->p_emul);
236: HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
237:
238: SCARG(&ap, path) = SCARG(uap, path);
239: SCARG(&ap, argp) = SCARG(uap, argp);
240: SCARG(&ap, envp) = SCARG(uap, envp);
241:
242: return (sys_execve(p, &ap, retval));
243: }
CVSweb