flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 23 Dec 2007, 12:16
I strongly doubt that malloc is anything but cdecl. Perhaps a mistake in your code elsewhere is causing your problem?
|
|||
![]() |
|
zxcv 23 Dec 2007, 12:43
no!
Code: format pe console section '.code' code executable readable push 400 call [malloc] call [malloc] add esp, 4 ret section '.idata' import data readable dd 0,0,0,RVA msvcrt_name,RVA msvcrt_table dd 0,0,0,0,0 msvcrt_table: malloc dd RVA _malloc dd 0 msvcrt_name db 'msvcrt.dll',0 _malloc db 0,0,'malloc',0 Crashed! Windows error reporting and drwtsn32.exe |
|||
![]() |
|
revolution 23 Dec 2007, 12:51
Works for me! WinXP32 SP2. Even Olly show no stack adjustment from malloc.
Maybe you have a virus? |
|||
![]() |
|
vid 23 Dec 2007, 13:09
Works for me too.
Original code (in first post) doesn't remove arguments from stack. |
|||
![]() |
|
LocoDelAssembly 23 Dec 2007, 15:33
BTW, it is a mistake to reuse parameters, C language does not forbids you from using the arguments as variables on your functions so the second call to malloc is not guaranteed to recieve 400. This does not explains the error but I wanted to tell it anyway
![]() Last edited by LocoDelAssembly on 23 Dec 2007, 17:24; edited 1 time in total |
|||
![]() |
|
zxcv 23 Dec 2007, 16:59
why i cant reuse parameter if function is cdecl? please explain it to me why
many times i used _sleep and it worked. |
|||
![]() |
|
vid 23 Dec 2007, 17:11
Quote: why i cant reuse parameter if function is cdecl? Because function can overwrite the value on stack, like: Code: malloc: add [esp+4], sizeof_block_header ... Quote: please explain it to me why many times i used _sleep and it worked. elementary logic: if it works limited number of times, that doesn't mean it will work always. ![]() |
|||
![]() |
|
LocoDelAssembly 23 Dec 2007, 17:22
[edit]Same explanation as vid but in HLL[/edit]
Suppose that the function you call is the following Code: void do_nothing_but_overwrite_params(int param) { param += param; return; } If later you do Code:
push 5
call do_nothing_but_overwrite_params
call do_nothing_but_overwrite_params
The first call recieves 5 and the second 10. However not all functions writes to its parameters but you can't rely on that because the prototype is just "type func(type param, etc)" and nothing there says that the parameter on the stack will be preserved. |
|||
![]() |
|
zxcv 24 Dec 2007, 09:24
ok, but does any of winapi functions contain this trap?
|
|||
![]() |
|
revolution 24 Dec 2007, 10:18
zxcv wrote: ok, but does any of winapi functions contain this trap? [1] There are two api functions that are cdecl, one star will be given to anyone that can name them from memory without checking the docs. ![]() Edit by Loco: The "contest" is here |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.