Created
July 1, 2019 16:12
-
-
Save Lovesan/d8c184c8a2d286255af03852e3019bb2 to your computer and use it in GitHub Desktop.
A test case for the issue of SBCL crashes should it load .Net Core runtime on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; This file reproduces tha fact that SBCL crashes | |
;;; while .Net runtime is loaded | |
;;; .Net Core SDK must be installed | |
;;; run the file like 'sbcl --script sb-net-core-crash.lisp' | |
(defun version-compare (left right) | |
(labels ((parse (c) | |
;; Given .Net version naming convention, | |
;; 3.0.0 is actually greater then 3.0.0-rc1 | |
(or (ignore-errors (parse-integer c)) | |
-1)) | |
(split (str &aux (end (length str))) | |
(loop :with start = 0 | |
:with components = '() | |
:for i :below end | |
:for c = (char str i) | |
:when (member c '(#\. #\-)) | |
:do (push (subseq str start i) | |
components) | |
(setf start (1+ i)) | |
:finally (unless (= start end) | |
(push (subseq str start end) components)) | |
(return (nreverse (mapcar #'parse components))))) | |
(cmp (a b) (cond ((> a b) 1) ((< a b) -1) (t 0))) | |
(pad (list other-length) | |
(let ((length (length list))) | |
(if (< length other-length) | |
(append list (make-list (- other-length length) | |
:initial-element 0)) | |
list)))) | |
(loop :with v1 = (split left) | |
:with v2 = (split right) | |
:with v1-len = (length v1) | |
:with v2-len = (length v2) | |
:for left :on (pad v1 v2-len) | |
:and right :on (pad v2 v1-len) | |
:for a = (car left) | |
:for b = (car right) | |
:do (cond ((< a b) (return -1)) | |
((> a b) (return 1))) | |
:finally (return (cond (left (cmp a 0)) | |
(right (cmp 0 b)) | |
(t 0)))))) | |
(defun version> (left right) | |
(= 1 (version-compare left right))) | |
(defun find-dotnet () | |
(let* ((out (with-output-to-string (s) | |
(sb-ext:run-program "dotnet" '("--list-runtimes") | |
:search t | |
:output s))) | |
(list (with-input-from-string (in out) | |
(loop :for line = (read-line in nil) | |
:while line | |
:when (search "Microsoft.NETCore.App" line) | |
:collect (let* ((ver-start (1+ (position #\Space line))) | |
(ver-end (position #\Space line :start ver-start)) | |
(path-start (1+ (position #\[ line))) | |
(path-end (position #\] line)) | |
(version (subseq line ver-start ver-end)) | |
(dir (merge-pathnames | |
(make-pathname | |
:directory (list :relative version)) | |
(truename (subseq line path-start path-end)))) | |
(lib (truename | |
(merge-pathnames | |
#+win32 | |
"coreclr.dll" | |
#+linux | |
"libcoreclr.so" | |
#+darwin | |
"libcoreclr.dylib" | |
#-(or win32 linux darwin) | |
(error "Unsupported platform") | |
dir)))) | |
(cons version lib))))) | |
(latest (first (sort list #'version> :key #'car)))) | |
(cdr latest))) | |
(defvar *coreclr-location* (find-dotnet)) | |
(defun load-dotnet () | |
(format *error-output* "Loading ~a~%" *coreclr-location*) | |
(load-shared-object *coreclr-location*)) | |
(defvar *coreclr-lib* (load-dotnet)) | |
(defconstant +path-separator+ #+win32 #\; #-win32 #\:) | |
(defun get-trusted-platform-assemblies () | |
(format nil (concatenate 'string "~{~a" "~^" (string +path-separator+) "~}") | |
(directory (make-pathname :type "dll" | |
:name :wild | |
:defaults *coreclr-location*)))) | |
(defvar *trusted-platform-assemblies* | |
(get-trusted-platform-assemblies)) | |
#+win32 | |
(progn | |
(sb-alien:define-alien-routine | |
("GetModuleFileNameW" get-module-file-name) | |
sb-alien:unsigned-int | |
(module sb-sys:system-area-pointer) | |
(buffer sb-sys:system-area-pointer) | |
(size sb-alien:unsigned-int)) | |
(defun get-exe-path () | |
;; 1K ought to be enough for anybody | |
(sb-alien:with-alien ((buf (array char 1024))) | |
(get-module-file-name (sb-sys:int-sap 0) | |
(sb-alien:alien-sap buf) | |
1024) | |
(sb-alien:cast buf (c-string :external-format :utf-16le))))) | |
#+linux | |
(defun get-exe-path () | |
(namestring (truename "/proc/self/exe"))) | |
#+darwin | |
(progn | |
(sb-alien:define-alien-routine | |
("_NSGetExecutablePath" ns-get-executable-path) | |
sb-alien:int | |
(buf sb-sys:system-area-pointer) | |
(size sb-alien:unsigned-int)) | |
(defun get-exe-path () | |
;; 1K ought to be enough for anybody | |
(sb-alien:with-alien ((buf (array char 1024))) | |
(ns-get-executable-path (sb-alien:alien-sap buf) 1024) | |
(sb-alien:cast buf c-string)))) | |
(sb-alien:define-alien-routine | |
("coreclr_initialize" %coreclr-initialize) | |
sb-alien:unsigned-int | |
(exe-path sb-alien:c-string) | |
(app-domain-name sb-alien:c-string) | |
(propcount sb-alien:int) | |
(propkeys (array sb-alien:c-string 1)) | |
(propvals (array sb-alien:c-string 1)) | |
(host-handle sb-alien:system-area-pointer :out) | |
(domain-id sb-alien:unsigned-int :out)) | |
(defun coreclr-initialize () | |
(sb-alien:with-alien ((keys (array sb-alien:c-string 1)) | |
(values (array sb-alien:c-string 1))) | |
(let ((key (sb-alien:make-alien-string "TRUSTED_PLATFORM_ASSEMBLIES")) | |
(value (sb-alien:make-alien-string *trusted-platform-assemblies*))) | |
(setf (sb-alien:deref keys 0) key | |
(sb-alien:deref values 0) value) | |
(unwind-protect | |
(multiple-value-bind | |
(rv host-handle domain-id) | |
(%coreclr-initialize (get-exe-path) "SBCL" 1 keys values) | |
(unless (zerop rv) | |
(error "Unable to initialize CoreCLR: 0x~8,'0X" rv)) | |
(format *error-output* "Initialized CoreCLR ~%") | |
(cons host-handle domain-id)) | |
(sb-alien:free-alien key) | |
(sb-alien:free-alien value))))) | |
(defvar *host-domain* (coreclr-initialize)) | |
;;; Here you'll get the crash on Linux | |
(dotimes (i 1000) | |
(compile 'foo `(lambda (x) (+ x ,(random 100))))) |
Sent the dump to sbcl-devel and attached it to the bug report on launchpad https://bugs.launchpad.net/sbcl/+bug/1834964
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Мдя, нахрапом тут не возьмешь
1.3.2 Signal Related Bugs
http://www.sbcl.org/manual/index.html
Можешь отправить мой дамп:
=>
[(nil)/(nil)] /entering interrupt_init()
[(nil)/(nil)] /returning from interrupt_init()
code scavenged: 0 total, 0 skipped
Next gc when 75009331 bytes have been consed
Loading /usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/libcoreclr.so
Initialized CoreCLR
fatal error encountered in SBCL pid 19111(tid 0x7fb16a2f0b80):
blockable signals partially blocked: {1,2,3,13,14,15,17,20,23,24,25,26,27,28,29}
0: Foreign function (null), pc = 0x41866a, fp = 0x7fb169385e50
1: Foreign function (null), pc = 0x4187f8, fp = 0x7fb169385f40
2: Foreign function all_signals_blocked_p, pc = 0x4193fd, fp = 0x7fb1693860d0
3: Foreign function interrupt_handle_pending, pc = 0x41af2d, fp = 0x7fb169386100
4: Foreign function handle_trap, pc = 0x41c47d, fp = 0x7fb169386140
5: Foreign function (null), pc = 0x4190de, fp = 0x7fb169386180
6: Foreign function (null), pc = 0x7fb168e10359, fp = 0x7fb1693861b0
7: Foreign function (null), pc = 0x7fb169cca0e0, fp = 0x7fb169386778
8: SB-IMPL::%MAKE-HASH-TABLE, pc = 0x52456f7f, fp = 0x7fb1693867f8
9: MAKE-HASH-TABLE, pc = 0x5211b21c, fp = 0x7fb1693868a8
10: SB-C::MAKE-IR2-COMPONENT, pc = 0x52420bbd, fp = 0x7fb169386958
11: SB-C::GTN-ANALYZE, pc = 0x524ecdb7, fp = 0x7fb169386988
12: SB-C::%COMPILE-COMPONENT, pc = 0x5230ebc8, fp = 0x7fb169386a10
13: SB-C::COMPILE-COMPONENT, pc = 0x5221884f, fp = 0x7fb169386a38
14: SB-C::%COMPILE, pc = 0x52310bdf, fp = 0x7fb169386ad0
15: (FLET "LAMBDA0" :IN "SYS:SRC;COMPILER;TARGET-MAIN.LISP"), pc = 0x521eb1d8, fp = 0x7fb169386ba0
16: (FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT), pc = 0x5226625d, fp = 0x7fb169386c80
17: SB-C::COMPILE-IN-LEXENV, pc = 0x521ebda4, fp = 0x7fb169386da8
18: COMPILE, pc = 0x5216fd7f, fp = 0x7fb169386de0
19: (LAMBDA () :IN "/home/test/crash.lisp"), pc = 0x52b53ef4, fp = 0x7fb169386e00
20: SB-INT::SIMPLE-EVAL-IN-LEXENV, pc = 0x52227f8a, fp = 0x7fb169386ec8
21: SB-EXT::EVAL-TLF, pc = 0x52353efd, fp = 0x7fb169386ef0
22: (LABELS SB-FASL::EVAL-FORM :IN SB-INT::LOAD-AS-SOURCE), pc = 0x52294ff8, fp = 0x7fb169387120
23: (LAMBDA (SB-KERNEL::FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS) :IN SB-INT::LOAD-AS-SOURCE), pc = 0x522947f1, fp = 0x7fb169387270
24: SB-C::%DO-FORMS-FROM-INFO, pc = 0x52266d90, fp = 0x7fb169387330
25: SB-INT::LOAD-AS-SOURCE, pc = 0x522942c8, fp = 0x7fb1693874f0
26: (FLET SB-FASL::THUNK :IN LOAD), pc = 0x521cf93a, fp = 0x7fb1693875f8
27: SB-FASL::CALL-WITH-LOAD-BINDINGS, pc = 0x5236f36b, fp = 0x7fb169387680
28: (FLET SB-FASL::LOAD-STREAM :IN LOAD), pc = 0x521cfaed, fp = 0x7fb169387788
29: LOAD, pc = 0x521cf567, fp = 0x7fb169387880
30: (FLET SB-IMPL::LOAD-SCRIPT :IN SB-IMPL::PROCESS-SCRIPT), pc = 0x522edb84, fp = 0x7fb169387960
31: (FLET SB-UNIX::BODY :IN SB-IMPL::PROCESS-SCRIPT), pc = 0x522ed304, fp = 0x7fb169387a00
32: (FLET "WITHOUT-INTERRUPTS-BODY-2" :IN SB-IMPL::PROCESS-SCRIPT), pc = 0x522ed035, fp = 0x7fb169387ac0
33: SB-IMPL::PROCESS-SCRIPT, pc = 0x522ece2a, fp = 0x7fb169387b60
34: SB-IMPL::TOPLEVEL-INIT, pc = 0x52256a8d, fp = 0x7fb169387d30
35: (FLET SB-UNIX::BODY :IN SB-EXT::SAVE-LISP-AND-DIE), pc = 0x523b98e2, fp = 0x7fb169387e00
36: (FLET "WITHOUT-INTERRUPTS-BODY-7" :IN SB-EXT::SAVE-LISP-AND-DIE), pc = 0x523b9698, fp = 0x7fb169387ef8
37: (LABELS SB-IMPL::RESTART-LISP :IN SB-EXT::SAVE-LISP-AND-DIE), pc = 0x523b948b, fp = 0x7fb169387fc8
<=