Some linux changes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@939 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
047feee80d
commit
60490c14c8
3 changed files with 98 additions and 6 deletions
|
|
@ -16,6 +16,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#ifdef WAD_SOLARIS
|
||||||
|
#include <procfs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -37,7 +41,7 @@ typedef struct WadSegment {
|
||||||
char mappath[MAX_PATH]; /* Full path to mapname */
|
char mappath[MAX_PATH]; /* Full path to mapname */
|
||||||
} WadSegment;
|
} WadSegment;
|
||||||
|
|
||||||
extern void wad_segment_print(WadSegment *s);
|
extern void wad_segment_print();
|
||||||
extern WadSegment *wad_segment_find(char *addr);
|
extern WadSegment *wad_segment_find(char *addr);
|
||||||
extern void wad_segment_release();
|
extern void wad_segment_release();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ tcl::
|
||||||
cp wad.so libwadtcl.so
|
cp wad.so libwadtcl.so
|
||||||
cp libwadtcl.so ..
|
cp libwadtcl.so ..
|
||||||
|
|
||||||
|
linux::
|
||||||
|
cc -DWAD_LINUX $(INCLUDE) segment.c debug.c
|
||||||
|
|
||||||
debug::
|
debug::
|
||||||
cc -g debug.c $(INCLUDE) -L. -R. -lwad
|
cc -g debug.c $(INCLUDE) -L. -R. -lwad
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#include "wad.h"
|
#include "wad.h"
|
||||||
#include <procfs.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
|
|
||||||
/* The segment map is actually stored in an mmap'd data structure so we
|
/* The segment map is actually stored in an mmap'd data structure so we
|
||||||
can avoid the use of malloc()/free(). */
|
can avoid the use of malloc()/free(). */
|
||||||
|
|
@ -24,15 +22,19 @@ static int segments_size; /* Size of mmap'd region */
|
||||||
static int nsegments = 0; /* Number of segments */
|
static int nsegments = 0; /* Number of segments */
|
||||||
|
|
||||||
/* This function reads the segment map into memory */
|
/* This function reads the segment map into memory */
|
||||||
|
#ifdef WAD_SOLARIS
|
||||||
|
|
||||||
|
/* ------------- Solaris Version ------------------ */
|
||||||
|
|
||||||
static
|
static
|
||||||
void read_segments() {
|
void read_segments() {
|
||||||
int fd;
|
int fd;
|
||||||
int dz;
|
int dz;
|
||||||
prmap_t pmap;
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int i;
|
int i;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
WadSegment *s;
|
WadSegment *s;
|
||||||
|
prmap_t pmap;
|
||||||
|
|
||||||
/* Try to load the virtual address map */
|
/* Try to load the virtual address map */
|
||||||
fd = open("/proc/self/map", O_RDONLY);
|
fd = open("/proc/self/map", O_RDONLY);
|
||||||
|
|
@ -49,7 +51,7 @@ void read_segments() {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
dz = open("/dev/zero", O_RDWR, 0644);
|
dz = open("/dev/zero", O_RDWR, 0644);
|
||||||
if (fd < 0) {
|
if (dz < 0) {
|
||||||
puts("Couldn't open /dev/zero\n");
|
puts("Couldn't open /dev/zero\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -83,6 +85,81 @@ void read_segments() {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WAD_LINUX
|
||||||
|
|
||||||
|
/* ------------- Linux Version ------------------ */
|
||||||
|
|
||||||
|
static
|
||||||
|
void read_segments() {
|
||||||
|
FILE *f;
|
||||||
|
int dz;
|
||||||
|
int offset = 0;
|
||||||
|
int i;
|
||||||
|
int n = 0;
|
||||||
|
char pbuffer[1024];
|
||||||
|
char *c;
|
||||||
|
WadSegment *s;
|
||||||
|
|
||||||
|
/* Try to load the virtual address map */
|
||||||
|
f = fopen("/proc/self/maps", "r");
|
||||||
|
if (!f) return;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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 */
|
||||||
|
|
||||||
|
/* Break up the field into records */
|
||||||
|
/* 0-8 : Starting address
|
||||||
|
9-17 : Ending Address
|
||||||
|
18 : r
|
||||||
|
19 : w
|
||||||
|
20 : x
|
||||||
|
21 : p
|
||||||
|
23-31 : Offset
|
||||||
|
49- : Filename */
|
||||||
|
|
||||||
|
pbuffer[8] = 0;
|
||||||
|
pbuffer[17] = 0;
|
||||||
|
pbuffer[31] = 0;
|
||||||
|
strcpy(s->mapname, pbuffer+49);
|
||||||
|
strcpy(s->mappath, pbuffer+49);
|
||||||
|
|
||||||
|
s->vaddr = (char *) strtoul(pbuffer,NULL,16);
|
||||||
|
s->size = strtoul(pbuffer+9,NULL,16) - (long) (s->vaddr);
|
||||||
|
s->offset = strtoul(pbuffer+23,NULL,16);
|
||||||
|
s->base = s->vaddr;
|
||||||
|
s->flags = 0;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_segment_release()
|
* wad_segment_release()
|
||||||
*
|
*
|
||||||
|
|
@ -133,7 +210,14 @@ wad_segment_find(char *addr) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
wad_segment_print(WadSegment *s) {
|
wad_segment_print() {
|
||||||
|
int i;
|
||||||
|
WadSegment *s;
|
||||||
|
if (!segments) {
|
||||||
|
read_segments();
|
||||||
|
}
|
||||||
|
s = segments;
|
||||||
|
for (i = 0; i < nsegments; i++, s++) {
|
||||||
printf("Segment %x:::\n",s);
|
printf("Segment %x:::\n",s);
|
||||||
printf(" mapname = %s\n", s->mapname);
|
printf(" mapname = %s\n", s->mapname);
|
||||||
printf(" mappath = %s\n", s->mappath);
|
printf(" mappath = %s\n", s->mappath);
|
||||||
|
|
@ -141,4 +225,5 @@ wad_segment_print(WadSegment *s) {
|
||||||
printf(" size = %d\n", s->size);
|
printf(" size = %d\n", s->size);
|
||||||
printf(" offset = %d\n", s->offset);
|
printf(" offset = %d\n", s->offset);
|
||||||
printf(" flags = 0x%x\n", s->flags);
|
printf(" flags = 0x%x\n", s->flags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue