Date: Wed, 11 Nov 1998 12:25:50 -0500 (EST) From: Brian Feldman <green@unixhelp.org> To: current@FreeBSD.ORG Subject: Re: RFSIGSHARE ready? (fwd) Message-ID: <Pine.BSF.4.05.9811111225130.24080-100000@janus.syracuse.net>
next in thread | raw e-mail | index | archive | help
Sorry, this message should have gotten sent correctly the first time :( freebsd itself is not a domain though, so here it is. ---------- Forwarded message ---------- Date: Wed, 11 Nov 1998 12:23:46 -0500 (EST) From: Brian Feldman <green@unixhelp.org> To: "Richard Seaman, Jr." <lists@tar.com> Cc: "current@freebsd." <current@freebsd> Subject: Re: RFSIGSHARE ready? Thanks, you're helping a lot here! We're trying to accomplish different things, and imho mine is the only correct way. We need to be entirely binary-compatible with Linux (not FreeBSD binaries, but be able to run Linux binaries, static, unmodified), and this will have to be done in the kernel. I'm going to take you're information and work on LinuxThreads more. Since you know the code, here's your assignment(should you choose to accept it;): using the original LinuxThreads code (NO mods except for debug info) and compiling with a Linux cross-devel toolchain, I need you're assistance figuring out what's wrong here. In some programs, the program getsto spinning in pthread_handle_create and CANNOT be killed, for some reason or another. In other cases, tsleep (invoked from sigsuspend) is sleeping forever, of course wakeup works but it's still in a while() loop so it just continues. In this manner, both situations are unkillable, no matter WHAT signal is sent (I sent all of them to test by the way) Example: 294 green 89 0 1068K 440K RUN 22:15 93.77% 93.77% ex5 {"/home/green"}$ for i in USR1 USR2 ILL SEGV KILL BUS > do kill -$i 294 > done 294 green 105 0 1068K 440K RUN 23:15 96.21% 96.21% ex5 Think you can figure this all out, at least somewhat? I'll see about the stack allocation MAP_GROWSDOWN, look how it's done in sys/vm. It would be helpful if you (or anyone else reading this) would help out as much as possible. For instance, if someone would figure out why I am not able to signal these processes for instance (perhaps a stupid coding bug about initialization of a member of struct proc/(user/procsig), and I'm unintentionally creating an artificial signal blocking situation? Thanks in advance to all who will help. Cheers, Brian Feldman And here are the latest patches, which now have parent signaling implemented: --- src/sys/i386/linux/linux_dummy.c.orig Thu Nov 6 14:28:52 1997 +++ src/sys/i386/linux/linux_dummy.c Wed Nov 11 11:20:58 1998 @@ -212,13 +212,6 @@ } int -linux_clone(struct proc *p, struct linux_clone_args *args) -{ - printf("Linux-emul(%d): clone() not supported\n", p->p_pid); - return ENOSYS; -} - -int linux_uname(struct proc *p, struct linux_uname_args *args) { printf("Linux-emul(%d): uname() not supported\n", p->p_pid); --- src/sys/i386/linux/linux_misc.c.orig Mon Oct 5 08:40:42 1998 +++ src/sys/i386/linux/linux_misc.c Wed Nov 11 11:26:15 1998 @@ -41,6 +41,7 @@ #include <sys/resourcevar.h> #include <sys/stat.h> #include <sys/sysctl.h> +#include <sys/unistd.h> #include <sys/vnode.h> #include <sys/wait.h> #include <sys/time.h> @@ -558,6 +559,55 @@ if (p->p_retval[1] == 1) p->p_retval[0] = 0; return 0; +} + +#define CLONE_VM 0x100 +#define CLONE_FS 0x200 +#define CLONE_FILES 0x400 +#define CLONE_SIGHAND 0x800 +#define CLONE_PID 0x1000 + +int +linux_clone(struct proc *p, struct linux_clone_args *args) +{ + int error, ff = RFPROC, top; + struct proc *p2; + +#ifdef SMP + printf("linux_clone(%d): does not work with SMP\n", p->p_pid); + return (EOPNOTSUPP); +#else +#ifdef DEBUG_CLONE + if (args->flags & CLONE_PID) + printf("linux_clone(%d): CLONE_PID not yet supported\n", p->p_pid); + if (args->flags & CLONE_FS) + printf("linux_clone(%d): CLONE_FS not yet supported\n", p->p_pid); +#endif + if (args->flags & CLONE_VM) + ff |= RFMEM; + if (args->flags & CLONE_SIGHAND) + ff |= RFSIGSHARE; + if (!(args->flags & CLONE_FILES)) + ff |= RFFDG; + if (error = fork1(p, ff)) + return error; + p2 = pfind(p->p_retval[0]); + if (p2 == 0) + return ESRCH; + if (args->stack) { + copyin(args->stack, &top, 4); + p2->p_md.md_regs->tf_esp = (int)args->stack; + p2->p_md.md_regs->tf_eip = top; + } + p2->p_sigparent = args->flags & 0x000000ff; +#ifdef DEBUG_CLONE + copyin(args->stack + 4, &top, 4); + printf("linux_clone: pids %d, %d; child eip=%#x, esp=%#x, *esp=%#x\n", + p->p_pid, p2->p_pid, p2->p_md.md_regs->tf_eip, p2->p_md.md_regs->tf_esp, + top); +#endif + return 0; +#endif } /* XXX move */ --- src/sys/i386/linux/linux_proto.h.orig Fri Jul 10 18:30:04 1998 +++ src/sys/i386/linux/linux_proto.h Wed Nov 11 11:20:58 1998 @@ -2,7 +2,7 @@ * System call prototypes. * * DO NOT EDIT-- this file is automatically generated. - * created from Id: syscalls.master,v 1.11 1998/06/09 03:28:14 bde Exp + * created from Id: syscalls.master,v 1.12 1998/07/10 22:30:08 jkh Exp */ #ifndef _LINUX_SYSPROTO_H_ @@ -301,7 +301,8 @@ struct linux_sigcontext * scp; char scp_[PAD_(struct linux_sigcontext *)]; }; struct linux_clone_args { - register_t dummy; + int flags; char flags_[PAD_(int)]; + void * stack; char stack_[PAD_(void *)]; }; struct linux_newuname_args { struct linux_newuname_t * buf; char buf_[PAD_(struct linux_newuname_t *)]; --- src/sys/i386/linux/linux_syscall.h.orig Fri Jul 10 18:30:06 1998 +++ src/sys/i386/linux/linux_syscall.h Wed Nov 11 11:20:58 1998 @@ -2,7 +2,7 @@ * System call numbers. * * DO NOT EDIT-- this file is automatically generated. - * created from Id: syscalls.master,v 1.11 1998/06/09 03:28:14 bde Exp + * created from Id: syscalls.master,v 1.12 1998/07/10 22:30:08 jkh Exp */ #define LINUX_SYS_linux_setup 0 --- src/sys/i386/linux/linux_sysent.c.orig Fri Jul 10 18:30:07 1998 +++ src/sys/i386/linux/linux_sysent.c Wed Nov 11 11:20:59 1998 @@ -2,7 +2,7 @@ * System call switch table. * * DO NOT EDIT-- this file is automatically generated. - * created from Id: syscalls.master,v 1.11 1998/06/09 03:28:14 bde Exp + * created from Id: syscalls.master,v 1.12 1998/07/10 22:30:08 jkh Exp */ #include "opt_compat.h" @@ -134,7 +134,7 @@ { 5, (sy_call_t *)linux_ipc }, /* 117 = linux_ipc */ { 1, (sy_call_t *)fsync }, /* 118 = fsync */ { 1, (sy_call_t *)linux_sigreturn }, /* 119 = linux_sigreturn */ - { 0, (sy_call_t *)linux_clone }, /* 120 = linux_clone */ + { 2, (sy_call_t *)linux_clone }, /* 120 = linux_clone */ { 2, (sy_call_t *)setdomainname }, /* 121 = setdomainname */ { 1, (sy_call_t *)linux_newuname }, /* 122 = linux_newuname */ { 3, (sy_call_t *)linux_modify_ldt }, /* 123 = linux_modify_ldt */ --- src/sys/i386/linux/syscalls.master.orig Fri Jul 10 18:30:08 1998 +++ src/sys/i386/linux/syscalls.master Wed Nov 11 11:20:59 1998 @@ -171,7 +171,7 @@ caddr_t ptr); } 118 NOPROTO LINUX { int fsync(int fd); } 119 STD LINUX { int linux_sigreturn(struct linux_sigcontext *scp); } -120 STD LINUX { int linux_clone(void); } +120 STD LINUX { int linux_clone(int flags, void *stack); } 121 NOPROTO LINUX { int setdomainname(char *name, \ int len); } 122 STD LINUX { int linux_newuname(struct linux_newuname_t *buf); } --- src/sys/kern/kern_fork.c.orig Mon Nov 9 10:07:41 1998 +++ src/sys/kern/kern_fork.c Wed Nov 11 11:24:06 1998 @@ -325,6 +325,17 @@ p2->p_cred->p_refcnt = 1; crhold(p1->p_ucred); + if (flags & RFSIGSHARE) { + p2->p_sig->ps_refcnt++; + } else { + p2->p_sig = malloc(sizeof(struct procsig), M_TEMP, M_WAITOK); + p2->p_sig->ps_refcnt = 1; + bcopy(&p1->p_sig->ps_begincopy, &p2->p_sig->ps_begincopy, + (unsigned)&p1->p_sig->ps_endcopy - + (unsigned)&p1->p_sig->ps_begincopy); + p2->p_sigacts = &p2->p_sig->ps_sigacts; + } + /* bump references to the text vnode (for procfs) */ p2->p_textvp = p1->p_textvp; if (p2->p_textvp) --- src/sys/kern/kern_exit.c.orig Wed Nov 11 05:03:54 1998 +++ src/sys/kern/kern_exit.c Wed Nov 11 11:23:05 1998 @@ -324,6 +324,14 @@ /* move this to cpu_exit */ p->p_addr->u_pcb.pcb_savacc.faddr = (float *)NULL; #endif + + if (p->p_sigparent && p->p_pptr->p_pid != 1) { + struct kill_args ka; + ka.signum = p->p_sigparent; + ka.pid = p->p_pptr->p_pid; + kill(p, &ka); + } + /* * Clear curproc after we've done all operations * that could block, and before tearing down the rest @@ -339,6 +347,9 @@ FREE(p->p_limit, M_SUBPROC); p->p_limit = NULL; } + + if (--p->p_sig->ps_refcnt == 0) + free(p->p_sig, M_TEMP); /* * Finally, call machine-dependent code to release the remaining --- src/sys/kern/init_main.c.orig Thu Oct 15 13:09:19 1998 +++ src/sys/kern/init_main.c Wed Nov 11 11:20:59 1998 @@ -83,6 +83,7 @@ static struct pgrp pgrp0; struct proc proc0; static struct pcred cred0; +static struct procsig procsig0; static struct filedesc0 filedesc0; static struct plimit limit0; static struct vmspace vmspace0; @@ -415,6 +416,10 @@ p->p_ucred = crget(); p->p_ucred->cr_ngroups = 1; /* group 0 */ + /* Create procsig. */ + p->p_sig = &procsig0; + p->p_sig->ps_refcnt = 2; + /* Create the file descriptor table. */ fdp = &filedesc0; p->p_fd = &fdp->fd_fd; @@ -461,11 +466,12 @@ #endif /* - * We continue to place resource usage info and signal - * actions in the user struct so they're pageable. + * We continue to place resource usage info in the user struct so + * it's pageable. */ p->p_stats = &p->p_addr->u_stats; - p->p_sigacts = &p->p_addr->u_sigacts; + + p->p_sigacts = &p->p_sig->ps_sigacts; /* * Charge root for one process. --- src/sys/sys/proc.h.orig Wed Nov 11 05:56:05 1998 +++ src/sys/sys/proc.h Wed Nov 11 11:22:17 1998 @@ -47,6 +47,7 @@ #include <sys/rtprio.h> /* For struct rtprio. */ #include <sys/select.h> /* For struct selinfo. */ #include <sys/signal.h> +#include <sys/signalvar.h> #ifndef KERNEL #include <sys/time.h> /* For structs itimerval, timeval. */ #endif @@ -78,6 +79,16 @@ int pg_jobc; /* # procs qualifying pgrp for job control */ }; +struct procsig { +#define ps_begincopy ps_sigmask + sigset_t ps_sigmask; /* Current signal mask. */ + sigset_t ps_sigignore; /* Signals being ignored. */ + sigset_t ps_sigcatch; /* Signals being caught by user. */ + struct sigacts ps_sigacts; +#define ps_endcopy ps_refcnt + int ps_refcnt; +}; + /* * Description of a process. * @@ -164,17 +175,18 @@ char p_pad3[2]; /* padding for alignment */ register_t p_retval[2]; /* syscall aux returns */ struct sigiolst p_sigiolst; /* list of sigio sources */ + int p_sigparent; /* signal to parent on exit */ /* End area that is zeroed on creation. */ #define p_endzero p_startcopy /* The following fields are all copied upon creation in fork. */ -#define p_startcopy p_sigmask - - sigset_t p_sigmask; /* Current signal mask. */ - sigset_t p_sigignore; /* Signals being ignored. */ - sigset_t p_sigcatch; /* Signals being caught by user. */ +#define p_startcopy p_sig + struct procsig *p_sig; +#define p_sigmask p_sig->ps_sigmask +#define p_sigignore p_sig->ps_sigignore +#define p_sigcatch p_sig->ps_sigcatch u_char p_priority; /* Process priority. */ u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */ char p_nice; /* Process "nice" value. */ --- src/sys/sys/unistd.h.orig Sat Mar 28 06:51:01 1998 +++ src/sys/sys/unistd.h Wed Nov 11 11:20:59 1998 @@ -186,6 +186,7 @@ #define RFCENVG (1<<11) /* UNIMPL zero plan9 `env space' */ #define RFCFDG (1<<12) /* zero fd table */ #define RFTHREAD (1<<13) /* enable kernel thread support */ +#define RFSIGSHARE (1<<14) /* share signal masks */ #define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ #endif /* !_POSIX_SOURCE */ --- src/sys/sys/user.h.orig Wed Jul 15 16:18:00 1998 +++ src/sys/sys/user.h Wed Nov 11 11:20:59 1998 @@ -102,7 +102,6 @@ struct user { struct pcb u_pcb; - struct sigacts u_sigacts; /* p_sigacts points here (use it!) */ struct pstats u_stats; /* p_stats points here (use it!) */ /* --- src/sys/sys/proc.h.orig Wed Nov 11 05:56:05 1998 +++ src/sys/sys/proc.h Wed Nov 11 11:22:17 1998 @@ -47,6 +47,7 @@ #include <sys/rtprio.h> /* For struct rtprio. */ #include <sys/select.h> /* For struct selinfo. */ #include <sys/signal.h> +#include <sys/signalvar.h> #ifndef KERNEL #include <sys/time.h> /* For structs itimerval, timeval. */ #endif @@ -78,6 +79,16 @@ int pg_jobc; /* # procs qualifying pgrp for job control */ }; +struct procsig { +#define ps_begincopy ps_sigmask + sigset_t ps_sigmask; /* Current signal mask. */ + sigset_t ps_sigignore; /* Signals being ignored. */ + sigset_t ps_sigcatch; /* Signals being caught by user. */ + struct sigacts ps_sigacts; +#define ps_endcopy ps_refcnt + int ps_refcnt; +}; + /* * Description of a process. * @@ -164,17 +175,18 @@ char p_pad3[2]; /* padding for alignment */ register_t p_retval[2]; /* syscall aux returns */ struct sigiolst p_sigiolst; /* list of sigio sources */ + int p_sigparent; /* signal to parent on exit */ /* End area that is zeroed on creation. */ #define p_endzero p_startcopy /* The following fields are all copied upon creation in fork. */ -#define p_startcopy p_sigmask - - sigset_t p_sigmask; /* Current signal mask. */ - sigset_t p_sigignore; /* Signals being ignored. */ - sigset_t p_sigcatch; /* Signals being caught by user. */ +#define p_startcopy p_sig + struct procsig *p_sig; +#define p_sigmask p_sig->ps_sigmask +#define p_sigignore p_sig->ps_sigignore +#define p_sigcatch p_sig->ps_sigcatch u_char p_priority; /* Process priority. */ u_char p_usrpri; /* User-priority based on p_cpu and p_nice. */ char p_nice; /* Process "nice" value. */ --- src/sys/vm/vm_glue.c.orig Tue Oct 13 04:24:43 1998 +++ src/sys/vm/vm_glue.c Wed Nov 11 11:20:59 1998 @@ -235,8 +235,6 @@ * p_stats; zero the rest of p_stats (statistics). */ p2->p_stats = &up->u_stats; - p2->p_sigacts = &up->u_sigacts; - up->u_sigacts = *p1->p_sigacts; bzero(&up->u_stats.pstat_startzero, (unsigned) ((caddr_t) &up->u_stats.pstat_endzero - (caddr_t) &up->u_stats.pstat_startzero)); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9811111225130.24080-100000>