flat assembler
Message board for the users of flat assembler.

Index > Main > Error handling design

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Jul 2006, 18:42
I was thinking about how to return error info in FASMLIB. Originally i was thinking about some static structure in memory, but then friend found out that this can't be used with multi-threaded apps.

Right now, the error status is always(!) returned in CF, and if error occurs, then nothing else is returned.

One idea is to return address of error structure in EAX, this seems nice, but problem arises - how to allocate memory? In future i plan to implement automatic callstack to become part of error info (in debugging versions), so it cannot be just some small chunk of memory.

Second idea is to rely on system memory allocation, and if it fails then return some kind of "Error info couldn't be generated" instead of description / call stack / anything

anyone has better ideas?

PS: maybe even other register could be used, so you can change it in handler, but which? this is just an idea, i personally dislike it.
Post 31 Jul 2006, 18:42
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum 31 Jul 2006, 18:55
Quote:

but then friend found out that this can't be used with multi-threaded apps

Why not use TLS?
Post 31 Jul 2006, 18:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 31 Jul 2006, 19:00
If I remember well the TLS slot for the EXE module is 0 so doing "mov dword [fs:0], something" should be enough. For DLLs you should use the API function to get a slot.

Regards
Post 31 Jul 2006, 19:00
View user's profile Send private message Reply with quote
Thaorius



Joined: 27 Jul 2006
Posts: 42
Thaorius 31 Jul 2006, 19:12
you could set the CF to 1 and do something like this:
Code:
lea eax,ERROR_OOOPPS

ERROR_OOOPPS db 'Something is wrong...',13,10,0    


then you return from the procedure and that is, you should have the memory address of the message and even you can use something like putting on ah the memory address and in al some error number.

Bye
Post 31 Jul 2006, 19:12
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Aug 2006, 07:32
Thaorious - that's way i use already, but i also need some strings created dynamically (like "Error in procedure %s: arg1 = %8X, arg2 = %8X" etc...), so i need memory for this

what's that TLS? i am not familiar with it
Post 01 Aug 2006, 07:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 01 Aug 2006, 12:31
TLS is only in PE files. FASMLIB is supposed to be OS-independent, and so error handling must be the same on all OSes.
Post 01 Aug 2006, 12:31
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 01 Aug 2006, 13:26
it is possible with additional optional parameter. if caller wish to get error info - it allocates space for error structure and pass pointer as parameter to the function (it has to be able to fill it) - if there is no error - it simply deleted, otherwise - used (filled by called function, of course). if caller do not care about error - 0 passed as this parameter. that structure can be created even in stack as local var, so, no problems with multythreading.
Post 01 Aug 2006, 13:26
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 01 Aug 2006, 14:40
You have Thread Local Store (TLS) on Windows and Thread Specific Data (TSD) on Linux. Again if I remember well on Linux you can use "mov [fs:0], something" but I'd never used it on Linux so you must Google it.
Post 01 Aug 2006, 14:40
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Sep 2006, 15:10
locodelassembly wrote:
If I remember well the TLS slot for the EXE module is 0 so doing "mov dword [fs:0], something" should be enough. For DLLs you should use the API function to get a slot.


Absolutelly wrong.

Microsoft systems journal - Under The Hood [MATT PIETREK] wrote:

Instruction MOV ECX,FS:[2C]
Purpose Makes a pointer to the Thread Local Storage (TLS) array
Examples

ECX,DWORD PTR FS:[0000002C]
EDX,DWORD PTR [ECX+EAX*4]
Description At offset 0x2C in the TEB is a pointer to the TLS array for the thread. This array contains 64 DWORDs, each corresponding to a particular index value that would be passed to TlsGetValue. Code that uses FS:[2C] is using TLS.

http://www.microsoft.com/msj/0298/hood0298.aspx
Post 08 Sep 2006, 15:10
View user's profile Send private message Reply with quote
jbojarczuk



Joined: 21 Jun 2006
Posts: 27
jbojarczuk 09 Sep 2006, 03:34
[fs:0] is the head of the exception handling linked list.
If you want more info, contact me.
Post 09 Sep 2006, 03:34
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Sep 2006, 14:51
There was a big mess yesterday for that http://board.flatassembler.net/topic.php?t=5807

Thanks anyway.
Post 09 Sep 2006, 14:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.