From 3cda0369cb1d64fbe290fc1192ab832dc916a966 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann <ludwig.ortmann@fu-berlin.de> Date: Fri, 18 Jul 2014 10:07:02 +0200 Subject: [PATCH] native: cleanup fix style fix some syscall declarations reorder syscall declarations init syscalls in dedicated function substitute 1 with EXIT_FAILURE --- boards/native/drivers/native-uart0.c | 4 ++-- cpu/native/include/native_internal.h | 14 +++++++----- cpu/native/startup.c | 25 ++------------------ cpu/native/syscalls.c | 34 +++++++++++++++++++++++++--- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index 6ba53fc03c..443b4a2983 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -180,7 +180,7 @@ void handle_uart_in(void) nread = _native_read(STDIN_FILENO, buf, sizeof(buf)); if (nread == -1) { - err(1, "handle_uart_in(): read()"); + err(EXIT_FAILURE, "handle_uart_in(): read()"); } else if (nread == 0) { /* end of file / socket closed */ @@ -200,7 +200,7 @@ void handle_uart_in(void) errx(EXIT_FAILURE, "handle_uart_in: unhandled situation!"); } } - for(int pos = 0; pos < nread; pos++) { + for (int pos = 0; pos < nread; pos++) { uart0_handle_incoming(buf[pos]); } uart0_notify_thread(); diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index 5857516048..a6285669a1 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -49,6 +49,7 @@ extern void _native_sig_leave_tramp(void); void _native_syscall_leave(void); void _native_syscall_enter(void); +void _native_init_syscalls(void); /** * external functions regularly wrapped in native for direct use @@ -56,21 +57,22 @@ void _native_syscall_enter(void); extern ssize_t (*real_read)(int fd, void *buf, size_t count); extern ssize_t (*real_write)(int fd, const void *buf, size_t count); extern size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); -extern void* (*real_malloc)(size_t size); extern void (*real_clearerr)(FILE *stream); extern void (*real_free)(void *ptr); extern void* (*real_calloc)(size_t nmemb, size_t size); +extern void* (*real_malloc)(size_t size); extern void* (*real_realloc)(void *ptr, size_t size); -extern int (*real_getpid)(void); -extern int (*real_pipe)(int[2]); extern int (*real_close)(int); +extern int (*real_dup2)(int, int); +extern int (*real_execve)(const char *, char *const[], char *const[]); extern int (*real_feof)(FILE *stream); extern int (*real_ferror)(FILE *stream); extern int (*real_fork)(void); -extern int (*real_dup2)(int, int); -extern int (*real_unlink)(const char *); -extern int (*real_execve)(const char *, char *const[], char *const[]); +extern int (*real_getpid)(void); extern int (*real_pause)(void); +extern int (*real_pipe)(int[2]); +extern int (*real_printf)(const char *format, ...); +extern int (*real_unlink)(const char *); extern FILE* (*real_fopen)(const char *path, const char *mode); /** diff --git a/cpu/native/startup.c b/cpu/native/startup.c index bc0e894c0a..49db1e1be8 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -37,8 +37,6 @@ #include "native_internal.h" #include "tap.h" -int (*real_printf)(const char *format, ...); -int (*real_getpid)(void); int _native_null_in_pipe[2]; int _native_null_out_file; const char *_progname; @@ -55,7 +53,7 @@ const char *_native_unix_socket_path = NULL; void _native_null_in(char *stdiotype) { if (real_pipe(_native_null_in_pipe) == -1) { - err(1, "_native_null_in(): pipe()"); + err(EXIT_FAILURE, "_native_null_in(): pipe()"); } if (strcmp(stdiotype, "stdio") == 0) { @@ -196,26 +194,7 @@ The order of command line arguments matters.\n"); __attribute__((constructor)) static void startup(int argc, char **argv) { - /* get system read/write/printf */ - *(void **)(&real_read) = dlsym(RTLD_NEXT, "read"); - *(void **)(&real_write) = dlsym(RTLD_NEXT, "write"); - *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); - *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); - *(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); - *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); - *(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid"); - *(void **)(&real_pipe) = dlsym(RTLD_NEXT, "pipe"); - *(void **)(&real_close) = dlsym(RTLD_NEXT, "close"); - *(void **)(&real_fork) = dlsym(RTLD_NEXT, "fork"); - *(void **)(&real_dup2) = dlsym(RTLD_NEXT, "dup2"); - *(void **)(&real_unlink) = dlsym(RTLD_NEXT, "unlink"); - *(void **)(&real_execve) = dlsym(RTLD_NEXT, "execve"); - *(void **)(&real_pause) = dlsym(RTLD_NEXT, "pause"); - *(void **)(&real_fopen) = dlsym(RTLD_NEXT, "fopen"); - *(void **)(&real_fread) = dlsym(RTLD_NEXT, "fread"); - *(void **)(&real_feof) = dlsym(RTLD_NEXT, "feof"); - *(void **)(&real_ferror) = dlsym(RTLD_NEXT, "ferror"); - *(void **)(&real_clearerr) = dlsym(RTLD_NEXT, "clearerr"); + _native_init_syscalls(); _native_argv = argv; _progname = argv[0]; diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index cc3abda816..1ba4d14c67 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -51,20 +51,22 @@ extern volatile tcb_t *sched_active_thread; ssize_t (*real_read)(int fd, void *buf, size_t count); ssize_t (*real_write)(int fd, const void *buf, size_t count); size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream); -void* (*real_malloc)(size_t size); void (*real_clearerr)(FILE *stream); void (*real_free)(void *ptr); +void* (*real_malloc)(size_t size); void* (*real_calloc)(size_t nmemb, size_t size); void* (*real_realloc)(void *ptr, size_t size); +int (*real_printf)(const char *format, ...); +int (*real_getpid)(void); int (*real_pipe)(int[2]); int (*real_close)(int); -int (*real_fork)(void); int (*real_dup2)(int, int); -int (*real_unlink)(const char *); int (*real_execve)(const char *, char *const[], char *const[]); +int (*real_fork)(void); int (*real_feof)(FILE *stream); int (*real_ferror)(FILE *stream); int (*real_pause)(void); +int (*real_unlink)(const char *); FILE* (*real_fopen)(const char *path, const char *mode); void _native_syscall_enter(void) @@ -339,3 +341,29 @@ int _gettimeofday(struct timeval *tp, void *restrict tzp) { return 0; } #endif + +/** + * set up native internal syscall symbols + */ +void _native_init_syscalls(void) +{ + *(void **)(&real_read) = dlsym(RTLD_NEXT, "read"); + *(void **)(&real_write) = dlsym(RTLD_NEXT, "write"); + *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); + *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); + *(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); + *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); + *(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid"); + *(void **)(&real_pipe) = dlsym(RTLD_NEXT, "pipe"); + *(void **)(&real_close) = dlsym(RTLD_NEXT, "close"); + *(void **)(&real_fork) = dlsym(RTLD_NEXT, "fork"); + *(void **)(&real_dup2) = dlsym(RTLD_NEXT, "dup2"); + *(void **)(&real_unlink) = dlsym(RTLD_NEXT, "unlink"); + *(void **)(&real_execve) = dlsym(RTLD_NEXT, "execve"); + *(void **)(&real_pause) = dlsym(RTLD_NEXT, "pause"); + *(void **)(&real_fopen) = dlsym(RTLD_NEXT, "fopen"); + *(void **)(&real_fread) = dlsym(RTLD_NEXT, "fread"); + *(void **)(&real_feof) = dlsym(RTLD_NEXT, "feof"); + *(void **)(&real_ferror) = dlsym(RTLD_NEXT, "ferror"); + *(void **)(&real_clearerr) = dlsym(RTLD_NEXT, "clearerr"); +} -- GitLab