Преглед на файлове

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());
}

Зареждане…
Отказ
Запис