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;
57
58pub extern "c" fn purge(mode: c_int) c_int;
59
60pub extern "c" fn perf_event(type: PERF_EVENT, arg1: usize, arg2: usize) c_int;
61pub extern "c" fn perf_register_string(string: [*]const u8, string_length: usize) c_int;
62
63pub extern "c" fn get_stack_bounds(user_stack_base: *usize, user_stack_size: *usize) c_int;
64
65pub extern "c" fn anon_create(size: usize, options: O) c_int;
66
67pub 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;
68pub 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;
69
70// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L29
71pub const IP = struct {
72 pub const TOS = 1;
73 pub const TTL = 2;
74 pub const MULTICAST_LOOP = 3;
75 pub const ADD_MEMBERSHIP = 4;
76 pub const DROP_MEMBERSHIP = 5;
77 pub const MULTICAST_IF = 6;
78 pub const MULTICAST_TTL = 7;
79 pub const BLOCK_SOURCE = 8;
80 pub const ADD_SOURCE_MEMBERSHIP = 7;
81 pub const DROP_SOURCE_MEMBERSHIP = 8;
82 pub const UNBLOCK_SOURCE = 9;
83 pub const OPTIONS = 10;
84};
85
86// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L81
87pub const IPV6 = struct {
88 pub const UNICAST_HOPS = 1;
89 pub const MULTICAST_HOPS = 2;
90 pub const MULTICAST_LOOP = 3;
91 pub const MULTICAST_IF = 4;
92 pub const ADD_MEMBERSHIP = 5;
93 pub const DROP_MEMBERSHIP = 6;
94 pub const V6ONLY = 9;
95 pub const JOIN_GROUP = 5;
96 pub const LEAVE_GROUP = 6;
97 pub const RECVPKTINFO = 10;
98 pub const PKTINFO = 11;
99 pub const RECVHOPLIMIT = 12;
100 pub const HOPLIMIT = 13;
101};
102
103// https://github.com/SerenityOS/serenity/blob/5bd8af99be0bc4b2e14f361fd7d7590e6bcfa4d6/Kernel/API/POSIX/netinet/in.h#L40
104pub const IPTOS = struct {
105 pub const LOWDELAY = 16;
106 pub const THROUGHPUT = 8;
107 pub const RELIABILITY = 4;
108};