* Fix module map addresses
Most modules are mapped starting at 0x800000000, with no gaps between mappings.
* Hardcode hardware accurate base address
Looking at our address space, all platforms will have this base address mapped, so there shouldn't be any problem in using it.
* Clang
* Swap module mapping to NoFlags, remove offset code
Since real hardware has no gap between module mappings, the Fixed flag is just an annoyance to work around, and has no impact on the actual mappings.
Swapping the module mappings to use flags NoFlags instead simplifies our code slightly.
* Fix module mapping names
On real hardware, the file extension is part of the mapping name. Easiest way to manage this is to swap the name to be `file.filename().string()` instead of `file.stem().string()`
* Fix patches
Completely missed this, whoops.
* Proper handling of whence 3 & 4
* Accurate directory handling in open
Directories can be opened, and can be created in open, these changes should handle that more accurately.
* Mount /app0 as read only
On real hardware, it's read only.
* Proper directory flag handling.
Even when directory is specified, it will still succeed to open non-directories.
* Check for read only directories
* Earlier ro check in posix_rmdir
Hardware tests suggest these checks are in a different order
* Clear temp folder on boot
My tests rely on this, and some games do too.
Two birds with one stone
* Clang
* Add missing DeleteHandle calls
Whoops
* Final flags adjustment in sceKernelOpen
All my current tests are now hardware accurate.
* Fix truncates
Host ftruncate consistently fails on EINVAL, I'll need to test if this issue affected Windows too.
* Windows hacks
Windows is more limiting about how folders are opened and things like that. For now, pretend these calls didn't error.
Also fixes compilation for Windows
* Final touch-ups
After expanding my test suite further, I found a couple more edge cases that needed addressing.
Bloodborne audio is still broken, I'll look into that soon.
* Remove hacky read-only behavior in posix_stat
Bloodborne apparently uses the mode parameter here when querying it's audio files, and the mode we returned led to it disabling audio entirely.
* Clang
* Cleaner code
* Combine fsync and sync flags
According to FreeBSD docs, the "sync" flag is synonymous with the fsync flag, and is only included to meet the POSIX spec.
* Log if any currently unhandled flags are encountered.
These are rare and probably not too important, but log a warning when they're seen.
* Update file_system.cpp
* Update file_system.cpp
* Clang
* Revert truncate fix
Using ftruncate works fine after moving the call to before the proper file opening code.
* Truncate before open
Open the file as read-write, then try truncating.
This fixes read | truncate flag behavior on Windows.
* Slightly adjust check for invalid flags
Any open call with invalid flags should return EINVAL, regardless of other errors parameters might cause.
* Fix GetModule exception
Simple mistake
* Prevent OOB writes in add_segment
Due to mistakes in our linker logic, OpenOrbis' libSceFios2 causes OOB writes here.
While the ideal solution would be to fix the erroneous behavior, the best I'm capable of right now is just preventing the OOB writes.
* Implement sceKernelGetModuleInfo, sceKernelGetModuleInfoInternal, sceKernelGetModuleList
These are implemented based on hardware observations and a homebrew sample made by red_prig. I've yet to test what error cases can show up.
* Clang
* Accurate error returns
If there are more modules than provided space, then return kernel ENOMEM.
If either handles or out_count are null, return kernel EFAULT.
* Accurate error checks in ModuleInfo functions
* Clang
* Readable VideoOutEvent data packing
Inspired by the work of former shadPS4 devs and mostly based on red_prig's current code.
* Apply DceData struct to sceVideoOutGetEventCount
Makes the code easier to read
* Update equeue.h
* Update main.cpp
* Update equeue.h
* Proper struct names
* Fix hint mask
Thanks to red_prig for catching my mistake here.
* Clang
* Fix header discrepancy
* Some sysmodules inconsistencies fixed. Based on Visual studio flags if they are irrelevant lmk
* Suggestions - info passed to sceKernelGetModuleInfoForUnwind and if name field matches it gets zeroed
* Final suggestions
* reverting OrbisModuleInfoForUnwind and modifing header.
* Implement sceImeDialogGetPanelSize
* Fix header
* Clang
* Adjust values that are different from Ime
* Add original sizes as comments
* clang
* At this point half of the PR is from squidbus, and I'm just typing out what they say
---------
Co-authored-by: squidbus <175574877+squidbus@users.noreply.github.com>
* Update memory.cpp
* Clean logic
FindDmemArea guarantees that the first dmem area we check contains search_start. Any dmem areas beyond the first one will be entirely past search_start, so checking against it in the loop is unnecessary.
Under normal circumstances, this mapping should only occur when libSceGnmDriver initializes. From what I can tell, this can be after game code starts running. Until there's a better way to accurately handle this, allocating this memory breaks some games.
This revert fixes the regression in games using the GFD engine.
* Add the NpAuth library
* clang
* you didn't see anything
* Add some random return to make games at least start using this library
* i'm once again asking for your continued ignorance of what i'm forgetting to not push
* debug logging
* apparently just this is still enough
* this isn't used but it still shouldn't be incorrect
* Emulate memory behavior of libSceGnmDriver _DT_INIT
Due to the unique way some games check for sceKernelAllocateDirectMemory failures, emulating this properly is necessary.
* Clang
* Fix address input for direct memory call
* Fix bug with DirectQueryAvailable
Missed this in my prior PR.
* DirectQueryAvailable fix
Fixes error cases to be more hardware accurate.
* AllocateDirectMemory fixes
search_start and search_end were ignored in certain cases, this fixes that issue.
I've also basically rewritten the function in the process, since the lack of documentation made it difficult to make the proper adjustments.
* DirectQueryAvailable fixes
remaining_size was calculated incorrectly in cases where a free dmem_area had a base earlier than search_start, or an end after search_end.
* Reduce sceKernelGetDirectMemorySize log severity
By this point, we've confirmed that sceKernelGetDirectMemorySize is hardware-accurate. There's no reason to clog logs with this function, which games usually call before every sceKernelAllocateDirectMemory call.
* Clang
* Fix phys_addr_out
phys_addr_out should be equal to search_start in cases where search_start is greater than the dmem_area base.
* Dividing by zero is fun
Need to check for alignment when aligning things.
* Update memory.cpp
* Clang
* Implement sceVideoOutDeleteVblankEvent
* Implement sceVideoOutGetEventCount
Based on decompilation, needs testing.
I also tidied up some types for other functions in here.
* Change hexadecimal numbers to lowercase
A minor change to make sure my implementation follows the formatting standards seen in https://github.com/shadps4-emu/shadPS4/pull/2423
* cpu_patches: Remove CPU patches for macOS and bump minimum OS version to 15.4
* cpu_patches: Remove BMI1 patches
These are now only good for very old Intel CPUs that:
* Still do not currently function due to other CPU instruction issues.
* Will probably be too slow to run shadPS4 well.
* Fix sceNgs2SystemCreateWithAllocator
The cause of the exceptions without libraries.
* Remove error handling for unimplemented functions
Since nothing exists to create any VoiceHandle or RackHandle, we were consistently hitting those error returns.
Also promotes logs for stubbed functions back to LOG_ERROR, with the exception of two functions that get spammed pretty frequently.
* Use Core::ExecuteGuest to execute allocator alloc and free
* Clang
* Fix function definitions in ngs2.h
These should be using the SYSV ABI
* Fix function defs in ngs2_impl.h
This will (hopefully) fix compilation
* Clang
* Clang
again
* usbd: Implement libusb passthrough
* clang-format
* only do kernel activities on non-windows
* use variable to represent "fake" windows kernel driver
---------
Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
* sceKernelDebugOutText
Some homebrew use this for logging, and these logs do show up in console klogs.
I wasn't sure where the most suitable place for this function would be, so I made a separate file for these debug functions.
* Implement kernel exit
Some homebrew I have use this exit when an error occurs. Since actually closing the emulator isn't implemented yet, I've used an unreachable message that logs the status code.
I've placed it in process.cpp for now, let me know if I should change that.
* Improved implementations for sceKernelDebugRaiseException functions
These functions take in two parameters, an error code and some other value that I have no idea what is for. If that second parameter is not zero, they return ORBIS_KERNEL_ERROR_EINVAL before any calls to mdbg_service.
These improved implementations add the early error return and a message with the error code to the unreachable.
* Add missing exports
Homebrew apps like to use these kernel exports of posix functions instead.
* Clang
* Adding names to gui buttoms and adjusting spacing.
* moving refresh button to last slot.
* Changing the implementation to tooltips for hover over them - qstring to detect background color.
* Fixing some themes with inverted tooltip base
* Suggestions / Fixes - Pause and FullScreen Buttons
* Update REUSE.toml
* cleaning up
* Icons stuff
* clang
* Buttons toggle - Cleaning code - Fixing Icons
* cleaning boolean
* Toggle pause and play icons and label to "Resume" when paused.
* Simplifying the toggles.
* New icons and final Push to review
* Reuse
* Icon rename, adding f9 press for pause game when no gui is on without needed of debug menu
* clang + reuse
* clang dosent work on this part
* again Clang
* Last fix for review. Light theme white resume icon fix.
* Proper fix for Resume icon
* New Rebase
* Fixed Orientation with docking issues and cleaning boxlayout code
* Adding spacer to separate actions, sizeslider on top of search bar. And adding margins
* Fixed Background not showing on OLED Theme
* Fixing check marks
* Adding all Daniel Suggestions and fixed F9 not working with debug menu open.
* Clang
* reverting all OLED theme changes
* Final suggestions
* sceKernelOpen: Clean up flag handling
* sceKernelOpen: fix params
Based on decompilation, the second parameter of _open should be flags.
Additionally swaps the return and parameter types to align with our current standards.
* sceKernelOpen: Fix errors
Based on POSIX spec, if part of the path is missing, ENOENT is the correct return.
Additionally, decompilation suggests that open sets errno too.
* Fix exports
Fixes function exports to align with what they should be, based on what I've seen from decompilation and our module generator.
* Proper errno behavior on open
Since sceKernelOpen calls posix_open, errno should be set during this process.
Simplest way to handle that is to move the actual open code to posix_open and adjust error cases accordingly.
* Reorganize open calls, add error log
* Improve close
Removes the EPERM return, as it makes no sense, and swaps sceKernelClose with posix_close to properly emulate errno behavior.
* Fix log on close
* posix_open fixups
* Readd hack in posix_close
It's either this, or removing LLE DiscMap.
Or shadow implements posix sockets.
* Missing exports
Commented out while I gradually work through them all
* Remaining placeholder exports
* Swap some stuff around
I see nothing that suggests "open" only takes two parameters, so this should be completely safe.
It's also more accurate to how these are handled in libkernel, and means I won't need to reorganize anything for readv and writev.
* Update file_system.cpp
* Implement write and posix_write
* Oops
* Implement posix_readv and sceKernelReadv
Also fixes error behavior on readv, as that function shouldn't be returning any kernel error codes.
* Move sceKernelUnlink
Will deal with this one later, was just annoyed by how it's location doesn't align with the export order.
* Cleanup readv
* Implement posix_writev and sceKernelWritev
Also fixes error behavior on writev, since it shouldn't ever return kernel errors (since our device files return those)
* More cleanup on older functions
* Swap around sceKernelLseek and posix_lseek
This ensures that these have the correct error behavior, and makes their behavior align with the updated implementations for earlier functions.
* Update file_system.cpp
* Implement read
Also fixes error behavior
* Swap sceKernelMkdir and posix_mkdir
Fixes errno behavior on kernel calls, also fixed some incorrect error returns.
* Fix errno behavior on sceKernelRmdir
Also reduces function logging to bring it closer to the level of logging seen in other filesystem functions.
* Slight clean up of sceKernelStat
Fixes error behavior and changes some of the old data types.
* Refactor fstat
Fixes errno behavior, implements fstat, and shifts exports around based on file position.
Might reorganize function locations later though.
* Implement posix_ftruncate
Implements posix_ftruncate and fixes errno behavior for sceKernelFtruncate
* Add missing error conversions for more device functions
* Implement posix_rename, fix sceKernelRename errno behavior
* Add posix_preadv and posix_pread
Also fixes some incorrect error returns, fixes errno behavior, and removes an unnecessary hack.
* Fix compile
* Implement posix_getdents, getdirentries, and posix_getdirentries
Also fixes errno behavior for the kernel variants of these functions.
* Fix errno behavior of sceKernelFsync
* Implement posix_pwrite and posix_unlink
Also fixes errno behavior in related functions.
* Update file_system.cpp
* Remove SetPosixErrno
Ideally, we've handled all possible error conditions before calling these functions, so treat errors in platform-specific code as IO errors and return POSIX_EIO instead.
* Update header exports
Not sure where these get used, but might as well keep them consistent with the rest of this.
* Check if file exists before calling platform-specific code
Bloodborne checks if a file doesn't exist using open, checking if it specifically failed with error code ENOENT. To avoid working with platform-specific errnos, add a proper error return for if the file doesn't exist.
Fixes a regression in Bloodborne.
* Clang
Out of all the changes, this is apparently the only thing Clang-Format doesn't like.
I'm honestly surprised.
* Improve error checks on posix_unlink
Just because a file isn't opened doesn't mean the file doesn't exist.
Fixes the error returned if host_path.empty(), and removes the error return for when GetFile fails.
* Fix the Bloodborne fix
* Limit exports to tested functions
* More confirmed working exports
* Remaining stuff my games can test
* FS exports from firmware tests
* Bring back missing exports from main
I don't have any bootable things that call these, but since they were working well enough on main, they should be fine to readd.
* Add export for posix_pread
Spotted in Dreams a while back, might as well add it.
* Revert "Remove SetPosixErrno"
This reverts commit bdfc0c246c.
* Revert SetPosixErrno changes
shadow's using it for posix sockets, so significant modifications would introduce unnecessary merge conflicts.
* Update comment
* Add EACCES errno to SetPosixErrno
Seen in Gravity Rush.
Also reorganizes the switch case based on the posix errno value, since ordering by errno makes no sense on some OSes.
* More export fixups
Missed these during my initial pass through FS stuff because they were in kernel.cpp for some reason.
* Symbols from FS tests
Tested by messing around with firmware elfs, these atleast don't cause any crashes.
* Remove inaccurate error behavior
Seek can have offsets past the end of a file.
Also add logging for two valid whence values that are unsupported on Windows.
I'll need to verify that SEEK_HOLE and SEEK_DATA correspond to 3 and 4 respectively, I've yet to check source to verify.
* Fix error log
Oops
* Clang
Clang
* Remove close hack
Since LLE libSceDiscMap is no longer a concern, this hack shouldn't be needed.
Since sockets are still stubbed, and close can be used on sockets, I've added a warning log just in case this still occurs in some titles.
* Change SetPosixErrno unreachable to warning
I changed it to an unreachable in an earlier commit to make testing easier.
At this point, having an unreachable for this seems unnecessary, so change it to a warning instead.
* Remove Bloodborne hack
Games should be able to unlink files that aren't opened file descriptors. As far as I've tested, this doesn't break Bloodborne.
* Using OrbisKernelTimespec under clock_gettime, orbis_clock_gettime, sceKernelClockGettime to fix compatibility issues.
* final fix test
* Roamic suggestions
* rewrite splash
removed Splash class
rewrite using imgui texture manager
fix crashes & old validation error
* handle games with abnormal aspect ratios
* Export sceVideoOutGetBufferLabelAddress
It's an exported function, used by red_prig's BLACKSQUAR2 homebrew sample.
This also fixes the function's return type accordingly.
* More sceVideoOutGetBufferLabelAddress fixups
Library decomp shows a hardcoded return 16 on success. Not sure why it does that, but it never hurts to be accurate.
Also needs to have an openOrbis-specific export to get it to work with the homebrew sample I'm testing.
* Final fixups
Removed the port assert and added asserts in libSceGnmDriver for when sceVideoOutGetBufferLabelAddress calls fail.
* host_shaders: support for includes
* video_core: add a simpler vulkan asserts
* video_core: refactored post processing pipeline to another file
* renderer_vulkan: add define param to compile shader utility
* video_core: fsr implementation
* devtools: show resolution & fsr state
* Fix error return on sceKernelMunmap
FreeBSD docs state that len <= 0 is a EINVAL return.
* Early return on ReleaseDirectMemory with len = 0
Calls to these two functions with len = 0 cause an assert in CarveDmemArea. Since there's no memory to release, an early return should be safe here.
* Remove check for negative length in munmap
Addresses review comment