File: syscalls.ha

package info (click to toggle)
harec 0.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,480 kB
  • sloc: ansic: 20,054; asm: 335; makefile: 116; lisp: 80; sh: 45
file content (90 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
export @symbol("write") fn write(fd: int, buf: *const opaque, count: size) size;

export @symbol("close") fn close(fd: int) int;

export @symbol("dup2") fn dup2(old: int, new: int) int;

export @symbol("getpid") fn getpid() int;

export def EXIT_SUCCESS: int = 0;

export @symbol("exit") fn exit(status: int) never;

export @symbol("fork") fn fork() int;

export @symbol("execve") fn execve(path: *const u8, argv: *[*]nullable *const u8,
		envp: *[*]nullable *const u8) int;

export type time_t = i64;
export type suseconds_t = i64;

export type timeval = struct {
	tv_sec: time_t,
	tv_usec: suseconds_t,
};

export type rusage = struct {
	ru_utime: timeval,
	ru_stime: timeval,
	ru_maxrss: i64,
	ru_ixrss: i64,
	ru_idrss: i64,
	ru_isrss: i64,
	ru_minflt: i64,
	ru_majflt: i64,
	ru_nswap: i64,
	ru_inblock: i64,
	ru_oublock: i64,
	ru_msgsnd: i64,
	ru_msgrcv: i64,
	ru_nsignals: i64,
	ru_nvcsw: i64,
	ru_nivcsw: i64,
};

export @symbol("wait4") fn wait4(
	wpid: int,
	status: *int,
	options: int,
	rusage: nullable *rusage
) int;

export fn wifexited(status: int) bool = wtermsig(status) == 0;
export fn wexitstatus(status: int) int = (status & 0xff00) >> 8;

export fn wtermsig(status: int) int = status & 0x7f;
export fn wifsignaled(status: int) bool =
	wtermsig(status) != 0o177 && wtermsig(status) != 0 && status != 0x13;

export @symbol("kill") fn kill(pid: int, signal: int) int;

export @symbol("pipe2") fn pipe2(pipefd: *[2]int, flags: int) int;

export def MAP_SHARED: uint = 0x0001;
export def MAP_PRIVATE: uint = 0x0002;
export def MAP_FIXED: uint = 0x0010;
export def __MAP_NOREPLACE: uint = 0x0800;
export def MAP_ANON: uint = 0x1000;
export def MAP_ANONYMOUS: uint = MAP_ANON;
export def __MAP_NOFAULT: uint = 0x2000;
export def MAP_STACK: uint = 0x4000;
export def MAP_CONCEAL: uint = 0x8000;

def PROT_NONE: uint = 0x00;
def PROT_READ: uint = 0x01;
def PROT_WRITE: uint = 0x02;
def PROT_EXEC: uint = 0x04;

export @symbol("mmap") fn mmap(
	addr: nullable *opaque,
	length: size,
	prot: int,
	flags: int,
	fd: int,
	offs: i64
) *opaque;

export @symbol("munmap") fn munmap(addr: *opaque, length: size) int;

export def SIGABRT: int	= 6;
export def SIGCHLD: int	= 20;