From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 22 09:42:15 2007 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ED17216A469 for ; Wed, 22 Aug 2007 09:42:15 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.227]) by mx1.freebsd.org (Postfix) with ESMTP id A907F13C48E for ; Wed, 22 Aug 2007 09:42:15 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: by wx-out-0506.google.com with SMTP id i29so109640wxd for ; Wed, 22 Aug 2007 02:42:14 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ENKNQevGb8ZVMZy0E827bMsVhK3Km3XL7W1osJZmYLuJsvJFuoe2oxwgpvotnQNX+YAQRIOk81p+qV3S5eoyUVKSMaHxfoN6WAIgYqHZTue6eH/t3jqCGJIv/57/m5FJbtwbYQBTSMhUKIedGRA/kA4rMpNLqBP4SEVUUfDc/xQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=t1/qgTlQzk9DZDXe+qv9k6g6iPC5cz2oOMISMLf1DrGzQgMhFyB/y+sm4XBXJM8dYkpxgHrJnmHn0mCPG4AocX0RV9MTkNHBG3konpLev6FKF9gI4i+bleYJSsTieth49Bt80xVnB7TsnzggUJLV64RBISLpZHKfc+V6fzlibpQ= Received: by 10.90.83.14 with SMTP id g14mr4030730agb.1187775733229; Wed, 22 Aug 2007 02:42:13 -0700 (PDT) Received: by 10.90.84.15 with HTTP; Wed, 22 Aug 2007 02:42:13 -0700 (PDT) Message-ID: Date: Wed, 22 Aug 2007 13:42:13 +0400 From: "Yuriy Tsibizov" To: freebsd-hackers@freebsd.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Mailman-Approved-At: Wed, 22 Aug 2007 11:26:37 +0000 Cc: freebsd-emulation@freebsd.org Subject: Re: User-mode Linux (Was: modify syscall nr on-the-fly) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Aug 2007 09:42:16 -0000 > 2007/8/21, Yuriy Tsibizov : > > 2007/8/20, Kostik Belousov : > > > On Sat, Aug 18, 2007 at 02:01:26PM +0400, Yuriy Tsibizov wrote: > > > > I'm trying to get user-mode Linux to run under FreeBSD Linux emulation (on > > > > i386). > > > > > > > > User-mode Linux in it's start-up tests tries to modify syscall number (to be > > > > called by kernel) on-the-fly > > > > (http://fxr.watson.org/fxr/source/arch/um/os-Linux/start_up.c?v=linux-2.6). > > > > It forks a child thread that stops > > > > (using SIGSTOP), calls getpid() (that will be intercepted by parent thread > > > > using PTRACE_SYSCALL) > > > > and return some value based on getpid() results. Main thread waits for > > > > SIGSTOP in child process and > > > > enables PTRACE_SYSCALL (I have some code that implements it. It makes some > > > > incompatible changes > > > > to PT_SYSCALL that will break FreeBSD applications, but works for Linux > > > > apps). When main thread > > > > catches SIGTRAP (generated by ptrace) it tries to modify EAX of child thread > > > > (with PTRACE_PEEKUSR > > > > and PTRACE_POKEUSR) to replace getpid syscall with getppid. > > > > > > > > is it possible to get updated EAX (and other registers as well) in > > > > syscall(...) after ptracestop(...) in PTRACESTOP_SC(...) returns? > > > > > > > > Hope for your help, > > > > > > > > Yuriy. > > > > > > If I understand right what you want, I doubt that existing code would > > > allow you to change syscall number in debugger process for debuggee. > > > You shall look at the sys/i386/i386/trap.c, syscall() function [adjust > > > as needed for other arches]. It calculates callp before doing PTRACESTOP_SC, > > > as well as copies the syscall arguments into the kernel address space. > > > > Yes, I know this. I'm going to recalculate callp after PTRACESTOP_SC. > > And, there will be no need to copyin from user space -- all syscalls > > parameters are passed in registers (it will be used only for processes > > running under Linux emulation). > Updated registers are available via *frame. > > With some hacks (some return codes needed by user-mode Linux are > hardcoded into kernel) it loads: [...] > I'll need two more flags in p_stops to add two optios: > - respect PTRACE_(OLD)SETOPTIONS PTRACE_O_TRACESYSGOOD (generate > SIGTRAP | 0x80 instead of plain SIGTRAP) > - use Linux PTRACE_SYSCALL conventions (clear S_PT_SCE and S_PT_SCX in > PTRACESTOP_SC) > to make it more than just a set of hacks to run single program. > > PTRACE_(PEEK|POKE)USR seems to need small rewrite too. patch (against -CURRENT) is available on http://chibis.persons.gfk.ru/linux/ptrace.diff You will need to rebuild both kernel an linux module. Yuriy.