Add system calls for working directory

This commit is contained in:
Baptiste Wicht 2014-02-23 21:19:02 +01:00
parent b3152b16ff
commit 5d827dca9d
3 changed files with 46 additions and 0 deletions

View File

@ -41,6 +41,9 @@ bool has_handle(size_t fd);
void release_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
#endif

View File

@ -41,6 +41,7 @@ struct process_control_t {
size_t rounds;
size_t sleep_timeout;
std::vector<std::string> handles;
std::vector<std::string> working_directory;
};
//The Process Control Block
@ -861,6 +862,14 @@ const std::string& scheduler::get_handle(size_t 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
extern "C" {

View File

@ -130,6 +130,32 @@ void sc_read(interrupt::syscall_regs* regs){
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
void system_call_entry(interrupt::syscall_regs* regs){
@ -208,6 +234,14 @@ void system_call_entry(interrupt::syscall_regs* regs){
sc_read(regs);
break;
case 304:
sc_pwd(regs);
break;
case 305:
sc_cwd(regs);
break;
case 0x666:
//TODO Do something with return code
scheduler::kill_current_process();