X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fexhaust.lisp;h=7de2f007085623ee139b3a457b7c35ae4f4c4c55;hb=ca267caa3bdb897a93a1e69ae7300ba3ba5d391f;hp=18792451a9ced4b9e73333a4bbe221bfd20e66b0;hpb=ec2616d216958a608581802c47496c0194478dc8;p=sbcl.git diff --git a/src/code/exhaust.lisp b/src/code/exhaust.lisp index 1879245..7de2f00 100644 --- a/src/code/exhaust.lisp +++ b/src/code/exhaust.lisp @@ -1,4 +1,5 @@ -;;;; detecting and handling exhaustion of memory (stack or heap) +;;;; detecting and handling exhaustion of fundamental system resources +;;;; (stack or heap) ;;;; This software is part of the SBCL system. See the README file for ;;;; more information. @@ -10,60 +11,11 @@ ;;;; files for more information. (in-package "SB!KERNEL") +(define-alien-routine ("protect_control_stack_guard_page" + %protect-control-stack-guard-page) + sb!alien:int (thread-id sb!alien:int) (protect-p sb!alien:int)) +(defun protect-control-stack-guard-page (n) + (%protect-control-stack-guard-page + (sb!thread:current-thread-id) (if n 1 0))) -;;; A native address on a 4-byte boundary can be thought of (and -;;; passed around in Lisp code as) a FIXNUM. This function converts -;;; from a byte address represented as an unsigned integer to such -;;; a FIXNUM. -;;; -;;; FIXME: There should be some better place for this definition to -;;; go. (Or a redundant definition might already exist. Especially -;;; since this is essentially just a type pun, so there might be some -;;; VOP or something which'd do it for us.) -(eval-when (:compile-toplevel :load-toplevel :execute) - (defun native-address-encoded-as-fixnum (native-address) - (declare (type unsigned-byte native-address)) - (aver (zerop (logand native-address 3))) - (let* (;; naive encoding - (first-try (ash native-address -2)) - ;; final encoding - (second-try - (if (<= first-try sb!xc:most-positive-fixnum) - ;; looks good - first-try - ;; When the naive encoding fails to make a FIXNUM - ;; because the sign is wrong, subtracting *T-M-P-F* - ;; should fix it. - (- first-try sb!xc:most-positive-fixnum)))) - (aver (<= second-try sb!xc:most-positive-fixnum)) - second-try))) -;;; a FIXNUM, to be interpreted as a native pointer, which serves -;;; as a boundary to catch stack overflow -;;; -;;; When stack overflow is detected, this is to be bound to a new -;;; value (allowing some more space for error handling) around the -;;; call to ERROR. -;;; -;;; FIXME: Maybe (probably?) this should be in SB!VM. And maybe the -;;; size of the buffer zone should be set in src/compiler/cpu/parms.lisp -;;; instead of constantly 1Mb for all CPU architectures? -(defvar *stack-exhaustion* - ;; (initialized in cold init) - ) -(defun !exhaust-cold-init () - (setf *stack-exhaustion* - #.(native-address-encoded-as-fixnum - #!+stack-grows-downward (+ sb!vm:control-stack-start (expt 2 20)) - #!+stack-grows-upward (- sb!vm:control-stack-end (expt 2 20))))) - -;;; FIXME: Even though this is only called when (> SAFETY (MAX SPEED SPACE)) -;;; it's still annoyingly wasteful for it to be a full function call. -;;; It should probably be a VOP calling an assembly routine or something -;;; like that. -(defun %detect-stack-exhaustion () - ;; FIXME: Check the stack pointer against *STACK-EXHAUSTION*, and if - ;; out of range signal an error (in a context where *S-E* has been - ;; rebound to give some space to let error handling code do its - ;; thing without new exhaustion problems). - (values))