Cleanup
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@943 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f5d2474195
commit
832a1f4713
4 changed files with 129 additions and 75 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
SRCS = default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
SRCS = default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
||||||
OBJS = default.o stack.o stab.o elf.o object.o signal.o segment.o init.o main.o
|
OBJS = default.o stack.o stab.o elf.o object.o signal.o segment.o init.o main.o
|
||||||
INCLUDE = -I../Include
|
INCLUDE = -I../Include -I.
|
||||||
OPT = -DWAD_SOLARIS
|
OPT = -DWAD_SOLARIS
|
||||||
|
|
||||||
PYINCLUDE = -I/usr/local/include/python2.0
|
PYINCLUDE = -I/usr/local/include/python2.0
|
||||||
|
|
@ -27,7 +27,7 @@ tcl::
|
||||||
cp libwadtcl.so ..
|
cp libwadtcl.so ..
|
||||||
|
|
||||||
linux::
|
linux::
|
||||||
cc -DWAD_LINUX $(INCLUDE) segment.c debug.c
|
cc -DWAD_LINUX $(INCLUDE) segment.c init.c debug.c
|
||||||
|
|
||||||
debug::
|
debug::
|
||||||
cc -g debug.c $(INCLUDE) -L. -R. -lwad
|
cc -g debug.c $(INCLUDE) -L. -R. -lwad
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,11 @@ void wad_init() {
|
||||||
if (getenv("WAD_DEBUG_STABS")) {
|
if (getenv("WAD_DEBUG_STABS")) {
|
||||||
wad_debug_mode |= DEBUG_STABS;
|
wad_debug_mode |= DEBUG_STABS;
|
||||||
}
|
}
|
||||||
|
#ifndef WAD_LINUX
|
||||||
if (!init) {
|
if (!init) {
|
||||||
wad_signal_init();
|
wad_signal_init();
|
||||||
wad_object_init();
|
wad_object_init();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,44 +11,21 @@
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
* See the file LICENSE for information on usage and redistribution.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static
|
static FILE *
|
||||||
WadSegment *wad_segment_read() {
|
segment_open() {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int dz;
|
f = fopen("/proc/self/maps", "r");
|
||||||
int offset = 0;
|
return f;
|
||||||
int i;
|
}
|
||||||
int n = 0;
|
|
||||||
|
static int
|
||||||
|
segment_read(FILE *fs, WadSegment *s)
|
||||||
|
{
|
||||||
char pbuffer[1024];
|
char pbuffer[1024];
|
||||||
char *c;
|
char *c;
|
||||||
WadSegment *s;
|
int len;
|
||||||
|
c = fgets(pbuffer,1024,fs);
|
||||||
/* Try to load the virtual address map */
|
if (!c) return 0;
|
||||||
f = fopen("/proc/self/maps", "r");
|
|
||||||
if (!f) return 0;
|
|
||||||
nsegments = 0;
|
|
||||||
while (1) {
|
|
||||||
if (fgets(pbuffer,1024,f) == NULL) break;
|
|
||||||
nsegments++;
|
|
||||||
}
|
|
||||||
nsegments++;
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
dz = open("/dev/zero", O_RDWR, 0644);
|
|
||||||
if (dz < 0) {
|
|
||||||
puts("Couldn't open /dev/zero\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
segments = (WadSegment *) mmap(NULL, nsegments*sizeof(WadSegment), PROT_READ | PROT_WRITE, MAP_PRIVATE, dz, 0);
|
|
||||||
close(dz);
|
|
||||||
segments_size = nsegments*sizeof(WadSegment);
|
|
||||||
|
|
||||||
f = fopen("/proc/self/maps","r");
|
|
||||||
if (!f) return;
|
|
||||||
i = 0;
|
|
||||||
s = segments;
|
|
||||||
while (1) {
|
|
||||||
c = fgets(pbuffer,1024,f);
|
|
||||||
if (!c) break;
|
|
||||||
|
|
||||||
pbuffer[strlen(pbuffer)-1] = 0; /* Chop off endline */
|
pbuffer[strlen(pbuffer)-1] = 0; /* Chop off endline */
|
||||||
|
|
||||||
|
|
@ -62,32 +39,22 @@ WadSegment *wad_segment_read() {
|
||||||
23-31 : Offset
|
23-31 : Offset
|
||||||
49- : Filename */
|
49- : Filename */
|
||||||
|
|
||||||
|
len = strlen(pbuffer);
|
||||||
pbuffer[8] = 0;
|
pbuffer[8] = 0;
|
||||||
pbuffer[17] = 0;
|
pbuffer[17] = 0;
|
||||||
pbuffer[31] = 0;
|
pbuffer[31] = 0;
|
||||||
|
s->mapname[0] = 0;
|
||||||
|
s->mappath[0] = 0;
|
||||||
|
if (len >= 49) {
|
||||||
strcpy(s->mapname, pbuffer+49);
|
strcpy(s->mapname, pbuffer+49);
|
||||||
strcpy(s->mappath, pbuffer+49);
|
strcpy(s->mappath, pbuffer+49);
|
||||||
|
}
|
||||||
s->vaddr = (char *) strtoul(pbuffer,NULL,16);
|
s->vaddr = (char *) strtoul(pbuffer,NULL,16);
|
||||||
s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr);
|
s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr);
|
||||||
s->offset = strtoul(pbuffer+23,NULL,16);
|
s->offset = strtoul(pbuffer+23,NULL,16);
|
||||||
s->base = s->vaddr;
|
s->base = s->vaddr;
|
||||||
s++;
|
s++;
|
||||||
}
|
return 1;
|
||||||
fclose(f);
|
|
||||||
return segments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* wad_segment_release()
|
|
||||||
*
|
|
||||||
* This function releases all of the segments.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
wad_segment_release() {
|
|
||||||
munmap((void *)segments, segments_size);
|
|
||||||
segments = 0;
|
|
||||||
segments_size = 0;
|
|
||||||
nsegments = 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,92 @@
|
||||||
#include "plat/segment_linux.c"
|
#include "plat/segment_linux.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* wad_segment_read()
|
||||||
|
*
|
||||||
|
* Read all of the memory segments.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
WadSegment *
|
||||||
|
wad_segment_read() {
|
||||||
|
FILE *fs;
|
||||||
|
int dz;
|
||||||
|
int offset = 0;
|
||||||
|
int i;
|
||||||
|
int n = 0;
|
||||||
|
int nsegments;
|
||||||
|
WadSegment *segments;
|
||||||
|
WadSegment *s;
|
||||||
|
WadSegment ws;
|
||||||
|
|
||||||
|
/* Try to load the virtual address map */
|
||||||
|
fs = segment_open();
|
||||||
|
if (!fs) return 0;
|
||||||
|
nsegments = 0;
|
||||||
|
while (1) {
|
||||||
|
n = segment_read(fs,&ws);
|
||||||
|
if (n <= 0) break;
|
||||||
|
nsegments++;
|
||||||
|
}
|
||||||
|
nsegments+=3;
|
||||||
|
fclose(fs);
|
||||||
|
|
||||||
|
dz = open("/dev/zero", O_RDWR, 0644);
|
||||||
|
if (dz < 0) {
|
||||||
|
puts("Couldn't open /dev/zero\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
segments = (WadSegment *) mmap(NULL, nsegments*sizeof(WadSegment), PROT_READ | PROT_WRITE, MAP_PRIVATE, dz, 0);
|
||||||
|
close(dz);
|
||||||
|
|
||||||
|
fs = segment_open();
|
||||||
|
i = 0;
|
||||||
|
s = segments;
|
||||||
|
|
||||||
|
/* First segment is a map to the segment list */
|
||||||
|
s->base = (char *) segments;
|
||||||
|
s->vaddr = (char *) segments;
|
||||||
|
s->size = nsegments*sizeof(WadSegment);
|
||||||
|
s->mapname[0] = 0;
|
||||||
|
s->mappath[0] = 0;
|
||||||
|
s++;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
n = segment_read(fs,&ws);
|
||||||
|
if (n <= 0) break;
|
||||||
|
strcpy(s->mapname, ws.mapname);
|
||||||
|
strcpy(s->mappath, ws.mappath);
|
||||||
|
s->vaddr = ws.vaddr;
|
||||||
|
s->base = ws.base;
|
||||||
|
s->size = ws.size;
|
||||||
|
s->offset = ws.offset;
|
||||||
|
if (wad_debug_mode & DEBUG_SEGMENT) {
|
||||||
|
printf("wad_segment: read : %08x-%08x in %s\n", s->vaddr, ((char *) s->vaddr) + s->size, s->mappath);
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
/* Create sentinel */
|
||||||
|
s->base = 0;
|
||||||
|
s->vaddr = 0;
|
||||||
|
s->size = 0;
|
||||||
|
s->offset = 0;
|
||||||
|
s->mapname[0] =0;
|
||||||
|
s->mappath[0] = 0;
|
||||||
|
fclose(fs);
|
||||||
|
return segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* wad_segment_release()
|
||||||
|
*
|
||||||
|
* This function releases all of the segments.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
wad_segment_release(WadSegment *s) {
|
||||||
|
munmap((void *)s, s->size);
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_segment_find()
|
* wad_segment_find()
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue