/* * $Header: /afs/pdc.kth.se/src/projects/perftools/iotrack/iotrack/callmacros-x86-linux.h,v 1.8 2004/10/15 16:06:07 pek Exp $ * * pek@pdc.kth.se $Date: 2004/10/15 16:06:07 $ * * Linux x86 glibc syscalls/stream I/O * */ #include #include #include #include #include #define REAL_OPEN __open #define REAL_OPEN64 __open64 #define REAL_CLOSE __close #define REAL_DUP2 __dup2 #define REAL_READV __libc_readv #define REAL_WRITEV __libc_writev #define REAL_READ __read #define REAL_WRITE __write #define REAL_FCNTL __fcntl #define REAL_LSEEK __lseek #define REAL_FORK __libc_fork #if defined(NPTL) #define __thread __threadp #endif #define REAL_LSEEK64 __libc_lseek64 #define REAL_PREAD #define REAL_PWRITE #define REAL_FDOPEN _IO_fdopen #define REAL_FCLOSE _IO_fclose #define REAL_FWRITE _IO_fwrite #define REAL_FREAD _IO_fread #define REAL_FSEEK #define REAL_FSEEK64 #define REAL_REWIND #define REAL_FSETPOS _IO_fsetpos #define REAL_FGETC _IO_getc #define REAL_FGETS _IO_fgets #define REAL_GETC _IO_getc #define REAL_GETS _IO_gets /* #define REAL_FPUTC */ #define REAL_FPUTS _IO_fputs #define REAL_PUTC _IO_putc #define REAL_PUTS _IO_puts #define REAL_UNGETC _IO_ungetc #define REAL_VFSCANF __vfscanf #define REAL_FPRINTF _IO_vfprintf #define REAL_FSCANF _vfscanf #define REAL_VFPRINTF _IO_vfprintf /* #define REAL_EXECVE __execve */ /* static inline int REAL_EXECV(const char *path, char *const argv[]) */ /* { */ /* return REAL_EXECVE(path, argv, environ); */ /* } */ static inline int REAL_DUP(int oldfd) { return REAL_FCNTL(oldfd, F_DUPFD, 0); } static inline int REAL_CREAT(const char *file, mode_t mode) { return REAL_OPEN(file, O_WRONLY|O_CREAT|O_TRUNC, mode); } static inline int REAL_CREAT64(const char *file, mode_t mode) { return REAL_OPEN64(file, O_WRONLY|O_CREAT|O_TRUNC, mode); } static inline FILE *REAL_FOPEN(const char *path, const char *mode) { static FILE *(*real_fopen)(const char *, const char *) = NULL; if (real_fopen == NULL) { real_fopen = dlsym(RTLD_NEXT,"fopen"); if (real_fopen == NULL) { char *error = dlerror(); if (error != NULL) { fprintf(stderr,"iowrap : Failed to find symbol for fopen: %s\n", error); exit(1); } else { fprintf(stderr,"iowrap : Failed to find non-NULL symbol for fopen\n"); exit(1); } } } return (*real_fopen)(path,mode); } static inline FILE *REAL_FOPEN64(const char *path, const char *mode) { static FILE *(*real_fopen64)(const char *, const char *) = NULL; if (real_fopen64 == NULL) { real_fopen64 = dlsym(RTLD_NEXT,"fopen64"); if (real_fopen64 == NULL) { char *error = dlerror(); if (error != NULL) { fprintf(stderr,"iowrap : Failed to find symbol for fopen64: %s\n", error); exit(1); } else { fprintf(stderr,"iowrap : Failed to find non-NULL symbol for fopen64\n"); exit(1); } } } return (*real_fopen64)(path,mode); } static inline int REAL_SOCKET(int domain, int type, int proto) { unsigned long a[3]; a[0] = domain; a[1] = type; a[2] = proto; return syscall(SYS_socketcall, SYS_SOCKET, a); } static inline int REAL_ACCEPT(int s, struct sockaddr *addr, socklen_t *addrlen) { unsigned long a[3]; a[0] = s; a[1] = (unsigned long)addr; a[2] = (unsigned long)addrlen; return (syscall(SYS_socketcall, SYS_ACCEPT, a)); } static inline ssize_t REAL_SEND(int s, const void *buf, size_t len, int flags) { unsigned long a[4]; a[0] = s; a[1] = (unsigned long) buf; a[2] = (unsigned long) len; a[3] = (unsigned long) flags; return (syscall(SYS_socketcall, SYS_SEND, a)); } static inline ssize_t REAL_SENDTO(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { unsigned long a[6]; a[0] = s; a[1] = (unsigned long) buf; a[2] = (unsigned long) len; a[3] = (unsigned long) flags; a[4] = (unsigned long) to; a[5] = (unsigned long) tolen; return(syscall(SYS_socketcall, SYS_SENDTO, a)); } static inline ssize_t REAL_SENDMSG(int s, const struct msghdr *msg, int flags) { unsigned long a[3]; a[0] = s; a[1] = (unsigned long) msg; a[2] = (unsigned long) flags; return(syscall(SYS_socketcall, SYS_SENDMSG, a)); } static inline ssize_t REAL_RECV(int s, void *buf, size_t len, int flags) { unsigned long a[4]; a[0] = s; a[1] = (unsigned long) buf; a[2] = (unsigned long) len; a[3] = (unsigned long) flags; return(syscall(SYS_socketcall, SYS_RECV, a)); } static inline ssize_t REAL_RECVFROM(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { unsigned long a[6]; a[0] = s; a[1] = (unsigned long) buf; a[2] = (unsigned long) len; a[3] = (unsigned long) flags; a[4] = (unsigned long) from; a[5] = (unsigned long) fromlen; return(syscall(SYS_socketcall, SYS_RECVFROM, a)); } static inline ssize_t REAL_RECVMSG(int s, struct msghdr *msg, int flags) { unsigned long a[3]; a[0] = s; a[1] = (unsigned long) msg; a[2] = (unsigned long) flags; return(syscall(SYS_socketcall, SYS_RECVMSG, a)); }