File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed
plugins/primus_lisp/site-lisp Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 2424 (set X1 0 ))
2525
2626
27- (defun setup-stack-canary ()
27+ (defun setup-thread-local-storage ()
2828 (declare (context (abi " sysv" ))
29- (global program :FS_BASE))
30- (set FS_BASE (- brk 0x28))
31- (memory-allocate brk (sizeof ptr_t))
32- (write-word ptr_t brk 0xDEADBEEFBEAFDEAD)
33- (+= brk (sizeof ptr_t)))
29+ (global x86-64 :FS_BASE))
30+ (let ((tcb-size (+ (* 6 (sizeof ptr_t))
31+ (* 2 (sizeof int)))))
32+ (set FS_BASE brk)
33+ ; ; tcbhead_t structure
34+ (memory-allocate brk tcb-size 0 )
35+ (write-word ptr_t brk brk) ; tcb
36+ (write-word ptr_t (+ brk 0x28) 0xDEADBEEFBEAFDEAD) ; stack_guard
37+ ; ; ptmalloc structure
38+ (memory-allocate (- brk 0x28) (sizeof ptr_t) 0 ) ; arena
39+ (memory-allocate (- brk 0x38) (sizeof ptr_t) 0 ) ; freelist
40+ ; ; misc
41+ (memory-allocate (- brk 0x40) (sizeof int) 0 ) ; errno
42+ (+= brk tcb-size)))
3443
3544(defun init (main argc argv auxv)
3645 " GNU libc initialization stub"
3746 (declare (external " __libc_start_main" )
3847 (context (abi " sysv" )))
39- (setup-stack-canary )
48+ (setup-thread-local-storage )
4049 (exit-with (invoke-subroutine main argc argv)))
4150
4251(defun init (args on-exit main)
Original file line number Diff line number Diff line change 130130 (memory-write (+ ptr (min n i)) 0 :8)
131131 ptr))))
132132
133+ (defun gets (ptr)
134+ (declare (external " gets" ))
135+ (let ((str *standard-input* )
136+ (i 0 )
137+ (continue true))
138+ (while continue
139+ (let ((c (fgetc str)))
140+ (if (= c -1 )
141+ (set continue false)
142+ (memory-write (+ ptr i) (cast char c))
143+ (set continue (/= c 0xA))
144+ (incr i))))
145+ (memory-write (+ ptr i) 0 :8)
146+ ptr))
147+
133148
134149(defun getchar ()
135150 (declare (external " getchar" " getchar_unlocked" ))
Original file line number Diff line number Diff line change 8989 (declare (external " strrchr" " rindex" ))
9090 (memrchr p c (+ (strlen p) 1 )))
9191
92+ (defun strchrnul (p c)
93+ (declare (external " strchrnul" ))
94+ (let ((p (strchr p c)))
95+ (if p p (strchr p 0 ))))
9296
9397(defun strpbrk (str set )
9498 (declare (external " strpbrk" ))
You can’t perform that action at this time.
0 commit comments