Date: Thu, 11 Mar 2004 16:11:50 +0000 From: Antony T Curtis <antony.t.curtis@ntlworld.com> To: Robert Watson <rwatson@freebsd.org> Cc: David Gilbert <dgilbert@dclg.ca> Subject: Re: usermode linux on BSD? Message-ID: <1079021510.6829.444.camel@pcgem.rdg.cyberkinetica.com> In-Reply-To: <Pine.NEB.3.96L.1040310091301.52867E-100000@fledge.watson.org> References: <Pine.NEB.3.96L.1040310091301.52867E-100000@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 2004-03-10 at 14:13, Robert Watson wrote: > On Wed, 10 Mar 2004, David Gilbert wrote: > > > Has anyone made an attempt to run usermode linux on FreeBSD? Is the > > issue-list long? > > There was a neat paper at BSDCon 2003 discussing running usermode FreeBSD > on Linux, and it talked about what would be necessary to make usermode > FreeBSD run on FreeBSD. You can find the paper off the USENIX web site, > or perhaps via Google. I think it was a relatively small set of changes. I have been toying with user mode BSD... and maybe even run user-mode Linux on FreeBSD.... And one of the requirements is to be able to alter syscalls in flight. I think something line the following patch would help... The concept goes something like this... The User-mode-unix would rfork and set up ptrace, The parent monitors the child process for syscalls... child = rfork_thread(RFPROC|RFMEM, stack, child_func, NULL); waitpid(child, &status, WUNTRACED); ptrace(PT_TO_SCE, child, (caddr_t)1, 0); for (;;) { waitpid(child, &status, WUNTRACED); if (WSTOPSIG(status) == SIGTRAP) { struct reg r; ptrace(PT_GETREGS, child, (caddr_t)&r, 0); save_syscall= r.r_eax; r.r_eax = SYS_getpid; ptrace(PT_SETREGS, child, (caddr_t)&r, 0); ptrace(PT_TO_SCX, child, (caddr_t)1, 0); waitpid(child, &status, WUNTRACED); ptrace(PT_GETREGS, child, (caddr_t)&r, 0); r.r_eax = save_syscall; simulate_syscall(&r); ptrace(PT_SETREGS, child, (caddr_t)&r, 0); } ptrace(PT_TO_SCE, child, (caddr_t)1, 0); } User mode Linux works with a similar mechanism. BTW, I haven't yet tested the patch below - just want some wiser, more experienced eyes to look at it first. --- trap.c.orig Thu Mar 11 15:22:17 2004 +++ trap.c Thu Mar 11 15:50:06 2004 @@ -936,6 +936,7 @@ cred_update_thread(td); if (p->p_flag & P_SA) thread_user_enter(p, td); + redo_syscall: params = (caddr_t)frame.tf_esp + sizeof(int); code = frame.tf_eax; orig_tf_eflags = frame.tf_eflags; @@ -1003,7 +1004,17 @@ STOPEVENT(p, S_SCE, narg); - PTRACESTOP_SC(p, td, S_PT_SCE); + + if ((p->p_flag & P_TRACED) && (p->p_stops & S_PT_SCE)) { + PROC_LOCK(p); + ptracestop(td, SIGTRAP); + if (!((p->p_flag & P_TRACED) && + (p->p_stops & S_PT_SCE))) { + if ((callp->sy_narg & SYF_MPSAFE) == 0) + mtx_unlock(&Giant); + goto redo_syscall; + } + } error = (*callp->sy_call)(td, args); } > Robert N M Watson FreeBSD Core Team, TrustedBSD Projects > robert@fledge.watson.org Senior Research Scientist, McAfee Research > > > > > > Dave. > > > > -- > > ============================================================================ > > |David Gilbert, Independent Contractor. | Two things can only be | > > |Mail: dave@daveg.ca | equal if and only if they | > > |http://daveg.ca | are precisely opposite. | > > =========================================================GLO================ > > _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" > > > > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" > FLAGS (\Seen)) -- Antony T Curtis BSc Unix Analyst Programmer http://homepage.ntlworld.com/antony.t.curtis/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1079021510.6829.444.camel>