2
This file is part of the Free Pascal run time library.
3
Copyright (c) 1999-2000 by Pierre Muller,
4
member of the Free Pascal development team.
6
Unit to Load DXE files for Go32V2
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************
22
function dxe_load(filename : string) : pointer;
29
function dxe_load(filename : string) : pointer;
31
Copyright (C) 1995 Charles Sandmann (sandmann@clio.rice.edu)
32
translated to Free Pascal by Pierre Muller
35
{ to avoid range check problems }
36
pointer_array = array[0..maxlongint div sizeof(pointer)-1] of pointer;
52
{ quit if no file !! }
56
blockread(f,dh,sizeof(dxe_header),i);
57
if (i<>sizeof(dxe_header)) or (dh.magic<>DXE_MAGIC) then
62
{ get memory for code }
63
getmem(data,dh.element_size);
66
{ get memory for relocations }
67
getmem(relocs,dh.nrelocs*sizeof(pointer));
70
freemem(data,dh.element_size);
74
blockread(f,data^,dh.element_size);
75
blockread(f,relocs^,dh.nrelocs*sizeof(pointer));
77
{ relocate internal references }
78
for i:=0 to dh.nrelocs-1 do
80
cardinal(addr):=cardinal(data)+cardinal(relocs^[i]);
81
addr^:=addr^+cardinal(data);
83
FreeMem(relocs,dh.nrelocs*sizeof(pointer));
84
dxe_load:=pointer( dh.symbol_offset + cardinal(data));