From 641cb4c48830b130d21290307c260da6853e76fd Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 14 Nov 2014 17:48:25 +0100 Subject: [PATCH 1/4] native: add accept syscall declaration --- boards/native/drivers/native-uart0.c | 2 +- cpu/native/include/native_internal.h | 2 ++ cpu/native/syscalls.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index 4f651d3b7f..cbed70d90d 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -217,7 +217,7 @@ void handle_uart_sock(void) t = sizeof(remote); _native_syscall_enter(); - if ((s = accept(_native_uart_sock, &remote, &t)) == -1) { + if ((s = real_accept(_native_uart_sock, &remote, &t)) == -1) { err(EXIT_FAILURE, "handle_uart_sock: accept"); } else { diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index 28c814c734..fa9880ff00 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -78,6 +78,8 @@ 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); /* The ... is a hack to save includes: */ +extern int (*real_accept)(int socket, ...); +/* The ... is a hack to save includes: */ extern int (*real_bind)(int socket, ...); extern int (*real_close)(int); extern int (*real_dup2)(int, int); diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 01bc226c17..38714e5577 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -55,6 +55,7 @@ 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_accept)(int socket, ...); int (*real_bind)(int socket, ...); int (*real_printf)(const char *format, ...); int (*real_getpid)(void); @@ -355,6 +356,7 @@ void _native_init_syscalls(void) *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); *(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); + *(void **)(&real_accept) = dlsym(RTLD_NEXT, "accept"); *(void **)(&real_bind) = dlsym(RTLD_NEXT, "bind"); *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); *(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid"); From a1b530a98d5900c1ff3ebb4a63b2b6e0ab16b296 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 14 Nov 2014 20:50:39 +0100 Subject: [PATCH 2/4] native: shutdown -> native_shutdown --- cpu/native/irq_cpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/native/irq_cpu.c b/cpu/native/irq_cpu.c index a47bd4b620..a9283decb1 100644 --- a/cpu/native/irq_cpu.c +++ b/cpu/native/irq_cpu.c @@ -421,7 +421,7 @@ int unregister_interrupt(int sig) return 0; } -void shutdown(int sig, siginfo_t *info, void *context) +static void native_shutdown(int sig, siginfo_t *info, void *context) { (void)sig; (void)info; @@ -510,8 +510,8 @@ void native_interrupt_init(void) } /* allow for ctrl+c to shut down gracefully always */ - //register_interrupt(SIGINT, shutdown); - sa.sa_sigaction = shutdown; + //register_interrupt(SIGINT, native_shutdown); + sa.sa_sigaction = native_shutdown; if (sigdelset(&_native_sig_set, SIGINT) == -1) { err(EXIT_FAILURE, "native_interrupt_init: sigdelset"); } From acaa6481cbffb3eaa8f7bc3599a9caebe0a32825 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Fri, 14 Nov 2014 20:52:17 +0100 Subject: [PATCH 3/4] native: add more syscall declarations --- boards/native/drivers/native-uart0.c | 14 +++++++------- cpu/native/include/native_internal.h | 8 ++++++++ cpu/native/syscalls.c | 12 +++++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/boards/native/drivers/native-uart0.c b/boards/native/drivers/native-uart0.c index cbed70d90d..676be2a8ae 100644 --- a/boards/native/drivers/native-uart0.c +++ b/boards/native/drivers/native-uart0.c @@ -106,24 +106,24 @@ int init_tcp_socket(char *tcpport) hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - if ((i = getaddrinfo(NULL, tcpport, &hints, &info)) != 0) { + if ((i = real_getaddrinfo(NULL, tcpport, &hints, &info)) != 0) { errx(EXIT_FAILURE, - "init_uart_socket: getaddrinfo: %s", gai_strerror(i)); + "init_uart_socket: getaddrinfo: %s", real_gai_strerror(i)); } for (p = info; p != NULL; p = p->ai_next) { - if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { + if ((s = real_socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { warn("init_uart_socket: socket"); continue; } i = 1; - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(int)) == -1) { + if (real_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(int)) == -1) { err(EXIT_FAILURE, "init_uart_socket: setsockopt"); } if (real_bind(s, p->ai_addr, p->ai_addrlen) == -1) { - close(s); + real_close(s); warn("init_uart_socket: bind"); continue; } @@ -133,7 +133,7 @@ int init_tcp_socket(char *tcpport) if (p == NULL) { errx(EXIT_FAILURE, "init_uart_socket: failed to bind\n"); } - freeaddrinfo(info); + real_freeaddrinfo(info); if (real_listen(s, 1) == -1) { err(EXIT_FAILURE, "init_uart_socket: listen"); @@ -147,7 +147,7 @@ int init_unix_socket(void) int s; struct sockaddr_un sa; - if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + if ((s = real_socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { err(EXIT_FAILURE, "init_unix_socket: socket"); } diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index fa9880ff00..b73c16e4e7 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -43,6 +43,7 @@ #include #endif #endif // BSD/Linux +#include #include "kernel_types.h" @@ -78,6 +79,8 @@ 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); /* The ... is a hack to save includes: */ +extern void (*real_freeaddrinfo)(struct addrinfo *res); +/* The ... is a hack to save includes: */ extern int (*real_accept)(int socket, ...); /* The ... is a hack to save includes: */ extern int (*real_bind)(int socket, ...); @@ -87,12 +90,17 @@ 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); +/* The ... is a hack to save includes: */ +extern int (*real_getaddrinfo)(const char *node, ...); extern int (*real_getpid)(void); extern int (*real_listen)(int socket, int backlog); extern int (*real_pause)(void); extern int (*real_pipe)(int[2]); +extern int (*real_setsockopt)(int socket, ...); +extern int (*real_socket)(int domain, int type, int protocol); extern int (*real_printf)(const char *format, ...); extern int (*real_unlink)(const char *); +extern const char* (*real_gai_strerror)(int errcode); extern FILE* (*real_fopen)(const char *path, const char *mode); /** diff --git a/cpu/native/syscalls.c b/cpu/native/syscalls.c index 38714e5577..716997ee7e 100644 --- a/cpu/native/syscalls.c +++ b/cpu/native/syscalls.c @@ -55,11 +55,12 @@ 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); +void (*real_freeaddrinfo)(struct addrinfo *res); int (*real_accept)(int socket, ...); int (*real_bind)(int socket, ...); int (*real_printf)(const char *format, ...); +int (*real_getaddrinfo)(const char *node, ...); int (*real_getpid)(void); -int (*real_pipe)(int[2]); int (*real_close)(int); int (*real_dup2)(int, int); int (*real_execve)(const char *, char *const[], char *const[]); @@ -68,7 +69,11 @@ int (*real_feof)(FILE *stream); int (*real_ferror)(FILE *stream); int (*real_listen)(int socket, int backlog); int (*real_pause)(void); +int (*real_pipe)(int[2]); +int (*real_setsockopt)(int socket, ...); +int (*real_socket)(int domain, int type, int protocol); int (*real_unlink)(const char *); +const char* (*real_gai_strerror)(int errcode); FILE* (*real_fopen)(const char *path, const char *mode); void _native_syscall_enter(void) @@ -356,14 +361,19 @@ void _native_init_syscalls(void) *(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc"); *(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc"); *(void **)(&real_free) = dlsym(RTLD_NEXT, "free"); + *(void **)(&real_freeaddrinfo) = dlsym(RTLD_NEXT, "freeaddrinfo"); *(void **)(&real_accept) = dlsym(RTLD_NEXT, "accept"); *(void **)(&real_bind) = dlsym(RTLD_NEXT, "bind"); *(void **)(&real_printf) = dlsym(RTLD_NEXT, "printf"); + *(void **)(&real_gai_strerror) = dlsym(RTLD_NEXT, "gai_strerror"); + *(void **)(&real_getaddrinfo) = dlsym(RTLD_NEXT, "getaddrinfo"); *(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_setsockopt) = dlsym(RTLD_NEXT, "setsockopt"); + *(void **)(&real_socket) = dlsym(RTLD_NEXT, "socket"); *(void **)(&real_unlink) = dlsym(RTLD_NEXT, "unlink"); *(void **)(&real_execve) = dlsym(RTLD_NEXT, "execve"); *(void **)(&real_listen) = dlsym(RTLD_NEXT, "listen"); From 42e43d5e1292228b15e4415a788924b2d5f5efc1 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 17 Nov 2014 09:55:56 +0100 Subject: [PATCH 4/4] FIXUP: remove erroneous comment --- cpu/native/include/native_internal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/cpu/native/include/native_internal.h b/cpu/native/include/native_internal.h index b73c16e4e7..62947d6314 100644 --- a/cpu/native/include/native_internal.h +++ b/cpu/native/include/native_internal.h @@ -78,7 +78,6 @@ 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); -/* The ... is a hack to save includes: */ extern void (*real_freeaddrinfo)(struct addrinfo *res); /* The ... is a hack to save includes: */ extern int (*real_accept)(int socket, ...);