X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Subject: Re: protecting program memory To: djgpp AT delorie DOT com X-Mailer: Lotus Notes Release 7.0.2 September 26, 2006 Message-ID: From: Gordon DOT Schumacher AT seagate DOT com Date: Fri, 23 Mar 2007 16:37:27 -0600 X-MIMETrack: Serialize by Router on SV-GW1/Seagate Internet(Release 7.0.1 HF29|March 07, 2006) at 03/23/2007 03:37:32 PM MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-Proofpoint-FWRule: outbound2 X-Proofpoint-Virus-Version: vendor=fsecure engine=4.65.5502:2.3.11,1.2.37,4.0.164 definitions=2007-03-23_04:2007-03-22,2007-03-23,2007-03-23 signatures=0 tim DOT nicholson AT skyforcekent DOT com wrote on 23 Mar 2007 04:16:50 -0700: # Is there an easy way to protect the memory used to store the # program op codes from a rogue memory write from within the # application? I have a large (100,000+ line) DJGPP # application which sometimes crashes with SIGILL - It would # seem the program is cannibalizing itself! In order # to find how this is happening, I would like to protect the # entire block of memory that contains the application code # so that an exception occurs at the point the corruption occurs # rather than the point that the corrupted code is executed. # # I guest I need to make the memory block read only, but I am # not sure how to do that. Not without DPMI 1.0, you can't. But here's an alternative: checksum the executable space. You can get a pointer to the beginning of code and its size by applying some mild abuse of GCC and the linker map: extern char* _text asm(".text"); extern char* _etext asm("etext"); static char* __my_progstart = NULL; static size_t __my_progsize = 0; __my_progstart = (char*) &_text; __my_progsize = (&_etext - &_text) - sizeof(void*); There are any number of things that you can do now, armed with that data! (Look into instrumentation with GCC...)