diff options
| -rw-r--r-- | syscall.jai | 69 | ||||
| -rw-r--r-- | ttt.jai | 16 |
2 files changed, 79 insertions, 6 deletions
diff --git a/syscall.jai b/syscall.jai new file mode 100644 index 0000000..46a9d84 --- /dev/null +++ b/syscall.jai @@ -0,0 +1,69 @@ +#import "Basic"; +#import "POSIX"; + +// This prototype is suposed to allow me to use the "open" posix syscall +// that returns a file-descriptor (fd) that can then be used by the mmap +// syscall that allows to map a file to memory. +// +// Syscall info: https://filippo.io/linux-syscall-table/ + +main :: () { + print("starting syscall\n"); + + sys_exit(-1); + fd := sys_open("./dummy"); + print("fd is %\nerrno is %\n", fd, errno()); + + print("done syscall\n"); + LOOPER :: "\\|/-"; + idx := 0; + loop: string; + loop.count = 1; + for 0..3 { + sleep_milliseconds(1000); + loop.data = *LOOPER.data[idx]; + idx = (idx + 1) % LOOPER.count; + print("\rlooping %", loop); + } + + sys_close(fd); + print("\rclosed\n"); + + for 0..3 { + sleep_milliseconds(1000); + loop.data = *LOOPER.data[idx]; + idx = (idx + 1) % LOOPER.count; + print("\rlooping %", loop); + } +} + +sys_open :: (path: string) -> fd: s64 { + SYS_OPEN :: 2; + return syscall(SYS_OPEN, cast(*s8)path.data, O_RDONLY); +} + +sys_close :: (fd: s64) { + SYS_CLOSE :: 3; + syscall(SYS_CLOSE, fd); +} + +sys_exit :: (status: s32) { +#if OS == .WINDOWS { + // @Note TerminateProcess may be better, as it can't deadlock + ExitProcess :: (error_code: u32) #foreign kernel32; + ExitProcess(xx errno); +} +else #if OS == .LINUX { + SYS_EXIT_GROUP :: 231; + #if CPU==.X64 { + print("\rLINUX-ASM\n"); + #asm SYSCALL_SYSRET { + mov eax: gpr === a, SYS_EXIT_GROUP; + mov out: gpr === di, status; + syscall t1:, t2:, eax, out; + }; + } else { + syscall(SYS_EXIT_GROUP, status); + } +} +} @@ -1250,15 +1250,19 @@ typedef struct { int64_t total_times[NUM_WEEK_DAYS]; } database_st; */ -/* -Database :: struct { - active_task : *~s64 Task = null; - selected_task : *~s64 Task = null; + +DatabaseX :: struct { + active_idx : s64; + selected_task : s64; modified_on : s64; total_times : [NUM_WEEK_DAYS] s64; - tasks : [..] Task; + tasks : [] Task; } -*/ + + + dd: DatabaseX; + + db : Database; |
