Skip to content

Commit

Permalink
Remove 'nonwr' stuff, now useless
Browse files Browse the repository at this point in the history
  • Loading branch information
alainfrisch committed Aug 2, 2018
1 parent 6299d12 commit 47e7180
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
15 changes: 6 additions & 9 deletions flexdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ typedef unsigned long uintnat;
#define RELOC_DONE 0x0100

typedef struct { UINT_PTR kind; char *name; UINT_PTR *addr; } reloc_entry;
typedef struct { char *first; char *last; DWORD old; } nonwr;
typedef struct { nonwr *nonwr; reloc_entry entries[]; } reloctbl;
typedef struct { UINT_PTR magic; reloc_entry entries[]; } reloctbl;
typedef struct { void *addr; char *name; } dynsymbol;
typedef struct { UINT_PTR size; dynsymbol entries[]; } symtbl;
typedef struct dlunit {
Expand Down Expand Up @@ -122,16 +121,10 @@ static char *ll_dlerror(void)

static void dump_reloctbl(reloctbl *tbl) {
reloc_entry *ptr;
nonwr *wr;

if (!tbl) { printf("No relocation table\n"); return; }
printf("Dynamic relocation table found at %p\n", tbl);

for (wr = tbl->nonwr; wr->last != 0; wr++)
printf(" Non-writable relocation in zone %p -> %p\n",
wr->first,
wr->last);

for (ptr = tbl->entries; ptr->kind; ptr++)
printf(" %p (kind:%04lx) (now:%p) %s\n",
(void *)ptr->addr,
Expand All @@ -158,7 +151,6 @@ static void cannot_resolve_msg(char *name) {

static void relocate(resolver f, void *data, reloctbl *tbl) {
reloc_entry *ptr;
nonwr *wr;
INT_PTR s;
DWORD prev_protect;
static long int page_size = 0;
Expand All @@ -167,6 +159,10 @@ static void relocate(resolver f, void *data, reloctbl *tbl) {
char *prev_page_start = (char*)1, *prev_page_end = (char*)1;

if (!tbl) return;
if (tbl->magic != 42) {
error = 4;
return;
}

if (0 == page_size) {
GetSystemInfo (&si);
Expand Down Expand Up @@ -463,6 +459,7 @@ char *flexdll_dlerror() {
case 1: error = 0; return ll_dlerror();
case 2: error = 0; return error_buffer;
case 3: error = 0; return error_buffer;
case 4: error = 0; return "Invalid flexdll magic number (flexdll version mismatch?)";
}
return NULL;
}
Expand Down
30 changes: 6 additions & 24 deletions reloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,14 @@ let add_reloc_table obj obj_name p =
let sect = Section.create ".reltbl" 0xc0300040l in
let data = Buffer.create 1024 in
let strings = Buffer.create 1024 in
let nonwr = ref [] in
let nonwrsym = Symbol.intern sect 0l in
let strsym = Symbol.intern sect 0l in
let str_pos = Hashtbl.create 16 in

Reloc.abs !machine sect 0l nonwrsym;
int_to_buf data 0;
int_to_buf data 42;

(* TODO: use a single symbol per section *)
let syms = ref [] in
let reloc secsym min max rel =
let reloc secsym rel =
if p rel.symbol then (
(* kind *)
let kind = match !machine, rel.rtype with
Expand Down Expand Up @@ -422,8 +419,6 @@ let add_reloc_table obj obj_name p =
(Lazy.force secsym);
int_to_buf data (Int32.to_int rel.addr);

if rel.addr <= !min then min := rel.addr;
if rel.addr >= !max then max := rel.addr;
false
) else true
in
Expand All @@ -437,36 +432,23 @@ let add_reloc_table obj obj_name p =
sec.sec_name <- Printf.sprintf ".flexrefptrsection%i" (Oo.id (object end));
end;

let min = ref Int32.max_int and max = ref Int32.min_int in
let sym = lazy (let s = Symbol.intern sec 0l in
syms := s :: !syms;
s) in

sec.relocs <- filter (reloc sym min max) sec.relocs;
if (sec.sec_opts &&& 0x80000000l = 0l) && !min <= !max then
nonwr := (!min,!max,Lazy.force sym) :: !nonwr
sec.relocs <- filter (reloc sym) sec.relocs
in
List.iter section obj.sections;
int_to_buf data 0;
strsym.value <- Int32.of_int (Buffer.length data);
Buffer.add_buffer data strings;
nonwrsym.value <- Int32.of_int (Buffer.length data);
List.iter
(fun (min,max,secsym) ->
Reloc.abs !machine sect (Int32.of_int (Buffer.length data)) secsym;
int_to_buf data (Int32.to_int min);
Reloc.abs !machine sect (Int32.of_int (Buffer.length data)) secsym;
int_to_buf data (Int32.to_int max);
int_to_buf data 0;
)
!nonwr;
int_to_buf data 0;
int_to_buf data 0;
strsym.value <- Int32.of_int (Buffer.length data);
Buffer.add_buffer data strings;
sect.data <- `String (Buffer.to_bytes data);
obj.sections <- sect :: obj.sections;
obj.symbols <-
(Symbol.export sname sect 0l) ::
strsym :: nonwrsym :: List.filter (fun x -> not (p x)) obj.symbols
strsym :: List.filter (fun x -> not (p x)) obj.symbols
@ !syms;
sname

Expand Down

0 comments on commit 47e7180

Please sign in to comment.