aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-02-26 03:06:09 +0000
committerdam <dam@gudinoff>2023-02-26 03:06:09 +0000
commitb75c965d3d2bb4bd9059d0df0366cd54f76825ff (patch)
treefee595959de6c3a52fe0113247dcace1d0810993
parent1c4f10d917b8bdff3c2b066f4b51843d4ad490b7 (diff)
downloadtask-time-tracker-b75c965d3d2bb4bd9059d0df0366cd54f76825ff.tar.zst
task-time-tracker-b75c965d3d2bb4bd9059d0df0366cd54f76825ff.zip
Prototyping syscalls.
-rw-r--r--syscall.jai69
-rw-r--r--ttt.jai16
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);
+ }
+}
+}
diff --git a/ttt.jai b/ttt.jai
index 584548a..e69132e 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -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;