From owner-p4-projects@FreeBSD.ORG Tue Nov 4 08:49:36 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5666F106568F; Tue, 4 Nov 2008 08:49:36 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 135B01065689 for ; Tue, 4 Nov 2008 08:49:36 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 017848FC0A for ; Tue, 4 Nov 2008 08:49:36 +0000 (UTC) (envelope-from peter-gmail@wemm.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id mA48nZTc057131 for ; Tue, 4 Nov 2008 08:49:35 GMT (envelope-from peter-gmail@wemm.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id mA48nZ44057129 for perforce@freebsd.org; Tue, 4 Nov 2008 08:49:35 GMT (envelope-from peter-gmail@wemm.org) Date: Tue, 4 Nov 2008 08:49:35 GMT Message-Id: <200811040849.mA48nZ44057129@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter-gmail@wemm.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 152445 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Nov 2008 08:49:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=152445 Change 152445 by peter@peter_overcee on 2008/11/04 08:48:40 Add get/set/swap_context(). This doesn't preserve kernel semantics - the kernel saves/restores *all* registers bar the return values. This clobbers everything not guaranteed by the C calling convention. In reality, this doesn't matter because this is called from C. Affected files ... .. //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#12 edit .. //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#23 edit Differences ... ==== //depot/projects/valgrind/coregrind/m_syswrap/priv_syswrap-freebsd.h#12 (text+ko) ==== @@ -176,6 +176,9 @@ DECL_TEMPLATE(freebsd, sys_sigreturn); DECL_TEMPLATE(freebsd, sys_sigtimedwait); DECL_TEMPLATE(freebsd, sys_sigwaitinfo); +DECL_TEMPLATE(freebsd, sys_getcontext); +DECL_TEMPLATE(freebsd, sys_setcontext); +DECL_TEMPLATE(freebsd, sys_swapcontext); DECL_TEMPLATE(freebsd, sys___acl_get_file); DECL_TEMPLATE(freebsd, sys___acl_set_file); DECL_TEMPLATE(freebsd, sys___acl_get_fd); ==== //depot/projects/valgrind/coregrind/m_syswrap/syswrap-freebsd.c#23 (text+ko) ==== @@ -2859,6 +2859,54 @@ PRE_MEM_READ( "__acl_aclcheck_link(aclp)", ARG3, sizeof(struct vki_acl) ); } +/* The *_context() wrappers aren't really safe. They clobber registers not + preserved by the calling convention. The kernel doesn't do this. However, + in realtity it doesn't matter because we call these from C rather than asm. */ +PRE(sys_getcontext) +{ + PRINT("sys_getcontext ( %#lx )", ARG1); + PRE_REG_READ1(long, "getcontext", + struct vki_ucontext *, ucp); + PRE_MEM_WRITE( "getcontext(ucp)", ARG1, sizeof(struct vki_ucontext) ); +} + +POST(sys_getcontext) +{ + POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) ); +} + +PRE(sys_setcontext) +{ + PRINT("sys_setcontext ( %#lx )", ARG1); + PRE_REG_READ1(long, "setcontext", + struct vki_ucontext *, ucp); + + PRE_MEM_READ( "setcontext(ucp)", ARG1, sizeof(struct vki_ucontext) ); + PRE_MEM_WRITE( "setcontext(ucp)", ARG1, sizeof(struct vki_ucontext) ); +} + +POST(sys_setcontext) +{ + /* changes uc_link etc */ + POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) ); +} + +PRE(sys_swapcontext) +{ + PRINT("sys_swapcontext ( %#lx, %#lx )", ARG1, ARG2); + PRE_REG_READ2(long, "swapcontext", + struct vki_ucontext *, oucp, struct vki_ucontext *, ucp); + + PRE_MEM_READ( "swapcontext(ucp)", ARG2, sizeof(struct vki_ucontext) ); + PRE_MEM_WRITE( "swapcontext(oucp)", ARG1, sizeof(struct vki_ucontext) ); +} + +POST(sys_swapcontext) +{ + if (SUCCESS) + POST_MEM_WRITE( ARG1, sizeof(struct vki_ucontext) ); +} + #undef PRE #undef POST @@ -3389,9 +3437,9 @@ // __xfstat 419 // __xlstat 420 - // getcontext 421 - // setcontext 422 - // swapcontext 423 + BSDXY(__NR_getcontext, sys_getcontext), // 421 + BSDXY(__NR_setcontext, sys_setcontext), // 422 + BSDXY(__NR_swapcontext, sys_swapcontext), // 423 // swapoff 424 BSDXY(__NR___acl_get_link, sys___acl_get_link), // 425