sysdeps/managarm: Implement F_GETFD fcntl()
@@ -52,7 +52,6 @@ namespace mlibc {
int sys_chroot(const char *path) {
HelAction actions[3];
-
globalQueue.trim();
managarm::posix::CntRequest<MemoryAllocator> req(getAllocator());
@@ -146,9 +145,39 @@ int sys_fcntl(int fd, int request, va_list args) {
return -1;
return newfd;
}else if(request == F_GETFD) {
- frigg::infoLogger() << "\e[31mmlibc: fcntl(F_GETFD) is not implemented correctly"
- << "\e[39m" << frigg::endLog;
- return 0;
+ HelAction actions[3];
+ globalQueue.trim();
+
+ managarm::posix::CntRequest<MemoryAllocator> req(getAllocator());
+ req.set_request_type(managarm::posix::CntReqType::FD_GET_FLAGS);
+ req.set_fd(fd);
+
+ frigg::String<MemoryAllocator> ser(getAllocator());
+ 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(getAllocator());
+ resp.ParseFromArray(recv_resp->data, recv_resp->length);
+ __ensure(resp.error() == managarm::posix::Errors::SUCCESS);
+ return resp.flags();
}else if(request == F_SETFD) {
frigg::infoLogger() << "\e[31mmlibc: fcntl(F_SETFD) is not implemented correctly"
<< "\e[39m" << frigg::endLog;
