aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-02-27 03:16:54 +0000
committerdam <dam@gudinoff>2023-02-27 03:16:54 +0000
commit968ffd3966f5b23bb2b32cff803229732ae8bdb1 (patch)
tree9670491ccd796461e1ab9910594cc4146b3da111
parenta17d91de4bbbdf01f1a157d9825fd13db6be72da (diff)
downloadtask-time-tracker-968ffd3966f5b23bb2b32cff803229732ae8bdb1.tar.zst
task-time-tracker-968ffd3966f5b23bb2b32cff803229732ae8bdb1.zip
Implemented prototypes for sys_stat and sys_fstat to replace lseek used to get file size.
-rw-r--r--syscall.jai108
-rw-r--r--ttt.jai34
2 files changed, 119 insertions, 23 deletions
diff --git a/syscall.jai b/syscall.jai
index e5dee41..d04897c 100644
--- a/syscall.jai
+++ b/syscall.jai
@@ -10,7 +10,9 @@
main :: () {
//sys_exit(-1);
- print("> open dummy\n");
+ size_stat, error_stat := sys_stat("./dummy");
+ print("> dymmy has stat size % widh error %\n", size_stat.st_size, error_stat);
+
fd, error_open := sys_open("./dummy", O_RDONLY, O_RDONLY);
print("> opened dummy with fd % and errno %\n", fd, error_open);
if fd < 0 return;
@@ -28,8 +30,11 @@ main :: () {
//}
- size, error_lseek := sys_lseek(fd, 0, SEEK_END);
- print("\r> dummy has size % with error %\n", size, error_lseek);
+ size_lseek, error_lseek := sys_lseek(fd, 0, SEEK_END);
+ print("\r> dummy has lseek size % with error %\n", size_lseek, error_lseek);
+
+ size_fstat, error_fstat := sys_fstat(fd);
+ print("\r> dummy has fstat size % with error %\n", size_fstat.st_size, error_fstat);
error_close := sys_close(fd);
print("\r> close(%) with errno %\n", fd, error_close);
@@ -43,16 +48,83 @@ main :: () {
}
+sys_stat :: (path: string) -> result: stat_t, error: s64{
+ print("\r# sys_stat\n");
+ #if OS == .LINUX {
+ SYS_STAT :: 4;
+ stats: stat_t = ---;
+ result: s64 = ---;
+ #if CPU == .X64 {
+ print("\r# LINUX:ASM\n");
+ path_p: *s8 = xx path.data;
+ stats_p := *stats;
+ #asm SYSCALL_SYSRET {
+ mov rax: gpr === a, SYS_STAT;
+ mov rdi: gpr === di, path_p;
+ mov rsi: gpr === si, stats_p;
+ syscall
+ rcx: gpr === c, // Implicitly used by syscall to store RIP
+ r11: gpr === 11, // Implicitly used by syscall to store RFLAGS
+ rax, rdi, rsi;
+ mov result, rax;
+ }
+ if result < 0
+ return .{}, -result; // Error.
+ else
+ return stats, 0; // OK.
+ } else {
+ print("\r# LINUX:LIBC\n");
+ path_p: *s8 = xx path.data;
+ error := syscall(SYS_STAT, path_p, *stats);
+ if error < 0
+ return .{}, errno(); // Error.
+ else
+ return stats, 0; // OK.
+ }
+ } else {
+ print("TODO Implement this\n"); // TODO Implement this.
+ }
+}
-
-
+sys_fstat :: (file_descriptor: s64) -> result: stat_t, error: s64{
+ print("\r# sys_fstat\n");
+ #if OS == .LINUX {
+ SYS_FSTAT :: 5;
+ stats: stat_t = ---;
+ stats_p := *stats;
+ result: s64 = ---;
+ #if CPU == .X64 {
+ print("\r# LINUX:ASM\n");
+ #asm SYSCALL_SYSRET {
+ mov rax: gpr === a, SYS_FSTAT;
+ mov rdi: gpr === di, file_descriptor;
+ mov rsi: gpr === si, stats_p;
+ syscall
+ rcx: gpr === c, // Implicitly used by syscall to store RIP
+ r11: gpr === 11, // Implicitly used by syscall to store RFLAGS
+ rax, rdi, rsi;
+ mov result, rax;
+ }
+ if result < 0
+ return .{}, -result; // Error.
+ else
+ return stats, 0; // OK.
+ } else {
+ print("\r# LINUX:LIBC\n");
+ error := syscall(SYS_FSTAT, file_descriptor, *result);
+ if error < 0
+ return .{}, errno(); // Error.
+ else
+ return stats, 0; // OK.
+ }
+ } else {
+ print("TODO Implement this\n"); // TODO Implement this.
+ }
+}
sys_lseek :: (file_descriptor: s64, offset: s64, whence: s64) -> offset_location: s64, error: s64 {
print("\r# sys_lseek\n");
- #if OS == .WINDOWS {
- print("TODO Implement this\n"); // TODO Implement this.
- }
- else #if OS == .LINUX {
+ #if OS == .LINUX {
SYS_LSEEK :: 8;
result: s64 = ---;
#if CPU == .X64 {
@@ -81,15 +153,14 @@ sys_lseek :: (file_descriptor: s64, offset: s64, whence: s64) -> offset_location
else
return result, 0; // OK.
}
- }
+ } else {
+ print("TODO Implement this\n"); // TODO Implement this.
+ }
}
sys_open :: (path: string, flags: s64, mode: s64) -> file_descriptor: s64, error: s64 {
print("\r# sys_open\n");
- #if OS == .WINDOWS {
- print("TODO Implement this\n"); // TODO Implement this.
- }
- else #if OS == .LINUX {
+ #if OS == .LINUX {
SYS_OPEN :: 2;
data: *s8 = xx path.data;
result: s64 = ---;
@@ -119,15 +190,14 @@ sys_open :: (path: string, flags: s64, mode: s64) -> file_descriptor: s64, error
else
return result, 0; // OK.
}
+ } else {
+ print("TODO Implement this\n"); // TODO Implement this.
}
}
sys_close :: (file_descriptor: s64) -> error: s64 {
print("\r# sys_close\n");
- #if OS == .WINDOWS {
- print("TODO Implement this\n"); // TODO Implement this.
- }
- else #if OS == .LINUX {
+ #if OS == .LINUX {
SYS_CLOSE :: 3;
result: s64 = ---;
#if CPU == .X64 {
@@ -147,5 +217,7 @@ sys_close :: (file_descriptor: s64) -> error: s64 {
result = syscall(SYS_CLOSE, file_descriptor);
return ifx result < 0 then errno() else 0;
}
+ } else {
+ print("TODO Implement this\n"); // TODO Implement this.
}
}
diff --git a/ttt.jai b/ttt.jai
index 9592d5b..7612f1b 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -1258,14 +1258,14 @@ main :: () {
//c, d := file_open(ar_file_path);
mfi, success := map_entire_file_start(ar_file_path);
print("Success is %\n", success);
- print("MFI is %\n", mfi);
+ //print("MFI is %\n", mfi);
print("MFI.data.count is %\n", mfi.data.count);
- print("MFI.data.data[1] is %\n", mfi.data.data[123]);
+ //print("MFI.data.data[1] is %\n", mfi.data.data[123]);
print("%\n", ifx success then "success" else "fail");
print("--------------------------------------\n");
-
- print(">>>%\n", mfi.map_info.file.handle.unknown_pre[111]);
- print("###%\n", mfi.map_info.file.handle._file);
+ //print(">>>%\n", mfi.map_info.file.handle.unknown_pre[111]);
+ //print("###%\n", mfi.map_info.file.handle._file);
+ print("###%\n", mfi.map_info.file_descriptor);
//file_h := c.handle;
//for file_h.cena
//if it == 4 {
@@ -1282,6 +1282,30 @@ main :: () {
//}
//print("%\n", <<mfi.map_info.file.handle);
+ print("> IN LOOP <\n");
+ peek :string;
+ peek.data = mfi.map_info.data.data;
+ peek.count = 1;
+ seek := 0;
+ while true {
+ //sleep_milliseconds(10);
+ print("peeking '%'\n", peek);
+ peek.data += 100000;
+ seek += 100000;
+ if seek >= (186880600/2)
+ break;
+ }
+ print("-- peek complete\n");
+ print("MFI.data.count is %\n", mfi.data.count);
+ sleep_milliseconds(10000);
+ print("-- unloading...");
+ map_entire_file_end(*mfi);
+ print("done\n");
+ sleep_milliseconds(10000);
+ //print("-- reading entire file");
+ //read_entire_file(ar_file_path);
+ //print("done\n");
+ //sleep_milliseconds(10000);
return;
}