From owner-freebsd-hackers Wed Sep 26 9:21:35 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from raven.ravenbrook.com (raven.ravenbrook.com [193.82.131.18]) by hub.freebsd.org (Postfix) with ESMTP id 5684037B412 for ; Wed, 26 Sep 2001 09:21:31 -0700 (PDT) Received: from thrush.ravenbrook.com (thrush.ravenbrook.com [193.112.141.249]) by raven.ravenbrook.com (8.11.3/8.11.3) with ESMTP id f8QGLMa53462 for ; Wed, 26 Sep 2001 17:21:22 +0100 (BST) (envelope-from nb@ravenbrook.com) Received: from thrush.ravenbrook.com (localhost [127.0.0.1]) by thrush.ravenbrook.com (8.11.4/8.11.2) with ESMTP id f8QGKVx52874 for ; Wed, 26 Sep 2001 17:20:31 +0100 (BST) (envelope-from nb@thrush.ravenbrook.com) From: Nick Barnes To: freebsd-hackers@freebsd.org Subject: distinguising read faults and write faults Date: Wed, 26 Sep 2001 17:20:31 +0100 Message-ID: <52872.1001521231@thrush.ravenbrook.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I am in the process of porting an incremental garbage collector to FreeBSD on x86. This garbage collector uses read barriers and write barriers for incrementality. The details are irrelevant; the key part is that I want to protect parts of memory and handle faults on the protected pages. On FreeBSD, I will be using mmap(MAP_ANON) to obtain memory, and mprotect() to raise the barriers, with a signal handler to handle barrier hits. I have worked out that I need to handle SIGBUS (not SIGSEGV, which surprised me), and that ucontext->mcontext.mc_trapno will be 12 (T_PAGEFLT, not T_PROTFLT, which surprised me). However, I don't see any way of distinguishing between read faults and write faults. This information doesn't appear to be anywhere in the ucontext or the siginfo. Is there any way of distingushing read faults from write faults (other than by decoding the instruction at mc_eip)? Matching code for Linux below: Nick Barnes /* distinguishing read faults from write faults on Linux */ static void sigHandle(int sig, struct sigcontext context) { if(context.trapno == 14) { /* page fault */ int write = ((context.err & 0x2) != 0); /* write */ ... To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message