sysdeps/managarm: Implement chdir()
@@ -52,10 +52,45 @@ HelHandle __mlibc_getPassthrough(int fd) {
namespace mlibc {
int sys_chdir(const char *path) {
- mlibc::infoLogger() << "\e[31mmlibc: chdir() is not implemented correctly\e[39m"
- << frg::endlog;
+ SignalGuard sguard;
+ HelAction actions[3];
+ globalQueue.trim();
+
+ managarm::posix::CntRequest<MemoryAllocator> req(getSysdepsAllocator());
+ req.set_request_type(managarm::posix::CntReqType::CHDIR);
+ req.set_path(frigg::String<MemoryAllocator>(getSysdepsAllocator(), path));
+
+ frigg::String<MemoryAllocator> ser(getSysdepsAllocator());
+ req.SerializeToString(&ser);
+ actions[0].type = kHelActionOffer;
+ actions[0].flags = kHelItemAncillary;
+ actions[1].type = kHelActionSendFromBuffer;
+ actions[1].flags = kHelItemChain;
+ actions[1].buffer = ser.data();
+ actions[1].length = ser.size();
+ actions[2].type = kHelActionRecvInline;
+ actions[2].flags = 0;
+ HEL_CHECK(helSubmitAsync(kHelThisThread, actions, 3,
+ globalQueue.getQueue(), 0, 0));
+
+ auto element = globalQueue.dequeueSingle();
+ auto offer = parseSimple(element);
+ auto send_req = parseSimple(element);
+ auto recv_resp = parseInline(element);
+
+ HEL_CHECK(offer->error);
+ HEL_CHECK(send_req->error);
+ HEL_CHECK(recv_resp->error);
+
+ managarm::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
+ resp.ParseFromArray(recv_resp->data, recv_resp->length);
+ if(resp.error() == managarm::posix::Errors::FILE_NOT_FOUND) {
+ return ENOENT;
+ }else{
+ __ensure(resp.error() == managarm::posix::Errors::SUCCESS);
return 0;
}
+}
int sys_chroot(const char *path) {
SignalGuard sguard;
