浏览代码

Some mild additional safety and a PSA

master
Ludovic 'Archivist' Lagouardette 3 年前
父节点
当前提交
a0992a2067
共有 1 个文件被更改,包括 26 次插入9 次删除
  1. +26
    -9
      extra_tests/001_test/syscall.hpp

+ 26
- 9
extra_tests/001_test/syscall.hpp 查看文件

@ -3,10 +3,22 @@
#include <cstddef>
#include <gp/containers/buffer.hpp>
#if defined(__x86_64__)
#if defined(__linux__)
constexpr bool is_x86_64_linux = true;
#else
constexpr bool is_x86_64_linux = false;
#endif
#else
constexpr bool is_x86_64_linux = false;
#endif
template<int64_t syscall_id, int arg_count>
struct syscall;
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 1> {
int64_t operator()(int64_t p1) const {
int64_t ret;
@ -22,6 +34,7 @@ struct syscall {
};
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 2> {
int64_t operator()(int64_t p1,int64_t p2) const {
int64_t ret;
@ -37,6 +50,7 @@ struct syscall {
};
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 3> {
int64_t operator()(int64_t p1,int64_t p2,int64_t p3) const {
int64_t ret;
@ -52,6 +66,7 @@ struct syscall {
};
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 4> {
int64_t operator()(int64_t p1,int64_t p2,int64_t p3,int64_t p4) const {
int64_t ret;
@ -68,6 +83,7 @@ struct syscall {
};
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 5> {
int64_t operator()(int64_t p1,int64_t p2,int64_t p3,int64_t p4,int64_t p5) const {
int64_t ret;
@ -85,6 +101,7 @@ struct syscall {
};
template<int64_t syscall_id>
requires is_x86_64_linux
struct syscall<syscall_id, 6> {
int64_t operator()(int64_t p1,int64_t p2,int64_t p3,int64_t p4,int64_t p5,int64_t p6) const {
int64_t ret;
@ -124,19 +141,19 @@ inline int munmap(void *addr, size_t length) {
return _munmap((int64_t)addr, (int64_t)length);
}
inline int read(int fd, gp::buffer<char> buffer) {
return _read((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size());
}
inline int write(int fd, gp::buffer<char> buffer) {
return _write((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size());
}
extern "C" {
/// Yes, __attribute__((__noreturn__)), not [[noreturn]], because some God forsaken potato decided that those attributes are not the attributes I am looking for
inline __attribute__ ((__noreturn__)) void exit(int status) {
_exit((int64_t)status);
while(true);
}
}
inline int read(int fd, gp::buffer<char> buffer) {
return _read((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size());
}
inline int write(int fd, gp::buffer<char> buffer) {
return _write((int64_t)fd, (int64_t)buffer.begin().data, (int64_t)buffer.size());
}

正在加载...
取消
保存