Commit Graph

1151 Commits

Author SHA1 Message Date
Stephen Miller
528a060709 Core: Memory code cleanup and further direct memory fixes (#3655)
* Remove mapped dmem type

Since physical addresses can be mapped multiple times, tracking mapped pages is not necessary.
This also allows me to significantly simplify the MapMemory physical address validation logic.

* Proper implementation for sceKernelMtypeprotect

I've rewritten SetDirectMemoryType to use virtual addresses instead of physical addresses, allowing it to be used in sceKernelMtypeprotect.

To accommodate this change, I've also moved address and size alignment out of MemoryManager::Protect

* Apply memory type in sceKernelMemoryPoolCommit

* Organization

Some potentially important missing mutexes, removed some unnecessary mutexes, moved some mutexes after early error returns, and updated copyright dates

* Iterator logic cleanup

Missing end check in ClampRangeSize, and adjusted VirtualQuery and DirectMemoryQuery.

* Clang

* Adjustments

* Properly account for behavior differences in MapDirectMemory2

Undid the changes to direct memory areas, added more robust logic for changing dma types, and fixed DirectMemoryQuery to return hardware-accurate direct memory information in cases where dmas split here, but not on real hardware.

I've also changed MapMemory's is_exec flag to a validate_dmem flag, used to handle alternate behavior in MapDirectMemory2. is_exec is now determined by the use of MemoryProt::CpuExec instead.

* Clang

* Add execute permissions to physical backing

Needed for executable mappings to work properly on Windows, fixes regression in RE2 with prior commit.

* Minor variable cleanup

* Update memory.h

* Prohibit direct memory mappings with exec protections

Did a quick hardware test to confirm, only seems to be prohibited for dmem mappings though.

* Update memory.cpp
2025-09-26 02:28:32 -07:00
georgemoralis
6e27842562 Trophy fixes IXXXX (#3653)
* fixing missing trophy files extraction

* implemented sceNpTrophyGetGameIcon

* adjustments

* improvements

* argg

* added assert

* done

* fixed compiling
2025-09-26 00:00:12 -07:00
Vinicius Rangel
71f343d2d6 Impl sceSystemServiceLoadExec (#3647)
* Add support for restarting the emulator with new configurations

- Implement `Restart` function in `Emulator` to enable process relaunch with updated parameters.
- Modify `sceSystemServiceLoadExec` to use the restart functionality.

* Add logging for emulator restart and system service load execution

* Add IPC emulator PID output command

Impl `PID` output command to return the emulator process ID
- required for launches supporting emulator restart

* Add log file append mode support (used after restarting to keep the same log file)

* Keep game root between restarts

* add --wait-for-debugger option flag

* add --wait-for-pid flag

used for sync between parent & child process during restart

* impl restart via ipc

* fix override game root

* add qt flags to allow restart
2025-09-25 23:01:52 -03:00
Marcin Mikołajczyk
a6f5e4c7dc net: silence some epoll logs (#3654) 2025-09-25 12:41:31 -07:00
Stephen Miller
98ceb6e43e Allow overlapping direct memory mappings (#3648)
Real hardware allows this, and it worked fine in the past, so allow it here.
2025-09-24 19:22:48 +03:00
Stephen Miller
eeee6ad0ee Memory: Implement sceKernelMemoryPoolGetBlockStats (#3646)
* Implement sceKernelMemoryPoolGetBlockStats

Not entirely sure on the logic behind the cached blocks work, but flushed blocks seems to just be based on committed direct memory.

* Fix comment
2025-09-24 02:40:26 -07:00
Stephen Miller
5d8027f0c0 Core: Refactor direct memory handling (#3645)
* Refactor direct memory areas

At this point, swapping the multiple booleans for an enum is cleaner, and makes it easier to track the state of a direct memory area.

I've also sped up the logic for mapping direct memory by checking for out-of-bounds physical addresses before looping, and made the logic more solid using my dma type logic.

* Fix PoolCommit assert

Windows devices will throw an access violation if we don't check for iterator reaching end.
2025-09-23 22:42:15 +03:00
Vladislav Mikhalin
1eead6a5ee avplayer: fix play request state handling (#3644) 2025-09-23 21:17:48 +03:00
Stephen Miller
419ea140ab Core: physical backing for flexible and pooled memory allocations (#3639)
* Fix isDevKit

Previously, isDevKit could increase the physical memory used above the length we reserve in the backing file.

* Physical backing for flexible allocations

I took the simple approach here, creating a separate map for flexible allocations and pretty much just copying over the logic used in the direct memory map.

* Various fixups

* Fix mistake #1

* Assert + clang

* Fix 2

* Clang

* Fix CanMergeWith

Validate physical base for flexible mappings

* Clang

* Physical backing for pooled memory

* Allow VMA splitting in NameVirtualRange

This should be safe, since with the changes in this PR, the only issues that come from discrepancies between address space and vma_map are issues related to vmas being larger than address space mappings. NameVirtualRange will only ever shrink VMAs by naming part of one.

* Fix

* Fix NameVirtualRange

* Revert NameVirtualRange changes

Seems like it doesn't play nice for Windows

* Clean up isDevKit logic

We already log both isNeo and isDevKit in Emulator::Run, so the additional logging in MemoryManager::SetupMemoryRegions isn't really necessary.

I've also added a separate constant for non-pro devkit memory, as suggested.

Finally I've changed a couple constants to use the ORBIS prefix we generally follow here, instead of the SCE prefix.

* Erase flexible memory contents from physical memory on unmap

Flexible memory should not be preserved on unmap, so erase flexible contents from the physical backing when unmapping.

* Expand flexible memory map

Some games will end up fragmenting the physical backing space used for flexible memory. To reduce the frequency of this happening under normal circumstances, allocate the entirety of the remaining physical backing to the flexible memory map.

This is effectively a workaround to the problem, but at the moment I think this should suffice.

* Clang
2025-09-23 17:24:37 +03:00
Marcin Mikołajczyk
976d12f4e6 Epolls are file descriptors (#3622)
* net: Register epolls in file descriptor table

* fstat: stub epoll, resolver

* Fake async hostname resolution

* net: epoll fixes

* epoll: actually close the file descriptor
2025-09-22 22:57:51 +03:00
Vladislav Mikhalin
50a3081084 ajm: handle ParseRiffHeader flag (#3618)
* ajm: handle ParseRiffheader flag

* small optimizations and cleanup

* allow uninitialized instances handle RIFF

* fixed audio cutoff and small refactoring

* small fix to the returned data

* fix gapless init, reset total samples on RIFF init

* warning reporting + consume input buffer on gapless loop
2025-09-22 18:50:57 +03:00
Vladislav Mikhalin
525d24a7fc avplayer: do not start the video multiple times (#3638) 2025-09-21 16:03:24 +03:00
Missake212
51c96b8ee6 Lower "Trophy key is not specified" message from critical to info (#3636) 2025-09-20 12:47:46 -07:00
Vladislav Mikhalin
2b1c0b4f82 avplayer: implemented AddSourceEx, SetAvSyncMode, Pause and Resume (#2456)
* avplayer: code improvements

* avplayer: implemented pause/resume

* avplayer: implemented sync modes

* avplayer: issue warning on loopback

* avplayer: sync on video ts in default mode when audio ts is not available

* avplayer: removed waits for the frame in Get*Data, replaced cv with sleep

* avplayer: removed all waits from GetVideoData

* avplayer: fix warning propagation + small fixes

* Using texture memory for video frames, dropped video frame cache, syncing audio to video

* do not sync to audio when audio is not enabled

* removed logs, fixed sync

* reverted the removal of pre-allocated buffers
2025-09-20 19:27:16 +03:00
squidbus
be80276ec3 Fix Pthread memset warning and add comment. (#3625) 2025-09-19 02:17:30 -07:00
Marcin Mikołajczyk
7bd3eb485f Epoll (#3476)
* Epoll

* Change companion util stub to return NO_EVENT

* Revert "Change companion util stub to return NO_EVENT"

This reverts commit 8dd9913cda39b641cd3b65925e1f31fa713e8a24.

* added wepoll

* shallow..

* dist branch

* updated wepoll

* compiles on windows

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
2025-09-18 11:53:04 +03:00
nickci2002
0d09c32df9 Ds4 Speaker Audio Rebase Fix (#3607)
* Logic update, no QT ui

* Fixing errors

* Gui boxes

* fixes

* prevent device list refreshing too fast when game not running

* Removed duplicate Socket declarations in kernel/file_system.cpp and fs.h

* Fixed clang-format and micDevice errors

* Ran clang-format and fixed rebase compiler issues

* Settings dialog fix

* Addressed squidbus' concerns

* Update config.cpp to adhere to clang-format

* Removed a space causing clang-format to complain

* Addressed squidbus' concerns and added fallbacks

Concerns:
- Changed dev_name construct to remove unnecessary cast
- Added an invalid AudioDeviceID macro to replace magic number

---------

Co-authored-by: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com>
2025-09-18 08:28:12 +03:00
Gabriel
7101caa80b Fix: Extend strlcpy implementation to Linux builds (#3616)
* Fix: Add libbsd dependency for Linux builds

Adds conditional libbsd support to resolve strlcpy undefined reference
on Linux systems. Includes proper CMake detection and header includes.

* Fix: Use internal strlcpy implementation for Linux

- Extend existing Windows strlcpy implementation to Linux
- Remove libbsd dependency from CMakeLists.txt
- Resolves undefined reference to strlcpy on glibc systems

Uses the project's existing approach instead of adding external dependencies.
2025-09-17 20:45:28 -07:00
Marcin Mikołajczyk
6ab7aa3b18 Open a dummy audio input device if none is present in the system (#3514) 2025-09-17 12:50:47 -07:00
Stephen Miller
775d27c0cd Core: Log error on MapMemory out of flexible memory case (#3614)
* Log error for out-of-flexible-memory error case in MapMemory

Should reduce confusion when looking as some logs.

* Clang
2025-09-17 21:58:48 +03:00
squidbus
fb090dc90f kernel: More thread code clean-up. (#3599) 2025-09-14 02:22:13 -07:00
squidbus
21a1888857 build: Fix a couple more warnings. (#3598) 2025-09-13 15:33:42 -07:00
squidbus
321fa34892 kernel: Improvements to condvars. (#3592) 2025-09-13 08:41:26 -07:00
squidbus
dc6bfbeb12 build: Fix a few warnings (#3581) 2025-09-12 09:31:59 -07:00
squidbus
de7652384d video_core: Upload buffer memory around unmapped pages (#3580) 2025-09-12 18:23:00 +03:00
kalaposfos13
f3e344dfcf Add missing ioctl export (#3579) 2025-09-12 00:44:02 -07:00
Missake212
b132739014 sceVideoOutSetWindowModeMargins Stub (#3578) 2025-09-11 21:08:38 -07:00
Stephen Miller
99d0f85739 libkernel: Reduce log spam (#3569)
* Fix address formatting for invalid address asserts

* Reduce event flag message to trace

This log effectively contributes nothing to debugging.

* Remove excess logging in sceKernelBatchMap

Every one of these opcodes will just log from their individual function calls anyway, and if there were issues with batch map logic, we would've known for a while now.

* Log error return during sceKernelBatchMap

May help with debugging some unstable UE games?
2025-09-10 17:38:56 -07:00
Stephen Miller
35d3d4f763 Core: Fix MXCSR and FPUCW registers on created threads (#3568)
* Use _mm_setcsr over assembly

Exists on all platforms, so might as well use it.

* Clang

* Missing include

* Unconditionally set FPUCW

As per review suggestions.

* Fix FPUCW and MXCSR registers on Windows

For some reason only Microsoft knows, settings these values in the context doesn't work.
Also their controlfp functions don't seem to work either, so I used assembly instead.

* Set MXCSR on all platforms

All three platforms use the same default MXCSR register value. Use an assembly instruction to set this for all platforms.
2025-09-10 14:32:05 -07:00
zf06gaius
2c4f573d3a Simple implementation of sceGnmUnmapComputeQueue in gnmdriver (#3565) 2025-09-10 11:03:49 -07:00
kalaposfos13
4abc6b3010 Implement getargc and getargv (#3562)
* Implement getargc and getargv

* update copyright year

* the loathsome clang-formatter
2025-09-09 14:58:22 -07:00
Fire Cube
c05695fde5 extend IPC functionalities (#3545)
* extend IPC

* clang

* clang
2025-09-09 14:57:42 -07:00
squidbus
ac318b56ac equeue: Few fixes for sceKernelWaitEqueue (#3548) 2025-09-08 19:47:12 -07:00
Stephen Miller
f4531fd927 Core: Remove checks for symbol version_major and version_minor (#3540)
* Remove checks for module version_major and version_minor

Following this rule broke linking for some libraries, and introduced extra effort needed to get some homebrew running.

* Clang

* Fix rebase

* Disable libSceSsl HLE

Real hardware uses a title workaround to determine if base libSceSsl is needed. Currently, this title workaround applies to absolutely nothing.
2025-09-08 19:30:03 -07:00
Stephen Miller
707fe9faff Core: Improve memory address validation logic (#3556)
Somehow I missed that we already had a IsValidAddress function that could be used for ensuring addresses is inside vma map (for non Mac platforms at least). This PR swaps my Contains(addr) checks for calls to IsValidAddress.

This should help with some weird inconsistent memory asserts and exceptions caused by inconsistent iterator behavior on Windows devices.
2025-09-08 19:25:41 -07:00
Stephen Miller
133f4b9187 Core: ClampRangeSize fixes (#3555)
* Swap !IsFree() for IsMapped()

IsFree only checks if the VMAType == Free. As is, that means ClampRangeSize will include memory that is Reserved or PoolReserved, and neither of those types are GPU mapped.

This fixes this bug, may help with some non-GPU memory asserts.

* Apply ClampRangeSize to vertex buffers

Helps with some cases encountered by UE and Minecraft.
2025-09-07 20:27:40 -07:00
squidbus
ce6681b991 externals: Update libusb to fix more ABI issues. (#3551) 2025-09-07 14:39:16 -07:00
Stephen Miller
b5d8426db7 Libraries: Implement sceKernelIsInSandbox, update OrbisSysModule enum (#3546)
* Implement sceKernelIsInSandbox

libSceSysmodule uses this to determine if it should use sceKernelGetFsSandboxRandomWord or just hardcode "system" for retrieving modules.
Also changes some function types to use our types.

* Update OrbisSysModule enum

Adds missing values based on library testing.

* Clang
2025-09-07 13:11:15 -07:00
georgemoralis
d34ae8ce08 Net Fixes (#3468)
* Fix handling of ORBIS_NET_SO_ONESBCAST to support proper broadcast address translation on send.
    Fix setsockopt for SO_(RCV/SND)TIMEO on Windows/Linux.

* fixed suggestion

* fixes
2025-09-07 18:02:02 +03:00
UltraDaCat
5e3ffeafbe Replace Vblank Divider with Vblank Frequency (#3532) 2025-09-06 15:00:26 -07:00
Stephen Miller
0e7e100a7e Libraries: Np libraries cleanup (#3535)
* Np library cleanup

Moved all Np libraries to a Np folder, created files for Np error codes and structs shared between the libraries, removed empty auto-generated stubs from NpCommon and NpManager, and more things of that nature.

Also implemented sceNpGetAccountCountry, since we already had sceNpGetAccountCountryA anyway.

* Cleanup NpManager signed_out checks

The PR that introduced the PSN signed in status reverted some of the changes I'd previously made to improve accuracy.
Also they missed sceNpHasSignedUp, which just uses an internal variant of sceNpGetState for it's own check.

* Copyright dates

* Move signin check to NpManager RegisterLib

Hardcoding it the way I did caused it to read signin status before config was read.

* Fix RegisterLib names

Not sure why these weren't adjusted yet, so I've adjusted them myself.

* Fix NpCommon exports

* Basic parameter validation in sceNpDeleteRequest and sceNpCreateRequest

* More thorough request logic

Created an enum to capture the current state of each request, using a vector to store them.
I've made 3 states, none represents deleted requests, active represents requests that were made, but haven't been used yet, and complete represents used requests (a request cannot be used for multiple functions).

* Functions

sceNpCheckAvailability, sceNpCheckAvailabilityA, sceNpCheckNpReachability, sceNpGetAccountDateOfBirth, sceNpGetAccountDateOfBirthA added.

* sceNpGetAccountLanguage, sceNpGetAccountLanguageA

* sceNpGetGamePresenceStatus, sceNpGetGamePresenceStatusA

Also reduced debug logging for functions with early signed out returns, since those should behave identically to real hardware so long as you keep PSN emulation disabled.

* Fix sceNpGetAccountLanguage parameters

Oops

* sceNpGetNpReachabilityState

* sceNpGetParentalControlInfo, sceNpGetParentalControlInfoA

* Move OrbisNpState back to np_manager.h

Until this sees use elsewhere, this doesn't need to be with np-wide things.

* Clang
2025-09-06 14:32:22 -07:00
kalaposfos13
72e00e5d91 Add missing export (#3538) 2025-09-06 22:10:59 +03:00
Marcin Mikołajczyk
90f6bf0516 AF_UNIX preliminary support (#3506)
* AF_UNIX preliminary support

* fixed windows

* added windows implemenation for socketpair

* More gotos

* added sys_socketpair for libkernel_ps2emu

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
2025-09-06 19:49:21 +03:00
Marcin Mikołajczyk
53181b005c Handle null event flags in cancel and clear (#3530) 2025-09-06 00:05:43 +03:00
squidbus
43b72b59a2 rtc: Fix date parsing detection. (#3524) 2025-09-05 06:50:54 -07:00
georgemoralis
e06667d307 SaveData fixes IXXXXXX (#3511)
* fixed possible savepath issue

* one more fix
2025-09-04 15:16:50 -03:00
kalaposfos13
bcbe07e6b1 Hotkey config changes (#3391)
* This works, but it's missing some hotkeys and the GUI isn't hooked up to anything now

* More hotkeys

* Remove debug log

* clang

* accidentally used the wrong value here

* gui changes for new backend (#10)

* gui changes for new backend

* fix lmeta

* don't erase non-hotkey lines

* do not erase hotkey configs in kbm or controller guis

* Fix repeated inputs

* Documentation

---------

Co-authored-by: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com>
2025-09-04 20:47:06 +03:00
rainmakerv2
77b1d11796 Qt: Add FSR options to settings GUI (#3504)
* Qt: Add FSR settings to settings GUI

* Move FSR settings from Imgui.ini to main config

* move passing fsr settings to presenter constuctor

* cleanup: use struct instead of function call

* cleanup: make variable names consistent with others

* Update fsr settings real-time in qt, save button in Imgui

* Linux build fix, missing running game check

* syntax fix

* Change gamerunning checks to if (presenter)
2025-09-02 12:03:33 -07:00
Stephen Miller
bcea7a02c3 Return EINVAL if mmap is called with length 0 (#3496)
Hit by some multimedia apps
2025-08-31 16:14:51 -07:00
Marcin Mikołajczyk
be8c35eef1 Implement send/recvmsg (#3487)
* Implement send/recvmsg

* Windows

* fixed windows

* cleanups

* updated

* suggestions

---------

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
2025-09-01 01:02:26 +03:00