syscall.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <stddef.h>
23 
24 #include <errno.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <sys/stat.h>
30 #include <sys/time.h>
31 #include <sys/types.h>
32 #include <sys/times.h>
33 #include <regex.h>
34 
35 #define UNHANDLED() \
36  { \
37  const char *str_text = "\033[1;33mWARNING\033[0m: unsupported libc function called = "; \
38  const char *str_func = __PRETTY_FUNCTION__; \
39  const char *str_endl = "\n"; \
40  write(0, str_text, strlen(str_text)); \
41  write(0, str_func, strlen(str_func)); \
42  write(0, str_endl, strlen(str_endl)); \
43  }
44 
45 extern "C" clock_t
46 times(struct tms *buf)
47 {
48  (void) buf;
49 
50  UNHANDLED();
51 
52  return 0;
53 }
54 
55 extern "C" int
56 execve(const char *path, char *const argv[], char *const envp[])
57 {
58  (void) path;
59  (void) argv;
60  (void) envp;
61 
62  UNHANDLED();
63 
64  errno = -ENOSYS;
65  return -1;
66 }
67 
68 extern "C" pid_t
69 getpid(void)
70 {
71  UNHANDLED();
72 
73  return 0;
74 }
75 
76 extern "C" int
77 isatty(int fd)
78 {
79  (void) fd;
80 
81  UNHANDLED();
82 
83  errno = -ENOSYS;
84  return -1;
85 }
86 
87 extern "C" off_t
88 lseek(int fd, off_t offset, int whence)
89 {
90  (void) fd;
91  (void) offset;
92  (void) whence;
93 
94  UNHANDLED();
95 
96  errno = -ENOSYS;
97  return -1;
98 }
99 
100 extern "C" void
101 _init(void)
102 { }
103 
104 extern "C" int
105 kill(pid_t _pid, int _sig)
106 {
107  (void) _pid;
108  (void) _sig;
109 
110  UNHANDLED();
111 
112  errno = -ENOSYS;
113  return -1;
114 }
115 
116 extern "C" pid_t
118 {
119  (void) status;
120 
121  UNHANDLED();
122 
123  errno = -ENOSYS;
124  return -1;
125 }
126 
127 extern "C" _READ_WRITE_RETURN_TYPE
128 read(int fd, void *buffer, size_t length)
129 {
130  (void) fd;
131  (void) buffer;
132  (void) length;
133 
134  UNHANDLED();
135 
136  errno = -ENOSYS;
137  return -1;
138 }
139 
140 extern "C" int
141 unlink(const char *file)
142 {
143  (void) file;
144 
145  UNHANDLED();
146 
147  errno = -ENOSYS;
148  return -1;
149 }
150 
151 extern "C" pid_t
152 fork(void)
153 {
154  UNHANDLED();
155 
156  errno = -ENOSYS;
157  return -1;
158 }
159 
160 extern "C" void *
161 sbrk(ptrdiff_t __incr)
162 {
163  (void) __incr;
164 
165  UNHANDLED();
166 
167  errno = -ENOSYS;
168  return reinterpret_cast<void *>(-1);
169 }
170 
171 extern "C" int
172 regcomp(regex_t *preg, const char *regex, int cflags)
173 {
174  (void) preg;
175  (void) regex;
176  (void) cflags;
177 
178  UNHANDLED();
179 
180  return REG_NOMATCH;
181 }
182 
183 extern "C" int
184 gettimeofday(struct timeval *tp, void *tzp)
185 {
186  (void) tp;
187  (void) tzp;
188 
189  UNHANDLED();
190 
191  errno = -ENOSYS;
192  return -1;
193 }
194 
195 extern "C" int
196 clock_gettime(clockid_t clk_id, struct timespec *tp) __THROW
197 {
198  (void) clk_id;
199  (void) tp;
200 
201  UNHANDLED();
202 
203  errno = -ENOSYS;
204  return -1;
205 }
206 
207 extern "C" int
208 regexec(const regex_t *preg, const char *string,
209  size_t nmatch, regmatch_t pmatch[], int eflags)
210 {
211  (void) preg;
212  (void) string;
213  (void) nmatch;
214  (void) pmatch;
215  (void) eflags;
216 
217  UNHANDLED();
218 
219  return REG_NOMATCH;
220 }
221 
222 extern "C" void
223 _fini(void)
224 { }
225 
226 extern "C" int
227 stat(const char *pathname, struct stat *buf)
228 {
229  (void) pathname;
230  (void) buf;
231 
232  UNHANDLED();
233 
234  errno = -ENOSYS;
235  return -1;
236 }
237 
238 extern "C" int
239 link(const char *oldpath, const char *newpath)
240 {
241  (void) oldpath;
242  (void) newpath;
243 
244  UNHANDLED();
245 
246  errno = -ENOSYS;
247  return -1;
248 }
249 
250 extern "C" void
252 {
253  (void) status;
254 
255  UNHANDLED();
256 
257  while (1);
258 }
259 
260 extern "C" int
261 open(const char *file, int mode, ...)
262 {
263  (void) file;
264  (void) mode;
265 
266  UNHANDLED();
267 
268  errno = -ENOSYS;
269  return -1;
270 }
271 
272 extern "C" void
273 regfree(regex_t *preg)
274 {
275  UNHANDLED();
276 
277  (void) preg;
278 }
279 
280 extern "C" int
281 fcntl(int fd, int cmd, ...)
282 {
283  (void) fd;
284  (void) cmd;
285 
286  UNHANDLED();
287 
288  errno = -ENOSYS;
289  return -1;
290 }
291 
292 extern "C" int
293 mkdir(const char *path, mode_t mode)
294 {
295  (void) path;
296  (void) mode;
297 
298  UNHANDLED();
299 
300  errno = -ENOSYS;
301  return -1;
302 }
303 
304 extern "C" int
305 posix_memalign(void **memptr, size_t alignment, size_t size)
306 {
307  (void) memptr;
308  (void) alignment;
309  (void) size;
310 
311  UNHANDLED();
312 
313  return 0;
314 }
315 
316 extern "C" int
317 close(int fd)
318 {
319  (void) fd;
320 
321  UNHANDLED();
322 
323  errno = -ENOSYS;
324  return -1;
325 }
326 
327 extern "C" int
328 sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
329 {
330  (void) how;
331  (void) set;
332  (void) oldset;
333 
334  UNHANDLED();
335 
336  errno = -ENOSYS;
337  return -1;
338 }
339 
340 extern "C" long
342 {
343  (void) name;
344 
345  UNHANDLED();
346 
347  errno = -EINVAL;
348  return -1;
349 }
350 
351 extern "C" int
352 nanosleep(const struct timespec *req, struct timespec *rem)
353 {
354  (void) req;
355  (void) rem;
356 
357  UNHANDLED();
358 
359  errno = -ENOSYS;
360  return -1;
361 }
362 
363 extern "C" void *
364 malloc(size_t size)
365 {
366  return _malloc_r(0, size);
367 }
368 
369 extern "C" void
370 free(void *ptr)
371 {
372  _free_r(0, ptr);
373 }
374 
375 extern "C" void *
376 calloc(size_t nmemb, size_t size)
377 {
378  return _calloc_r(0, nmemb, size);
379 }
380 
381 extern "C" void *
382 realloc(void *ptr, size_t size)
383 {
384  return _realloc_r(0, ptr, size);
385 }
386 
387 extern "C" int
388 fstat(int file, struct stat *sbuf)
389 {
390  (void) file;
391  (void) sbuf;
392 
393  errno = -ENOSYS;
394  return -1;
395 }
396 
397 extern "C" int
398 getentropy(void *buf, size_t buflen)
399 {
400  (void) buf;
401  (void) buflen;
402 
403  errno = -EIO;
404  return -1;
405 }
406 
407 extern "C" int
408 __fpclassifyf(float val)
409 {
410  (void) val;
411  return 0; // FP_NAN
412 }
413 
414 extern "C" int
415 __fpclassifyd(double val)
416 {
417  (void) val;
418  return 0; // FP_NAN
419 }
420 
421 extern "C" double
422 ldexp(double x, int exp)
423 {
424  return __builtin_ldexp(x, exp);
425 }
426 
427 extern "C" float
428 nanf(const char *tagp)
429 {
430  return __builtin_nanf(tagp);
431 }
432 
433 extern "C" int
435 {
436  return 0;
437 }
int stat(const char *pathname, struct stat *buf)
Definition: syscall.cpp:227
int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
Definition: syscall.cpp:208
int posix_memalign(void **memptr, size_t alignment, size_t size)
Definition: syscall.cpp:305
int kill(pid_t _pid, int _sig)
Definition: syscall.cpp:105
void free(void *ptr)
Definition: syscall.cpp:370
Definition: file.h:35
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
Definition: syscall.cpp:328
off_t lseek(int fd, off_t offset, int whence)
Definition: syscall.cpp:88
void regfree(regex_t *preg)
Definition: syscall.cpp:273
void _exit(int status)
Definition: syscall.cpp:251
int link(const char *oldpath, const char *newpath)
Definition: syscall.cpp:239
double ldexp(double x, int exp)
Definition: syscall.cpp:422
void * realloc(void *ptr, size_t size)
Definition: syscall.cpp:382
int fstat(int file, struct stat *sbuf)
Definition: syscall.cpp:388
void * malloc(size_t size)
Definition: syscall.cpp:364
#define UNHANDLED()
Definition: syscall.cpp:35
int fcntl(int fd, int cmd,...)
Definition: syscall.cpp:281
void _init(void)
Definition: syscall.cpp:101
int __fpclassifyf(float val)
Definition: syscall.cpp:408
int execve(const char *path, char *const argv[], char *const envp[])
Definition: syscall.cpp:56
void * sbrk(ptrdiff_t __incr)
Definition: syscall.cpp:161
int isatty(int fd)
Definition: syscall.cpp:77
void * calloc(size_t nmemb, size_t size)
Definition: syscall.cpp:376
constexpr const auto size
int unlink(const char *file)
Definition: syscall.cpp:141
clock_t times(struct tms *buf)
Definition: syscall.cpp:46
int clock_gettime(clockid_t clk_id, struct timespec *tp) __THROW
Definition: syscall.cpp:196
int getentropy(void *buf, size_t buflen)
Definition: syscall.cpp:398
pid_t wait(int *status)
Definition: syscall.cpp:117
long sysconf(int name)
Definition: syscall.cpp:341
int nanosleep(const struct timespec *req, struct timespec *rem)
Definition: syscall.cpp:352
pid_t fork(void)
Definition: syscall.cpp:152
int __fpclassifyd(double val)
Definition: syscall.cpp:415
int regcomp(regex_t *preg, const char *regex, int cflags)
Definition: syscall.cpp:172
int sched_yield(void)
Definition: syscall.cpp:434
int open(const char *file, int mode,...)
Definition: syscall.cpp:261
pid_t getpid(void)
Definition: syscall.cpp:69
int close(int fd)
Definition: syscall.cpp:317
int gettimeofday(struct timeval *tp, void *tzp)
Definition: syscall.cpp:184
int mkdir(const char *path, mode_t mode)
Definition: syscall.cpp:293
constexpr const auto name
Definition: cpuid_x64.h:81
void _fini(void)
Definition: syscall.cpp:223
float nanf(const char *tagp)
Definition: syscall.cpp:428
_READ_WRITE_RETURN_TYPE read(int fd, void *buffer, size_t length)
Definition: syscall.cpp:128
#define offset(a, b)
Definition: test.cpp:192