i needed a little function to probe the stack down
i started out by getting the page size with GetSystemInfo
then, i found that there is no need to know the page size
(i know - it's always 4 kb, but that could change on newer OS's)
in the NT_TIB structure, EXCEPTION_REGISTRATION_RECORD, there is a member named "StackLimit"
as it turned out, the code is small enough to use in-line
ASSUME FS:Nothing
mov eax,esp
sub eax,<bytes required>
and al,-16 ;must be at least 4-aligned, 16-aligned used in this case
@@: push eax
mov esp,fs:[8]
cmp eax,esp
jb @B
mov esp,eax
ASSUME FS:ERROR
or, if you prefer...
ASSUME FS:Nothing
mov eax,esp
sub eax,<bytes required>
and al,-4 ;must be at least 4-aligned
.repeat
push edx
mov esp,fs:[8]
.until eax>=esp
mov esp,eax
ASSUME FS:ERROR
any register may be used, really - doesn't have to be EAX
and - the register that is PUSH'ed can be any general register
doesn't have to be the one used for calculation
it may be slightly faster if a different register is PUSH'ed, due to dependancy (as in second example)
it could be made into a macro rather easily
with a second optional arg for alignment