News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

A memory bug

Started by TouEnMasm, May 16, 2013, 05:56:12 PM

Previous topic - Next topic

qWord

Quote from: dedndave on May 17, 2013, 11:46:50 PM
that code assumes what ? 4 kb pages ?
i thought they were 2 kb - lol
please show me a x86 processor that supports 2 kb pages.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

you're right - they are 4 kb
as i said, you don't have to know what the page size is if you use my code   :P

qWord

Quote from: dedndave on May 18, 2013, 12:03:14 AM
as i said, you don't have to know what the page size is if you use my code   :P
indeed, your solution is better because it is page-size-independent :icon14:
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

a little demo
you can watch the bottom-of-stack (TIB.StackLimit) value change at each loop pass

actually, i think that's the top-of-stack, but the wiki page calls it the bottom   :P

TouEnMasm


Perhaps an explain on how it work,the FS[8] change,How ?.
And where did you find this ?
Fa is a musical note to play with CL

dedndave

the operating system maintains the value in the thread information block
as you use more stack space, it commits additional pages, as required

i didn't find it - i wrote it

dedndave

i was using some other code previously - it used GetSystemInfo to find the page size
but, i wanted a faster method for inline probing to create buffers for an EnumReg function i was writing
so, i did a little research and found that the TIB had the stack limit value
it dawned on me that the page size isn't needed if you use the current stack limit value   :P
how ever much the OS commits (even if it were more than 1 page), you probe the current limit until you get what you want

TouEnMasm


Ok , your method is an answer to the memory problem with openfilename.
There is no problem after changing the stack size with the right clic.
:t
I find just an error,the stack is full when you exit,modify it like below:

bytes_required = 0A000h
mov keepesp,esp  ;keep the actual esp in data

        ASSUME  FS:Nothing

        mov     eax,esp
        sub     eax,bytes_required
        and     al,-16                ;let's use 16-align for demo purposes

@@:     push    eax
        ;call    ShowStackBottom       ;for demo purposes only
        mov     esp,fs:[8]
        cmp     eax,esp
        jb      @B

        mov     esp,keepesp    ;old position

        ASSUME  FS:ERROR
Fa is a musical note to play with CL

qWord

Quote from: ToutEnMasm on May 18, 2013, 02:23:01 AMOk , your method is an answer to the memory problem with openfilename.
There is no problem after changing the stack size with the right clic.
The simples method is to leave the stack as it is. I'm really curios what you want to archive...
MREAL macros - when you need floating point arithmetic while assembling!

TouEnMasm


Quote
The simples method is to leave the stack as it is. I'm really curios what you want to archive...
The increase of the stack size allow fast load (see microsoft) .
Sample,when you load mutiples files an put them in a richedit,the work is faster with a modify stack.The result is visible.

Fa is a musical note to play with CL

dedndave

if you go back to reply #4, you will see that the original ESP is stored in EDX, then restored when done probing
you only need to change the 32768 to 0A000h in that code

qWord

Quote from: ToutEnMasm on May 18, 2013, 03:00:19 AMThe increase of the stack size allow fast load (see microsoft)
where can I read about that (link)?
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: ToutEnMasm on May 18, 2013, 03:00:19 AMSample,when you load mutiples files an put them in a richedit,the work is faster with a modify stack.The result is visible.

I am very curious to see a comparison. Seriously - I'd love to speed up my RichMasm editor.

TouEnMasm

Quote
I am very curious to see a comparison. Seriously - I'd love to speed up my RichMasm editor.

Simple,made test on your IDE changing the stack size with the linker,you will have an answer.
Fa is a musical note to play with CL

TouEnMasm

Here a full explain of the method and a proc who give the amount of desired memory in bytes rounded to the next upper page.

comment µ
NT_TIB STRUCT DEFALIGNMASM ;winnt.sdk
ExceptionList DWORD ?
StackBase DWORD ?
StackLimit DWORD ?
SubSystemTib DWORD ?
IF DEFINED(_MSC_EXTENSIONS)
union
FiberData DWORD ?
Version DWORD ?
ENDS
ELSE
FiberData DWORD ?
ENDIF
ArbitraryUserPointer DWORD ?
Self DWORD ?
NT_TIB ENDS
µ
;nbytes,desired sizeof stack,rounded to the next upper page
;################################################################
SystemIncreaseStack PROC nbytes:DWORD
Local keepesp:DWORD
mov ecx,0
mov keepesp,esp
ASSUME  FS:Nothing
stackloop:
mov edx,FS:[ecx].NT_TIB.StackLimit
mov eax,FS:[ecx].NT_TIB.StackBase
sub eax,edx  ;allocated stack
.if eax < nbytes   ;let's the system made a round in page
mov esp,FS:[ecx].NT_TIB.StackLimit
push eax ;write outside this limit and let the system increase the stack
jmp stackloop
.endif
ASSUME  FS:ERROR
mov     esp,keepesp
;eax new size
         ret
SystemIncreaseStack endp

Fa is a musical note to play with CL