flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Two threads. But second thread crash first.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 467
I have two threads.
I do this to avoid crash first thread.

My first thread(main) load dll.
And call InitDll.
InitDll function create second thread and return.

Second thread do Globalalloc memory 20 kb.
And read 20 kb.
If second thread went beyond 20 kb then second thread crash and then crash first thread.

How do right so as not to fall first thread ?

PS: Second thread could crash if data not have right format. This main task for using second thread and keep working first thread.
Post 27 Feb 2019, 19:55
View user's profile Send private message Reply with quote
Marut



Joined: 18 Jun 2017
Posts: 9
Location: Veneto, Italy
On Windows if a thread crashes the whole process crashes, so you need to handle the exception on the second thread and either call ExitThread from there, or handle the exception in some other way.

On 32-bit programs a good way to do so could be either SEH or SetUnhandledExceptionFilter.
Post 27 Feb 2019, 21:18
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 507
Location: Belarus
But please don’t, ’cause going beyond the allocated memory block is basically a buffer overflow vulnerability which is a bug in the software that should be fixed, not silenced by handling the exception and proceeding. Your handling will almost definitely be to do nothing and just ignore the exception which is a bad way, or it may be to change the target address to another address (say, for making a circular buffer) in which case the solution is not very performance-friendly.
Post 27 Feb 2019, 22:17
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1129
Location: Russian Federation
Roman, what is the end goal? DimonSoft already pointed out that the cause of the crash is something that really should crash the process.
Post 28 Feb 2019, 01:38
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16518
Location: M87*
If your program is crashing because you exceed your buffer allocation then you need to sanitise your inputs before placing them in a buffer. Make sure you have enough space free before copying data in. If you have more data coming in than you have buffer space, then either discard that data, truncate the data, or increase the buffer size. Don't simply blindly copy in data and hope/pray that it will fit.
Post 28 Feb 2019, 18:30
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.