From owner-svn-src-all@freebsd.org Sat Jul 11 19:47:38 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB5DD9998FA; Sat, 11 Jul 2015 19:47:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 53BAE1A9D; Sat, 11 Jul 2015 19:47:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t6BJlWSv014775 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 11 Jul 2015 22:47:33 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t6BJlWSv014775 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t6BJlWBZ014774; Sat, 11 Jul 2015 22:47:32 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 11 Jul 2015 22:47:32 +0300 From: Konstantin Belousov To: Ed Schouten Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r285404 - head/sys/compat/cloudabi Message-ID: <20150711194732.GB2404@kib.kiev.ua> References: <201507111941.t6BJfV1a072539@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201507111941.t6BJfV1a072539@repo.freebsd.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Jul 2015 19:47:39 -0000 On Sat, Jul 11, 2015 at 07:41:31PM +0000, Ed Schouten wrote: > Author: ed > Date: Sat Jul 11 19:41:31 2015 > New Revision: 285404 > URL: https://svnweb.freebsd.org/changeset/base/285404 > > Log: > Implement normal and abnormal process termination. > > CloudABI does not provide an explicit kill() system call, for the reason > that there is no access to the global process namespace. Instead, it > offers a raise() system call that can at least be used to terminate the > process abnormally. > > CloudABI does not support installing signal handlers. CloudABI's raise() > system call should behave as if the default policy is set up. Call into > kern_sigaction(SIG_DFL) before calling sys_kill() to force this. > > Obtained from: https://github.com/NuxiNL/freebsd > > Modified: > head/sys/compat/cloudabi/cloudabi_proc.c > > Modified: head/sys/compat/cloudabi/cloudabi_proc.c > ============================================================================== > --- head/sys/compat/cloudabi/cloudabi_proc.c Sat Jul 11 19:14:09 2015 (r285403) > +++ head/sys/compat/cloudabi/cloudabi_proc.c Sat Jul 11 19:41:31 2015 (r285404) > @@ -26,6 +26,11 @@ > #include > __FBSDID("$FreeBSD$"); > > +#include > +#include > +#include > +#include > + > #include > > int > @@ -42,8 +47,8 @@ cloudabi_sys_proc_exit(struct thread *td > struct cloudabi_sys_proc_exit_args *uap) > { > > - /* Not implemented. */ > - return (ENOSYS); > + exit1(td, W_EXITCODE(uap->rval, 0)); > + /* NOTREACHED */ > } > > int > @@ -59,7 +64,49 @@ int > cloudabi_sys_proc_raise(struct thread *td, > struct cloudabi_sys_proc_raise_args *uap) > { > - > - /* Not implemented. */ > - return (ENOSYS); > + static const int signals[] = { > + [CLOUDABI_SIGABRT] = SIGABRT, > + [CLOUDABI_SIGALRM] = SIGALRM, > + [CLOUDABI_SIGBUS] = SIGBUS, > + [CLOUDABI_SIGCHLD] = SIGCHLD, > + [CLOUDABI_SIGCONT] = SIGCONT, > + [CLOUDABI_SIGFPE] = SIGFPE, > + [CLOUDABI_SIGHUP] = SIGHUP, > + [CLOUDABI_SIGILL] = SIGILL, > + [CLOUDABI_SIGINT] = SIGINT, > + [CLOUDABI_SIGKILL] = SIGKILL, > + [CLOUDABI_SIGPIPE] = SIGPIPE, > + [CLOUDABI_SIGQUIT] = SIGQUIT, > + [CLOUDABI_SIGSEGV] = SIGSEGV, > + [CLOUDABI_SIGSTOP] = SIGSTOP, > + [CLOUDABI_SIGSYS] = SIGSYS, > + [CLOUDABI_SIGTERM] = SIGTERM, > + [CLOUDABI_SIGTRAP] = SIGTRAP, > + [CLOUDABI_SIGTSTP] = SIGTSTP, > + [CLOUDABI_SIGTTIN] = SIGTTIN, > + [CLOUDABI_SIGTTOU] = SIGTTOU, > + [CLOUDABI_SIGURG] = SIGURG, > + [CLOUDABI_SIGUSR1] = SIGUSR1, > + [CLOUDABI_SIGUSR2] = SIGUSR2, > + [CLOUDABI_SIGVTALRM] = SIGVTALRM, > + [CLOUDABI_SIGXCPU] = SIGXCPU, > + [CLOUDABI_SIGXFSZ] = SIGXFSZ, > + }; > + static const struct sigaction sigdfl = { > + .sa_handler = SIG_DFL, > + }; > + struct kill_args kill_args = { > + .pid = td->td_proc->p_pid, > + }; > + > + if (uap->sig >= nitems(signals) || > + (uap->sig != 0 && signals[uap->sig] == 0)) { > + /* Invalid signal. */ > + return (EINVAL); > + } > + kill_args.signum = signals[uap->sig]; > + > + /* Restore to default signal action and send signal. */ > + kern_sigaction(td, kill_args.signum, &sigdfl, NULL, 0); > + return (sys_kill(td, &kill_args)); > } This is very strange and unmaintanable approach. Also, you cannot handle traps this way. If your ABI does not provide any way to install a signal handler, then you probably should be already fully set up, due to execsigs() performed on each exec(2).