-
Notifications
You must be signed in to change notification settings - Fork 0
/
jts_libc.h
69 lines (61 loc) · 2.35 KB
/
jts_libc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// include headers provided by compiler
#include <stddef.h>
#include <stdint.h>
#include <float.h>
//#include <iso646.h>
#include <limits.h>
#include <stdarg.h>
#include <stdalign.h>
#include <stdnoreturn.h>
#include <stdbool.h>
// open() flag macros. defines are taken from: /usr/include/asm-generic/fcntl.h
#define O_ACCMODE 00000003
#define O_RDONLY 00000000
#define O_WRONLY 00000001
#define O_RDWR 00000002
#define O_CREAT 00000100 /* not fcntl */
#define O_EXCL 00000200 /* not fcntl */
#define O_NOCTTY 00000400 /* not fcntl */
#define O_TRUNC 00001000 /* not fcntl */
#define O_APPEND 00002000
#define O_NONBLOCK 00004000
// mmap flag macros
#define PROT_READ 0x1 /* Page can be read. */
#define PROT_WRITE 0x2 /* Page can be written. */
#define PROT_EXEC 0x4 /* Page can be executed. */
#define PROT_NONE 0x0 /* Page can not be accessed. */
#define PROT_GROWSDOWN 0x01000000 /* Extend change to start of
growsdown vma (mprotect only). */
#define PROT_GROWSUP 0x02000000 /* Extend change to start of
growsup vma (mprotect only). */
/* Sharing types (must choose one and only one of these). */
#define MAP_SHARED 0x01 /* Share changes. */
#define MAP_PRIVATE 0x02 /* Changes are private. */
#define MAP_ANONYMOUS 0x20 /* Don't use a file. */
#define MAP_ANON MAP_ANONYMOUS
// end mmap macros
// fd const macros
#define STDIN 0
#define STDOUT 1
#define STDERR 2
// typedefs for glibc compat
typedef unsigned short umode_t;
/*
Here is the x64 syscall chart I used:
https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86_64-64_bit
*/
void jts_exit(int code);
int jts_close(int fd);
int jts_open(char *filename, int flags, umode_t mode);
intmax_t jts_read(int fd, void *buf, uintmax_t count);
intmax_t jts_write(int fd, const void *buf, uintmax_t count);
uintmax_t jts_strlen(char *s);
uintmax_t jts_true(void);
uintmax_t jts_false(void);
void jts_nop(void);
int jts_strcmp(char*,char*);
void *jts_memset(void *str, int c, size_t n);
// typedef for mmap
typedef long int off_t;
void *jts_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
int jts_munmap(void *addr, size_t length);