From owner-freebsd-emulation@FreeBSD.ORG Tue Aug 21 19:22:22 2007 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B38B016A421 for ; Tue, 21 Aug 2007 19:22:22 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.236]) by mx1.freebsd.org (Postfix) with ESMTP id 7138213C474 for ; Tue, 21 Aug 2007 19:22:22 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: by wx-out-0506.google.com with SMTP id i29so1483472wxd for ; Tue, 21 Aug 2007 12:22:21 -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:mime-version:content-type:content-transfer-encoding:content-disposition; b=LVqPpitbrD0WiF5RxuMmAH4GMeau5B4QRRYty6k7/r/WYG7du08UrQXzK3ws8Q6TE0yU4XL5ReWJSR9F/Mg8FaWpaFTLtE2RFXTgRn1f1zSFleO62KgJNQXEZc3NgLS2wxa2gW6XXF/53Itn5Po/gD8g+PpAPUY3uoFtNT7270c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=qE2/3HQLtYYld0u4il8JqDoq6LUU7PPj55WegOMYHblp1dQwkK9y4W2nb3q93h7osyMyJcbFypY91HiOFshA4J0BG1p1W7rWXGz7vRjr2Zt+0rX+/gOrg9RcSSpXCNt9VVNmxwVP68LwE2zjau4TDSHKC51kccRLudS4vRZAUdU= Received: by 10.90.71.3 with SMTP id t3mr2623491aga.1187722403776; Tue, 21 Aug 2007 11:53:23 -0700 (PDT) Received: by 10.90.84.15 with HTTP; Tue, 21 Aug 2007 11:53:23 -0700 (PDT) Message-ID: Date: Tue, 21 Aug 2007 22:53:23 +0400 From: "Yuriy Tsibizov" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Cc: freebsd-emulation@freebsd.org Subject: User-mode Linux (Was: modify syscall nr on-the-fly) X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2007 19:22:22 -0000 (replying to myself) 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: Core dump limits : soft - NONE hard - NONE Checking that ptrace can change system call numbers...OK Checking syscall emulation patch for ptrace...missing Checking for tmpfs mount on /dev/shm...nothing mounted on /dev/shm Checking PROT_EXEC mmap in /tmp/...OK Checking for the skas3 patch in the host: - /proc/mm... - PTRACE_FAULTINFO... - PTRACE_LDT...UML running in SKAS0 mode Linux version 2.6.22-rc2 (jdike@tp.user-mode-linux.org) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-51)) #342 Wed May 23 11:56:49 EDT 2007 Built 1 zonelists. Total pages: 8128 Kernel command line: root=98:0 PID hash table entries: 128 (order: 7, 512 bytes) Dentry cache hash table entries: 4096 (order: 2, 16384 bytes) Inode-cache hash table entries: 2048 (order: 1, 8192 bytes) Memory: 30288k available Mount-cache hash table entries: 512 Checking for host processor cmov support...Yes Checking for host processor xmm support...No openpty failed, errno = 22 openpty failed, errno = 22 aio_thread failed to initialize context, err = 38 2.6 AIO not supported on the host - reverting to 2.4 AIO 2.6 host AIO support not used - falling back to I/O thread NET: Registered protocol family 16 NET: Registered protocol family 2 IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 1024 (order: 1, 8192 bytes) TCP bind hash table entries: 1024 (order: 0, 4096 bytes) TCP: Hash tables configured (established 1024 bind 1024) TCP reno registered Checking host MADV_REMOVE support...OK os_set_fd_async : Failed to fcntl F_SETOWN (or F_SETSIG) fd 6 to pid 1191, errno = 22 Failed to get IRQ for management console os_set_fd_async : Failed to fcntl F_SETOWN (or F_SETSIG) fd 8 to pid 1191, errno = 22 um_request_irq failed - errno = 22 Host TLS support detected Detected host type: i386 VFS: Disk quotas dquot_6.5.1 Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) io scheduler noop registered io scheduler anticipatory registered (default) io scheduler deadline registered io scheduler cfq registered TCP cubic registered NET: Registered protocol family 1 NET: Registered protocol family 17 Initialized stdio console driver Console initialized on /dev/tty0 Initializing software serial port version 1 Couldn't stat "root_fs" : err = 2 Failed to initialize ubd device 0 :Couldn't determine size of device's file VFS: Cannot open root device "98:0" or unknown-block(98,0) Please append a correct "root=" boot option; here are the available partitions: Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(98,0) EIP: 0033:[<28093021>] CPU: 0 Not tainted ESP: 003b:28068fc4 EFLAGS: 00000246 Not tainted EAX: 00000000 EBX: 000004aa ECX: 00000013 EDX: 000004aa ESI: 000004a7 EDI: 00000000 EBP: 28068fd8 DS: 003b ES: 003b 087fce64: [<08069628>] show_regs+0xb4/0xb9 087fce90: [<08057ca8>] panic_exit+0x25/0x3f 087fcea4: [<08078720>] notifier_call_chain+0x21/0x46 087fcec4: [<080787bb>] __atomic_notifier_call_chain+0x17/0x19 087fcee0: [<080787d2>] atomic_notifier_call_chain+0x15/0x17 087fcefc: [<0806daba>] panic+0x52/0xdd 087fcf1c: [<08049af9>] mount_block_root+0x100/0x116 087fcf70: [<08049b5b>] mount_root+0x4c/0x54 087fcf94: [<08049c41>] prepare_namespace+0xde/0x10a 087fcfa4: [<08049827>] kernel_init+0x79/0x85 087fcfb4: [<08063a39>] run_kernel_thread+0x37/0x42 087fcfe0: [<08058095>] new_thread_handler+0x57/0x7e 087fcffc: [] 0xa55a5a5a 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. Yuriy.