Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
223 Beiträge
 
#24

AW: In Asm-Prozedur eine Exception auslösen

  Alt 5. Nov 2023, 10:22
I am trying here to explain and language barrier is playing huge role.

This will work on x64 for this exact procedure
Code:
PROCEDURE test;
const
   pExClass:ExceptClass=( Exception );
   sErr:String=' My message ';
asm
    {$IfDef CPUX86}
   mov ecx,sErr
   mov dl ,1
   mov eax,pExClass
   call Exception .Create
   call System.@RaiseExcept
   {$Else}
   push rbp
   sub rsp,$20
   mov rbp,rsp
   mov r8,sErr
   mov dl ,$01
   mov rcx,pExClass
   call Exception .Create // Seems to work
   mov rcx,rax
   call System.@RaiseExcept // Here it crashes. " ACCESS VIOLATION"
   lea rsp,[rbp+$20]
   pop rbp
   pop rbp
   {$EndIf}
end ;
BUT will fail on many other places and different situations or for just little more complex assembly above that system.@RaiseExcept !!!

The reasoning : i put a frame stack for it and so it worked, now if your assembly is using variables or utilizing the stack or even the compiler went ahead and added a frame on its own to build right assembly, we will end up with double frame and whole different mess and that solution become broken again and you should remove that stack i introduced, this is one hand on other hand this can't be guaranteed to be working on future compiler, tested it on XE8 and your test procedure and it is raising stack overflow on my machine not an access violation!
That why i moved the raising call to its own pascal procedure, this guaranteed to have right frame stack and the compiler will handle it right, as i said that in my humble opinion and according to my experience this is the closest for assembly to raise an exception without braking things every time you modify your assembly and guaranteed to be working on different compilers including future ones, also will not send tools like EurekaLog after witch hunting!

I hope that is clear.

ps : this was a good question and might help many who interested.
  Mit Zitat antworten Zitat