return 1;
}
+void cpr_segv_handler(int sig, siginfo_t *info, void *context) {
+ void *newmem;
+
+ DPRINTF("SEGV at %p, mapping memory\n", info->si_addr);
+ errno = 0;
+ newmem = mmap(info->si_addr, 1, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
+ if (newmem != info->si_addr) {
+ perror("libusb-driver.so: Can't map memory, crashing now");
+ exit(EXIT_FAILURE);
+ }
+}
+
/* XilCommNS::CPortResources::Instance() */
void* _ZN9XilCommNS14CPortResources8InstanceEv() {
static void* (*func) (void) = NULL;
- static char *NetString = NULL;
- static char *NetString2 = NULL;
char *filename = NULL;
void *ret;
+ int i;
- if (!func)
- func = (void* (*) (void)) dlsym(RTLD_NEXT, "_ZN9XilCommNS14CPortResources8InstanceEv");
+ if (!func) {
+ struct sigaction act, oldact;
+ int sighand_installed = 0;
- if (!NetString)
- NetString = (char*)dlsym(RTLD_NEXT, "_ZTSN9XilCommNS9NetStringE");
+ func = (void* (*) (void)) dlsym(RTLD_NEXT, "_ZN9XilCommNS14CPortResources8InstanceEv");
- if (!NetString2)
- NetString2 = (char*)dlsym(RTLD_NEXT, "_ZTIN9XilCommNS9NetStringE");
-
- if (NetString && (!strcmp((char*)(NetString+0xb0), "/proc/sys/dev/parport/%s/base-addr")))
- filename = (char*)(NetString+0xb0);
+ DPRINTF("Installing signal-handler for SIGSEGV\n");
+ bzero(&act, sizeof(struct sigaction));
+ act.sa_sigaction = cpr_segv_handler;
+ act.sa_flags = SA_SIGINFO;
+ if (sigaction(SIGSEGV, &act, &oldact) == 0) {
+ sighand_installed = 1;
+ }
- if (NetString2 && (!strcmp((char*)(NetString2+0xa4), "/proc/sys/dev/parport/%s/base-addr")))
- filename = (char*)(NetString2+0xa4);
+ DPRINTF("Searching for filename starting at %p\n", func);
+ for(i = 0; i < 32768; i++) {
+ if (!strcmp(((char*)func)+i, "/proc/sys/dev/parport/%s/base-addr")) {
+ filename = ((char*)func)+i;
+ DPRINTF("Filename found at offset %p\n", (void*)(filename - ((char*)func)));
+ break;
+ }
+ }
+ if (sighand_installed) {
+ DPRINTF("Restoring signal-handler for SIGSEGV\n");
+ sigaction(SIGSEGV, &oldact, NULL);
+ }
+ if (!filename)
+ fprintf(stderr, "libusb-driver.so: Can't find memory to patch, parallel cables will probably not work!\n");
+ }
if (filename) {
long pagesize;