Implements IRIX sproc(2) and friends.

There may be a problem with stack size overflow in this implementation
This commit is contained in:
manu 2002-04-28 17:21:58 +00:00
parent c583268d4e
commit 3568060679
7 changed files with 271 additions and 28 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: irix_prctl.c,v 1.4 2001/12/25 19:04:18 manu Exp $ */
/* $NetBSD: irix_prctl.c,v 1.5 2002/04/28 17:21:58 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -37,13 +37,19 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_prctl.c,v 1.4 2001/12/25 19:04:18 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_prctl.c,v 1.5 2002/04/28 17:21:58 manu Exp $");
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/systm.h>
#include <sys/exec.h>
#include <uvm/uvm_extern.h>
#include <machine/regnum.h>
#include <machine/vmparam.h>
#include <compat/svr4/svr4_types.h>
@ -52,6 +58,15 @@ __KERNEL_RCSID(0, "$NetBSD: irix_prctl.c,v 1.4 2001/12/25 19:04:18 manu Exp $");
#include <compat/irix/irix_signal.h>
#include <compat/irix/irix_syscallargs.h>
struct irix_sproc_child_args {
struct proc **isc_proc;
void *isc_entry;
void *isc_arg;
};
static void irix_sproc_child __P((struct irix_sproc_child_args *));
static int irix_sproc __P((void *, unsigned int, void *, caddr_t, size_t,
pid_t, struct proc *, register_t *));
int
irix_sys_prctl(p, v, retval)
struct proc *p;
@ -85,3 +100,178 @@ irix_sys_prctl(p, v, retval)
}
return 0;
}
int
irix_sys_pidsprocsp(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct irix_sys_pidsprocsp_args /* {
syscallarg(void *) entry;
syscallarg(unsigned) inh;
syscallarg(void *) arg;
syscallarg(caddr_t) sp;
syscallarg(irix_size_t) len;
syscallarg(irix_pid_t) pid;
} */ *uap = v;
/* pid is ignored for now */
printf("Warning: unsupported pid argument to IRIX sproc\n");
return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
SCARG(uap, sp), SCARG(uap, len), SCARG(uap, pid), p, retval);
}
int
irix_sys_sprocsp(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct irix_sys_sprocsp_args /* {
syscallarg(void *) entry;
syscallarg(unsigned) inh;
syscallarg(void *) arg;
syscallarg(caddr_t) sp;
syscallarg(irix_size_t) len;
} */ *uap = v;
return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
SCARG(uap, sp), SCARG(uap, len), 0, p, retval);
}
int
irix_sys_sproc(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct irix_sys_sproc_args /* {
syscallarg(void *) entry;
syscallarg(unsigned) inh;
syscallarg(void *) arg;
} */ *uap = v;
return irix_sproc(SCARG(uap, entry), SCARG(uap, inh), SCARG(uap, arg),
NULL, 0, 0, p, retval);
}
static int irix_sproc(entry, inh, arg, sp, len, pid, p, retval)
void *entry;
unsigned int inh;
void *arg;
caddr_t sp;
size_t len;
pid_t pid;
struct proc *p;
register_t *retval;
{
int bsd_flags = 0;
struct exec_vmcmd vmc;
struct frame *tf = (struct frame *)p->p_md.md_regs;
int error;
struct proc *p2;
struct irix_sproc_child_args isc;
#ifdef DEBUG_IRIX
printf("irix_sproc(): entry = %p, inh = %d, arg = %p, sp = 0x%08lx, len = 0x%08lx, pid = %d\n", entry, inh, arg, (u_long)sp, (u_long)len, pid);
#endif
if (inh & IRIX_PR_SADDR)
bsd_flags |= FORK_SHAREVM;
if (inh & IRIX_PR_SFDS)
bsd_flags |= FORK_SHAREFILES;
if (inh & IRIX_PR_SDIR)
bsd_flags |= FORK_SHARECWD;
if (inh & IRIX_PR_SUMASK)
printf("Warning: unimplemented IRIX sproc flag PR_SUMASK\n");
if (inh & IRIX_PR_SULIMIT)
printf("Warning: unimplemented IRIX sproc flag PR_SULIMIT\n");
if (inh & IRIX_PR_SID)
printf("Warning: unimplemented IRIX sproc flag PR_SID\n");
/*
* Setting up child stack
*/
if (len == 0)
len = (u_long)p->p_vmspace->vm_minsaddr
- (u_long)p->p_vmspace->vm_maxsaddr;
if (sp == NULL)
sp = (caddr_t)(round_page(tf->f_regs[SP])
- IRIX_SPROC_STACK_OFFSET - len);
if (inh & IRIX_PR_SADDR) {
bzero(&vmc, sizeof(vmc));
vmc.ev_addr = trunc_page((u_long)sp);
vmc.ev_len = round_page(len);
vmc.ev_prot = UVM_PROT_RWX;
vmc.ev_flags = UVM_FLAG_COPYONW|UVM_FLAG_FIXED|UVM_FLAG_OVERLAY;
vmc.ev_proc = vmcmd_map_zero;
#ifdef DEBUG_IRIX
printf("irix_sproc(): new stack addr=0x%08lx, len=0x%08lx\n",
(u_long)sp, (u_long)len);
#endif
if ((error = (*vmc.ev_proc)(p, &vmc)) != 0)
return error;
p->p_vmspace->vm_maxsaddr = (void *)trunc_page((u_long)sp);
}
/*
* Arguments for irix_sproc_child()
*/
isc.isc_proc = &p2;
isc.isc_entry = entry;
isc.isc_arg = arg;
if ((error = fork1(p, bsd_flags, SIGCHLD, (void *)sp, len,
(void *)irix_sproc_child, (void *)&isc, retval, &p2)) != 0)
return error;
/*
* Some local variables are referenced in irix_sproc_child()
* through isc. We need to ensure the child does not use them
* anymore before leaving.
*/
(void)ltsleep((void *)&isc, 0, "sproc", 0, NULL);
retval[0] = (register_t)p2->p_pid;
retval[1] = 0;
return 0;
}
static void
irix_sproc_child(isc)
struct irix_sproc_child_args *isc;
{
struct proc *p2 = *isc->isc_proc;
struct frame *tf = (struct frame *)p2->p_md.md_regs;
/*
* Setup PC to return to the child entry point
*/
tf->f_regs[PC] = (unsigned long)isc->isc_entry;
/*
* Setup child arguments
*/
tf->f_regs[A0] = (unsigned long)isc->isc_arg;
tf->f_regs[A1] = tf->f_regs[S3]; /* XXX Really useful? */
/*
* We do not need isc anymore, we can wakeup our parent
*/
wakeup((void *)isc);
/*
* Return to userland for a newly created process
*/
child_return((void *)p2);
return;
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: irix_prctl.h,v 1.1 2001/12/02 09:23:59 manu Exp $ */
/* $NetBSD: irix_prctl.h,v 1.2 2002/04/28 17:21:59 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -62,4 +62,17 @@
#define IRIX_PR_THREAD_CTL 21
#define IRIX_PR_LASTSHEXIT 22
#define IRIX_PR_SPROC 0x00000001
#define IRIX_PR_SFDS 0x00000002
#define IRIX_PR_SDIR 0x00000004
#define IRIX_PR_SUMASK 0x00000008
#define IRIX_PR_SULIMIT 0x00000010
#define IRIX_PR_SID 0x00000020
#define IRIX_PR_SADDR 0x00000040
#define IRIX_PR_THREADS 0x00000080
#define IRIX_PR_BLOCK 0x01000000
#define IRIX_PR_NOLIBC 0x02000000
#define IRIX_PR_EVENT 0x04000000
#define IRIX_SPROC_STACK_OFFSET 0x04000000
#endif /* _IRIX_IRIX_PRCTL_H_ */

View File

@ -1,10 +1,10 @@
/* $NetBSD: irix_syscall.h,v 1.39 2002/04/23 05:47:38 manu Exp $ */
/* $NetBSD: irix_syscall.h,v 1.40 2002/04/28 17:21:59 manu Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.37 2002/04/22 05:58:49 manu Exp
* created from NetBSD: syscalls.master,v 1.38 2002/04/23 05:47:38 manu Exp
*/
/* syscall: "syscall" ret: "int" args: */
@ -286,9 +286,15 @@
/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" */
#define IRIX_SYS_gettimeofday 128
/* syscall: "sproc" ret: "irix_pid_t" args: "void *" "unsigned int" "void *" */
#define IRIX_SYS_sproc 129
/* syscall: "prctl" ret: "ptrdiff_t" args: "unsigned int" "void *" */
#define IRIX_SYS_prctl 130
/* syscall: "sprocsp" ret: "irix_pid_t" args: "void *" "unsigned int" "void *" "caddr_t" "irix_size_t" */
#define IRIX_SYS_sprocsp 132
/* syscall: "mmap" ret: "void *" args: "void *" "irix_size_t" "int" "int" "int" "irix_off_t" */
#define IRIX_SYS_mmap 134
@ -388,5 +394,8 @@
/* syscall: "ngetdents64" ret: "int" args: "int" "irix_dirent64_t *" "unsigned short" "int *" */
#define IRIX_SYS_ngetdents64 208
/* syscall: "pidsprocsp" ret: "irix_pid_t" args: "void *" "unsigned int" "void *" "caddr_t" "irix_size_t" "irix_pid_t" */
#define IRIX_SYS_pidsprocsp 210
#define IRIX_SYS_MAXSYSCALL 236
#define IRIX_SYS_NSYSENT 236

View File

@ -1,10 +1,10 @@
/* $NetBSD: irix_syscallargs.h,v 1.39 2002/04/23 05:47:38 manu Exp $ */
/* $NetBSD: irix_syscallargs.h,v 1.40 2002/04/28 17:21:59 manu Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.37 2002/04/22 05:58:49 manu Exp
* created from NetBSD: syscalls.master,v 1.38 2002/04/23 05:47:38 manu Exp
*/
#ifndef _IRIX_SYS__SYSCALLARGS_H_
@ -82,11 +82,25 @@ struct irix_sys_sigreturn_args {
syscallarg(int) signo;
};
struct irix_sys_sproc_args {
syscallarg(void *) entry;
syscallarg(unsigned int) inh;
syscallarg(void *) arg;
};
struct irix_sys_prctl_args {
syscallarg(unsigned int) option;
syscallarg(void *) arg1;
};
struct irix_sys_sprocsp_args {
syscallarg(void *) entry;
syscallarg(unsigned int) inh;
syscallarg(void *) arg;
syscallarg(caddr_t) sp;
syscallarg(irix_size_t) len;
};
struct irix_sys_mmap_args {
syscallarg(void *) addr;
syscallarg(irix_size_t) len;
@ -194,6 +208,15 @@ struct irix_sys_ngetdents64_args {
syscallarg(int *) eof;
};
struct irix_sys_pidsprocsp_args {
syscallarg(void *) entry;
syscallarg(unsigned int) inh;
syscallarg(void *) arg;
syscallarg(caddr_t) sp;
syscallarg(irix_size_t) len;
syscallarg(irix_pid_t) pid;
};
/*
* System call prototypes.
*/
@ -296,7 +319,9 @@ int sys_getitimer(struct proc *, void *, register_t *);
int sys_setitimer(struct proc *, void *, register_t *);
int sys_adjtime(struct proc *, void *, register_t *);
int svr4_sys_gettimeofday(struct proc *, void *, register_t *);
int irix_sys_sproc(struct proc *, void *, register_t *);
int irix_sys_prctl(struct proc *, void *, register_t *);
int irix_sys_sprocsp(struct proc *, void *, register_t *);
int irix_sys_mmap(struct proc *, void *, register_t *);
int sys_munmap(struct proc *, void *, register_t *);
int sys_mprotect(struct proc *, void *, register_t *);
@ -330,4 +355,5 @@ int irix_sys_getmountid(struct proc *, void *, register_t *);
int irix_sys_getdents64(struct proc *, void *, register_t *);
int irix_sys_ngetdents(struct proc *, void *, register_t *);
int irix_sys_ngetdents64(struct proc *, void *, register_t *);
int irix_sys_pidsprocsp(struct proc *, void *, register_t *);
#endif /* _IRIX_SYS__SYSCALLARGS_H_ */

View File

@ -1,14 +1,14 @@
/* $NetBSD: irix_syscalls.c,v 1.39 2002/04/23 05:47:38 manu Exp $ */
/* $NetBSD: irix_syscalls.c,v 1.40 2002/04/28 17:21:59 manu Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.37 2002/04/22 05:58:49 manu Exp
* created from NetBSD: syscalls.master,v 1.38 2002/04/23 05:47:38 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_syscalls.c,v 1.39 2002/04/23 05:47:38 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_syscalls.c,v 1.40 2002/04/28 17:21:59 manu Exp $");
#if defined(_KERNEL_OPT)
#if defined(_KERNEL_OPT)
@ -176,10 +176,10 @@ const char *const irix_syscallnames[] = {
"setitimer", /* 126 = setitimer */
"adjtime", /* 127 = adjtime */
"gettimeofday", /* 128 = gettimeofday */
"#129 (unimplemented sproc)", /* 129 = unimplemented sproc */
"sproc", /* 129 = sproc */
"prctl", /* 130 = prctl */
"#131 (unimplemented procblk)", /* 131 = unimplemented procblk */
"#132 (unimplemented sprocsp)", /* 132 = unimplemented sprocsp */
"sprocsp", /* 132 = sprocsp */
"#133 (unimplemented sgigsc)", /* 133 = unimplemented sgigsc */
"mmap", /* 134 = mmap */
"munmap", /* 135 = munmap */
@ -257,7 +257,7 @@ const char *const irix_syscallnames[] = {
"ngetdents", /* 207 = ngetdents */
"ngetdents64", /* 208 = ngetdents64 */
"#209 (unimplemented sgi_sesmgr)", /* 209 = unimplemented sgi_sesmgr */
"#210 (unimplemented pidsprocsp)", /* 210 = unimplemented pidsprocsp */
"pidsprocsp", /* 210 = pidsprocsp */
"#211 (unimplemented rexec)", /* 211 = unimplemented rexec */
"#212 (unimplemented timer_create)", /* 212 = unimplemented timer_create */
"#213 (unimplemented timer_delete)", /* 213 = unimplemented timer_delete */

View File

@ -1,14 +1,14 @@
/* $NetBSD: irix_sysent.c,v 1.39 2002/04/23 05:47:38 manu Exp $ */
/* $NetBSD: irix_sysent.c,v 1.40 2002/04/28 17:21:59 manu Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.37 2002/04/22 05:58:49 manu Exp
* created from NetBSD: syscalls.master,v 1.38 2002/04/23 05:47:38 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_sysent.c,v 1.39 2002/04/23 05:47:38 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_sysent.c,v 1.40 2002/04/28 17:21:59 manu Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ntp.h"
@ -308,14 +308,14 @@ struct sysent irix_sysent[] = {
sys_adjtime }, /* 127 = adjtime */
{ 1, s(struct svr4_sys_gettimeofday_args), 0,
svr4_sys_gettimeofday }, /* 128 = gettimeofday */
{ 0, 0, 0,
sys_nosys }, /* 129 = unimplemented sproc */
{ 3, s(struct irix_sys_sproc_args), 0,
irix_sys_sproc }, /* 129 = sproc */
{ 2, s(struct irix_sys_prctl_args), 0,
irix_sys_prctl }, /* 130 = prctl */
{ 0, 0, 0,
sys_nosys }, /* 131 = unimplemented procblk */
{ 0, 0, 0,
sys_nosys }, /* 132 = unimplemented sprocsp */
{ 5, s(struct irix_sys_sprocsp_args), 0,
irix_sys_sprocsp }, /* 132 = sprocsp */
{ 0, 0, 0,
sys_nosys }, /* 133 = unimplemented sgigsc */
{ 6, s(struct irix_sys_mmap_args), 0,
@ -470,8 +470,8 @@ struct sysent irix_sysent[] = {
irix_sys_ngetdents64 }, /* 208 = ngetdents64 */
{ 0, 0, 0,
sys_nosys }, /* 209 = unimplemented sgi_sesmgr */
{ 0, 0, 0,
sys_nosys }, /* 210 = unimplemented pidsprocsp */
{ 6, s(struct irix_sys_pidsprocsp_args), 0,
irix_sys_pidsprocsp }, /* 210 = pidsprocsp */
{ 0, 0, 0,
sys_nosys }, /* 211 = unimplemented rexec */
{ 0, 0, 0,

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.38 2002/04/23 05:47:38 manu Exp $
$NetBSD: syscalls.master,v 1.39 2002/04/28 17:21:59 manu Exp $
; @(#)syscalls.master 8.1 (Berkeley) 7/19/93
@ -244,11 +244,14 @@
127 NOARGS { int sys_adjtime(struct timeval *delta, \
struct timeval *olddelta); }
128 NOARGS { int svr4_sys_gettimeofday(struct timeval *tp); }
129 UNIMPL sproc
129 STD { irix_pid_t irix_sys_sproc(void *entry, \
unsigned int inh, void *arg); }
130 STD { ptrdiff_t irix_sys_prctl(unsigned int option, \
void *arg1); }
131 UNIMPL procblk
132 UNIMPL sprocsp
132 STD { irix_pid_t irix_sys_sprocsp(void *entry, \
unsigned int inh, void *arg, caddr_t sp, \
irix_size_t len); }
133 UNIMPL sgigsc
134 STD { void *irix_sys_mmap(void *addr, irix_size_t len, \
int prot, int flags, int fd, irix_off_t pos); }
@ -355,7 +358,9 @@
irix_dirent64_t *buf, unsigned short nbyte, \
int *eof); }
209 UNIMPL sgi_sesmgr
210 UNIMPL pidsprocsp
210 STD { irix_pid_t irix_sys_pidsprocsp(void *entry, \
unsigned int inh, void *arg, caddr_t sp, \
irix_size_t len, irix_pid_t pid); }
211 UNIMPL rexec
212 UNIMPL timer_create
213 UNIMPL timer_delete