From c0e3a774b2ef79f2b2e310c4d3255aa57eda78cb Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 11 Oct 2010 02:24:39 +0100 Subject: [PATCH] [linux] Fix building on RHEL5 and similar platforms Signed-off-by: Michael Brown --- src/arch/x86/core/linux/linux_api.c | 88 +++++++++++++---------------- src/include/linux_api.h | 49 ++++++++-------- 2 files changed, 65 insertions(+), 72 deletions(-) diff --git a/src/arch/x86/core/linux/linux_api.c b/src/arch/x86/core/linux/linux_api.c index e5786870..c8a09b7d 100644 --- a/src/arch/x86/core/linux/linux_api.c +++ b/src/arch/x86/core/linux/linux_api.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -FILE_LICENCE(GPL2_OR_LATER); +FILE_LICENCE ( GPL2_OR_LATER ); /** @file * @@ -29,86 +29,78 @@ FILE_LICENCE(GPL2_OR_LATER); #include #include -int linux_open(const char *pathname, int flags) -{ - return linux_syscall(__NR_open, pathname, flags); +int linux_open ( const char *pathname, int flags ) { + return linux_syscall ( __NR_open, pathname, flags ); } -int linux_close(int fd) -{ - return linux_syscall(__NR_close, fd); +int linux_close ( int fd ) { + return linux_syscall ( __NR_close, fd ); } -ssize_t linux_read(int fd, void *buf, size_t count) -{ - return linux_syscall(__NR_read, fd, buf, count); +__kernel_ssize_t linux_read ( int fd, void *buf, __kernel_size_t count ) { + return linux_syscall ( __NR_read, fd, buf, count ); } -ssize_t linux_write(int fd, const void *buf, size_t count) -{ - return linux_syscall(__NR_write, fd, buf, count); +__kernel_ssize_t linux_write ( int fd, const void *buf, + __kernel_size_t count ) { + return linux_syscall ( __NR_write, fd, buf, count ); } -int linux_fcntl(int fd, int cmd, ...) -{ +int linux_fcntl ( int fd, int cmd, ... ) { long arg; va_list list; - va_start(list, cmd); - arg = va_arg(list, long); - va_end(list); + va_start ( list, cmd ); + arg = va_arg ( list, long ); + va_end ( list ); - return linux_syscall(__NR_fcntl, fd, cmd, arg); + return linux_syscall ( __NR_fcntl, fd, cmd, arg ); } -int linux_ioctl(int fd, int request, ...) -{ +int linux_ioctl ( int fd, int request, ... ) { void *arg; va_list list; - va_start(list, request); - arg = va_arg(list, void *); - va_end(list); + va_start ( list, request ); + arg = va_arg ( list, void * ); + va_end ( list ); - return linux_syscall(__NR_ioctl, fd, request, arg); + return linux_syscall ( __NR_ioctl, fd, request, arg ); } -int linux_poll(struct pollfd *fds, nfds_t nfds, int timeout) -{ - return linux_syscall(__NR_poll, fds, nfds, timeout); +int linux_poll ( struct pollfd *fds, nfds_t nfds, int timeout ) { + return linux_syscall ( __NR_poll, fds, nfds, timeout ); } -int linux_nanosleep(const struct timespec *req, struct timespec *rem) -{ - return linux_syscall(__NR_nanosleep, req, rem); +int linux_nanosleep ( const struct timespec *req, struct timespec *rem ) { + return linux_syscall ( __NR_nanosleep, req, rem ); } -int linux_usleep(useconds_t usec) -{ +int linux_usleep ( useconds_t usec ) { struct timespec ts = { - .tv_sec = (long) (usec / 1000000), - .tv_nsec = (long) (usec % 1000000) * 1000ul + .tv_sec = ( ( long ) ( usec / 1000000 ) ), + .tv_nsec = ( ( long ) ( usec % 1000000 ) * 1000UL ), }; - return linux_nanosleep(&ts, NULL); + return linux_nanosleep ( &ts, NULL ); } -int linux_gettimeofday(struct timeval *tv, struct timezone *tz) -{ - return linux_syscall(__NR_gettimeofday, tv, tz); +int linux_gettimeofday ( struct timeval *tv, struct timezone *tz ) { + return linux_syscall ( __NR_gettimeofday, tv, tz ); } -void *linux_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) -{ - return (void *)linux_syscall(__SYSCALL_mmap, addr, length, prot, flags, fd, offset); +void * linux_mmap ( void *addr, __kernel_size_t length, int prot, int flags, + int fd, __kernel_off_t offset ) { + return ( void * ) linux_syscall ( __SYSCALL_mmap, addr, length, prot, + flags, fd, offset ); } -void *linux_mremap(void *old_address, size_t old_size, size_t new_size, int flags) -{ - return (void *)linux_syscall(__NR_mremap, old_address, old_size, new_size, flags); +void * linux_mremap ( void *old_address, __kernel_size_t old_size, + __kernel_size_t new_size, int flags ) { + return ( void * ) linux_syscall ( __NR_mremap, old_address, old_size, + new_size, flags ); } -int linux_munmap(void *addr, size_t length) -{ - return linux_syscall(__NR_munmap, addr, length); +int linux_munmap ( void *addr, __kernel_size_t length ) { + return linux_syscall ( __NR_munmap, addr, length ); } diff --git a/src/include/linux_api.h b/src/include/linux_api.h index 6f591d82..066cdd30 100644 --- a/src/include/linux_api.h +++ b/src/include/linux_api.h @@ -33,40 +33,41 @@ FILE_LICENCE(GPL2_OR_LATER); #include -typedef int pid_t; - +#define __KERNEL_STRICT_NAMES #include #include +typedef __kernel_pid_t pid_t; +typedef __kernel_time_t time_t; +typedef __kernel_suseconds_t suseconds_t; +typedef __kernel_loff_t loff_t; #include #include #include #include #include - -typedef uint32_t useconds_t; - -extern long linux_syscall(int number, ...); - -extern int linux_open(const char *pathname, int flags); -extern int linux_close(int fd); -extern ssize_t linux_read(int fd, void *buf, size_t count); -extern ssize_t linux_write(int fd, const void *buf, size_t count); -extern int linux_fcntl(int fd, int cmd, ...); -extern int linux_ioctl(int fd, int request, ...); - typedef unsigned long nfds_t; -extern int linux_poll(struct pollfd *fds, nfds_t nfds, int timeout); +typedef uint32_t useconds_t; +#define MAP_FAILED ( ( void * ) -1 ) -extern int linux_nanosleep(const struct timespec *req, struct timespec *rem); -extern int linux_usleep(useconds_t usec); -extern int linux_gettimeofday(struct timeval *tv, struct timezone *tz); +extern long linux_syscall ( int number, ... ); -#define MAP_FAILED ((void *)-1) +extern int linux_open ( const char *pathname, int flags ); +extern int linux_close ( int fd ); +extern __kernel_ssize_t linux_read ( int fd, void *buf, __kernel_size_t count ); +extern __kernel_ssize_t linux_write ( int fd, const void *buf, + __kernel_size_t count ); +extern int linux_fcntl ( int fd, int cmd, ... ); +extern int linux_ioctl ( int fd, int request, ... ); +extern int linux_poll ( struct pollfd *fds, nfds_t nfds, int timeout ); +extern int linux_nanosleep ( const struct timespec *req, struct timespec *rem ); +extern int linux_usleep ( useconds_t usec ); +extern int linux_gettimeofday ( struct timeval *tv, struct timezone *tz ); +extern void * linux_mmap ( void *addr, __kernel_size_t length, int prot, + int flags, int fd, off_t offset ); +extern void * linux_mremap ( void *old_address, __kernel_size_t old_size, + __kernel_size_t new_size, int flags ); +extern int linux_munmap ( void *addr, __kernel_size_t length ); -extern void *linux_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); -extern void *linux_mremap(void *old_address, size_t old_size, size_t new_size, int flags); -extern int linux_munmap(void *addr, size_t length); - -extern const char *linux_strerror(int errnum); +extern const char * linux_strerror ( int errnum ); #endif /* _LINUX_API_H */