From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 21 05:17:29 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 C946A16A469 for ; Tue, 21 Aug 2007 05:17:29 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.245]) by mx1.freebsd.org (Postfix) with ESMTP id 7870913C4CE for ; Tue, 21 Aug 2007 05:17:29 +0000 (UTC) (envelope-from yuriy.tsibizov@gmail.com) Received: by an-out-0708.google.com with SMTP id c14so181309anc for ; Mon, 20 Aug 2007 22:17:28 -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=kR/dnk1JW1C/bw5lThMpQW6izMN4JYmTnN1WPbm05U/8M6Khy/5GyyETGWY0s3LYZVt4NhaYjcqm+ZSz2X9b40YZQs/cphDHb1qQbWtKFNd6wKAFvVZ3akHdcsx/qBgv6c5HodbJdGBYU9a/JB9xLVaqdU7eGxBW2ZJ7Ncz2eWw= 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=ayFDcHneCmKcsmT4Xv6G+LwA44dbMbVlu+Xxm1ZtsbQtYL5Af4jp7vKQRr6YWQhiLho+xZgw5qytlzAZ/KfyH6wSbLYXQNUIeKEur+hBb2eowmUwGtGza2XwRe4890euo4DfZYPfg/GEG0Z4Khg1hN3dxPotDaFDA2WJWorgViA= Received: by 10.90.34.3 with SMTP id h3mr866280agh.1187671709288; Mon, 20 Aug 2007 21:48:29 -0700 (PDT) Received: by 10.90.84.15 with HTTP; Mon, 20 Aug 2007 21:48:29 -0700 (PDT) Message-ID: Date: Tue, 21 Aug 2007 08:48:29 +0400 From: "Yuriy Tsibizov" To: "Kostik Belousov" In-Reply-To: <20070820160853.GS2738@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20070820160853.GS2738@deviant.kiev.zoral.com.ua> X-Mailman-Approved-At: Tue, 21 Aug 2007 11:28:21 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: 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: Tue, 21 Aug 2007 05:17:29 -0000 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). I know that there is no real use for this feature for native code. Yuriy