Browse Source

native: add missing syscall declarations

dev/timer
Ludwig Ortmann 8 years ago
parent
commit
7901d24053
  1. 10
      cpu/native/include/native_internal.h
  2. 6
      cpu/native/lpm_cpu.c
  3. 2
      cpu/native/native_cpu.c
  4. 18
      cpu/native/net/tap.c
  5. 12
      cpu/native/startup.c
  6. 23
      cpu/native/syscalls.c

10
cpu/native/include/native_internal.h

@ -44,6 +44,7 @@
#endif
#endif // BSD/Linux
#include <netdb.h>
#include <ifaddrs.h>
#include "kernel_types.h"
@ -77,17 +78,21 @@ 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_clearerr)(FILE *stream);
extern __attribute__((noreturn)) void (*real_exit)(int status);
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 void (*real_freeaddrinfo)(struct addrinfo *res);
extern void (*real_freeifaddrs)(struct ifaddrs *ifa);
extern void (*real_srandom)(unsigned int seed);
/* 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);
/* The ... is a hack to save includes: */
extern int (*real_creat)(const char *path, ...);
extern int (*real_dup2)(int, int);
extern int (*real_execve)(const char *, char *const[], char *const[]);
extern int (*real_feof)(FILE *stream);
@ -95,10 +100,15 @@ 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_getifaddrs)(struct ifaddrs **ifap);
extern int (*real_getpid)(void);
extern int (*real_ioctl)(int fildes, int request, ...);
extern int (*real_listen)(int socket, int backlog);
extern int (*real_open)(const char *path, int oflag, ...);
extern int (*real_pause)(void);
extern int (*real_pipe)(int[2]);
/* The ... is a hack to save includes: */
extern int (*real_select)(int nfds, ...);
extern int (*real_setsockopt)(int socket, ...);
extern int (*real_socket)(int domain, int type, int protocol);
extern int (*real_printf)(const char *format, ...);

6
cpu/native/lpm_cpu.c

@ -54,7 +54,7 @@ void _native_lpm_sleep(void)
nfds++;
_native_in_syscall++; // no switching here
nfds = select(nfds, &_native_rfds, NULL, NULL, NULL);
nfds = real_select(nfds, &_native_rfds, NULL, NULL, NULL);
_native_in_syscall--;
DEBUG("_native_lpm_sleep: returned: %i\n", nfds);
@ -129,11 +129,11 @@ enum lpm_mode lpm_set(enum lpm_mode target)
case LPM_OFF:
printf("lpm_set(): exit()\n");
exit(0);
real_exit(EXIT_SUCCESS);
default:
DEBUG("XXX: unsupported power mode: %i\n", native_lpm);
exit(1);
real_exit(EXIT_FAILURE);
}
return last_lpm;

2
cpu/native/native_cpu.c

@ -161,7 +161,7 @@ void cpu_switch_context_exit(void)
#ifdef NATIVE_AUTO_EXIT
if (sched_num_threads <= 1) {
DEBUG("cpu_switch_context_exit(): last task has ended. exiting.\n");
exit(EXIT_SUCCESS);
real_exit(EXIT_SUCCESS);
}
#endif

18
cpu/native/net/tap.c

