Skip to content

Instantly share code, notes, and snippets.

@eugeneia
Created July 5, 2017 19:58
Show Gist options
  • Save eugeneia/a13f4b4b106af56a566d97065739c2ee to your computer and use it in GitHub Desktop.
Save eugeneia/a13f4b4b106af56a566d97065739c2ee to your computer and use it in GitHub Desktop.
;;; Look for "lea -nnnn(%rip),%fn" AT the tra; if that's present, use
;;; the dispacement -nnnn to find the function. The end of the
;;; encoded displacement is
;;; x8664::recover-fn-from-rip-disp-offset (= 7) bytes from the tra.
(defx86lapfunction %return-address-function ((r arg_z))
; extract tag into imm0
(extract-lisptag r imm0)
; assert first byte of imm0 = tra tag
(cmpb ($ x8664::tag-tra) (% imm0.b))
(jne @fail)
; assert *r = #x8d4c
(cmpw ($ x8664::recover-fn-from-rip-word0) (@ (% r)))
(jne @fail)
; check *(r+2) = #x2d
(cmpb ($ x8664::recover-fn-from-rip-byte2) (@ 2 (% r)))
; copy 2 words from *(r+3) to imm0
(movslq (@ x8664::recover-fn-from-rip-disp-offset (% r)) (% imm0))
; if cmpb failed, bail
(jne @fail)
; load word at *(r+7+imm0) into arg_z
(lea (@ x8664::recover-fn-from-rip-length (% imm0) (% r)) (% arg_z))
; arg_z points to the function object
(single-value-return)
@fail
(movl ($ (target-nil-value)) (% arg_z.l))
(single-value-return))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment