master
1const std = @import("../std.zig");
2const assert = std.debug.assert;
3const builtin = @import("builtin");
4const O = std.c.O;
5const clockid_t = std.c.clockid_t;
6const pid_t = std.c.pid_t;
7const timespec = std.c.timespec;
8
9comptime {
10 assert(builtin.os.tag == .serenity); // Prevent access of std.c symbols on wrong OS.
11}
12
13// https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/futex.h#L46-L53
14pub const FUTEX = struct {
15 pub const WAIT = 1;
16 pub const WAKE = 2;
17 pub const REQUEUE = 3;
18 pub const CMP_REQUEUE = 4;
19 pub const WAKE_OP = 5;
20 pub const WAIT_BITSET = 9;
21 pub const WAKE_BITSET = 10;
22
23 pub const CLOCK_REALTIME = 1 << 8;
24 pub const PRIVATE_FLAG = 1 << 9;
25};
26
27// https://github.com/SerenityOS/serenity/blob/54e79aa1d90bbcb69014255a59afb085802719d3/Kernel/API/POSIX/serenity.h#L18-L36
28pub const PERF_EVENT = packed struct(c_int) {
29 SAMPLE: bool = false,
30 MALLOC: bool = false,
31 FREE: bool = false,
32 MMAP: bool = false,
33 MUNMAP: bool = false,
34 PROCESS_CREATE: bool = false,
35 PROCESS_EXEC: bool = false,
36 PROCESS_EXIT: bool = false,
37 THREAD_CREATE: bool = false,
38 THREAD_EXIT: bool = false,
39 CONTEXT_SWITCH: bool = false,
40 KMALLOC: bool = false,
41 KFREE: bool = false,
42 PAGE_FAULT: bool = false,
43 SYSCALL: bool = false,
44 SIGNPOST: bool = false,
45 FILESYSTEM: bool = false,
46};
47
48// https://github.com/SerenityOS/serenity/blob/abc150085f532f123b598949218893cb272ccc4c/Userland/Libraries/LibC/serenity.h
49
50pub extern "c" fn disown(pid: pid_t) c_int;
51
52pub extern "c" fn profiling_enable(pid: pid_t, event_mask: PERF_EVENT) c_int;
53pub extern "c" fn profiling_disable(pid: pid_t) c_int;
54pub extern "c" fn profiling_free_buffer(pid: pid_t) c_int;
55
56pub extern "c" fn futex(userspace_address: *u32, futex_op: c_int, value: u32, timeout: *const timespec, userspace_address2: *u32, value3: u32) c_int;
57pub extern "c" fn futex_wait(userspace_address: *u32, value: u32, abstime: *const timespec, clockid: clockid_t, process_shared: c_int) c_int;
58pub extern "c" fn futex_wake(userspace_address: *u32, count: u32, process_shared: c_int) c_int;
59
60pub extern "c" fn purge(mode: c_int) c_int;
61
62pub extern "c" fn perf_event(type: PERF_EVENT, arg1: usize, arg2: usize) c_int;
63pub extern "c" fn perf_register_string(string: [*]const u8, string_length: usize) c_int;
64
65pub extern "c" fn get_stack_bounds(user_stack_base: *usize, user_stack_size: *usize) c_int;
66
67pub extern "c" fn anon_create(size: usize, options: O) c_int;
68
69pub extern "c" fn serenity_readlink(path: [*]const u8, path_length: usize, buffer: [*]u8, buffer_size: usize) c_int;
70pub extern "c" fn serenity_open(path: [*]const u8, path_length: usize, options: c_int, ...) c_int;
71
72pub extern "c" fn getkeymap(name_buffer: [*]u8, name_buffer_size: usize, map: [*]u32, shift_map: [*]u32, alt_map: [*]u32, altgr_map: [*]u32, shift_altgr_map: [*]u32) c_int;
73pub extern "c" fn setkeymap(name: [*]const u8, map: [*]const u32, shift_map: [*]const u32, alt_map: [*]const u32, altgr_map: [*]const u32, shift_altgr_map: [*]const u32) c_int;
74
75// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L29
76pub const IP = struct {
77 pub const TOS = 1;
78 pub const TTL = 2;
79 pub const MULTICAST_LOOP = 3;
80 pub const ADD_MEMBERSHIP = 4;
81 pub const DROP_MEMBERSHIP = 5;
82 pub const MULTICAST_IF = 6;
83 pub const MULTICAST_TTL = 7;
84 pub const BLOCK_SOURCE = 8;
85 pub const ADD_SOURCE_MEMBERSHIP = 7;
86 pub const DROP_SOURCE_MEMBERSHIP = 8;
87 pub const UNBLOCK_SOURCE = 9;
88 pub const OPTIONS = 10;
89};
90
91// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L81
92pub const IPV6 = struct {
93 pub const UNICAST_HOPS = 1;
94 pub const MULTICAST_HOPS = 2;
95 pub const MULTICAST_LOOP = 3;
96 pub const MULTICAST_IF = 4;
97 pub const ADD_MEMBERSHIP = 5;
98 pub const DROP_MEMBERSHIP = 6;
99 pub const V6ONLY = 9;
100 pub const JOIN_GROUP = 5;
101 pub const LEAVE_GROUP = 6;
102 pub const RECVPKTINFO = 10;
103 pub const PKTINFO = 11;
104 pub const RECVHOPLIMIT = 12;
105 pub const HOPLIMIT = 13;
106};
107
108// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L40
109pub const IPTOS = struct {
110 pub const LOWDELAY = 16;
111 pub const THROUGHPUT = 8;
112 pub const RELIABILITY = 4;
113};