summaryrefslogblamecommitdiffstats
path: root/abi/syscall.h
blob: e336fe6688374132774f8b3df7afc07c8d8e74f0 (plain) (tree)
1
2
3
4
5


                            

                   








                        
                             
                      
                     

  


                    
                


                         


                 



                                                                                 
 
                                       






                                                    




                                             
      
#ifndef JOVE_ABI_SYSCALL_H
#define JOVE_ABI_SYSCALL_H 1

#include <stdint.h>

typedef struct syscall {
    int id;
} syscall_t;

struct syscall_log {
    syscall_t syscall;
    const char *message;
};

struct syscall_mem_takefree {
    syscall_t syscall;
    uintptr_t npages;
};

enum
{
    SYSCALL_LOG = 0,
    SYSCALL_TID,

    SYSCALL_MEM_TAKEFREE,

    SYSCALL_COUNT
};

#define _SYSCALL(data) \
    intmax_t ax; \
    __asm__ volatile("movq %0, %%rdi\nsyscall": "=a"(ax): "r"(data): "memory"); \
    return ax

int _syscall_log(const char *message) {
    struct syscall_log syscall_data = {
        .syscall = (syscall_t){ .id = SYSCALL_LOG },
        .message = message
    };
    _SYSCALL(&syscall_data);
}

intmax_t _syscall_tid(void) {
    syscall_t syscall_data = { SYSCALL_TID };
    _SYSCALL(&syscall_data);
}

#endif