Author Topic: A memory bug  (Read 26574 times)

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: A memory bug
« Reply #15 on: May 17, 2013, 11:58:36 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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: A memory bug
« Reply #16 on: May 18, 2013, 12:03:14 AM »
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: A memory bug
« Reply #17 on: May 18, 2013, 12:12:31 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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: A memory bug
« Reply #18 on: May 18, 2013, 12:26:01 AM »
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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: A memory bug
« Reply #19 on: May 18, 2013, 01:33:48 AM »

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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: A memory bug
« Reply #20 on: May 18, 2013, 01:57:03 AM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: A memory bug
« Reply #21 on: May 18, 2013, 02:06:09 AM »
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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: A memory bug
« Reply #22 on: May 18, 2013, 02:23:01 AM »

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:
Code: [Select]
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: A memory bug
« Reply #23 on: May 18, 2013, 02:37:17 AM »
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.
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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: A memory bug
« Reply #24 on: May 18, 2013, 03:00:19 AM »

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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: A memory bug
« Reply #25 on: May 18, 2013, 03:10:51 AM »
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: A memory bug
« Reply #26 on: May 18, 2013, 03:30:02 AM »
The 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

  • Member
  • *****
  • Posts: 13950
  • Assembly is fun ;-)
    • MasmBasic
Re: A memory bug
« Reply #27 on: May 18, 2013, 03:41:39 AM »
Sample,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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: A memory bug
« Reply #28 on: May 18, 2013, 03:19:19 PM »
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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: A memory bug
« Reply #29 on: May 18, 2013, 04:42:51 PM »
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.
Code: [Select]
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