mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 00:26:44 -04:00
Add system calls for working directory
This commit is contained in:
parent
b3152b16ff
commit
5d827dca9d
@ -41,6 +41,9 @@ bool has_handle(size_t fd);
|
|||||||
void release_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);
|
||||||
|
|
||||||
|
const std::vector<std::string>& get_working_directory();
|
||||||
|
void set_working_directory(const std::vector<std::string>& directory);
|
||||||
|
|
||||||
} //end of namespace scheduler
|
} //end of namespace scheduler
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,6 +41,7 @@ struct process_control_t {
|
|||||||
size_t rounds;
|
size_t rounds;
|
||||||
size_t sleep_timeout;
|
size_t sleep_timeout;
|
||||||
std::vector<std::string> handles;
|
std::vector<std::string> handles;
|
||||||
|
std::vector<std::string> working_directory;
|
||||||
};
|
};
|
||||||
|
|
||||||
//The Process Control Block
|
//The Process Control Block
|
||||||
@ -861,6 +862,14 @@ const std::string& scheduler::get_handle(size_t fd){
|
|||||||
return pcb[current_pid].handles[fd];
|
return pcb[current_pid].handles[fd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<std::string>& scheduler::get_working_directory(){
|
||||||
|
return pcb[current_pid].working_directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
void scheduler::set_working_directory(const std::vector<std::string>& directory){
|
||||||
|
pcb[current_pid].working_directory = directory;
|
||||||
|
}
|
||||||
|
|
||||||
//Provided for task_switch.s
|
//Provided for task_switch.s
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -130,6 +130,32 @@ void sc_read(interrupt::syscall_regs* regs){
|
|||||||
regs->rax = vfs::read(fd, buffer, max);
|
regs->rax = vfs::read(fd, buffer, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sc_pwd(interrupt::syscall_regs* regs){
|
||||||
|
auto wd = scheduler::get_working_directory();
|
||||||
|
|
||||||
|
std::string path;
|
||||||
|
path += '/';
|
||||||
|
|
||||||
|
for(auto& part : wd){
|
||||||
|
path += part;
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
auto buffer = reinterpret_cast<char*>(regs->rbx);
|
||||||
|
for(int i = 0; i < path.size(); ++i){
|
||||||
|
buffer[i] = path[i];
|
||||||
|
}
|
||||||
|
buffer[path.size()] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void sc_cwd(interrupt::syscall_regs* regs){
|
||||||
|
auto p = reinterpret_cast<const char*>(regs->rbx);
|
||||||
|
std::string path(p);
|
||||||
|
|
||||||
|
auto cwd = std::split(path, '/');
|
||||||
|
scheduler::set_working_directory(cwd);
|
||||||
|
}
|
||||||
|
|
||||||
} //End of anonymous namespace
|
} //End of anonymous namespace
|
||||||
|
|
||||||
void system_call_entry(interrupt::syscall_regs* regs){
|
void system_call_entry(interrupt::syscall_regs* regs){
|
||||||
@ -208,6 +234,14 @@ void system_call_entry(interrupt::syscall_regs* regs){
|
|||||||
sc_read(regs);
|
sc_read(regs);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 304:
|
||||||
|
sc_pwd(regs);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 305:
|
||||||
|
sc_cwd(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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user