Loading...
Searching...
No Matches
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
30#ifndef NATIVE_INTERNAL_H
31#define NATIVE_INTERNAL_H
32
33#include <signal.h>
34#include <stdio.h>
35#include <stdint.h>
36#include <poll.h>
37/* enable signal handler register access on different platforms
38 * check here for more:
39 * http://sourceforge.net/p/predef/wiki/OperatingSystems/
40 */
41#ifdef __FreeBSD__
42#ifndef _XOPEN_SOURCE
43#define _XOPEN_SOURCE
44#include <ucontext.h>
45#undef _XOPEN_SOURCE
46#else
47#include <ucontext.h>
48#endif
49#elif defined(__linux__)
50#ifndef _GNU_SOURCE
51#define GNU_SOURCE
52#include <ucontext.h>
53#undef GNU_SOURCE
54#else
55#include <ucontext.h>
56#endif
57#endif /* BSD/Linux */
58#include <netdb.h>
59#include <ifaddrs.h>
60#include <time.h>
61#include <sys/time.h>
62#include <sys/stat.h>
63#include <sys/statvfs.h>
64#include <sys/uio.h>
65#include <dirent.h>
66
67#ifdef __cplusplus
68extern "C" {
69#endif
70
74typedef void (*_native_callback_t)(void);
75
80void native_cpu_init(void);
81void native_interrupt_init(void);
82
83void native_irq_handler(void);
84extern void _native_sig_leave_tramp(void);
85extern void _native_sig_leave_handler(void);
86
87void _native_syscall_leave(void);
88void _native_syscall_enter(void);
89void _native_init_syscalls(void);
90
94extern ssize_t (*real_read)(int fd, void *buf, size_t count);
95extern ssize_t (*real_write)(int fd, const void *buf, size_t count);
96extern off_t (*real_lseek)(int fd, off_t offset, int whence);
97extern off_t (*real_fstat)(int fd, struct stat *statbuf);
98extern int (*real_statvfs)(const char *restrict path, struct statvfs *restrict buf);
99extern int (*real_fsync)(int fd);
100extern size_t (*real_fread)(void *ptr, size_t size, size_t nmemb, FILE *stream);
101extern void (*real_clearerr)(FILE *stream);
102extern __attribute__((noreturn)) void (*real_exit)(int status);
103extern void (*real_free)(void *ptr);
104extern void* (*real_calloc)(size_t nmemb, size_t size);
105extern void* (*real_malloc)(size_t size);
106extern void* (*real_realloc)(void *ptr, size_t size);
107extern void (*real_freeaddrinfo)(struct addrinfo *res);
108extern void (*real_freeifaddrs)(struct ifaddrs *ifa);
109extern void (*real_srandom)(unsigned int seed);
110/* The ... is a hack to save includes: */
111extern int (*real_accept)(int socket, ...);
112/* The ... is a hack to save includes: */
113extern int (*real_bind)(int socket, ...);
114extern int (*real_connect)(int socket, ...);
115extern ssize_t (*real_recv)(int sockfd, void *buf, size_t len, int flags);
116extern int (*real_chdir)(const char *path);
117extern int (*real_close)(int);
118extern int (*real_fcntl)(int, int, ...);
119/* The ... is a hack to save includes: */
120extern int (*real_creat)(const char *path, ...);
121extern int (*real_dup2)(int, int);
122extern int (*real_execve)(const char *, char *const[], char *const[]);
123extern int (*real_feof)(FILE *stream);
124extern int (*real_ferror)(FILE *stream);
125extern int (*real_fork)(void);
126/* The ... is a hack to save includes: */
127extern int (*real_getaddrinfo)(const char *node, ...);
128extern int (*real_getifaddrs)(struct ifaddrs **ifap);
129extern int (*real_getpid)(void);
130extern int (*real_gettimeofday)(struct timeval *t, ...);
131extern int (*real_ioctl)(int fildes, unsigned long request, ...);
132extern int (*real_listen)(int socket, int backlog);
133extern int (*real_open)(const char *path, int oflag, ...);
134extern int (*real_mkdir)(const char *pathname, mode_t mode);
135extern int (*real_rmdir)(const char *pathname);
136extern DIR *(*real_opendir)(const char *name);
137extern struct dirent *(*real_readdir)(DIR *dirp);
138extern int (*real_closedir)(DIR *dirp);
139extern int (*real_pause)(void);
140extern int (*real_pipe)(int[2]);
141/* The ... is a hack to save includes: */
142extern int (*real_select)(int nfds, ...);
143extern int (*real_poll)(struct pollfd *nfds, ...);
144extern int (*real_setitimer)(int which, const struct itimerval
145 *__restrict value, struct itimerval *__restrict ovalue);
146extern int (*real_setsid)(void);
147extern int (*real_setsockopt)(int socket, ...);
148extern int (*real_socket)(int domain, int type, int protocol);
149extern int (*real_printf)(const char *format, ...);
150extern int (*real_unlink)(const char *);
151extern int (*real_rename)(const char *, const char *);
152extern long int (*real_random)(void);
153extern const char* (*real_gai_strerror)(int errcode);
154extern FILE* (*real_fopen)(const char *path, const char *mode);
155extern int (*real_fclose)(FILE *stream);
156extern int (*real_fseek)(FILE *stream, long offset, int whence);
157extern long (*real_ftell)(FILE *stream);
158extern int (*real_fputc)(int c, FILE *stream);
159extern int (*real_fgetc)(FILE *stream);
160extern mode_t (*real_umask)(mode_t cmask);
161extern ssize_t (*real_writev)(int fildes, const struct iovec *iov, int iovcnt);
162extern ssize_t (*real_send)(int sockfd, const void *buf, size_t len, int flags);
163
167extern volatile int native_interrupts_enabled;
168extern volatile uintptr_t _native_saved_eip;
169extern int _sig_pipefd[2];
170extern volatile int _native_sigpend;
171extern volatile int _native_in_isr;
172extern volatile int _native_in_syscall;
173
174extern char __isr_stack[];
175extern const size_t __isr_stack_size;
176extern ucontext_t native_isr_context;
177extern ucontext_t end_context;
178extern ucontext_t *_native_cur_ctx, *_native_isr_ctx;
179
180extern const char *_progname;
181extern char **_native_argv;
182extern pid_t _native_pid;
183extern pid_t _native_id;
184extern unsigned _native_rng_seed;
185extern int _native_rng_mode;
186extern const char *_native_unix_socket_path;
187
188ssize_t _native_read(int fd, void *buf, size_t count);
189ssize_t _native_write(int fd, const void *buf, size_t count);
190ssize_t _native_writev(int fildes, const struct iovec *iov, int iovcnt);
191
200
205
206#ifdef __cplusplus
207}
208#endif
209
210#include "sched.h"
211
213#endif /* NATIVE_INTERNAL_H */
int unregister_interrupt(int sig)
unregister interrupt handler for interrupt sig
int register_interrupt(int sig, _native_callback_t handler)
register interrupt handler handler for interrupt sig
void(* _native_callback_t)(void)
Prototype for native's internal callbacks.
int socket(int domain, int type, int protocol)
Create an endpoint for communication.
Scheduler API definition.
POSIX compatible sys/statvfs.h definitions.
stdio wrapper to extend the C libs stdio
Structure for scatter/gather I/O.
Definition uio.h:33
File system information.
Definition statvfs.h:46
Definition of struct timeval for the atmega.
Definition time.h:23
libc header for scatter/gather I/O