Index: /branches/watchpoints/level-1/x86-trap-support.lisp
===================================================================
--- /branches/watchpoints/level-1/x86-trap-support.lisp	(revision 12906)
+++ /branches/watchpoints/level-1/x86-trap-support.lisp	(revision 12907)
@@ -432,4 +432,6 @@
 	     ((= code 2)
 	      ;; Write to a watched object.
+	      ;; We somehow need to guard against another thread unwatching
+	      ;; the object out from underneath us.
 	      (flet ((%int-to-object (i)
 		       (rlet ((a :address))
@@ -445,4 +447,20 @@
 					   :object object)
 					  nil frame-ptr)
+		      ;; This certainly has the potential to cause amusing
+		      ;; errors.
+		      (allow ()
+			:report "Allow this write."
+			(let ((result nil)
+			      (ptr (%int-to-ptr
+				    (logandc2 addr (1- *host-page-size*)))))
+			  (with-other-threads-suspended
+			    (#_mprotect ptr *host-page-size*
+					#$PROT_WRITE)
+			    (setq result (x86-emulate-write-instruction xp insn addr object))
+			    (#_mprotect ptr *host-page-size*
+					(logior #$PROT_READ #$PROT_EXEC)))
+			  (if result
+			    (setq skip insn-length)
+			    (error "can't emulate this write"))))
 		      (ignore ()
 			:report "Ignore this write."
