mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 19:07:01 +02:00
kernel: retain POSIX file descriptor close-on-exec flags
This commit is contained in:
@@ -70,6 +70,7 @@ struct File {
|
||||
std::atomic_bool writable;
|
||||
std::atomic_bool append;
|
||||
std::atomic_bool sync_writes;
|
||||
std::atomic_bool close_on_exec;
|
||||
SpecialFile special;
|
||||
Common::Mutex mutex;
|
||||
std::vector<uint8_t> dirents;
|
||||
@@ -449,11 +450,12 @@ int KYTY_SYSV_ABI KernelOpen(const char* path, int flags, uint16_t mode) {
|
||||
|
||||
EXIT_IF(file == nullptr || file->opened || file->directory);
|
||||
|
||||
file->name = path;
|
||||
file->readable = rw_mode != Common::File::Mode::Write;
|
||||
file->writable = rw_mode != Common::File::Mode::Read;
|
||||
file->append = append;
|
||||
file->sync_writes = fsync || sync || dsync;
|
||||
file->name = path;
|
||||
file->readable = rw_mode != Common::File::Mode::Write;
|
||||
file->writable = rw_mode != Common::File::Mode::Read;
|
||||
file->append = append;
|
||||
file->sync_writes = fsync || sync || dsync;
|
||||
file->close_on_exec = (static_cast<uint32_t>(flags) & 0x00100000u) != 0;
|
||||
|
||||
if (!directory && IsRandomDevice(file->name)) {
|
||||
file->real_name = file->name;
|
||||
@@ -585,6 +587,27 @@ int KYTY_SYSV_ABI KernelClose(int d) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int KYTY_SYSV_ABI KernelFcntl(int d, int command, int arg) {
|
||||
PRINT_NAME();
|
||||
|
||||
if (d < DESCRIPTOR_MIN) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
auto* file = g_files->GetFile(d);
|
||||
if (file == nullptr || !file->opened) {
|
||||
return KERNEL_ERROR_EBADF;
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case 1: return file->close_on_exec.load(std::memory_order_relaxed); // F_GETFD
|
||||
case 2: // F_SETFD, FD_CLOEXEC
|
||||
file->close_on_exec.store((arg & 1) != 0, std::memory_order_relaxed);
|
||||
return OK;
|
||||
default: return KERNEL_ERROR_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t KYTY_SYSV_ABI KernelRead(int d, void* buf, size_t nbytes) {
|
||||
PRINT_NAME();
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ std::filesystem::path GetRealFilename(const std::string& mounted_file_name);
|
||||
|
||||
int KYTY_SYSV_ABI KernelOpen(const char* path, int flags, uint16_t mode);
|
||||
int KYTY_SYSV_ABI KernelClose(int d);
|
||||
int KYTY_SYSV_ABI KernelFcntl(int d, int command, int arg);
|
||||
int64_t KYTY_SYSV_ABI KernelRead(int d, void* buf, size_t nbytes);
|
||||
int64_t KYTY_SYSV_ABI KernelPread(int d, void* buf, size_t nbytes, int64_t offset);
|
||||
int64_t KYTY_SYSV_ABI KernelPreadv(int d, const KernelIovec* iov, int iovcnt, int64_t offset);
|
||||
|
||||
Reference in New Issue
Block a user