From owner-svn-src-head@freebsd.org Mon Jul 20 13:46:23 2015 Return-Path: Delivered-To: svn-src-head@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 8D5429A5040; Mon, 20 Jul 2015 13:46:23 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 63B708D4; Mon, 20 Jul 2015 13:46:23 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6KDkNPZ077569; Mon, 20 Jul 2015 13:46:23 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6KDkMht077567; Mon, 20 Jul 2015 13:46:22 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201507201346.t6KDkMht077567@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Mon, 20 Jul 2015 13:46:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285716 - in head/sys: amd64/cloudabi64 compat/cloudabi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jul 2015 13:46:23 -0000 Author: ed Date: Mon Jul 20 13:46:22 2015 New Revision: 285716 URL: https://svnweb.freebsd.org/changeset/base/285716 Log: Make forking of CloudABI processes work. Just like FreeBSD+Capsicum, CloudABI uses process descriptors. Return the file descriptor number to the parent process. To the child process we both return a special value for the file descriptor number (CLOUDABI_PROCESS_CHILD). We also return the thread ID of the new thread in the copied process, so the threading library can reinitialize itself. Obtained from: https://github.com/NuxiNL/freebsd Modified: head/sys/amd64/cloudabi64/cloudabi64_sysvec.c head/sys/compat/cloudabi/cloudabi_proc.c Modified: head/sys/amd64/cloudabi64/cloudabi64_sysvec.c ============================================================================== --- head/sys/amd64/cloudabi64/cloudabi64_sysvec.c Mon Jul 20 10:20:04 2015 (r285715) +++ head/sys/amd64/cloudabi64/cloudabi64_sysvec.c Mon Jul 20 13:46:22 2015 (r285716) @@ -169,6 +169,16 @@ cloudabi64_set_syscall_retval(struct thr } } +static void +cloudabi64_schedtail(struct thread *td) +{ + struct trapframe *frame = td->td_frame; + + /* Initial register values for processes returning from fork. */ + frame->tf_rax = CLOUDABI_PROCESS_CHILD; + frame->tf_rdx = td->td_tid; +} + static struct sysentvec cloudabi64_elf_sysvec = { .sv_size = CLOUDABI64_SYS_MAXSYSCALL, .sv_table = cloudabi64_sysent, @@ -185,6 +195,7 @@ static struct sysentvec cloudabi64_elf_s .sv_set_syscall_retval = cloudabi64_set_syscall_retval, .sv_fetch_syscall_args = cloudabi64_fetch_syscall_args, .sv_syscallnames = cloudabi64_syscallnames, + .sv_schedtail = cloudabi64_schedtail, }; INIT_SYSENTVEC(elf_sysvec, &cloudabi64_elf_sysvec); Modified: head/sys/compat/cloudabi/cloudabi_proc.c ============================================================================== --- head/sys/compat/cloudabi/cloudabi_proc.c Mon Jul 20 10:20:04 2015 (r285715) +++ head/sys/compat/cloudabi/cloudabi_proc.c Mon Jul 20 13:46:22 2015 (r285716) @@ -33,8 +33,10 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include int cloudabi_sys_proc_exec(struct thread *td, @@ -65,9 +67,15 @@ int cloudabi_sys_proc_fork(struct thread *td, struct cloudabi_sys_proc_fork_args *uap) { + struct proc *p2; + int error, fd; - /* Not implemented. */ - return (ENOSYS); + error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2, &fd, 0); + if (error != 0) + return (error); + /* Return the file descriptor to the parent process. */ + td->td_retval[0] = fd; + return (0); } int