From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 21 04:25:36 2007 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B2F316A419 for ; Tue, 21 Aug 2007 04:25:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com (relay02.kiev.sovam.com [62.64.120.197]) by mx1.freebsd.org (Postfix) with ESMTP id 3747E13C46E for ; Tue, 21 Aug 2007 04:25:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from [89.162.146.170] (helo=skuns.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1INKkL-000LCW-TU for hackers@freebsd.org; Tue, 21 Aug 2007 06:49:46 +0300 Received: from deviant.kiev.zoral.com.ua (root@[10.1.1.148]) by skuns.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l7KG8rXi053820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 20 Aug 2007 19:08:53 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l7KG8rWl074608; Mon, 20 Aug 2007 19:08:53 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1/Submit) id l7KG8rCT074607; Mon, 20 Aug 2007 19:08:53 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 20 Aug 2007 19:08:53 +0300 From: Kostik Belousov To: Yuriy Tsibizov Message-ID: <20070820160853.GS2738@deviant.kiev.zoral.com.ua> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="XhI9yHzIhar7c5RA" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.91.1, clamav-milter version 0.91.1 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.2.1 X-Spam-Checker-Version: SpamAssassin 3.2.1 (2007-05-02) on skuns.kiev.zoral.com.ua X-Scanner-Signature: 5e2df25549de819b25d1bfd51e9f52eb X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 1391 [August 20 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Method: none X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Cc: 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 04:25:36 -0000 --XhI9yHzIhar7c5RA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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). >=20 > 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=3Dlinux-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 thr= ead > (with PTRACE_PEEKUSR > and PTRACE_POKEUSR) to replace getpid syscall with getppid. >=20 > is it possible to get updated EAX (and other registers as well) in > syscall(...) after ptracestop(...) in PTRACESTOP_SC(...) returns? >=20 > Hope for your help, >=20 > 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. --XhI9yHzIhar7c5RA Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGybyVC3+MBN1Mb4gRAoihAKCTDL7I7Jl1iYmGLeIaLVUUFjpNHwCfV/wi T25OLXGdcNdI6pIaWn+inbw= =pij+ -----END PGP SIGNATURE----- --XhI9yHzIhar7c5RA--