]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added (but didn't implement yet) the close syscall
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sat, 2 Dec 2023 23:29:08 +0000 (00:29 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sat, 2 Dec 2023 23:29:08 +0000 (00:29 +0100)
doc.txt
kernel/src/ring3.S
kernel/src/ring3.cpp
test_module/src/test.S
test_module/src/test.cpp

diff --git a/doc.txt b/doc.txt
index 2eb0be8809a470407c2555e9c5db1138ba43eb58..cd179c8fb77a18eac82ab5c80af59cd9b336eba4 100644 (file)
--- a/doc.txt
+++ b/doc.txt
@@ -67,6 +67,10 @@ ssize_t write(fd_t file, char const data[len], ssize_t len);
        Write up to len characters to file.
        Return the number of actually written characters, or -1 on error.
 
+ssize_t close(fd_t file);
+       Termine the fd `file`. If there were no other copies of it, the corresponding file is closed.
+       Returns -1 if `file` isn't an opened file descriptor.
+
 ssize_t fseek(fd_t file, ssize_t offset, int from);
        If from is 0, seek offset bytes from start.
        If from is 1, seek offset bytes from current file position.
index 8e8fbcc7d503944c2b333c4bae54eb13b88434e7..fb5f837deafa3316d3a647996b22f428ab40e87d 100644 (file)
@@ -92,6 +92,7 @@ syscalls_call_table:
        .quad syscall_open
        .quad syscall_read
        .quad syscall_write
+       .quad syscall_close
        .quad syscall_fseek
 syscalls_call_table_end:
 .set syscall_n, (syscalls_call_table_end - syscalls_call_table) >> 3 # Because / 8 *doesn't work* !
index cc2d24fcc556adbca20839f0179e99696496b023..11e67469d9be83119797252c31543d4e0994eac2 100644 (file)
@@ -75,6 +75,12 @@ extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t
        return len;
 }
 
+// extern "C" std::int64_t syscall_close(std::int64_t file) {
+extern "C" std::int64_t syscall_close(std::int64_t) {
+       os::assert(false, "Close isn't implemented for now.");
+       __builtin_unreachable();
+}
+
 extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) {
        os::assert(file == 0, "Write isn't really implemented for now.");
        os::assert(len >= 0, "Write expects a positive size.");
index 8635763646e270c25c1314df92a7f263e6c0f862..2d326b2a075baff56328dfb3ba9a90ec30f501fb 100644 (file)
@@ -32,8 +32,14 @@ write:
        syscall
        ret
 
+.globl close
+close:
+       mov $3, %rax
+       syscall
+       ret
+
 .globl fseek
 fseek:
-       mov $3, %rax
+       mov $4, %rax
        syscall
        ret
index 0f6f836258c1006448d317f9df116d706bdc2646..14a0df2bb0cc47169b76abc50fcf89d1b32e8e61 100644 (file)
@@ -26,30 +26,36 @@ namespace sys {
 extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, open_options options);
 extern "C" int64_t read(int64_t file, char* data, int64_t len);
 extern "C" int64_t write(int64_t file, char const* data, int64_t len);
+extern "C" int64_t close(int64_t file);
 extern "C" int64_t fseek(int64_t file, int64_t offset, int from);
 } // namespace sys
 
 extern "C" void _start() {
-       const int64_t fd = 0; // sys::open(0, "/serial", 7, sys::MODE_RW | sys::OPTION_INPLACE);
+       const int64_t wd = sys::open(0, "/", 1, open_options(MODE_RW | OPTION_INPLACE | MODE_DIRECTORY));
+       const int64_t serial = sys::open(wd, "serial", 1, MODE_RW);
+       const int64_t serial_ = sys::open(wd, "/serial", 1, MODE_WO);
 
-       sys::write(fd, "Entrez votre nom: ", 18);
+       sys::write(serial, "Entrez votre nom: ", 18);
        char data[32];
        int64_t read = 0;
        int64_t read_this_time;
        do {
-               read_this_time = sys::read(fd, data + read, 1);
+               read_this_time = sys::read(serial, data + read, 1);
                if (read_this_time) {
                        if (data[read] == '\r') {
-                               sys::write(fd, "\n", 1);
+                               sys::write(serial, "\n", 1);
                        } else {
-                               sys::write(fd, data + read, 1);
+                               sys::write(serial, data + read, 1);
                        }
                }
                read += read_this_time;
        } while (read_this_time != 0 && read < 32 && data[read - 1] != '\r');
-       sys::write(fd, "Bonjour, ", 9);
-       sys::write(fd, data, read - (data[read - 1] == '\r' ? 1 : 0));
-       sys::write(fd, ".\n", 2);
+       sys::write(serial_, "Bonjour, ", 9);
+       sys::write(serial_, data, read - (data[read - 1] == '\r' ? 1 : 0));
+       sys::write(serial_, ".\n", 2);
+
+       sys::close(serial);
+       sys::close(serial_);
 
        while (true) {
                sys::fseek(0, 0, 1);