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 /* enable signal handler register access on different platforms
25  * check here for more:
26  * http://sourceforge.net/p/predef/wiki/OperatingSystems/
27  */
28 #if (defined(__FreeBSD__) || defined(__MACH__))
29 #ifndef _XOPEN_SOURCE
30 #define _XOPEN_SOURCE
31 #include <ucontext.h>
32 #undef _XOPEN_SOURCE
33 #else
34 #include <ucontext.h>
35 #endif
36 #elif defined(__linux__)
37 #ifndef _GNU_SOURCE
38 #define GNU_SOURCE
39 #include <ucontext.h>
40 #undef GNU_SOURCE
41 #else
42 #include <ucontext.h>
43 #endif
44 #endif // BSD/Linux
45 #include <netdb.h>
46 #include <ifaddrs.h>
47 #include <time.h>
48 #include <sys/time.h>
49 #include <sys/stat.h>
50 #include <sys/uio.h>
51 
52 #include "kernel_types.h"
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
61 typedef void (*_native_callback_t)(void);
62 
67 void native_cpu_init(void);
68 void native_interrupt_init(void);
69 
70 void native_irq_handler(void);
71 extern void _native_sig_leave_tramp(void);
72 extern void _native_sig_leave_handler(void);
73 
74 void _native_syscall_leave(void);
75 void _native_syscall_enter(void);
76 void _native_init_syscalls(void);
77 
81 extern ssize_t (*real_read)(int fd, void *buf, size_t count);
82 extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
83 extern size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream);
84 extern void (*real_clearerr)(FILE *stream);
85 extern __attribute__((noreturn)) void (*real_exit)(int status);
86 extern void (*real_free)(void *ptr);
87 extern void* (*real_calloc)(size_t nmemb, size_t size);
88 extern void* (*real_malloc)(size_t size);
89 extern void* (*real_realloc)(void *ptr, size_t size);
90 extern void (*real_freeaddrinfo)(struct addrinfo *res);
91 extern void (*real_freeifaddrs)(struct ifaddrs *ifa);
92 extern void (*real_srandom)(unsigned int seed);
93 /* The ... is a hack to save includes: */
94 extern int (*real_accept)(int socket, ...);
95 /* The ... is a hack to save includes: */
96 extern int (*real_bind)(int socket, ...);
97 extern int (*real_chdir)(const char *path);
98 extern int (*real_close)(int);
99 extern int (*real_fcntl)(int, int, ...);
100 /* The ... is a hack to save includes: */
101 extern int (*real_creat)(const char *path, ...);
102 extern int (*real_dup2)(int, int);
103 extern int (*real_execve)(const char *, char *const[], char *const[]);
104 extern int (*real_feof)(FILE *stream);
105 extern int (*real_ferror)(FILE *stream);
106 extern int (*real_fork)(void);
107 /* The ... is a hack to save includes: */
108 extern int (*real_getaddrinfo)(const char *node, ...);
109 extern int (*real_getifaddrs)(struct ifaddrs **ifap);
110 extern int (*real_getpid)(void);
111 extern int (*real_ioctl)(int fildes, int request, ...);
112 extern int (*real_listen)(int socket, int backlog);
113 extern int (*real_open)(const char *path, int oflag, ...);
114 extern int (*real_pause)(void);
115 extern int (*real_pipe)(int[2]);
116 /* The ... is a hack to save includes: */
117 extern int (*real_select)(int nfds, ...);
118 extern int (*real_setitimer)(int which, const struct itimerval
119  *__restrict value, struct itimerval *__restrict ovalue);
120 extern int (*real_setsid)(void);
121 extern int (*real_setsockopt)(int socket, ...);
122 extern int (*real_socket)(int domain, int type, int protocol);
123 extern int (*real_printf)(const char *format, ...);
124 extern int (*real_unlink)(const char *);
125 extern long int (*real_random)(void);
126 extern const char* (*real_gai_strerror)(int errcode);
127 extern FILE* (*real_fopen)(const char *path, const char *mode);
128 extern int (*real_fclose)(FILE *stream);
129 extern int (*real_fseek)(FILE *stream, long offset, int whence);
130 extern int (*real_fputc)(int c, FILE *stream);
131 extern int (*real_fgetc)(FILE *stream);
132 extern mode_t (*real_umask)(mode_t cmask);
133 extern ssize_t (*real_writev)(int fildes, const struct iovec *iov, int iovcnt);
134 
135 #ifdef __MACH__
136 #else
137 extern int (*real_clock_gettime)(clockid_t clk_id, struct timespec *tp);
138 #endif
139 
143 extern volatile int native_interrupts_enabled;
144 extern volatile unsigned int _native_saved_eip;
145 extern int _sig_pipefd[2];
146 extern volatile int _native_sigpend;
147 extern volatile int _native_in_isr;
148 extern volatile int _native_in_syscall;
149 
150 extern char __isr_stack[SIGSTKSZ];
151 extern char __end_stack[SIGSTKSZ];
152 extern ucontext_t native_isr_context;
153 extern ucontext_t end_context;
154 extern ucontext_t *_native_cur_ctx, *_native_isr_ctx;
155 
156 extern const char *_progname;
157 extern char **_native_argv;
158 extern pid_t _native_pid;
159 extern pid_t _native_id;
160 extern unsigned _native_rng_seed;
161 extern int _native_rng_mode;
162 extern const char *_native_unix_socket_path;
163 
164 ssize_t _native_read(int fd, void *buf, size_t count);
165 ssize_t _native_write(int fd, const void *buf, size_t count);
166 ssize_t _native_writev(int fildes, const struct iovec *iov, int iovcnt);
167 
175 int register_interrupt(int sig, _native_callback_t handler);
176 
180 int unregister_interrupt(int sig);
181 
182 //#include <sys/param.h>
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #include "sched.h"
189 
191 #endif /* NATIVE_INTERNAL_H */
Types used by the kernel.
uint32_t clockid_t
Used for clock ID type in the clock and timer functions.
Definition: msp430_types.h:76
void(* _native_callback_t)(void)
Prototype for native&#39;s internal callbacks.
char __isr_stack[ISR_STACKSIZE]
Memory used as stack for the interrupt context.
unsigned int size_t
Used for sizes of objects.
Definition: msp430_types.h:88
signed int ssize_t
Used for a count of bytes or an error indication.
Definition: msp430_types.h:89
Scheduler API definition.
int register_interrupt(int sig, _native_callback_t handler)
register interrupt handler handler for interrupt sig
Structure for scatter/gather I/O.
Definition: uio.h:33
stdio.h wrapper for MSP430
int pid_t
Used for process IDs and process group IDs.
Definition: msp430_types.h:87
libc header for scatter/gather I/O
int socket(int domain, int type, int protocol)
Create an endpoint for communication.
Definition of struct timespec for the MSP430.
Definition: msp430_types.h:58
int unregister_interrupt(int sig)
unregister interrupt handler for interrupt sig
uint32_t mode_t
Used for some file attributes.
Definition: msp430_types.h:84