delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/12/07/01:34:43

From: sandmann AT clio DOT rice DOT edu (Charles Sandmann)
Message-Id: <10212070634.AA13865@clio.rice.edu>
Subject: dxeload proposed patches
To: djgpp-workers AT delorie DOT com (DJGPP developers)
Date: Sat, 7 Dec 2002 00:34:10 -0600 (CST)
X-Mailer: ELM [version 2.5 PL2]
Mime-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

Proposed patches for dxeload and documentation below.  DXEGEN and DXE2OBJ
are still being tweaked, but dxeload hasn't changed substantially on my
system in a long time.

*** dxeload.c_	Fri Apr 26 12:52:54 1996
--- dxeload.c	Sat Nov 30 00:30:02 2002
***************
*** 1,3 ****
! /* Copyright (C) 1995 Charles Sandmann (sandmann AT clio DOT rice DOT edu)
     This software may be freely distributed with above copyright, no warranty.
     Based on code by DJ Delorie, it's really his, enhanced, bugs fixed. */
--- 1,3 ----
! /* Copyright (C) 1995,2002 Charles Sandmann (sandmann AT clio DOT rice DOT edu)
     This software may be freely distributed with above copyright, no warranty.
     Based on code by DJ Delorie, it's really his, enhanced, bugs fixed. */
***************
*** 8,11 ****
--- 8,14 ----
  #include <sys/dxe.h>
  
+ char *_dxe_data;
+ long *_dxe_fixup;
+ 
  void *_dxe_load(char *name)
  {
*************** void *_dxe_load(char *name)
*** 39,43 ****
      int i;
      _read(h, relocs, sizeof(long)*dh.nrelocs);
-     _close(h);
  
      for (i=0; i<dh.nrelocs; i++)
--- 42,45 ----
*************** void *_dxe_load(char *name)
*** 45,48 ****
--- 47,71 ----
    }
  
+   if (_dxe_fixup)
+   {
+     long relocs[2];
+     int i,j;
+ 
+     while( sizeof(relocs) == _read(h, relocs, sizeof(relocs)) ) {
+       i = relocs[0];
+       if (i == 0)
+         break;
+       else if (i < 0) 
+         j = _dxe_fixup[-i-1];				/* Absolute - data */
+       else
+         j = _dxe_fixup[i-1] - (int)data;		/* Relative - code */
+ 
+       *(long *)(data + relocs[1]) += j;
+     }
+     _dxe_fixup = NULL;
+   }
+   _close(h);
+ 
+   _dxe_data = data;
    return (void *)(data + dh.symbol_offset);
  }



*** dxeload.tx_	Sat Mar 20 16:48:18 1999
--- dxeload.txh	Sat Dec  7 00:19:18 2002
*************** entry point for the symbol associated wi
*** 15,18 ****
--- 15,26 ----
  to a structure or a function.
  
+ See the @code{dxegen} program documentation for information on creating DXEs.
+ 
+ To resolve references in the DXE to main image procedures and variables,
+ you need to set @code{_dxe_fixup} (@pxref{_dxe_fixup}).
+ 
+ To free the memory (unload the dyanmic image) when done, save the value 
+ stored in @code{_dxe_data} (@pxref{_dxe_data}) and pass this value to @code{free}.
+ 
  @subheading Return Value
  
*************** to a structure or a function.
*** 35,36 ****
--- 43,112 ----
  @end example
  
+ @c ----------------------------------------------------------------------
+ 
+ @node _dxe_data, misc
+ @subheading Syntax
+ 
+ @example
+ #include <sys/dxe.h>
+ 
+ char *_dxe_data;
+ @end example
+ 
+ @subheading Description
+ 
+ This data pointer stores the memory allocated by @code{_dxe_load} @pxref{_dxe_load}
+ when loading the dynamic executable image.  If desired, this value can be 
+ stored after the image is loaded and passed to @code{free} when the image is
+ no longer needed in memory.
+ 
+ @subheading Portability
+ 
+ @portability !ansi, !posix
+ 
+ @subheading Example
+ 
+ @example
+   char *dxe_base;
+   
+   add = _dxe_load("add.dxe");
+   dxe_base = _dxe_data;
+   ...
+   free(dxe_base);  
+ @end example
+ 
+ @c ----------------------------------------------------------------------
+ 
+ @node _dxe_fixup, misc
+ @subheading Syntax
+ 
+ @example
+ #include <sys/dxe.h>
+ 
+ long *_dxe_fixup;
+ @end example
+ 
+ @subheading Description
+ 
+ This data pointer should be set to a list of offsets needed to fix up 
+ symbol locations in a dynamic executable image which reference the main 
+ image.  The symbols and their order are defined by the DXE at the time
+ it is built.  After setting the data pointer, call @code{_dxe_load} which
+ will perform the fix ups.
+ 
+ Note:  @code{_dxe_load} will clear the pointer @code{_dxe_fixup} after it
+ is used, so you must set it before each call.
+   
+ @subheading Portability
+ 
+ @portability !ansi, !posix
+ 
+ @subheading Example
+ 
+ @example
+   static long dxefixup[] = @{ (long)&malloc, (long)&printf @};
+ 
+   _dxe_fixup = dxefixup;
+   add = _dxe_load("add.dxe");
+ @end example
+ 

- Raw text -


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