@ -124,7 +124,7 @@ void _native_handle_tap_input(void)
_native_in_syscall++; // no switching here
if (select(_native_tap_fd + 1, &rfds, NULL, NULL, &t) == 1) {
if (real_select(_native_tap_fd + 1, &rfds, NULL, NULL, &t) == 1) {
int sig = SIGIO;
extern int _sig_pipefd[2];
extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
@ -177,7 +177,7 @@ void sigio_child(void)
FD_ZERO(&rfds);
FD_SET(_native_tap_fd, &rfds);
if (select(_native_tap_fd + 1, &rfds, NULL, NULL, NULL) == 1) {
if (real_select(_native_tap_fd + 1, &rfds, NULL, NULL, NULL) == 1) {
kill(parent, SIGIO);
}
else {
@ -259,14 +259,14 @@ int tap_init(char *name)
#endif
/* implicitly create the tap interface */
if ((_native_tap_fd = open(clonedev , O_RDWR)) == -1) {
if ((_native_tap_fd = real_open(clonedev , O_RDWR)) == -1) {
err(EXIT_FAILURE, "open(%s)", clonedev);
}
#if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */
struct ifaddrs *iflist;
if (getifaddrs(&iflist) == 0) {
if (real_getifaddrs(&iflist) == 0) {
for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) {
if ((cur->ifa_addr->sa_family == AF_LINK) && (strcmp(cur->ifa_name, name) == 0) && cur->ifa_addr) {
struct sockaddr_dl *sdl = (struct sockaddr_dl *)cur->ifa_addr;
@ -275,7 +275,7 @@ int tap_init(char *name)
}
}
freeifaddrs(iflist);
real_freeifaddrs(iflist);
}
#else /* Linux */
@ -283,11 +283,11 @@ int tap_init(char *name)
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(_native_tap_fd, TUNSETIFF, (void *)&ifr) == -1) {
if (real_ioctl(_native_tap_fd, TUNSETIFF, (void *)&ifr) == -1) {
_native_in_syscall++;
warn("ioctl TUNSETIFF");
warnx("probably the tap interface (%s) does not exist or is already in use", name);
exit(EXIT_FAILURE);
real_exit(EXIT_FAILURE);
}
/* TODO: use strncpy */
@ -298,7 +298,7 @@ int tap_init(char *name)
memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name);
if (ioctl(_native_tap_fd, SIOCGIFHWADDR, &ifr) == -1) {
if (real_ioctl(_native_tap_fd, SIOCGIFHWADDR, &ifr) == -1) {
_native_in_syscall++;
warn("ioctl SIOCGIFHWADDR");
@ -306,7 +306,7 @@ int tap_init(char *name)
warn("close");
}
exit(EXIT_FAILURE);
real_exit(EXIT_FAILURE);
}
memcpy(_native_tap_mac, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);

12
cpu/native/startup.c

@ -80,14 +80,14 @@ void _native_log_stdout(char *stdouttype)
return;
}
else if (strcmp(stdouttype, "null") == 0) {
if ((stdout_outfile = open("/dev/null", O_WRONLY)) == -1) {
if ((stdout_outfile = real_open("/dev/null", O_WRONLY)) == -1) {
err(EXIT_FAILURE, "_native_log_stdout: open");
}
}
else if (strcmp(stdouttype, "file") == 0) {
char stdout_logname[255];
snprintf(stdout_logname, sizeof(stdout_logname), "/tmp/riot.stdout.%d", _native_pid);
if ((stdout_outfile = creat(stdout_logname, 0666)) == -1) {
if ((stdout_outfile = real_creat(stdout_logname, 0666)) == -1) {
err(EXIT_FAILURE, "_native_log_stdout: open");
}
}
@ -115,14 +115,14 @@ void _native_log_stderr(char *stderrtype)
return;
}
else if (strcmp(stderrtype, "null") == 0) {
if ((stderr_outfile = open("/dev/null", O_WRONLY)) == -1) {
if ((stderr_outfile = real_open("/dev/null", O_WRONLY)) == -1) {
err(EXIT_FAILURE, "_native_log_stderr: open");
}
}
else if (strcmp(stderrtype, "file") == 0) {
char stderr_logname[255];
snprintf(stderr_logname, sizeof(stderr_logname), "/tmp/riot.stderr.%d", _native_pid);
if ((stderr_outfile = creat(stderr_logname, 0666)) == -1) {
if ((stderr_outfile = real_creat(stderr_logname, 0666)) == -1) {
err(EXIT_FAILURE, "_native_log_stderr: open");
}
}
@ -143,7 +143,7 @@ void daemonize(void)
if (_native_pid > 0) {
real_printf("RIOT pid: %d\n", _native_pid);
exit(EXIT_SUCCESS);
real_exit(EXIT_SUCCESS);
}
else {
_native_pid = real_getpid();
@ -211,7 +211,7 @@ void usage_exit(void)
real_printf("\n\
The order of command line arguments matters.\n");
exit(EXIT_FAILURE);
real_exit(EXIT_FAILURE);
}

23
cpu/native/syscalls.c

@ -33,6 +33,7 @@
#ifdef MODULE_VTIMER
#include <sys/time.h>
#endif
#include <ifaddrs.h>
#include "kernel.h"
#include "cpu.h"
@ -51,26 +52,33 @@ 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_clearerr)(FILE *stream);
__attribute__((noreturn)) void (*real_exit)(int status);
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);
void (*real_freeifaddrs)(struct ifaddrs *ifa);
void (*real_srandom)(unsigned int seed);
int (*real_accept)(int socket, ...);
int (*real_bind)(int socket, ...);
int (*real_printf)(const char *format, ...);
int (*real_getaddrinfo)(const char *node, ...);
int (*real_getifaddrs)(struct ifaddrs **ifap);
int (*real_getpid)(void);
int (*real_close)(int);
int (*real_creat)(const char *path, ...);
int (*real_dup2)(int, int);
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_listen)(int socket, int backlog);
int (*real_ioctl)(int fildes, int request, ...);
int (*real_open)(const char *path, int oflag, ...);
int (*real_pause)(void);
int (*real_pipe)(int[2]);
int (*real_select)(int nfds, ...);
int (*real_setsockopt)(int socket, ...);
int (*real_socket)(int domain, int type, int protocol);
int (*real_unlink)(const char *);
@ -269,7 +277,7 @@ void vwarn(const char *fmt, va_list args)
if ((m = make_message(fmt, args)) == NULL) {
_native_write(STDERR_FILENO, "malloc\n", 7);
exit(EXIT_FAILURE);
real_exit(EXIT_FAILURE);
}
_native_write(STDERR_FILENO, _progname, strlen(_progname));
_native_write(STDERR_FILENO, ": ", 2);
@ -286,7 +294,7 @@ void vwarnx(const char *fmt, va_list args)
if ((m = make_message(fmt, args)) == NULL) {
_native_write(STDERR_FILENO, "malloc\n", 7);
exit(EXIT_FAILURE);
real_exit(EXIT_FAILURE);
}
_native_write(STDERR_FILENO, _progname, strlen(_progname));
_native_write(STDERR_FILENO, ": ", 2);
@ -298,13 +306,13 @@ void vwarnx(const char *fmt, va_list args)
void verr(int eval, const char *fmt, va_list args)
{
vwarn(fmt, args);
exit(eval);
real_exit(eval);
}
void verrx(int eval, const char *fmt, va_list args)
{
vwarnx(fmt, args);
exit(eval);
real_exit(eval);
}
void warn(const char *fmt, ...)
@ -362,25 +370,32 @@ void _native_init_syscalls(void)
*(void **)(&real_write) = dlsym(RTLD_NEXT, "write");
*(void **)(&real_malloc) = dlsym(RTLD_NEXT, "malloc");
*(void **)(&real_realloc) = dlsym(RTLD_NEXT, "realloc");
*(void **)(&real_exit) = dlsym(RTLD_NEXT, "exit");
*(void **)(&real_free) = dlsym(RTLD_NEXT, "free");
*(void **)(&real_freeaddrinfo) = dlsym(RTLD_NEXT, "freeaddrinfo");
*(void **)(&real_freeifaddrs) = dlsym(RTLD_NEXT, "freeifaddrs");
*(void **)(&real_srandom) = dlsym(RTLD_NEXT, "srandom");
*(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_getifaddrs) = dlsym(RTLD_NEXT, "getifaddrs");
*(void **)(&real_getpid) = dlsym(RTLD_NEXT, "getpid");
*(void **)(&real_pipe) = dlsym(RTLD_NEXT, "pipe");
*(void **)(&real_close) = dlsym(RTLD_NEXT, "close");
*(void **)(&real_creat) = dlsym(RTLD_NEXT, "creat");
*(void **)(&real_fork) = dlsym(RTLD_NEXT, "fork");
*(void **)(&real_dup2) = dlsym(RTLD_NEXT, "dup2");
*(void **)(&real_select) = dlsym(RTLD_NEXT, "select");
*(void **)(&real_setsockopt) = dlsym(RTLD_NEXT, "setsockopt");
*(void **)(&real_socket) = dlsym(RTLD_NEXT, "socket");
*(void **)(&real_unlink) = dlsym(RTLD_NEXT, "unlink");
*(void **)(&real_random) = dlsym(RTLD_NEXT, "random");
*(void **)(&real_execve) = dlsym(RTLD_NEXT, "execve");
*(void **)(&real_ioctl) = dlsym(RTLD_NEXT, "ioctl");
*(void **)(&real_listen) = dlsym(RTLD_NEXT, "listen");
*(void **)(&real_open) = dlsym(RTLD_NEXT, "open");
*(void **)(&real_pause) = dlsym(RTLD_NEXT, "pause");
*(void **)(&real_fopen) = dlsym(RTLD_NEXT, "fopen");
*(void **)(&real_fread) = dlsym(RTLD_NEXT, "fread");

Loading…
Cancel
Save