The MASM Forum

Projects => Rarely Used Projects => GoAsm => Topic started by: shankle on September 13, 2014, 12:48:57 AM

Title: Heap problem
Post by: shankle on September 13, 2014, 12:48:57 AM
                             9-12-2014

This is a 64-bit program
Running Windows 7 pro 64-bit and GoAsm
memory of the puter is 6G

This code is failing way before 1,600,000
In HeapCreate the 3rd parameter is set to zero and
what I see in the API Doc is that this will allocate
more memory as it is growable.
The actual # of bytes read by ReadFile is in the neighborhood
of 125000. Anything more causes failure.
No Heap errors are generated.

The file that is being read in is a tad less than 1,600,000 bytes.

BytesRead dq    0
FileSize     dq    0
HeapH     dq    0  ; heap handle
hFile        dq    0
PtrMem    dq    0
FileByte  . db    0

    invoke GetFileSize, [hFile],NULL
    mov [FileSize],rax       
    invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS,1600000,0
    mov [HeapH],rax
    invoke HeapAlloc, [HeapH],HEAP_GENERATE_EXCEPTIONS,1600000
    mov [PtrMem],rax
   
    mov rcx,[PtrMem]
    xor rsi,rsi
.n7   
   cmp rsi,[FileSize]
    jge >>.n9
    invoke ReadFile, [hFile],addr FileByte,1,addr BytesRead,NULL
   
    mov al,B[FileByte]
    mov B[rcx+rsi],al   ; builds data from readfile to memory
    inc rsi
    jmp <.n7
.n9
   
Help would be most appreciated.   

Title: Re: Heap problem
Post by: qWord on September 13, 2014, 01:06:52 AM
Quote from: shankle on September 13, 2014, 12:48:57 AM
BytesRead dq    0
HeapH     dq    0  ; heap handle
hFile     dq    0
PtrMem    dq    0
FileByte  db    0

   invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS,1600000,0
   mov [HeapH],rax
   invoke HeapAlloc, [HeapH],HEAP_GENERATE_EXCEPTIONS,0 ; <=========== dwBytes = 0 ???
    mov [PtrMem],rax
   
    invoke ReadFile, [hFile],addr FileByte,1,addr BytesRead,NULL  ; where is PtrMem used?
Title: Re: Heap problem
Post by: shankle on September 13, 2014, 01:50:55 AM
See above revamped code. Still does not work.
Title: Re: Heap problem
Post by: wjr on September 13, 2014, 02:12:58 AM
Your [PtrMem] value in rcx will get changed with the call to ReadFile. Try using rbx or rdi instead if available.
Title: Re: Heap problem
Post by: qWord on September 13, 2014, 02:40:07 AM
That loop is crap! Make one call to ReadFile with nNumberOfBytesToRead = FileSize and then process the read file-data.
Title: Re: Heap problem
Post by: shankle on September 14, 2014, 04:19:48 AM
Problem solved.
Thread closed