1 /* libusb/ppdev connector for XILINX impact
3 * Copyright (c) 2007 Michael Gernoth <michael@gernoth.net>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include <sys/types.h>
41 #include <sys/ioctl.h>
42 #include <sys/utsname.h>
43 #include <bits/wordsize.h>
44 #include "usb-driver.h"
48 static int (*ioctl_func
) (int, int, void *) = NULL
;
49 static int windrvrfd
= -1;
50 static unsigned long ppbase
= 0;
51 static unsigned long ecpbase
= 0;
52 static struct parport_config
*pport
= NULL
;
53 static struct xpcu_s
*xpcu
= NULL
;
54 static FILE *modulesfp
= NULL
;
55 static FILE *baseaddrfp
= NULL
;
56 static int baseaddrnum
= 0;
57 static int modules_read
= 0;
58 static unsigned long card_type
;
59 static int ints_enabled
= 0;
60 static pthread_mutex_t int_wait
= PTHREAD_MUTEX_INITIALIZER
;
64 void hexdump(unsigned char *buf
, int len
) {
67 for(i
=0; i
<len
; i
++) {
68 fprintf(stderr
,"%02x ", buf
[i
]);
76 static int do_wdioctl(int fd
, unsigned int request
, unsigned char *wdioctl
) {
77 struct header_struct
* wdheader
= (struct header_struct
*)wdioctl
;
78 struct version_struct
*version
;
81 if (wdheader
->magic
!= MAGIC
) {
82 fprintf(stderr
,"!!!ERROR: magic header does not match!!!\n");
83 return (*ioctl_func
) (fd
, request
, wdioctl
);
86 switch(request
& ~(0xc0000000)) {
88 version
= (struct version_struct
*)(wdheader
->data
);
89 strcpy(version
->version
, "libusb-driver.so version: " USB_DRIVER_VERSION
);
90 version
->versionul
= 802;
98 case CARD_REGISTER_OLD
:
100 DPRINTF("CARD_REGISTER\n");
102 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
104 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
106 (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
,
107 cr
->Card
.Item
[0].I
.IO
.dwBytes
,
108 cr
->Card
.Item
[0].I
.IO
.dwBar
);
110 DPRINTF("Items: %lu, Addr: 0x%lx, bytes: %lu, bar: %lu\n",
112 (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
,
113 cr
->Card
.Item
[1].I
.IO
.dwBytes
,
114 cr
->Card
.Item
[1].I
.IO
.dwBar
);
116 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
119 pport
= config_get((unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
/ 0x10);
123 ret
= pport
->open((unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
/ 0x10);
125 ppbase
= (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
;
127 if (cr
->Card
.dwItems
> 1 && cr
->Card
.Item
[1].I
.IO
.dwAddr
)
128 ecpbase
= (unsigned long)cr
->Card
.Item
[1].I
.IO
.dwAddr
;
136 DPRINTF("hCard: %lu\n", cr
->hCard
);
141 DPRINTF("in USB_TRANSFER");
143 struct usb_transfer
*ut
= (struct usb_transfer
*)(wdheader
->data
);
146 DPRINTF(" unique: %lu, pipe: %lu, read: %lu, options: %lx, size: %lu, timeout: %lx\n",
147 ut
->dwUniqueID
, ut
->dwPipeNum
, ut
->fRead
,
148 ut
->dwOptions
, ut
->dwBufferSize
, ut
->dwTimeout
);
149 if (ut
->dwPipeNum
== 0) {
150 DPRINTF("setup packet: ");
151 hexdump(ut
->SetupPacket
, 8);
154 if (!ut
->fRead
&& ut
->dwBufferSize
)
156 hexdump(ut
->pBuffer
, ut
->dwBufferSize
);
161 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
163 xpcu_transfer(xpcu
, ut
);
167 DPRINTF("Transferred: %lu (%s)\n",ut
->dwBytesTransferred
, (ut
->fRead
?"read":"write"));
168 if (ut
->fRead
&& ut
->dwBytesTransferred
)
171 hexdump(ut
->pBuffer
, ut
->dwBytesTransferred
);
179 DPRINTF("INT_ENABLE\n");
181 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
183 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
184 it
->hInterrupt
, it
->dwOptions
,
185 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
186 it
->dwLost
, it
->fStopped
);
191 pthread_mutex_trylock(&int_wait
);
197 DPRINTF("INT_DISABLE\n");
199 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
201 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
202 it
->hInterrupt
, it
->dwOptions
,
203 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
204 it
->dwLost
, it
->fStopped
);
206 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
211 if (pthread_mutex_trylock(&int_wait
) == EBUSY
)
212 pthread_mutex_unlock(&int_wait
);
214 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
215 it
->hInterrupt
, it
->dwOptions
,
216 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
217 it
->dwLost
, it
->fStopped
);
221 case USB_SET_INTERFACE
:
222 DPRINTF("USB_SET_INTERFACE\n");
224 struct usb_set_interface
*usi
= (struct usb_set_interface
*)(wdheader
->data
);
226 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
227 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
228 usi
->dwAlternateSetting
, usi
->dwOptions
);
230 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
234 xpcu
->handle
= usb_open(xpcu
->dev
);
237 usb_reset(xpcu
->handle
);
238 xpcu
->handle
= usb_open(xpcu
->dev
);
243 xpcu
->interface
= xpcu
->dev
->config
[0].interface
[usi
->dwInterfaceNum
].altsetting
[usi
->dwAlternateSetting
].bInterfaceNumber
;
244 xpcu
->alternate
= usi
->dwAlternateSetting
;
247 DPRINTF("unique: %lu, interfacenum: %lu, alternatesetting: %lu, options: %lx\n",
248 usi
->dwUniqueID
, usi
->dwInterfaceNum
,
249 usi
->dwAlternateSetting
, usi
->dwOptions
);
253 case USB_GET_DEVICE_DATA_OLD
:
254 case USB_GET_DEVICE_DATA
:
255 DPRINTF("USB_GET_DEVICE_DATA\n");
257 struct usb_get_device_data
*ugdd
= (struct usb_get_device_data
*)(wdheader
->data
);
260 DPRINTF("unique: %lu, bytes: %lu, options: %lx\n",
261 ugdd
->dwUniqueID
, ugdd
->dwBytes
,
264 pSize
= ugdd
->dwBytes
;
265 if (!ugdd
->dwBytes
) {
267 ugdd
->dwBytes
= xpcu_deviceinfo(xpcu
, NULL
);
270 xpcu_deviceinfo(xpcu
, (unsigned char*)ugdd
->pBuf
);
275 case EVENT_REGISTER_OLD
:
277 DPRINTF("EVENT_REGISTER\n");
279 struct event
*e
= (struct event
*)(wdheader
->data
);
282 int busnum
= -1, devnum
= -1;
285 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
286 e
->handle
, e
->dwAction
,
287 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
288 e
->hKernelPlugIn
, e
->dwOptions
,
289 e
->u
.Usb
.deviceId
.dwVendorId
,
290 e
->u
.Usb
.deviceId
.dwProductId
,
291 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
292 e
->dwNumMatchTables
);
294 devpos
= getenv("XILINX_USB_DEV");
295 if (devpos
!= NULL
) {
297 char *devstr
= NULL
, *remainder
;
299 DPRINTF("XILINX_USB_DEV=%s\n", devpos
);
301 for (j
= 0; j
< strlen(devpos
) && devpos
[j
] != 0; j
++) {
302 if (devpos
[j
] == ':') {
304 devstr
= &(devpos
[j
+1]);
308 if (devstr
&& strlen(devstr
) > 0) {
309 busnum
= strtol(devpos
, &remainder
, 10);
310 if (devpos
== remainder
) {
313 devnum
= strtol(devstr
, &remainder
, 10);
314 if (devstr
== remainder
) {
318 fprintf(stderr
,"Using XILINX platform cable USB at %03d:%03d\n",
325 for (i
= 0; i
< e
->dwNumMatchTables
; i
++) {
327 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
328 e
->matchTables
[i
].VendorId
,
329 e
->matchTables
[i
].ProductId
,
330 e
->matchTables
[i
].bDeviceClass
,
331 e
->matchTables
[i
].bDeviceSubClass
,
332 e
->matchTables
[i
].bInterfaceClass
,
333 e
->matchTables
[i
].bInterfaceSubClass
,
334 e
->matchTables
[i
].bInterfaceProtocol
);
336 for (bus
= xpcu
->busses
; bus
; bus
= bus
->next
) {
337 struct usb_device
*dev
;
339 if ((devnum
!= -1) && (strtol(bus
->dirname
, NULL
, 10) != busnum
))
342 for (dev
= bus
->devices
; dev
; dev
= dev
->next
) {
343 struct usb_device_descriptor
*desc
= &(dev
->descriptor
);
345 if((desc
->idVendor
== e
->matchTables
[i
].VendorId
) &&
346 (desc
->idProduct
== e
->matchTables
[i
].ProductId
) &&
347 (desc
->bDeviceClass
== e
->matchTables
[i
].bDeviceClass
) &&
348 (desc
->bDeviceSubClass
== e
->matchTables
[i
].bDeviceSubClass
) &&
349 ((devnum
== -1) || (strtol(dev
->filename
, NULL
, 10) == devnum
)) ) {
351 for (ac
= 0; ac
< desc
->bNumConfigurations
; ac
++) {
352 struct usb_interface
*interface
= dev
->config
[ac
].interface
;
355 for (ai
= 0; ai
< interface
->num_altsetting
; ai
++) {
357 DPRINTF("intclass: %x, intsubclass: %x, intproto: %x\n",
358 interface
->altsetting
[i
].bInterfaceClass
,
359 interface
->altsetting
[i
].bInterfaceSubClass
,
360 interface
->altsetting
[i
].bInterfaceProtocol
);
362 if ((interface
->altsetting
[ai
].bInterfaceSubClass
== e
->matchTables
[i
].bInterfaceSubClass
) &&
363 (interface
->altsetting
[ai
].bInterfaceProtocol
== e
->matchTables
[i
].bInterfaceProtocol
)){
364 /* TODO: check interfaceClass! */
365 DPRINTF("found device with libusb\n");
367 card_type
= e
->dwCardType
;
377 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
383 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lu, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
384 e
->handle
, e
->dwAction
,
385 e
->dwStatus
, e
->dwEventId
, e
->dwCardType
,
386 e
->hKernelPlugIn
, e
->dwOptions
,
387 e
->u
.Usb
.deviceId
.dwVendorId
,
388 e
->u
.Usb
.deviceId
.dwProductId
,
389 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
390 e
->dwNumMatchTables
);
392 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
393 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
394 e
->matchTables
[i
].VendorId
,
395 e
->matchTables
[i
].ProductId
,
396 e
->matchTables
[i
].bDeviceClass
,
397 e
->matchTables
[i
].bDeviceSubClass
,
398 e
->matchTables
[i
].bInterfaceClass
,
399 e
->matchTables
[i
].bInterfaceSubClass
,
400 e
->matchTables
[i
].bInterfaceProtocol
);
407 DPRINTF("TRANSFER\n");
409 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
412 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
414 ret
= pport
->transfer(tr
, fd
, request
, ppbase
, ecpbase
, 1);
419 case MULTI_TRANSFER_OLD
:
421 DPRINTF("MULTI_TRANSFER\n");
423 WD_TRANSFER
*tr
= (WD_TRANSFER
*)(wdheader
->data
);
424 unsigned long num
= wdheader
->size
/sizeof(WD_TRANSFER
);
426 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
428 ret
= pport
->transfer(tr
, fd
, request
, ppbase
, ecpbase
, num
);
433 case EVENT_UNREGISTER
:
434 DPRINTF("EVENT_UNREGISTER\n");
436 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
441 DPRINTF("INT_WAIT\n");
443 struct interrupt
*it
= (struct interrupt
*)(wdheader
->data
);
445 DPRINTF("Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
446 it
->hInterrupt
, it
->dwOptions
,
447 it
->dwCmds
, it
->fEnableOk
, it
->dwCounter
,
448 it
->dwLost
, it
->fStopped
);
451 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
454 if (it
->dwCounter
== 0) {
457 pthread_mutex_lock(&int_wait
);
458 pthread_mutex_unlock(&int_wait
);
461 pthread_mutex_lock(&int_wait
);
462 pthread_mutex_unlock(&int_wait
);
466 DPRINTF("INT_WAIT_RETURN: Handle: %lu, Options: %lx, ncmds: %lu, enableok: %lu, count: %lu, lost: %lu, stopped: %lu\n",
467 it
->hInterrupt
, it
->dwOptions
, it
->dwCmds
,
468 it
->fEnableOk
, it
->dwCounter
, it
->dwLost
,
473 case CARD_UNREGISTER
:
474 DPRINTF("CARD_UNREGISTER\n");
476 struct card_register
* cr
= (struct card_register
*)(wdheader
->data
);
478 DPRINTF("Addr: 0x%lx, bytes: %lu, bar: %lu\n",
479 (unsigned long)cr
->Card
.Item
[0].I
.IO
.dwAddr
,
480 cr
->Card
.Item
[0].I
.IO
.dwBytes
,
481 cr
->Card
.Item
[0].I
.IO
.dwBar
);
483 DPRINTF("hCard: %lu\n", cr
->hCard
);
486 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
489 pport
->close(cr
->hCard
);
497 DPRINTF("EVENT_PULL\n");
499 struct event
*e
= (struct event
*)(wdheader
->data
);
503 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
504 e
->handle
, e
->dwAction
, e
->dwStatus
,
505 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
506 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
507 e
->u
.Usb
.deviceId
.dwProductId
,
508 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
509 e
->dwNumMatchTables
);
511 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
512 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
513 e
->matchTables
[i
].VendorId
,
514 e
->matchTables
[i
].ProductId
,
515 e
->matchTables
[i
].bDeviceClass
,
516 e
->matchTables
[i
].bDeviceSubClass
,
517 e
->matchTables
[i
].bInterfaceClass
,
518 e
->matchTables
[i
].bInterfaceSubClass
,
519 e
->matchTables
[i
].bInterfaceProtocol
);
523 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
526 struct usb_interface
*interface
= xpcu
->dev
->config
->interface
;
528 e
->dwCardType
= card_type
;
531 e
->u
.Usb
.dwUniqueID
= 110;
532 e
->matchTables
[0].VendorId
= xpcu
->dev
->descriptor
.idVendor
;
533 e
->matchTables
[0].ProductId
= xpcu
->dev
->descriptor
.idProduct
;
534 e
->matchTables
[0].bDeviceClass
= xpcu
->dev
->descriptor
.bDeviceClass
;
535 e
->matchTables
[0].bDeviceSubClass
= xpcu
->dev
->descriptor
.bDeviceSubClass
;
536 e
->matchTables
[0].bInterfaceClass
= interface
->altsetting
[0].bInterfaceClass
;
537 e
->matchTables
[0].bInterfaceSubClass
= interface
->altsetting
[0].bInterfaceSubClass
;
538 e
->matchTables
[0].bInterfaceProtocol
= interface
->altsetting
[0].bInterfaceProtocol
;
543 DPRINTF("handle: %lu, action: %lu, status: %lu, eventid: %lu, cardtype: %lx, kplug: %lu, options: %lu, dev: %lx:%lx, unique: %lu, ver: %lu, nummatch: %lu\n",
544 e
->handle
, e
->dwAction
, e
->dwStatus
,
545 e
->dwEventId
, e
->dwCardType
, e
->hKernelPlugIn
,
546 e
->dwOptions
, e
->u
.Usb
.deviceId
.dwVendorId
,
547 e
->u
.Usb
.deviceId
.dwProductId
,
548 e
->u
.Usb
.dwUniqueID
, e
->dwEventVer
,
549 e
->dwNumMatchTables
);
551 for (i
= 0; i
< e
->dwNumMatchTables
; i
++)
552 DPRINTF("match: dev: %04x:%04x, class: %x, subclass: %x, intclass: %x, intsubclass: %x, intproto: %x\n",
553 e
->matchTables
[i
].VendorId
,
554 e
->matchTables
[i
].ProductId
,
555 e
->matchTables
[i
].bDeviceClass
,
556 e
->matchTables
[i
].bDeviceSubClass
,
557 e
->matchTables
[i
].bInterfaceClass
,
558 e
->matchTables
[i
].bInterfaceSubClass
,
559 e
->matchTables
[i
].bInterfaceProtocol
);
566 fprintf(stderr
,"!!!Unsupported IOCTL: %x!!!\n", request
);
568 ret
= (*ioctl_func
) (fd
, request
, wdioctl
);
576 int ioctl(int fd
, unsigned long int request
, ...) {
582 ioctl_func
= (int (*) (int, int, void *)) dlsym (RTLD_NEXT
, "ioctl");
584 va_start (args
, request
);
585 argp
= va_arg (args
, void *);
589 ret
= do_wdioctl(fd
, request
, argp
);
591 ret
= (*ioctl_func
) (fd
, request
, argp
);
596 int open (const char *pathname
, int flags
, ...) {
597 static int (*func
) (const char *, int, mode_t
) = NULL
;
603 func
= (int (*) (const char *, int, mode_t
)) dlsym (RTLD_NEXT
, "open");
605 if (flags
& O_CREAT
) {
606 va_start(args
, flags
);
607 mode
= va_arg(args
, mode_t
);
611 if (!strcmp (pathname
, "/dev/windrvr6")) {
612 DPRINTF("opening windrvr6\n");
614 windrvrfd
= fd
= (*func
) ("/dev/null", flags
, mode
);
616 windrvrfd
= fd
= (*func
) (pathname
, flags
, mode
);
624 return (*func
) (pathname
, flags
, mode
);
628 static int (*func
) (int) = NULL
;
631 func
= (int (*) (int)) dlsym(RTLD_NEXT
, "close");
633 if (fd
== windrvrfd
&& windrvrfd
>= 0) {
634 DPRINTF("close windrvrfd\n");
637 xpcu_claim(xpcu
, XPCU_RELEASE
);
638 usb_close(xpcu
->handle
);
642 xpcu
->interface
= -1;
650 FILE *fopen(const char *path
, const char *mode
) {
652 static FILE* (*func
) (const char*, const char*) = NULL
;
657 func
= (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT
, "fopen");
659 for (i
= 0; i
< 4; i
++) {
660 snprintf(buf
, sizeof(buf
), "/proc/sys/dev/parport/parport%d/base-addr", i
);
661 if (!strcmp(path
, buf
)) {
662 DPRINTF("open base-addr of parport%d\n", i
);
663 if (config_is_real_pport(i
)) {
664 ret
= (*func
) (path
, mode
);
666 ret
= (*func
) ("/dev/null", mode
);
678 ret
= (*func
) (path
, mode
);
680 if (!strcmp(path
, "/proc/modules")) {
681 DPRINTF("opening /proc/modules\n");
691 char *fgets(char *s
, int size
, FILE *stream
) {
692 static char* (*func
) (char*, int, FILE*) = NULL
;
693 const char modules
[][256] = {"windrvr6 1 0 - Live 0xdeadbeef\n", "parport_pc 1 0 - Live 0xdeadbeef\n"};
699 func
= (char* (*) (char*, int, FILE*)) dlsym(RTLD_NEXT
, "fgets");
701 if (modulesfp
== stream
) {
702 if (modules_read
< sizeof(modules
) / sizeof(modules
[0])) {
703 strcpy(s
, modules
[modules_read
]);
707 } else if (baseaddrfp
== stream
) {
708 snprintf(s
, sizeof(buf
), "%d\t%d\n",
709 (baseaddrnum
) * 0x10,
710 ((baseaddrnum
) * 0x10) + 0x400);
713 ret
= (*func
)(s
,size
,stream
);
719 int fclose(FILE *fp
) {
720 static int (*func
) (FILE*) = NULL
;
723 func
= (int (*) (FILE*)) dlsym(RTLD_NEXT
, "fclose");
725 if (fp
== modulesfp
) {
729 if (fp
== baseaddrfp
) {
736 int access(const char *pathname
, int mode
) {
737 static int (*func
) (const char*, int);
740 func
= (int (*) (const char*, int)) dlsym(RTLD_NEXT
, "access");
742 if (pathname
&& !strcmp(pathname
, "/dev/windrvr6")) {
745 return (*func
)(pathname
, mode
);
750 int uname (struct utsname
*__name
) {
751 static int (*func
) (struct utsname
*);
755 func
= (int (*) (struct utsname
*)) dlsym(RTLD_NEXT
, "uname");
757 ret
= (*func
)(__name
);
759 if (ret
== 0 && (!strcmp(__name
->machine
, "x86_64"))) {
760 strcpy(__name
->machine
, "i686");