This is an archive of the discontinued LLVM Phabricator instance.

ARM: support stack probe emission for Windows on ARM
ClosedPublic

Authored by abdulras on Apr 1 2014, 4:11 PM.

Details

Summary

This introduces the stack lowering emission of the stack probe function for
Windows on ARM. The stack on Windows on ARM is a dynamically paged stack where
any page allocation which crosses a page boundary of the following guard page
will cause a page fault. This page fault must be handled by the kernel to
ensure that the page is faulted in. If this does not occur and a write access
any memory beyond that, the page fault will go unserviced, resulting in an
abnormal program termination.

The watermark for the stack probe appears to be at 4080 bytes (for accommodating
the stack guard canaries and stack alignment). Follow suit and emit it at that
water mark (this would ideally be done similarly where if SSP is disabled, we
would use the 4096 value).

Diff Detail

Event Timeline

Hi Saleem,

The code seems a bit too specific (ie. Function symbols and registers) but I can't see a better way of doing this in a generic way. If no one has a better idea, apart from my other comments, looks good to me.

thanks,
--renato

lib/Target/ARM/ARMFrameLowering.cpp
192

A better comment here would be good

290

Maybe make it a constant, name it appropriately and comment on the constant?

321

I don't know much about the Windows ABI, but are those registers fixed by it? Or are them just the "next available GPRs on either side"?

abdulras added inline comments.Apr 2 2014, 8:48 AM
lib/Target/ARM/ARMFrameLowering.cpp
192

Fair enough.

290

I think I want to split it out into a function and base it on whether SSP is enabled or not. But, we can extract it now rather than later.

321

The R4 is definitely fixed. I use R12 as it is intra-procedural scratch, and this usage is in the stack setup.

The interface for __chkstk on WoA is as follows:

R4 = 32-bit *words* to be allocated
call __chkstk
Adjust SP by value in R4 (now containing bytes)

This is what the ABI/API is and we have no choice in the matter unfortunately.

rengolin added inline comments.Apr 2 2014, 10:46 AM
lib/Target/ARM/ARMFrameLowering.cpp
321

Ok, I'm happy with this.

abdulras accepted this revision.May 31 2014, 3:20 PM
abdulras added a reviewer: abdulras.

This has been committed already, just closing off the revision.

This revision is now accepted and ready to land.May 31 2014, 3:20 PM
abdulras closed this revision.May 31 2014, 3:20 PM