Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
355 Beiträge
 
#18

AW: In Asm-Prozedur eine Exception auslösen

  Alt 4. Nov 2023, 09:29
@Kas Ob.
Thanks for your detailed comments in #8.
Unfortunately not was I am looking for, because I dont want to call procedures outside of my Asm-Procedure (except system-routines).

What I am currently using is the following:

Delphi-Quellcode:
PROCEDURE RaiseException(const S:String);
begin
   raise Exception.Create(S);
end;
Delphi-Quellcode:
PROCEDURE Test;
const S:String='My Message';
asm
   {$IFDEF CPUX86}
   mov eax,S
   {$ELSE}
   mov rcx,S
   {$ENDIF}
   jmp RaiseException
end;
Thank you for clarifying and sorry if i wasn't clear enough.
Delphi assembler has very limited capability, eg. that is why you have to declare constant strings to be used with the assembler with typed strings.

My function above "ExceptionAsm32" is the closest thing you can do with assembly to create and raise exception without writing very complex and unreliable assembly code for Delphi assembler, because it is inconsistent not allow you to get or access specific types, VMT, offsets..etc

beantwortet, also:
Code:
  mov  eax,????
That i had answered , if you don't need to declare your own (or will not multiple ) then replace TMyException with the default Exception.
Code:
const
  pMyExClass: ExceptClass = (TMyException);
  ..
asm
  ..
  mov   eax, pMyExClass; // <-----
That way you can use multiple exception from asm block, only i use create because there is no way or at least no way i know to access the default constructor with compiler help, your assembly can't have the default constructor index to call Create directly for specific class.

ps: about this
Delphi-Quellcode:
PROCEDURE Test;
const S:String='My Message';
asm
   {$IFDEF CPUX86}
   mov eax,S
   {$ELSE}
   mov rcx,S
   {$ENDIF}
   jmp RaiseException
end;
I am against using jmp to raise exception, this will prevent one push on the stack which might leads to whole different story and confusion, just use call, the more code addresses on the stack the safer for OS to rewind correctly, see, when the system will unwind it might not see your that Test procedure at all and will report the caller to Test as the exception raiser.
Kas
  Mit Zitat antworten Zitat