delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/02/02/16:47:07

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Authentication-Warning: mcomail02.maxtor.com: iscan owned process doing -bs
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
MIME-Version: 1.0
Subject: Can a *program* know its size and location of code?
Date: Wed, 2 Feb 2005 14:17:00 -0700
Message-ID: <71078E41DDE3E541B024832F34BC3D0D4BBE5F@cowexc03.corp.mxtr.net>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Can a *program* know its size and location of code?
Thread-Index: AcUJbIkHIlN+I9OXSeyxac6txLJqfg==
From: "Schumacher, Gordon" <gordon_schumacher AT maxtor DOT com>
To: "DJGPP List \(E-mail\)" <djgpp AT delorie DOT com>
X-OriginalArrivalTime: 02 Feb 2005 21:17:01.0223 (UTC) FILETIME=[89294B70:01C5096C]
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id j12LjeWH018315

I saw out on the mailing list that there had been some questions in the past towards knowing a program's location and size in memory.  My question is slightly different, though; what I was wondering is whether this information can be determined programatically.  (I'm trying to be able to perform a checksum on my codespace to determine whether or not my program has been walking about on top of itself with its hobnailed boots on, as it were.  It should work unless the checksummer gets corrupted...)  Codespace - the part that shouldn't ever change - should be contiguous within virtual memory, even if it's fragmented within physical memory.

It looks like, looking at djgpp.djl, that code - the .text section - always starts at address 0x1000.  It also looks like it would be safe to determine it with something like this:

extern void __code()	asm("start");
void *__pgm_start = &__code;


That leaves me with needing to know how much space to compute the checksum for.  And for that I'm kind of stumped; reviewing a linker map hasn't really given me any clues.  Is there perhaps either a DPMI call or a call into the DJGPP runtime that could tell me this?  Or some bit of chicanery that I've otherwise missed?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019