Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat/irix Implements IRIX sproc(2) and friends.



details:   https://anonhg.NetBSD.org/src/rev/2e61763a42a4
branches:  trunk
changeset: 526226:2e61763a42a4
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Apr 28 17:21:58 2002 +0000

description:
Implements IRIX sproc(2) and friends.
There may be a problem with stack size overflow in this implementation

diffstat:

 sys/compat/irix/irix_prctl.c       |  196 ++++++++++++++++++++++++++++++++++++-
 sys/compat/irix/irix_prctl.h       |   17 ++-
 sys/compat/irix/irix_syscall.h     |   13 ++-
 sys/compat/irix/irix_syscallargs.h |   30 +++++-
 sys/compat/irix/irix_syscalls.c    |   12 +-
 sys/compat/irix/irix_sysent.c      |   18 +-
 sys/compat/irix/syscalls.master    |   13 +-
 7 files changed, 271 insertions(+), 28 deletions(-)

diffs (truncated from 506 to 300 lines):

diff -r 91df2de70c14 -r 2e61763a42a4 sys/compat/irix/irix_prctl.c
--- a/sys/compat/irix/irix_prctl.c      Sun Apr 28 17:21:33 2002 +0000
+++ b/sys/compat/irix/irix_prctl.c      Sun Apr 28 17:21:58 2002 +0000
@@ -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 @@
 #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 @@
        }
        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;
+}
+
diff -r 91df2de70c14 -r 2e61763a42a4 sys/compat/irix/irix_prctl.h
--- a/sys/compat/irix/irix_prctl.h      Sun Apr 28 17:21:33 2002 +0000
+++ b/sys/compat/irix/irix_prctl.h      Sun Apr 28 17:21:58 2002 +0000
@@ -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_ */
diff -r 91df2de70c14 -r 2e61763a42a4 sys/compat/irix/irix_syscall.h
--- a/sys/compat/irix/irix_syscall.h    Sun Apr 28 17:21:33 2002 +0000
+++ b/sys/compat/irix/irix_syscall.h    Sun Apr 28 17:21:58 2002 +0000
@@ -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



Home | Main Index | Thread Index | Old Index