1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/* $NetBSD: irix_exec.c,v 1.37 2003/12/20 19:01:30 fvdl Exp $ */
/*-
* Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Emmanuel Dreyfus.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.37 2003/12/20 19:01:30 fvdl Exp $");
#ifdef _KERNEL_OPT
#include "opt_syscall_debug.h"
#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/exec.h>
#include <sys/types.h>
#include <sys/malloc.h>
#include <machine/regnum.h>
#include <uvm/uvm_extern.h>
#include <compat/irix/irix_syscall.h>
#include <compat/irix/irix_types.h>
#include <compat/irix/irix_exec.h>
#include <compat/irix/irix_prctl.h>
#include <compat/irix/irix_signal.h>
#include <compat/irix/irix_errno.h>
#include <compat/irix/irix_sysctl.h>
#include <compat/irix/irix_usema.h>
extern const int native_to_svr4_signo[];
static void irix_e_proc_exec __P((struct proc *, struct exec_package *));
static void irix_e_proc_fork __P((struct proc *, struct proc *));
static void irix_e_proc_exit __P((struct proc *));
static void irix_e_proc_init __P((struct proc *, struct vmspace *));
extern struct sysent irix_sysent[];
extern const char * const irix_syscallnames[];
#ifndef __HAVE_SYSCALL_INTERN
void irix_syscall __P((void));
#else
void irix_syscall_intern __P((struct proc *));
#endif
/*
* Fake sigcode. COMPAT_IRIX does not use it, since the
* signal trampoline is provided by libc. However, some
* other part of the kernel will be happier if we still
* provide non NULL sigcode and esigcode.
*/
char irix_sigcode[] = { 0 };
const struct emul emul_irix = {
"irix",
"/emul/irix",
#ifndef __HAVE_MINIMAL_EMUL
0,
native_to_irix_errno,
IRIX_SYS_syscall,
IRIX_SYS_NSYSENT,
#endif
irix_sysent,
#ifdef SYSCALL_DEBUG
irix_syscallnames,
#else
NULL,
#endif
irix_sendsig,
trapsignal,
NULL,
irix_sigcode,
irix_sigcode,
NULL,
setregs,
irix_e_proc_exec,
irix_e_proc_fork,
irix_e_proc_exit,
NULL,
NULL,
#ifdef __HAVE_SYSCALL_INTERN
irix_syscall_intern,
#else
irix_syscall,
#endif
NULL,
irix_vm_fault,
};
/*
* set registers on exec for N32 applications
*/
void
irix_n32_setregs(l, pack, stack)
struct lwp *l;
struct exec_package *pack;
u_long stack;
{
struct frame *f = (struct frame *)l->l_md.md_regs;
/* Enable 64 bit instructions (eg: sd) */
f->f_regs[_R_SR] |= MIPS3_SR_UX;
}
/*
* per-process emuldata allocation
*/
static void
irix_e_proc_init(p, vmspace)
struct proc *p;
struct vmspace *vmspace;
{
struct irix_emuldata *ied;
vaddr_t vm_min;
vsize_t vm_len;
if (!p->p_emuldata)
p->p_emuldata = malloc(sizeof(struct irix_emuldata),
M_EMULDATA, M_WAITOK | M_ZERO);
ied = p->p_emuldata;
ied->ied_p = p;
LIST_INIT(&ied->ied_shared_regions);
vm_min = vm_map_min(&vmspace->vm_map);
vm_len = vm_map_max(&vmspace->vm_map) - vm_min;
irix_isrr_insert(vm_min, vm_len, IRIX_ISRR_SHARED, p);
}
/*
* exec() hook used to allocate per process structures
*/
static void
irix_e_proc_exec(p, epp)
struct proc *p;
struct exec_package *epp;
{
int error;
irix_e_proc_init(p, p->p_vmspace);
/* Initialize the process private area (PRDA) */
error = irix_prda_init(p);
#ifdef DEBUG_IRIX
if (error != 0)
printf("irix_e_proc_exec(): PRDA map failed ");
#endif
}
/*
* exit() hook used to free per process data structures
*/
static void
irix_e_proc_exit(p)
struct proc *p;
{
struct proc *pp;
struct irix_emuldata *ied;
struct irix_share_group *isg;
struct irix_shared_regions_rec *isrr;
/*
* Send SIGHUP to child process as requested using prctl(2)
*/
proclist_lock_read();
LIST_FOREACH(pp, &allproc, p_list) {
/* Select IRIX processes */
if (irix_check_exec(pp) == 0)
continue;
ied = (struct irix_emuldata *)(pp->p_emuldata);
if (ied->ied_termchild && pp->p_pptr == p)
psignal(pp, native_to_svr4_signo[SIGHUP]);
}
proclist_unlock_read();
/*
* Remove the process from share group processes list, if revelant.
*/
ied = (struct irix_emuldata *)(p->p_emuldata);
if ((isg = ied->ied_share_group) != NULL) {
lockmgr(&isg->isg_lock, LK_EXCLUSIVE, NULL);
LIST_REMOVE(ied, ied_sglist);
isg->isg_refcount--;
if (isg->isg_refcount == 0) {
/*
* This was the last process in the share group.
* Call irix_usema_exit_cleanup() to free in-kernel
* structures hold by the share group through
* the irix_usync_cntl system call.
*/
irix_usema_exit_cleanup(p, NULL);
/*
* Free the share group structure (no need to free
* the lock since we destroy it now).
*/
free(isg, M_EMULDATA);
ied->ied_share_group = NULL;
} else {
/*
* There are other processes remaining in the share
* group. Call irix_usema_exit_cleanup() to set the
* first of them as the owner of the structures
* hold in the kernel by the share group.
*/
irix_usema_exit_cleanup(p,
LIST_FIRST(&isg->isg_head)->ied_p);
lockmgr(&isg->isg_lock, LK_RELEASE, NULL);
}
} else {
/*
* The process is not part of a share group. Call
* irix_usema_exit_cleanup() to free in-kernel structures hold
* by the process through the irix_usync_cntl system call.
*/
irix_usema_exit_cleanup(p, NULL);
}
/* Free (un)shared region list */
while (!LIST_EMPTY(&ied->ied_shared_regions)) {
isrr = LIST_FIRST(&ied->ied_shared_regions);
LIST_REMOVE(isrr , isrr_list);
free(isrr, M_EMULDATA);
}
free(p->p_emuldata, M_EMULDATA);
p->p_emuldata = NULL;
}
/*
* fork() hook used to allocate per process structures
*/
static void
irix_e_proc_fork(p, parent)
struct proc *p, *parent;
{
struct irix_emuldata *ied1;
struct irix_emuldata *ied2;
p->p_emuldata = NULL;
/* Use parent's vmspace because our vmspace may not be setup yet */
irix_e_proc_init(p, parent->p_vmspace);
ied1 = p->p_emuldata;
ied2 = parent->p_emuldata;
(void) memcpy(ied1, ied2, (unsigned)
((caddr_t)&ied1->ied_endcopy - (caddr_t)&ied1->ied_startcopy));
}
|