X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Rod Pemberton" Newsgroups: comp.os.msdos.djgpp Subject: Re: protecting program memory Date: Fri, 23 Mar 2007 21:16:04 -0400 Organization: Aioe.org NNTP Server Lines: 51 Message-ID: References: NNTP-Posting-Host: IVw7K97ih4IohxRqyKkqFw.user.aioe.org X-Complaints-To: abuse AT aioe DOT org X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Priority: 3 X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MSMail-Priority: Normal To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com wrote in message news:OF8FAF1ED8 DOT 483B1086-ON872572A7 DOT 0078F978-872572A7 DOT 007C4A14 AT seagate DOT com... > > 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...) > Nice. Thanks. More info for my Grub MB header into first 8k of .exe without a linker script problem... Alternately, I was currently thinking about just destubbing the .exe's DPMI host and RM startup code, prepending an MB header using the same (DJ COFF?) 32-bit entry point as the DPMI host. Later, for a while anyway..., Rod Pemberton