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
6 changes: 5 additions & 1 deletion core/libs/prx/libkernel/File/src/Open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ static int NativeOpen(const std::filesystem::path& p, int nativeFlags, std::uint
}
static std::int64_t NativeLseek(int fd, std::int64_t offset, int whence) {
const auto result = File::SeekSharedMemory_nid_no_patch(fd, offset, whence);
return result == -2 ? ::_lseeki64(fd, offset, whence) : result;
if (result != -2) return result;
const auto position = ::_lseeki64(fd, offset, whence);
if (position < 0 || GetFileType(reinterpret_cast<HANDLE>(::_get_osfhandle(fd))) != FILE_TYPE_PIPE) return position;
errno = ESPIPE;
return -1;
}
static int NativeRead(int fd, void* buf, std::size_t n) {
if (n > static_cast<std::size_t>(std::numeric_limits<unsigned int>::max())) {
Expand Down
15 changes: 15 additions & 0 deletions core/libs/tests/GuestFilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ FileStream* APS5_VABI freopen_nid_postfix(const char*, const char*, FileStream*)
int* APS5_VABI __error_nid_postfix();
int APS5_VABI pipe_nid_postfix(int*);
int APS5_VABI dup2_nid_postfix(int, int);
std::int64_t APS5_VABI lseek_nid_postfix(int, std::int64_t, int);
std::int64_t APS5_VABI read_nid_postfix(int, void*, std::size_t);
std::int64_t APS5_VABI write_nid_postfix(int, const void*, std::size_t);
int APS5_VABI sceKernelDebugOutText(int, const char*);
Expand Down Expand Up @@ -217,6 +218,20 @@ int main() {
Require(read_nid_postfix(descriptors[0], received, sizeof(received)) == sizeof(received));
Require(std::memcmp(received, payload, sizeof(payload)) == 0);
Require(read_nid_postfix(descriptors[0], received, sizeof(received)) == 0);
{
int unseekable[2] = {-1, -1};
Require(pipe_nid_postfix(unseekable) == 0 && write_nid_postfix(unseekable[1], "pipe", 4) == 4);
for (const int end : unseekable) {
for (int whence = 0; whence < 3; ++whence) {
Require(lseek_nid_postfix(end, 0, whence) == -1 && *__error_nid_postfix() == 29);
Require(sceKernelLseek(end, 1, whence) == static_cast<int>(0x8002001du));
}
}
char piped[8]{};
Require(read_nid_postfix(unseekable[0], piped, sizeof(piped)) == 4 && std::memcmp(piped, "pipe", 4) == 0);
Require(close_nid_postfix(unseekable[0]) == 0 && close_nid_postfix(unseekable[1]) == 0);
Require(lseek_nid_postfix(unseekable[0], 0, 1) == -1 && *__error_nid_postfix() == 9);
}
{
std::filesystem::remove("creat_probe.bin");
int created = creat_nid_postfix("creat_probe.bin", 0644);
Expand Down
Loading