Changeset 11414

Nov 19, 2008, 6:25:17 AM (11 years ago)

In ALLOC-C-FRAME and ALLOC-VARIABLE-C-FRAME, enforce a minimum frame
size of 24 bytes. GCC on Darwin seems to do this (a non-leaf C
function with no locals seems to reserve 24 bytes). If this is
part of the ABI, it's not mentioned anywhere...

This issue came up in the context of this call: (#_open pathname
#$O_RDONLY). On entry to the C library routine, the stack contains
the return address, pathname, and flags. The routine sets a bit
in the (nominally optional) third argument (the file mode). This
clobbers the C frame link, since we only passed two args.

Since open(2) has a variadic prototype, I suppose that in C, this would
result in there always being a 0 on the stack in the position of
the mode argument (with two-arg open), so that would make _open safe, too.
(In the three-arg case, there'd be a 0 after the third arg, of course.)

1 edited


  • trunk/source/compiler/X86/X8632/x8632-vinsns.lisp

    r11355 r11414  
    36863686                                   ((temp :imm)))
    36873687  (movd (:@ (:%seg :rcontext) x8632::tcr.foreign-sp) (:%mmx x8632::stack-temp))
    3688   (subl (:$l (:apply ash nwords x8632::word-shift))
     3688  ;; make frame at least 24 bytes long
     3689  (subl (:$l (:apply ash (:apply max 6 nwords) x8632::word-shift))
    36893690        (:@ (:%seg :rcontext) x8632::tcr.foreign-sp))
    36903691  ;; align stack to 16-byte boundary
    36993700                                            ((temp :imm)))
    37003701  (movd (:@ (:%seg :rcontext) x8632::tcr.foreign-sp) (:%mmx x8632::stack-temp))
    3701   (subl (:%l nwords) (:@ (:%seg :rcontext) x8632::tcr.foreign-sp))
     3702  ;; make frame at least 24 bytes long (note that nwords is a fixnum)
     3703  (movl (:$l 24) (:%l temp))
     3704  (rcmpl (:%l nwords) (:%l temp))
     3705  (cmoval (:%l nwords) (:%l temp))
     3706  (subl (:%l temp) (:@ (:%seg :rcontext) x8632::tcr.foreign-sp))
    37023707  ;; align stack to 16-byte boundary
    37033708  (andb (:$b -16) (:@ (:%seg :rcontext) x8632::tcr.foreign-sp))
Note: See TracChangeset for help on using the changeset viewer.