syscall.h

Commit: 5ef818f0 Author: jokerz Raw Copy
1
/* syscall.h - System call interface for Pactor64 */
2
#ifndef _SYSCALL_H
3
#define _SYSCALL_H
4
5
#include "pactor64.h"
6
7
/* Linux x86-64 compatible syscall numbers */
8
#define SYS_READ    0
9
#define SYS_WRITE   1
10
#define SYS_OPEN    2
11
#define SYS_CLOSE   3
12
#define SYS_LSEEK   8
13
#define SYS_BRK     12
14
#define SYS_IOCTL   16
15
#define SYS_PIPE    22
16
#define SYS_DUP     32
17
#define SYS_GETPID  39
18
#define SYS_EXIT    60
19
#define SYS_GETUID  102
20
#define SYS_GETGID  104
21
22
/* MSR addresses for SYSCALL support */
23
#define MSR_STAR    0xC0000081
24
#define MSR_LSTAR   0xC0000082
25
#define MSR_FMASK   0xC0000084
26
27
#define MAX_SYSCALL 128
28
29
/* Initialize the syscall interface (sets up STAR/LSTAR MSRs) */
30
void syscall_init(void);
31
32
/* The syscall handler (called from assembly stub) */
33
uint64_t syscall_dispatch(uint64_t num, uint64_t arg1, uint64_t arg2,
34
                          uint64_t arg3, uint64_t arg4, uint64_t arg5);
35
36
/* Assembly syscall entry point */
37
extern void syscall_entry(void);
38
39
/* Return from userspace back to kernel shell (called from sys_exit) */
40
extern void return_to_kernel(void) __attribute__((noreturn));
41
42
/* Low-level MSR read/write */
43
static inline uint64_t read_msr(uint32_t msr) {
44
    uint32_t lo, hi;
45
    __asm__ volatile ("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr));
46
    return ((uint64_t)hi << 32) | lo;
47
}
48
49
static inline void write_msr(uint32_t msr, uint64_t val) {
50
    uint32_t lo = (uint32_t)val;
51
    uint32_t hi = (uint32_t)(val >> 32);
52
    __asm__ volatile ("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
53
}
54
55
#endif /* _SYSCALL_H */
56