dimanche 5 avril 2015

C++ and Assembly: call 'operator new' and 'operator delete' with ASM


Vote count:

0




I am trying to call operator new and operator delete with inline ASM in Visual C++.


For example, I have a function like this:



__forceinline void __fastcall deallocate(pointer& _ptr)
{
__asm
{
mov eax, dword ptr[_ptr]
mov ecx, dword ptr[eax]
mov dword ptr[eax], 0
push ecx
call operator delete
add esp, 4
}
}


Unfortunately, when compiling, I get these errors:



error C2414: illegal number of operands
error C2400: inline assembler syntax error in 'first operand'; found 'bad token'
error C2400: inline assembler syntax error in 'opcode'; found 'bad token'


I know this has to do with calling operator delete. If I replace it with a function like this:



__forceinline void _delete(pointer _ptr)
{
::operator delete(_ptr);
}


and write



call _delete


in the ASM code section, I get no errors. Can anybody tell me why and what should I do? I don't want to use this _delete function. This also happens if I try calling operator new in a similar manner. Thank you.



asked 19 secs ago







C++ and Assembly: call 'operator new' and 'operator delete' with ASM

Aucun commentaire:

Enregistrer un commentaire