Stepping is not GC-safe

Bug #1468495 reported by Stas Boukarev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Low
Unassigned

Bug Description

The function which is arranged to be called by the stepper gets moved by the GC:
(defun test-step-out/2 ()
  (let* ((count 0)
         (*stepper-hook* (lambda (condition)
                           (typecase condition
                             (step-form-condition
                              (if (>= (incf count) 3)
                                  (invoke-restart 'step-out)
                                  (invoke-restart 'step-into)))))))
    (step (out))))

(defun z (x)
  x)

(defun in ()
  (declare (optimize debug))
  (z 1)
  (z 2)
  (z 3)
  (z 4))

(defun out ()
  (declare (optimize debug))
  (in))

(sb-thread:make-thread
 (lambda ()
   (loop
    (handler-bind ((step-condition #'sb-impl::invoke-stepper))
      (test-step-out/2)))))

(sb-thread:make-thread
 (lambda ()
   (sb-ext:gc :full t)))

* CORRUPTION WARNING in SBCL pid 27887(tid 140736519829248):
Memory fault at (nil) (pc=(nil), sp=0x7fffc6456580)
The integrity of this image is possibly compromised.
Continuing with fingers crossed.

debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread
#<THREAD RUNNING {10034C1653}>:
  Unhandled memory fault at #x0.

Tags: step
Revision history for this message
Stas Boukarev (stassats) wrote :

It needs with-pinned-objects around the call to (setf (context-register context callee-register-offset) (get-lisp-obj-address new-callee)), since %set-context-register is a function and get-lisp-obj-address passes a fixnum representation of the function, which doesn't hold it. context is registered by fake_foreign_function_call, so once it's there, it's pinned down.
Will commit after the freeze.

Changed in sbcl:
assignee: nobody → Stas Boukarev (stassats)
Revision history for this message
Stas Boukarev (stassats) wrote :

In 433d08123bdcff2bb1868c2884beab8b431bdb75.

Changed in sbcl:
status: Triaged → Fix Committed
Stas Boukarev (stassats)
Changed in sbcl:
assignee: Stas Boukarev (stassats) → nobody
Stas Boukarev (stassats)
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.