forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnu_load.c
More file actions
76 lines (64 loc) · 1.99 KB
/
Copy pathgnu_load.c
File metadata and controls
76 lines (64 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* gnu_load for mdb.c
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <gnu/a.out.h>
_PROTOTYPE( unsigned int gnu_load, (char *filename, struct nlist **start) );
_PROTOTYPE( void do_error, (char *message) );
unsigned int gnu_load( filename, start)
char *filename;
struct nlist **start;
{
struct exec header;
unsigned int nsym, string_size;
char *names;
struct nlist *p;
int fd;
if ( (fd = open( filename, 0)) < 0 ||
read( fd, (char *) &header, sizeof header ) != sizeof header )
{
do_error( "gnu_load" );
if ( fd >= 0) close( fd );
return 0;
}
if ( lseek( fd, N_STROFF( header ), 0 ) != N_STROFF( header ) )
{
do_error( "gnu_load - reading header" );
close( fd );
return 0;
}
if ( read( fd, (char *) &string_size, sizeof string_size ) < 0 )
{
do_error( "gnu_load - reading header" );
close( fd );
return 0;
}
if ( (int) header.a_syms < 0 ||
(unsigned) header.a_syms != header.a_syms ||
(*start = (struct nlist *) malloc( (unsigned) header.a_syms +
string_size ))
== (struct nlist *) NULL &&
header.a_syms != 0 )
{
close( fd );
return 0;
}
lseek( fd, N_SYMOFF( header ), 0 );
if ( read( fd, (char *) *start, (int) header.a_syms + string_size ) < 0 )
{
do_error( "gnu_load - reading symbols" );
close( fd );
return 0;
}
close( fd );
nsym = (unsigned int) header.a_syms / sizeof (struct nlist);
names = (char *) *start + header.a_syms;
for ( p = *start; p < *start + nsym; p++)
if(p->n_un.n_strx)
p->n_un.n_name = names + p->n_un.n_strx;
return nsym;
}