2003-01-22 15:58:22 +03:00
|
|
|
/* $NetBSD: irix_exec.c,v 1.27 2003/01/22 12:58:22 rafal Exp $ */
|
2001-09-22 22:51:35 +04:00
|
|
|
|
|
|
|
/*-
|
2002-01-08 01:05:03 +03:00
|
|
|
* Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
|
2001-09-22 22:51:35 +04:00
|
|
|
* 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:
|
2001-11-27 00:36:24 +03:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
2001-09-22 22:51:35 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-22 15:58:22 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: irix_exec.c,v 1.27 2003/01/22 12:58:22 rafal Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
2001-09-22 22:51:35 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
2002-08-03 03:02:51 +04:00
|
|
|
#include <sys/lock.h>
|
2001-09-22 22:51:35 +04:00
|
|
|
#include <sys/exec.h>
|
- Introduce a e_fault field in struct proc to provide emulation specific
memory fault handler. IRIX uses irix_vm_fault, and all other emulation
use NULL, which means to use uvm_fault.
- While we are there, explicitely set to NULL the uninitialized fields in
struct emul: e_fault and e_sysctl on most ports
- e_fault is used by the trap handler, for now only on mips. In order to avoid
intrusive modifications in UVM, the function pointed by e_fault does not
has exactly the same protoype as uvm_fault:
int uvm_fault __P((struct vm_map *, vaddr_t, vm_fault_t, vm_prot_t));
int e_fault __P((struct proc *, vaddr_t, vm_fault_t, vm_prot_t));
- In IRIX share groups, all the VM space is shared, except one page.
This bounds us to have different VM spaces and synchronize modifications
to the VM space accross share group members. We need an IRIX specific hook
to the page fault handler in order to propagate VM space modifications
caused by page faults.
2002-09-22 01:14:54 +04:00
|
|
|
#include <sys/types.h>
|
2001-09-22 22:51:35 +04:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2002-01-08 02:12:30 +03:00
|
|
|
#include <machine/regnum.h>
|
- Introduce a e_fault field in struct proc to provide emulation specific
memory fault handler. IRIX uses irix_vm_fault, and all other emulation
use NULL, which means to use uvm_fault.
- While we are there, explicitely set to NULL the uninitialized fields in
struct emul: e_fault and e_sysctl on most ports
- e_fault is used by the trap handler, for now only on mips. In order to avoid
intrusive modifications in UVM, the function pointed by e_fault does not
has exactly the same protoype as uvm_fault:
int uvm_fault __P((struct vm_map *, vaddr_t, vm_fault_t, vm_prot_t));
int e_fault __P((struct proc *, vaddr_t, vm_fault_t, vm_prot_t));
- In IRIX share groups, all the VM space is shared, except one page.
This bounds us to have different VM spaces and synchronize modifications
to the VM space accross share group members. We need an IRIX specific hook
to the page fault handler in order to propagate VM space modifications
caused by page faults.
2002-09-22 01:14:54 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2001-11-28 15:00:53 +03:00
|
|
|
#include <compat/irix/irix_syscall.h>
|
2001-09-22 22:51:35 +04:00
|
|
|
#include <compat/irix/irix_types.h>
|
|
|
|
#include <compat/irix/irix_exec.h>
|
2002-06-13 00:33:20 +04:00
|
|
|
#include <compat/irix/irix_prctl.h>
|
2001-12-08 14:17:37 +03:00
|
|
|
#include <compat/irix/irix_signal.h>
|
2001-12-02 19:16:57 +03:00
|
|
|
#include <compat/irix/irix_errno.h>
|
2002-11-09 12:03:56 +03:00
|
|
|
#include <compat/irix/irix_sysctl.h>
|
2002-08-25 23:03:12 +04:00
|
|
|
#include <compat/irix/irix_usema.h>
|
2001-09-22 22:51:35 +04:00
|
|
|
|
2002-05-29 01:15:41 +04:00
|
|
|
extern const int native_to_svr4_signo[];
|
|
|
|
|
2002-04-15 01:50:49 +04:00
|
|
|
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 *));
|
2001-11-27 00:36:24 +03:00
|
|
|
|
2001-11-28 15:00:53 +03:00
|
|
|
extern struct sysent irix_sysent[];
|
2001-12-08 14:17:37 +03:00
|
|
|
extern const char * const irix_syscallnames[];
|
2001-11-27 00:36:24 +03:00
|
|
|
|
2001-09-22 22:51:35 +04:00
|
|
|
#ifndef __HAVE_SYSCALL_INTERN
|
2001-11-28 15:00:53 +03:00
|
|
|
void irix_syscall __P((void));
|
2001-09-22 22:51:35 +04:00
|
|
|
#else
|
2001-11-28 15:00:53 +03:00
|
|
|
void irix_syscall_intern __P((struct proc *));
|
2001-09-22 22:51:35 +04:00
|
|
|
#endif
|
|
|
|
|
2002-11-30 16:18:13 +03:00
|
|
|
const struct emul emul_irix = {
|
|
|
|
"irix",
|
2001-09-22 22:51:35 +04:00
|
|
|
"/emul/irix",
|
|
|
|
#ifndef __HAVE_MINIMAL_EMUL
|
|
|
|
0,
|
2001-12-02 19:16:57 +03:00
|
|
|
native_to_irix_errno,
|
2001-11-28 15:00:53 +03:00
|
|
|
IRIX_SYS_syscall,
|
2002-11-01 22:26:21 +03:00
|
|
|
IRIX_SYS_NSYSENT,
|
2001-09-22 22:51:35 +04:00
|
|
|
#endif
|
2001-11-28 15:00:53 +03:00
|
|
|
irix_sysent,
|
2001-09-22 22:51:35 +04:00
|
|
|
#ifdef SYSCALL_DEBUG
|
2001-11-28 15:00:53 +03:00
|
|
|
irix_syscallnames,
|
2001-09-22 22:51:35 +04:00
|
|
|
#else
|
|
|
|
NULL,
|
|
|
|
#endif
|
2001-12-08 14:17:37 +03:00
|
|
|
irix_sendsig,
|
2001-09-22 22:51:35 +04:00
|
|
|
trapsignal,
|
2002-01-08 01:05:03 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2002-04-15 01:50:49 +04:00
|
|
|
setregs,
|
|
|
|
irix_e_proc_exec,
|
|
|
|
irix_e_proc_fork,
|
|
|
|
irix_e_proc_exit,
|
2002-01-08 01:05:03 +03:00
|
|
|
#ifdef __HAVE_SYSCALL_INTERN
|
|
|
|
irix_syscall_intern,
|
|
|
|
#else
|
|
|
|
irix_syscall,
|
|
|
|
#endif
|
2002-11-09 12:03:56 +03:00
|
|
|
irix_sysctl,
|
- Introduce a e_fault field in struct proc to provide emulation specific
memory fault handler. IRIX uses irix_vm_fault, and all other emulation
use NULL, which means to use uvm_fault.
- While we are there, explicitely set to NULL the uninitialized fields in
struct emul: e_fault and e_sysctl on most ports
- e_fault is used by the trap handler, for now only on mips. In order to avoid
intrusive modifications in UVM, the function pointed by e_fault does not
has exactly the same protoype as uvm_fault:
int uvm_fault __P((struct vm_map *, vaddr_t, vm_fault_t, vm_prot_t));
int e_fault __P((struct proc *, vaddr_t, vm_fault_t, vm_prot_t));
- In IRIX share groups, all the VM space is shared, except one page.
This bounds us to have different VM spaces and synchronize modifications
to the VM space accross share group members. We need an IRIX specific hook
to the page fault handler in order to propagate VM space modifications
caused by page faults.
2002-09-22 01:14:54 +04:00
|
|
|
irix_vm_fault,
|
2002-01-08 01:05:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set registers on exec for N32 applications
|
|
|
|
*/
|
|
|
|
void
|
2003-01-22 15:58:22 +03:00
|
|
|
irix_n32_setregs(l, pack, stack)
|
|
|
|
struct lwp *l;
|
2002-01-08 01:05:03 +03:00
|
|
|
struct exec_package *pack;
|
|
|
|
u_long stack;
|
|
|
|
{
|
2003-01-22 15:58:22 +03:00
|
|
|
struct frame *f = (struct frame *)l->l_md.md_regs;
|
2002-01-08 01:05:03 +03:00
|
|
|
|
|
|
|
/* Enable 64 bit instructions (eg: sd) */
|
|
|
|
f->f_regs[SR] |= MIPS3_SR_UX;
|
|
|
|
}
|
2002-04-15 01:50:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* per-process emuldata allocation
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
irix_e_proc_init(p, vmspace)
|
|
|
|
struct proc *p;
|
|
|
|
struct vmspace *vmspace;
|
|
|
|
{
|
2002-08-03 03:02:51 +04:00
|
|
|
struct irix_emuldata *ied;
|
2002-10-15 01:14:23 +04:00
|
|
|
vaddr_t vm_min;
|
|
|
|
vsize_t vm_len;
|
2002-08-03 03:02:51 +04:00
|
|
|
|
2002-04-15 01:50:49 +04:00
|
|
|
if (!p->p_emuldata)
|
2002-08-03 03:02:51 +04:00
|
|
|
p->p_emuldata = malloc(sizeof(struct irix_emuldata),
|
|
|
|
M_EMULDATA, M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
ied = p->p_emuldata;
|
|
|
|
ied->ied_p = p;
|
2002-10-15 01:14:23 +04:00
|
|
|
|
|
|
|
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);
|
2002-04-15 01:50:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* exec() hook used to allocate per process structures
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
irix_e_proc_exec(p, epp)
|
|
|
|
struct proc *p;
|
|
|
|
struct exec_package *epp;
|
|
|
|
{
|
2002-04-20 20:19:22 +04:00
|
|
|
int error;
|
|
|
|
|
2002-04-15 01:50:49 +04:00
|
|
|
irix_e_proc_init(p, p->p_vmspace);
|
2002-04-20 20:19:22 +04:00
|
|
|
|
2002-06-13 00:33:20 +04:00
|
|
|
/* Initialize the process private area (PRDA) */
|
|
|
|
error = irix_prda_init(p);
|
2002-04-20 20:19:22 +04:00
|
|
|
#ifdef DEBUG_IRIX
|
|
|
|
if (error != 0)
|
2002-08-03 03:02:51 +04:00
|
|
|
printf("irix_e_proc_exec(): PRDA map failed ");
|
2002-04-20 20:19:22 +04:00
|
|
|
#endif
|
2002-04-15 01:50:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* exit() hook used to free per process data structures
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
irix_e_proc_exit(p)
|
|
|
|
struct proc *p;
|
|
|
|
{
|
2002-05-29 01:15:41 +04:00
|
|
|
struct proc *pp;
|
|
|
|
struct irix_emuldata *ied;
|
2002-08-03 03:02:51 +04:00
|
|
|
struct irix_share_group *isg;
|
2002-10-15 01:14:23 +04:00
|
|
|
struct irix_shared_regions_rec *isrr;
|
2002-05-29 01:15:41 +04:00
|
|
|
|
2002-08-03 03:02:51 +04:00
|
|
|
/*
|
|
|
|
* Send SIGHUP to child process as requested using prctl(2)
|
|
|
|
*/
|
|
|
|
proclist_lock_read();
|
2002-05-29 01:15:41 +04:00
|
|
|
LIST_FOREACH(pp, &allproc, p_list) {
|
2002-06-05 21:27:11 +04:00
|
|
|
/* Select IRIX processes */
|
|
|
|
if (irix_check_exec(pp) == 0)
|
2002-05-29 01:15:41 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ied = (struct irix_emuldata *)(pp->p_emuldata);
|
2002-08-03 03:02:51 +04:00
|
|
|
if (ied->ied_termchild && pp->p_pptr == p)
|
2002-05-29 01:15:41 +04:00
|
|
|
psignal(pp, native_to_svr4_signo[SIGHUP]);
|
|
|
|
}
|
2002-08-03 03:02:51 +04:00
|
|
|
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) {
|
2002-08-25 23:03:12 +04:00
|
|
|
/*
|
|
|
|
* 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).
|
|
|
|
*/
|
2002-08-03 03:02:51 +04:00
|
|
|
free(isg, M_EMULDATA);
|
|
|
|
ied->ied_share_group = NULL;
|
|
|
|
} else {
|
2002-08-25 23:03:12 +04:00
|
|
|
/*
|
|
|
|
* 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);
|
2002-08-03 03:02:51 +04:00
|
|
|
lockmgr(&isg->isg_lock, LK_RELEASE, NULL);
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:03:12 +04:00
|
|
|
} 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);
|
2002-08-03 03:02:51 +04:00
|
|
|
}
|
2002-05-29 01:15:41 +04:00
|
|
|
|
2002-10-15 01:14:23 +04:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2002-08-03 03:02:51 +04:00
|
|
|
free(p->p_emuldata, M_EMULDATA);
|
2002-04-15 01:50:49 +04:00
|
|
|
p->p_emuldata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fork() hook used to allocate per process structures
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
irix_e_proc_fork(p, parent)
|
|
|
|
struct proc *p, *parent;
|
|
|
|
{
|
2002-05-29 01:15:41 +04:00
|
|
|
struct irix_emuldata *ied1;
|
|
|
|
struct irix_emuldata *ied2;
|
|
|
|
|
2002-04-15 01:50:49 +04:00
|
|
|
p->p_emuldata = NULL;
|
|
|
|
|
2002-06-02 23:06:02 +04:00
|
|
|
/* Use parent's vmspace because our vmspace may not be setup yet */
|
2002-04-15 01:50:49 +04:00
|
|
|
irix_e_proc_init(p, parent->p_vmspace);
|
2002-05-29 01:15:41 +04:00
|
|
|
|
|
|
|
ied1 = p->p_emuldata;
|
|
|
|
ied2 = parent->p_emuldata;
|
|
|
|
|
|
|
|
(void) memcpy(ied1, ied2, (unsigned)
|
|
|
|
((caddr_t)&ied1->ied_endcopy - (caddr_t)&ied1->ied_startcopy));
|
2002-04-15 01:50:49 +04:00
|
|
|
}
|