Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Nov 2008 08:49:35 GMT
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 152445 for review
Message-ID:  <200811040849.mA48nZ44057129@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811040849.mA48nZ44057129>