7 #if defined(HAVE_GELF_H)
8 #if LIBELF_H_LFS_CONFLICT
12 # undef _LARGEFILE64_SOURCE
13 # undef _LARGEFILE_SOURCE
14 # undef _FILE_OFFSET_BITS
15 # define _FILE_OFFSET_BITS 32
17 #if defined(__LCLINT__)
19 typedef long long loff_t;
24 #if !defined(DT_GNU_PRELINKED)
25 #define DT_GNU_PRELINKED 0x6ffffdf5
27 #if !defined(DT_GNU_LIBLIST)
28 #define DT_GNU_LIBLIST 0x6ffffef9
39 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
49 static int open_dso(
const char * path, pid_t * pidp,
size_t *fsizep)
59 struct stat sb, * st = &sb;
60 if (stat(path, st) < 0)
62 *fsizep = (size_t)st->st_size;
65 fdno = open(path, O_RDONLY);
69 #if defined(HAVE_GELF_H) && defined(HAVE_LIBELF)
72 Elf_Data *data = NULL;
77 static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
79 static const char ** cmd_av = NULL;
80 static int cmd_ac = 0;
83 xx = pthread_mutex_lock(&_mutex);
85 oneshot = yarnNewLock(0);
87 const char * cmd =
rpmExpand(
"%{?__prelink_undo_cmd}", NULL);
88 (void) poptParseArgvString(cmd, &cmd_ac, &cmd_av);
91 xx = pthread_mutex_unlock(&_mutex);
98 (void) elf_version(EV_CURRENT);
101 if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
102 || elf_kind(elf) != ELF_K_ELF
103 || gelf_getehdr(elf, &ehdr) == NULL
104 || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC))
106 if (elf) (void) elf_end(elf);
108 yarnRelease(oneshot);
114 while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) {
115 (void) gelf_getshdr(scn, &shdr);
116 if (shdr.sh_type != SHT_DYNAMIC)
118 while (!bingo && (data = elf_getdata (scn, data)) != NULL) {
119 unsigned maxndx = (unsigned) (data->d_size / shdr.sh_entsize);
122 for (ndx = 0; ndx < maxndx; ++ndx) {
124 (void) gelf_getdyn (data, ndx, &dyn);
126 if (!(dyn.d_tag == DT_GNU_PRELINKED || dyn.d_tag == DT_GNU_LIBLIST))
136 yarnRelease(oneshot);
138 if (pidp != NULL && bingo) {
139 int pipes[2] = { -1, -1 };
147 {
const char ** av = NULL;
149 xx = close(pipes[0]);
150 xx = dup2(pipes[1], STDOUT_FILENO);
151 xx = close(pipes[1]);
152 if (!poptDupArgv(cmd_ac, cmd_av, &ac, &av)) {
156 xx = execve(av[0], (
char *
const *)av+1,
environ);
163 xx = close(pipes[1]);
176 static const char hmackey[] =
"orboDeJITITejsirpADONivirpUkvarP";
178 int dodigest(
int dalgo,
const char * fn,
unsigned char * digest,
179 unsigned dflags,
size_t *fsizep)
181 int asAscii = dflags & 0x01;
182 int doHmac = dflags & 0x02;
185 unsigned char * dsum = NULL;
187 unsigned char buf[32*BUFSIZ];
194 #if defined(HAVE_MMAP)
199 fdno =
open_dso(path, &pid, &fsize);
207 use_mmap = (pid == 0 && fsize <= 0x07ffffff);
212 #if defined(HAVE_MMAP)
215 void * mapped = NULL;
218 mapped = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fdno, 0);
219 if (mapped == (
void *)-1) {
225 #if defined(HAVE_MADVISE) && defined(MADV_SEQUENTIAL)
226 xx = madvise(mapped, fsize, MADV_SEQUENTIAL);
237 xx = munmap(mapped, fsize);
249 fd = (pid != 0) ?
fdDup(fdno) :
Fopen(fn,
"r.fdio");
251 if (fd == NULL ||
Ferror(fd)) {
262 while ((rc = (
int)
Fread(buf,
sizeof(buf[0]),
sizeof(buf), fd)) > 0)
276 (void) waitpid(pid, &status, 0);
278 if (!WIFEXITED(status) || WEXITSTATUS(status))
286 memcpy(digest, dsum, dlen);