Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions core/libs/prx/libSceLibcInternal/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ extern "C" void* APS5_VABI fdopendir_nid_postfix(int fd) {
}

extern "C" void* APS5_VABI __opendir2_nid_postfix(const char* name, int flags) {
constexpr int HideWhiteouts = 0x1;
constexpr int NoDuplicates = 0x2;
constexpr int Rewind = 0x4;
if ((flags & ~(HideWhiteouts | NoDuplicates | Rewind)) != 0) NotImplemented_nid_no_patch("__opendir2: flags other than DTF_HIDEW, DTF_NODUP and DTF_REWIND");
constexpr int ReadAll = 0x8;
constexpr int SkipRead = 0x10;
if ((flags & (ReadAll | SkipRead)) != 0) return nullptr;
return opendir_nid_postfix(name);
}
13 changes: 10 additions & 3 deletions core/libs/tests/GuestOpendir2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ int main() {
Require(plain != nullptr);
const auto expected = Entries(plain);
Require(expected.at("sample.txt") == 8 && expected.at("subdirectory") == 4);
for (const int flags : {0x7, 0x6}) {
for (const int flags : {0x7, 0x6, 0x0, 0x1, 0x20, 0x27, 0x100, 0x40000000, static_cast<int>(0xffffffe7u)}) {
void* directory = __opendir2_nid_postfix(path.c_str(), flags);
Require(directory != nullptr);
Require(Entries(directory) == expected);
}
for (const int flags : {0x8, 0x10, 0x18, 0xf, 0x1f, 0x7fffffff, -1}) {
*__error_nid_postfix() = 1234;
Require(__opendir2_nid_postfix(path.c_str(), flags) == nullptr && *__error_nid_postfix() == 1234);
Require(__opendir2_nid_postfix(nullptr, flags) == nullptr && *__error_nid_postfix() == 1234);
}
const auto missing = (root / "missing").string();
Require(opendir_nid_postfix(missing.c_str()) == nullptr);
const int missingError = *__error_nid_postfix();
*__error_nid_postfix() = 0;
Require(__opendir2_nid_postfix(missing.c_str(), 0x7) == nullptr && *__error_nid_postfix() == missingError);
for (const int flags : {0x7, 0x20}) {
*__error_nid_postfix() = 0;
Require(__opendir2_nid_postfix(missing.c_str(), flags) == nullptr && *__error_nid_postfix() == missingError);
}
std::filesystem::remove(root / "sample.txt");
std::filesystem::remove(root / "subdirectory");
std::filesystem::remove(root);
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/debt/libSceLibcInternal.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [makecontext](../../../core/libs/prx/libSceLibcInternal/UserContext.cpp) (libSceLibcInternal) follows FreeBSD 11's `lib/libc/amd64/gen/makecontext.c`: at most six arguments, a stack of at least `MINSIGSTKSZ` (2048) bytes, and `exit(0)` when the function returns with no `uc_link`. The console's version is not verified
- [makecontext](../../../core/libs/prx/libSceLibcInternal/UserContext.cpp) (libSceLibcInternal) on Windows pins its stack writable until a later `makecontext` stack overlaps it, since nothing tells the library when the guest frees the stack
- [Thread exit destructors](../../../core/libs/prx/libSceLibcInternal/Export.cpp) (libSceLibcInternal) run when a libkernel thread finishes; on the main or a host thread only `_sceLibcInternalThreadDtors` runs them, as `exit` does, else they are dropped
- [__opendir2](../../../core/libs/prx/libSceLibcInternal/Directory.cpp) (libSceLibcInternal, NID `KOy7MeQ7OAU`) - opens the directory as `opendir` does and ignores `DTF_HIDEW`, `DTF_NODUP` and `DTF_REWIND`; any other flag throws. In FreeBSD 11's [`opendir.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/gen/opendir.c#L76-L95) `DTF_NODUP` only changes what is read from a union mount, which AnyPS5 does not have; `DTF_HIDEW` also makes [`readdir`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/gen/readdir.c#L85) skip whiteout (`DT_WHT`) entries, which AnyPS5 never returns; `DTF_REWIND` is not read; `__DTF_READALL` and `__DTF_SKIPREAD` make the call fail. The signature is the one ps5-payload-sdk [declares](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/include/freebsd/dirent.h#L89-L90); the SDK's `fts_build` in PPSA99793 passes 7, or 6 with `FTS_WHITEOUT`. The console's answer for any flag is not measured
- [__opendir2](../../../core/libs/prx/libSceLibcInternal/Directory.cpp) (libSceLibcInternal, NID `KOy7MeQ7OAU`) - the device's answer to any flag is not measured; the flags follow FreeBSD 11.4's [`__opendir2`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/libc/gen/opendir.c#L76-L95)
- [fdopendir](../../../core/libs/prx/libSceLibcInternal/Directory.cpp) (libSceLibcInternal) follows FreeBSD 11's [`fdopendir`](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/lib/libc/gen/opendir.c#L67-L74): it sets `FD_CLOEXEC` on the descriptor first, and the stream starts at the descriptor's current position instead of the first entry. On Windows the stream skips the entries the descriptor's cursor (`lseek` or `getdirentries`) has passed, which assumes that the descriptor and the stream list a directory in the same host order; on Linux the stream is opened on a duplicate of the descriptor, which shares its position. The Linux path is not run by the tests here. As in FreeBSD, a descriptor that is not open fails with `EBADF`, one that is not a directory with `ENOTDIR` (both leave it open, and `FD_CLOEXEC` stays set on the latter), and `closedir` closes it
- [fstatvfs](../../../core/libs/prx/libSceLibcInternal/FilesystemStatistics.cpp) (libSceLibcInternal) converts `_fstatfs` to the 88-byte `struct statvfs` as FreeBSD 9.2's `sfs2svfs` does (`f_bsize` from the transfer size, `f_frsize` from the block size, `f_favail` equal to `f_ffree`, `f_fsid` 0, `ST_RDONLY` and `ST_NOSUID` only). Differences: `f_namemax` is the `statfs` value, not `fpathconf(_PC_NAME_MAX)`; negative `f_bavail` and `f_ffree` wrap to unsigned without `EOVERFLOW`, as the same-width copy in FreeBSD does; inode counts are 0 on Windows, inherited from `_fstatfs`; a null output returns `EFAULT` after the descriptor is validated, where FreeBSD would fault. Layout and conversion are unverified against the PS5 library (PS5MC imports `fstatvfs` but was not run)
- [posix_spawn and posix_spawnp](../../../core/libs/prx/libSceLibcInternal/Spawn.cpp) (libSceLibcInternal) create a native child running the requested program's converted image, which must be under `/app0/` (`/app0/eboot.bin` maps to the running image); `posix_spawnp` searches `PATH` as FreeBSD 11's `_execvpe`, and the FreeBSD 11.4 file actions and attributes are applied to the child. A null `argv` returns `EFAULT`; a null `envp` inherits the parent environment; guest process IDs are the host's. Limits: the child executes the conversion made at relink time; Windows redirects only descriptors 0 to 2 and starts the child on the parent's std handles; Linux applies only `POSIX_SPAWN_RESETIDS` and `POSIX_SPAWN_SETPGROUP`, other flags or a nonzero set on Windows throw. The console sandbox's effect on child creation is unverified, and null or uninitialized objects, which FreeBSD dereferences, throw. PPSA99305 (Dusklight) reaches this when SDL looks for `zenity`
Expand Down
Loading