- `(unwind-protect
- (let* ((*interrupts-enabled* nil)
- (*gc-inhibit* t))
- ,@body)
- (when (or (and *interrupts-enabled* *interrupt-pending*)
- (and (not *gc-inhibit*)
- (or *gc-pending* #!+sb-thread *stop-for-gc-pending*)))
- (sb!unix::receive-pending-interrupt))))
-
+ (with-unique-names (without-gcing-body)
+ `(dx-flet ((,without-gcing-body ()
+ ,@body))
+ (if *gc-inhibit*
+ (,without-gcing-body)
+ ;; We need to disable interrupts before disabling GC, so
+ ;; that signal handlers using locks don't accidentally try
+ ;; to grab them with GC inhibited.
+ (let ((*in-without-gcing* t))
+ (unwind-protect
+ (let* ((*allow-with-interrupts* nil)
+ (*interrupts-enabled* nil)
+ (*gc-inhibit* t))
+ (,without-gcing-body))
+ ;; This is not racy becuase maybe_defer_handler
+ ;; defers signals if *GC-INHIBIT* is NIL but there
+ ;; is a pending gc or stop-for-gc.
+ (when (or *interrupt-pending*
+ *gc-pending*
+ #!+sb-thread *stop-for-gc-pending*)
+ (sb!unix::receive-pending-interrupt))))))))