+}
+
+/* XilCommNS::CPortResources::Instance() */
+void* _ZN9XilCommNS14CPortResources8InstanceEv() {
+ static void* (*func) (void) = NULL;
+ char *filename = NULL;
+ void *ret;
+ int i;
+
+ if (!func) {
+ struct sigaction act, oldact;
+ int sighand_installed = 0;
+
+ func = (void* (*) (void)) dlsym(RTLD_NEXT, "_ZN9XilCommNS14CPortResources8InstanceEv");
+
+ 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;
+ }
+
+ 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;
+ size_t protectlen;
+ void *start;
+ int len = strlen(filename) + 1;
+ int ret;
+
+ pagesize = sysconf(_SC_PAGE_SIZE);
+ DPRINTF("You have %lu bytes sized pages!\n", pagesize);
+
+ start = (void*)((long)filename & (~(pagesize-1)));
+
+ protectlen = pagesize;
+ if ((long)(filename + len) > (long)(start + protectlen))
+ protectlen += pagesize;
+
+ DPRINTF("Unprotecting %zd bytes starting at %p\n", protectlen, start);
+ ret = mprotect(start, protectlen, PROT_READ|PROT_WRITE);
+ if (ret == -1)
+ perror("mprotect");
+
+ DPRINTF("Replacing %s with /dev/zero\n", filename);
+ strcpy(filename, "/dev/zero");
+
+ DPRINTF("Reprotecting %zd bytes starting at %p\n", protectlen, start);
+ ret = mprotect(start, protectlen, PROT_READ|PROT_EXEC);
+ if (ret == -1)
+ perror("mprotect");
+ }
+
+ DPRINTF("-> XilCommNS::CPortResources::Instance()\n");
+
+ ret = func();
+
+ DPRINTF("<- XilCommNS::CPortResources::Instance()\n");
+