mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-14 15:06:52 -04:00
Create close system call
This commit is contained in:
parent
de50d30d99
commit
04468b9f0b
@ -38,6 +38,7 @@ void sleep_ms(pid_t pid, size_t time);
|
|||||||
|
|
||||||
size_t register_new_handle(const std::string& path);
|
size_t register_new_handle(const std::string& path);
|
||||||
bool has_handle(size_t fd);
|
bool has_handle(size_t fd);
|
||||||
|
void release_handle(size_t fd);
|
||||||
const std::string& get_handle(size_t fd);
|
const std::string& get_handle(size_t fd);
|
||||||
|
|
||||||
} //end of namespace scheduler
|
} //end of namespace scheduler
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace vfs {
|
namespace vfs {
|
||||||
|
|
||||||
int64_t open(const char* file);
|
int64_t open(const char* file);
|
||||||
|
void close(size_t fd);
|
||||||
int64_t stat(size_t fd, stat_info& info);
|
int64_t stat(size_t fd, stat_info& info);
|
||||||
|
|
||||||
} //end of namespace vfs
|
} //end of namespace vfs
|
||||||
|
@ -814,6 +814,10 @@ size_t scheduler::register_new_handle(const std::string& path){
|
|||||||
return pcb[current_pid].handles.size() - 1;
|
return pcb[current_pid].handles.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scheduler::release_handle(size_t fd){
|
||||||
|
pcb[current_pid].handles[fd] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool scheduler::has_handle(size_t fd){
|
bool scheduler::has_handle(size_t fd){
|
||||||
return pcb[current_pid].handles.size() - 1 <= fd;
|
return pcb[current_pid].handles.size() - 1 <= fd;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ void sc_open(interrupt::syscall_regs* regs){
|
|||||||
regs->rax = vfs::open(file);
|
regs->rax = vfs::open(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sc_close(interrupt::syscall_regs* regs){
|
||||||
|
auto fd = regs->rbx;
|
||||||
|
|
||||||
|
vfs::close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
void sc_stat(interrupt::syscall_regs* regs){
|
void sc_stat(interrupt::syscall_regs* regs){
|
||||||
auto fd = regs->rbx;
|
auto fd = regs->rbx;
|
||||||
auto info = reinterpret_cast<stat_info*>(regs->rcx);
|
auto info = reinterpret_cast<stat_info*>(regs->rcx);
|
||||||
@ -186,6 +192,10 @@ void system_call_entry(interrupt::syscall_regs* regs){
|
|||||||
sc_stat(regs);
|
sc_stat(regs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 302:
|
||||||
|
sc_close(regs);
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x666:
|
case 0x666:
|
||||||
//TODO Do something with return code
|
//TODO Do something with return code
|
||||||
scheduler::kill_current_process();
|
scheduler::kill_current_process();
|
||||||
|
@ -55,6 +55,12 @@ int64_t vfs::open(const char* file_path){
|
|||||||
return -std::ERROR_NOT_EXISTS;
|
return -std::ERROR_NOT_EXISTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vfs::close(size_t fd){
|
||||||
|
if(scheduler::has_handle(fd)){
|
||||||
|
scheduler::release_handle(fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int64_t vfs::stat(size_t fd, stat_info& info){
|
int64_t vfs::stat(size_t fd, stat_info& info){
|
||||||
if(!disks::mounted_partition() || !disks::mounted_disk()){
|
if(!disks::mounted_partition() || !disks::mounted_disk()){
|
||||||
return -std::ERROR_NOTHING_MOUNTED;
|
return -std::ERROR_NOTHING_MOUNTED;
|
||||||
|
@ -87,6 +87,8 @@ int main(int argc, char* argv[]){
|
|||||||
} else {
|
} else {
|
||||||
printf("stat: error: %s\n", std::error_message(info.error()));
|
printf("stat: error: %s\n", std::error_message(info.error()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(*fd);
|
||||||
} else {
|
} else {
|
||||||
printf("stat: error: %s\n", std::error_message(fd.error()));
|
printf("stat: error: %s\n", std::error_message(fd.error()));
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <stat_info.hpp>
|
#include <stat_info.hpp>
|
||||||
|
|
||||||
std::expected<size_t> open(const char* file);
|
std::expected<size_t> open(const char* file);
|
||||||
|
void close(size_t fd);
|
||||||
std::expected<stat_info> stat(size_t fd);
|
std::expected<stat_info> stat(size_t fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,12 @@ std::expected<size_t> open(const char* file){
|
|||||||
return std::make_expected<size_t>(fd);
|
return std::make_expected<size_t>(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void close(size_t fd){
|
||||||
|
asm volatile("mov rax, 302; mov rbx, %[fd]; int 50;"
|
||||||
|
: /* No outputs */
|
||||||
|
: [fd] "g" (fd)
|
||||||
|
: "rax", "rbx");
|
||||||
|
}
|
||||||
|
|
||||||
std::expected<stat_info> stat(size_t fd){
|
std::expected<stat_info> stat(size_t fd){
|
||||||
stat_info info;
|
stat_info info;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user