native_internal.h
1 /*
2  * Copyright (C) 2013, 2014 Ludwig Knüpfer
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef NATIVE_INTERNAL_H
20 #define NATIVE_INTERNAL_H
21 
22 #include <signal.h>
23 #include <stdio.h>
24 #include <poll.h>
25 /* enable signal handler register access on different platforms
26  * check here for more:
27  * http://sourceforge.net/p/predef/wiki/OperatingSystems/
28  */
29 #if (defined(__FreeBSD__) || defined(__MACH__))
30 #ifndef _XOPEN_SOURCE
31 #define _XOPEN_SOURCE
32 #include <ucontext.h>
33 #undef _XOPEN_SOURCE
34 #else
35 #include <ucontext.h>
36 #endif
37 #elif defined(__linux__)
38 #ifndef _GNU_SOURCE
39 #define GNU_SOURCE
40 #include <ucontext.h>
41 #undef GNU_SOURCE
42 #else
43 #include <ucontext.h>
44 #endif
45 #endif /* BSD/Linux */
46 #include <netdb.h>
47 #include <ifaddrs.h>
48 #include <time.h>
49 #include <sys/time.h>
50 #include <sys/stat.h>
51 #include <sys/uio.h>
52 
53 #include "kernel_types.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
62 typedef void (*_native_callback_t)(void);
63 
68 void native_cpu_init(void);
69 void native_interrupt_init(void);
70 
71 void native_irq_handler(void);
72 extern void _native_sig_leave_tramp(void);
73 extern void _native_sig_leave_handler(void);
74 
75 void _native_syscall_leave(void);
76 void _native_syscall_enter(void);
77 void _native_init_syscalls(void);
78 
82 extern ssize_t (*real_read)(int fd, void *buf, size_t count);
83 extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
84 extern size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream);
85 extern void (*real_clearerr)(FILE *stream);
86 extern __attribute__((noreturn)) void (*real_exit)(int status);
87 extern void (*real_free)(void *ptr);
88 extern void* (*real_calloc)(size_t nmemb, size_t size);
89 extern void* (*real_malloc)(size_t size);
90 extern void* (*real_realloc)(void *ptr, size_t size);
91 extern void (*real_freeaddrinfo)(struct addrinfo *res);
92 extern void (*real_freeifaddrs)(struct ifaddrs *ifa);
93 extern void (*real_srandom)(unsigned int seed);
94 /* The ... is a hack to save includes: */
95 extern int (*real_accept)(int socket, ...);
96 /* The ... is a hack to save includes: */
97 extern int (*real_bind)(int socket, ...);
98 extern int (*real_connect)(int socket, ...);
99 extern int (*real_chdir)(const char *path);
100 extern int (*real_close)(int);
101 extern int (*real_fcntl)(int, int, ...);
102 /* The ... is a hack to save includes: */
103 extern int (*real_creat)(const char *path, ...);
104 extern int (*real_dup2)(int, int);
105 extern int (*real_execve)(const char *, char *const[], char *const[]);
106 extern int (*real_feof)(FILE *stream);
107 extern int (*real_ferror)(FILE *stream);
108 extern int (*real_fork)(void);
109 /* The ... is a hack to save includes: */
110 extern int (*real_getaddrinfo)(const char *node, ...);
111 extern int (*real_getifaddrs)(struct ifaddrs **ifap);
112 extern int (*real_getpid)(void);
113 extern int (*real_gettimeofday)(struct timeval *t, ...);
114 extern int (*real_ioctl)(int fildes, int request, ...);
115 extern int (*real_listen)(int socket, int backlog);
116 extern int (*real_open)(const char *path, int oflag, ...);
117 extern int (*real_pause)(void);
118 extern int (*real_pipe)(int[2]);
119 /* The ... is a hack to save includes: */
120 extern int (*real_select)(int nfds, ...);
121 extern int (*real_poll)(struct pollfd *nfds, ...);
122 extern int (*real_setitimer)(int which, const struct itimerval
123  *__restrict value, struct itimerval *__restrict ovalue);
124 extern int (*real_setsid)(void);
125 extern int (*real_setsockopt)(int socket, ...);
126 extern int (*real_socket)(int domain, int type, int protocol);
127 extern int (*real_printf)(const char *format, ...);
128 extern int (*real_unlink)(const char *);
129 extern long int (*real_random)(void);
130 extern const char* (*real_gai_strerror)(int errcode);
131 extern FILE* (*real_fopen)(const char *path, const char *mode);
132 extern int (*real_fclose)(FILE *stream);
133 extern int (*real_fseek)(FILE *stream, long offset, int whence);
134 extern int (*real_fputc)(int c, FILE *stream);
135 extern int (*real_fgetc)(FILE *stream);
136 extern mode_t (*real_umask)(mode_t cmask);
137 extern ssize_t (*real_writev)(int fildes, const struct iovec *iov, int iovcnt);
138 
139 #ifdef __MACH__
140 #else
141 extern int (*real_clock_gettime)(clockid_t clk_id, struct timespec *tp);
142 #endif
143 
147 extern volatile int native_interrupts_enabled;
148 extern volatile unsigned int _native_saved_eip;
149 extern int _sig_pipefd[2];
150 extern volatile int _native_sigpend;
151 extern volatile int _native_in_isr;
152 extern volatile int _native_in_syscall;
153 
154 extern char __isr_stack[SIGSTKSZ];
155 extern char __end_stack[SIGSTKSZ];
156 extern ucontext_t native_isr_context;
157 extern ucontext_t end_context;
158 extern ucontext_t *_native_cur_ctx, *_native_isr_ctx;
159 
160 extern const char *_progname;
161 extern char **_native_argv;
162 extern pid_t _native_pid;
163 extern pid_t _native_id;
164 extern unsigned _native_rng_seed;
165 extern int _native_rng_mode;
166 extern const char *_native_unix_socket_path;
167 
168 ssize_t _native_read(int fd, void *buf, size_t count);
169 ssize_t _native_write(int fd, const void *buf, size_t count);
170 ssize_t _native_writev(int fildes, const struct iovec *iov, int iovcnt);
171 
179 int register_interrupt(int sig, _native_callback_t handler);
180 
184 int unregister_interrupt(int sig);
185 
186 //#include <sys/param.h>
187 
188 #ifdef __cplusplus
189 }
190 #endif
191 
192 #include "sched.h"
193 
195 #endif /* NATIVE_INTERNAL_H */
_native_callback_t
void(* _native_callback_t)(void)
Native CPU internal declarations.
Definition: native_internal.h:62
sched.h
Scheduler API definition.
register_interrupt
int register_interrupt(int sig, _native_callback_t handler)
register interrupt handler handler for interrupt sig
uio.h
libc header for scatter/gather I/O
iovec
Structure for scatter/gather I/O.
Definition: uio.h:33
timeval
Definition of struct timeval for the atmega.
Definition: time.h:23
socket
int socket(int domain, int type, int protocol)
Create an endpoint for communication.
unregister_interrupt
int unregister_interrupt(int sig)
unregister interrupt handler for interrupt sig
kernel_types.h
Types used by the kernel.