AsmGrader 0.0.0
Loading...
Searching...
No Matches
syscall_entries.inl
Go to the documentation of this file.
1#pragma once
2
3// IWYU pragma: private; include "syscall.hpp"
4
6
7#include <range/v3/algorithm/generate.hpp>
8
9#include <array>
10#include <cstddef>
11#include <cstdio>
12
13#include <sys/syscall.h>
14#include <sys/types.h>
15
16namespace asmgrader {
17
18static constexpr int NUM_SYSCALLS = 545;
19
20static constexpr auto SYSCALL_MAP = [] {
21 std::array<SyscallEntry, NUM_SYSCALLS> syscall_map{};
22
23 ranges::generate(syscall_map, [nr = 0]() mutable { return SyscallEntry::unknown(nr++); });
24
25#define SYSENT(name, ret_type, ...) syscall_map[SYS_##name] = SyscallEntry(SYS_##name, #name, ret_type, {__VA_ARGS__})
26
27 using enum SyscallEntry::Type;
28
29 const auto size_type = SyscallEntry::type_of<std::size_t>;
30 const auto ssize_type = SyscallEntry::type_of<ssize_t>;
31 const auto mode_type = SyscallEntry::type_of<mode_t>;
32 const auto off_type = SyscallEntry::type_of<off_t>;
33
34#ifdef SYS_read
35 SYSENT(read, ssize_type, {Int32, "fd"}, {CString, "buf"}, {size_type, "count"});
36#endif
37
38#ifdef SYS_write
39 SYSENT(write, ssize_type, {Int32, "fd"}, {CString, "buf"}, {size_type, "count"});
40#endif
41
42#ifdef SYS_exit
43 SYSENT(exit, Unused, {Int32, "status"});
44#endif
45#ifdef SYS_exit_group
46 SYSENT(exit_group, Unused, {Int32, "status"});
47#endif
48
49#ifdef SYS_open
50 SYSENT(open, Int32, {CString, "pathname"}, {Int32, "flags"}, {mode_type, "mode"});
51#endif
52#ifdef SYS_creat
53 SYSENT(creat, Int32, {CString, "pathname"}, {Int32, "flags"}, {mode_type, "mode"});
54#endif
55#ifdef SYS_openat
56 SYSENT(openat, Int32, {Int32, "dirfd"}, {CString, "pathname"}, {Int32, "flags"}, {mode_type, "mode"});
57#endif
58
59#ifdef SYS_close
60 SYSENT(close, Int32, {Int32, "fd"});
61#endif
62
63#ifdef SYS_mmap
64 SYSENT(mmap, VoidPtr, {VoidPtr, "addr"}, {size_type, "length"}, {Int32, "prot"}, {Int32, "flags"}, {Int32, "fd"},
65 {off_type, "off_t"});
66#endif
67#ifdef SYS_munmap
68 SYSENT(munmap, VoidPtr, {VoidPtr, "addr"}, {size_type, "length"});
69#endif
70
71#ifdef SYS_nanosleep
72 SYSENT(nanosleep, Int32, {TimeSpecPtr, "req"}, {TimeSpecPtr, "rem"});
73#endif
74
75#ifdef SYS_execve
76 SYSENT(execve, Int32, {CString, "pathname"}, {NTCStringArray, "argv"}, {NTCStringArray, "envp"});
77#endif
78
79#undef SYSNAME_ELEM
80
81 return syscall_map;
82}();
83
84} // namespace asmgrader
Definition asm_buffer.hpp:19
Type
Definition syscall.hpp:25
static constexpr Type type_of
Primarally for converting integer-aliases (e.g., size_t, mode_t, pid_t, etc.) to the corresponding en...
Definition syscall.hpp:40
static constexpr SyscallEntry unknown(int nr)
Definition syscall.hpp:77
#define SYSENT(name, ret_type,...)