Commit Graph

4777 Commits

Author SHA1 Message Date
Zephyron 384a18927b
service/friend: Clean up friend service implementation
- Remove unused function stubs
- Improve GetCompletionEvent implementation
- Clean up response builder naming
2025-02-09 11:40:46 +10:00
Zephyron 76716b5248
service/audio: Clean up audio controller implementation
- Remove Unknown5000 function and related debug commands
- Fix incorrect service name in log message
2025-02-09 11:39:16 +10:00
Zephyron 6917a22a2c
service/acc: Clean up account service implementation
- Remove unused function stubs
- Add version information comments
- Add clang-format markers
- Remove duplicate TrySelectUserWithoutInteraction function
- Fix formatting and code style
2025-02-09 11:36:58 +10:00
Zephyron d783806b1e
service/friend: implement additional friend service functions
- Add implementations for previously stubbed functions:
  * Cancel - Handle operation cancellation
  * RequestSyncFriendList - Friend list synchronization
  * GetUserPresenceView - User presence information
  * LoadUserSetting - User settings loading
- Improve GetCompletionEvent implementation:
  * Add proper event signaling
  * Use clearer variable names
  * Improve debug logging
- Enhance logging messages:
  * Add more descriptive debug messages
  * Include user ID in presence view logging
  * Use consistent naming in response builders
- Fix response builder formatting for consistency

These changes improve the friend service implementation by adding
support for more friend-related functionality while enhancing
the debugging experience through better logging and code
organization.
2025-02-08 20:39:47 +10:00
Zephyron 268d322d7f
service/audio: implement Unknown5000 and add debug commands
- Add Unknown5000 implementation to create duplicate controller interface
- Add new debug-related command handlers:
  * OverrideDefaultTargetForDebug (50001)
  * SetForceOverrideExternalDeviceNameForDebug (50003)
  * ClearForceOverrideExternalDeviceNameForDebug (50004)
- Add proper debug logging for interface creation
- Update header with new function declaration
- Fix missing commas in function registration array

These changes improve the audio controller implementation by
adding support for interface duplication and debug override
functionality. The implementation maintains proper interface
lifetime management using SharedFrom.
2025-02-08 20:35:38 +10:00
Zephyron 92b70b31e0
service/nim: implement CreateServerInterface2 and improve logging
- Add CreateServerInterface2 implementation for NIM_ECA service
- Change log level from WARNING to DEBUG for CreateServerInterface
- Add descriptive log message for server interface creation
- Maintain consistent interface creation pattern between both versions
- Fix missing comma in function registration array

These changes improve the NIM service implementation by adding
support for the newer server interface creation method while
making logging more appropriate for stubbed functions.
2025-02-08 20:28:25 +10:00
Zephyron 4792ba752e
service/mm: add missing vector include and update copyright
- Add missing <vector> include for std::vector usage
- Add Citron copyright notice
- Maintain existing include ordering

This is a minor cleanup change to ensure proper header inclusion
and copyright attribution.
2025-02-08 20:24:09 +10:00
Zephyron b8fe6b6f7c
service/acc: implement Nintendo Account integration and cleanup
- Add Nintendo Account related implementations:
  * GetNintendoAccountId
  * GetNintendoAccountUserResourceCache
  * IsLinkedWithNintendoAccount
  * StoreSaveDataThumbnailApplication
- Improve version handling:
  * Add proper firmware version comments
  * Implement deprecated and new TrySelectUserWithoutInteraction
  * Update service interface versioning
- Clean up code organization:
  * Remove redundant clang-format markers
  * Fix constructor formatting
  * Improve error handling in InitializeApplicationInfoBase
  * Add proper debug logging
  * Update copyright headers
- Add proper documentation for buffer types and sizes

These changes improve Nintendo Account integration support while
cleaning up the codebase and improving version compatibility
handling. The implementation provides stubs for network-related
functionality to allow applications to proceed while proper
integration is developed.
2025-02-08 20:21:47 +10:00
Zephyron 0acfbc5fa1
service/nifm: implement additional network interface functions
- Add implementations for previously stubbed functions:
  * EnumerateNetworkInterfaces
  * EnumerateNetworkProfiles
  * ConfirmSystemAvailability
  * SetBackgroundRequestEnabled
- Add proper debug logging for new implementations
- Update header with new function declarations
- Add Citron copyright notice
- Improve response builder naming for clarity

These implementations return success status with empty results
to allow applications to proceed while proper network interface
management is developed. Debug logging has been added to track
usage of these functions.
2025-02-08 19:58:19 +10:00
Zephyron e3128c6e98
service/sm: improve service manager implementation
- Reorder error codes to match numerical order
- Rename RegisterClient to Initialize in service registration
  to match actual function name
- Update function declaration order in header to match implementation
- Improve QueryPointerBufferSize implementation:
  * Add proper documentation comment
  * Use constexpr for maximum transfer memory size
  * Use std::numeric_limits where appropriate
  * Improve debug logging message
  * Use meaningful constant name

These changes improve code organization and clarity while making
the service manager interface more consistent with Nintendo's
official naming conventions.
2025-02-08 19:50:28 +10:00
Zephyron b89a85e228
service/set: improve settings handling and update serial number
- Update default console serial number prefix from "YUZ" to "CIT"
- Improve GetSettingsItemValueImpl template implementation:
  * Add proper buffer management using std::vector
  * Fix potential buffer overflow issues
  * Use clearer variable naming
  * Add proper size handling with actual_size
  * Use memcpy for safer data copying

These changes improve the safety of settings handling while
updating the emulator's identity to use the Citron prefix
instead of yuzu's.
2025-02-08 19:45:27 +10:00
Zephyron cc48197448
service/hid: reorganize gesture-related functions
- Move SetGestureOutputRanges function registration to be with other
  gesture-related functions (next to ActivateGesture)
- Move SetGestureOutputRanges implementation to be with other
  gesture-related implementations
- Change log level from WARNING to DEBUG for SetGestureOutputRanges
- Move function declaration to private section with other IPC handlers
- Update function ordering to match service registration order

These changes improve code organization by grouping related
functionality together and maintain consistency between the
interface registration and implementation ordering.
2025-02-08 19:39:53 +10:00
Zephyron 0010882f36
service: fix typo in NPNS GetStateChangeEvent function name
Fix spelling of "GetStateChangeEvent" function name in both INpnsSystem
and INpnsUser interfaces. The function was incorrectly spelled as
"GetStateChangeEVent" with a capital 'V'.
2025-02-08 19:35:59 +10:00
Zephyron c31768ec15
core: improve nvdrv and buffer queue implementations
Buffer Queue Changes:
- Add assertion for buffer state in free slots
- Improve error handling for buffer dequeuing
- Add buffer count validation checks
- Update log levels for better diagnostics

NVDRV Changes:
- Add host1x reference to nvhost_nvdec_common
- Improve ioctl error reporting with more detailed messages
- Reorder function declarations in nvhost_ctrl_gpu
- Add stub for unimplemented ioctl command 0x13
- Clean up initialization of boolean flags

These changes improve error handling and debugging capabilities
while adding additional safety checks for buffer management.
The nvdrv interface is also made more robust with better error
reporting and proper hardware access patterns.
2025-02-08 19:29:49 +10:00
Zephyron 227db142e2
sockets: reorder errno values numerically
Reorder the Errno enum values to be in ascending numerical order,
moving NOMEM (12) to be between AGAIN (11) and INVAL (22). This
improves readability and makes it easier to verify completeness
of the error code list.
2025-02-08 19:21:47 +10:00
Zephyron f4b9e54b22
common/nvdrv: improve memory validation and error handling
Implements several improvements to memory handling and validation:

- host_memory: Add IsValidMapping() and IsDirectMappingEnabled() methods to
  validate memory access
- host_memory: Fix virtual base offset calculation to use proper pointer
  arithmetic
- host_memory: Add size field to track allocation size
- nvhost_ctrl_gpu: Return InvalidState instead of InvalidValue for TPC mask
  buffer size validation
- Update copyright year for citron

The changes improve memory safety by adding explicit validation checks and
fixing pointer arithmetic in the virtual memory implementation.
2025-02-01 21:50:33 +10:00
Zephyron ecc32958ec
nvdrv: Add GetTpcMasks2 support and improve memory mapping validation
This commit makes two main changes:

1. Adds support for GetTpcMasks2 (ioctl 0x13) in nvhost_ctrl_gpu:
- Implements new GetTpcMasks2 method to handle TPC mask queries
- Adds IoctlGetTpcMasks structure to store mask parameters
- Returns conservative single TPC configuration for compatibility

2. Enhances memory mapping validation in HostMemory:
- Adds verification check after memory mapping operations
- Improves error handling for direct mapped address enabling
- Adds logging for mapping and direct address failures

Additional changes:
- Updates copyright headers to include citron Emulator Project
- Improves error handling and validation in several paths
- Adds debug logging for TPC mask operations

This improves GPU virtualization support and memory mapping reliability.
2025-02-01 19:48:11 +10:00
Zephyron 6ab82e8eeb
service: Implement rebootless system update stubs and types
Adds initial support for rebootless system update related functionality:

- Add system archive title IDs for ApplicationBlackList, RebootlessSystemUpdateVersion,
  and ContentActionTable
- Add NS service result codes for system update operations
- Implement stubs for ISystemUpdateControl::SetupToReceiveSystemUpdate and
  RequestCheckLatestUpdateIncludesRebootlessUpdate
- Add RebootlessSystemUpdateVersion settings type and implement
  GetRebootlessSystemUpdateVersion in SET service
- Fix GetSettingsItemValueImpl template implementation

This provides basic infrastructure for handling system updates, particularly
the rebootless update feature, though actual update functionality remains
stubbed.
2025-01-30 22:10:08 +10:00
Zephyron 613099703a
kernel/svc: Implement InitialProcessIdRange and improve process exit handling
- Replace stubbed InitialProcessIdRange implementation with proper bounds (1-0x50)
- Add handle and info_sub_id validation for InitialProcessIdRange
- Replace process exit ASSERT with graceful error handling and logging
- Add try-catch block around system.Exit() for safer shutdown
- Add atomic header inclusion for binder.h

This improves system call reliability by properly implementing process ID
range checks and adding safer process exit handling with proper error logging.
2025-01-29 13:17:07 +10:00
Zephyron 8c630a8bea
network: Add NOMEM errno handling for socket operations
Implements support for ENOMEM (errno 12) across the network stack:
- Added NOMEM to Network::Errno enum
- Added NOMEM = 12 to sockets Errno enum
- Added translation case in sockets_translate.cpp

This is the first step towards addressing the 0.0 FPS bug that occurs
when the system runs out of memory during socket operations. Previously,
these operations would trigger an unimplemented assertion, causing the
emulator to halt. Now the error will be properly propagated to the guest
application.
2025-01-28 16:20:54 +10:00
Zephyron b7e11d3724 service: Implement GPU error handling IPC commands for AM
Implements several IPC commands in IApplicationFunctions related to GPU error
handling and system events:

- EnableApplicationAllThreadDumpOnCrash (cmd 124)
- SetDelayTimeToAbortOnGpuError (cmd 131)
- TryPopFromNotificationStorageChannel (cmd 151)
- SetHdcpAuthenticationActivated (cmd 170)
- GetLaunchRequiredVersion (cmd 180)
- UpgradeLaunchRequiredVersion (cmd 181)

Also adds the LaunchRequiredVersion struct definition to the header file.
These are currently stubbed implementations that log warnings when called.

REFS: switchbrew.org/wiki/Applet_Manager_services#GetGpuErrorDetectedSystemEvent
2025-01-27 00:45:27 +10:00
Zephyron a5d62fa4ec nvnflinger: Implement reference counting for binder objects
Implements proper reference counting for binder objects based on the official
documentation. This adds both weak and strong reference counting support to
the IBinder interface and its implementations (BufferQueueProducer and
BufferQueueConsumer).

The implementation follows the documented behavior where:
- type 0 affects weak references
- type 1 affects strong references
- During initialization: {addval=1, type=0} followed by {addval=1, type=1}
- For onFirstRef: {addval=1, type=1}
- For onLastStrongRef: {addval=-1, type=1}

Reference counters are implemented using std::atomic to ensure thread safety.

REFS: switchbrew.org/wiki/Nvnflinger_services#AdjustRefcount
2025-01-26 14:21:36 +10:00
Zephyron a6063bbd64 service: vi: Implement missing IApplicationDisplayService functions
Implements missing functions and improves permission handling in the VI
(Visual Interface) IApplicationDisplayService based on official documentation.

Key changes:
- Add session type enum to properly handle vi:u/vi:s/vi:m permissions
- Implement GetIndirectLayerImageCropMap for handling cropped layer images
- Implement GetDisplayVsyncEventForDebug for debug vsync event handling
- Add proper permission checks for GetSystemDisplayService and GetManagerDisplayService
- Improve AppletResourceUserId validation in OpenLayer
- Clean up logging and error handling

The changes follow the official documentation for permission handling:
- vi:u sessions can only use GetRelayService
- vi:s sessions can use everything except GetManagerDisplayService
- vi:m sessions can use all commands

REFS: switchbrew.org/wiki/Display_services#IApplicationDisplayService
2025-01-26 13:27:06 +10:00
Zephyron 5ba970b574 service: sm: Update to match official IPC interface
Updates the SM service implementation to better match the official
"nn::sm::detail::IUserInterface" interface. Key changes include:

- Replace Initialize with RegisterClient command (cmd 0)
- Add DetachClient command implementation (cmd 4)
- Update service name handling to use u64-encoded names
- Add proper PID descriptor handling for RegisterClient/DetachClient
- Add ResultNotAllowed error code
- Update handler registration for both CMIF and TIPC

This brings the implementation closer to the official documentation while
maintaining compatibility with existing code.

Refs: switchbrew.org/wiki/Services_API#sm:
2025-01-25 15:20:01 +10:00
Zephyron c279df9cfe service: mm: Refactor Memory Management service implementation
Refactors the MM (Memory Management) service implementation with improved:

- Session management using a vector of Session objects instead of global vars
- Type safety with proper enums and member encapsulation
- Error handling with consistent patterns
- Modern C++ features (std::erase_if, std::find_if, emplace_back)
- Logging with detailed debug messages
- Code organization and const correctness

Key changes:
- Add Session class with proper encapsulation
- Add EventClearMode enum (Manual = 0, Auto = 1)
- Update Module enum naming for consistency
- Implement proper session tracking and lookup
- Add detailed parameter logging
- Use modern C++ algorithms for session management

The implementation now properly handles multiple sessions and matches
the documented nn::mmnv::IRequest interface more closely.

Refs: switchbrew.org/wiki/Display_services#mm:u
2025-01-25 14:55:50 +10:00
Zephyron 0adeac26af service: mm: Implement proper parameter handling for MM service
Add proper type definitions and parameter handling for the Memory Management
(mm:u) service based on the Switch documentation:

- Add Module enum for hardware components (CPU, GPU, EMC, etc)
- Add Priority and Setting type definitions as u32
- Add EventClearMode enum for initialization
- Implement proper parameter handling for all IPC calls
- Add detailed logging with parameter values

The Module enum now properly reflects the documented hardware components:
CPU, GPU, EMC, System Bus, Memory Select, and NVIDIA modules (NVDEC,
NVENC, NVJPG).

This makes the implementation match the documented nn::mmnv::IRequest
interface.

Refs: switchbrew.org/wiki/Display_services#mm:u
2025-01-25 14:23:22 +10:00
Zephyron 774d8d9eba service/nvdrv: Relax GPU validation and improve error handling
Relaxes validation checks in the NVDRV GPU service and improves error notifier
handling to prevent potential hangs. Key changes:

- Remove strict size validation in SetErrorNotifier
- Relax GPFIFO entry count validation to only check for non-zero values
- Add proper error notifier state tracking in GPU class
- Improve debug logging messages

The previous strict validation was causing issues with some games like ACNH.
These changes maintain necessary checks while being more permissive with
edge cases that don't impact functionality.

Technical changes:
- Store error notifier state in GPU class for future implementation
- Remove upper bound check on GPFIFO entries
- Simplify error notifier setup flow

This should resolve hanging issues while maintaining core functionality.
2025-01-21 16:07:44 +10:00
Zephyron d7dc87bbf3 service/nvdrv: Implement stubbed GPU functions
Implements several previously stubbed functions in the NVDRV service:
- Initialize proper transfer memory handling
- Add error notifier configuration
- Implement channel timeout and timeslice management
- Add object context allocation and tracking
- Add GPU interface stubs for new functionality

The changes improve the accuracy of GPU-related operations while maintaining
compatibility with the existing codebase. All functions now properly validate
parameters and handle endianness correctly using _le types.
2025-01-20 18:04:11 +10:00
Zephyron b574aba98b service-am: Handle panic conditions in SetTerminateResult
- Prevents propagation of panic conditions when setting termination results
- Previously, panic error codes could trigger cascading crashes
- Only stores non-error termination results while allowing successful completion
- Fixes crash when applications set panic-related termination codes (0x1A80A)
2025-01-20 16:06:08 +10:00
Zephyron 6d225eb94a service: vi: Remove stubbed warning from GetManagerDisplayService
- The GetManagerDisplayService function in IApplicationDisplayService is fully implemented, so remove the stubbed warning and change the log level to DEBUG to match its implementation status.
2025-01-20 16:03:43 +10:00
Zephyron 498d016873 fix(sm_controller): Correct QueryPointerBufferSize implementation
- Updated the QueryPointerBufferSize function to return the correct u16 pointer buffer size.
- Ensured the function logs its call at the debug level.
- Used IPC::ResponseBuilder to construct the response with the correct buffer size.

This change addresses the stubbed implementation and ensures compliance with the HIPC protocol.
2025-01-15 19:38:09 +10:00
Zephyron 132077e18f fix: Implement SetGestureOutputRanges to handle unimplemented function error
- Added the SetGestureOutputRanges function to the IHidServer class to address the unimplemented function '92' error.
- This fix was discovered through log analysis, which showed a critical assertion failure in the HID service for an unknown function '92'.
- The log indicated a userspace panic and backtrace, pointing to the need for implementing this function to prevent execution breaks.
- Updated CMakeLists.txt to remove specific version requirements for several packages, enhancing flexibility.
- Updated subproject commit references for VulkanMemoryAllocator and vcpkg.

- REF: https://switchbrew.org/wiki/HID_services#ActivateGesture
2025-01-15 19:20:37 +10:00
Zephyron 9ae0eeeb87 Revert incorrect copyright attribution for non-contributed files
- In commit b3facaa6bb, the copyright header was
  updated to include "Citron Homebrew Project" across multiple files, regardless
  of whether any contributions were made.

- This commit removes the incorrect attribution and reverts the copyright header
  to its previous state.

- Copyright attribution should only be added when meaningful contributions have
  been made to the file.

- This commit ensures proper compliance with copyright standards and maintains
  correct attribution to the respective contributors.

- Special thanks to Tachi for pointing out the need for these corrections and
  ensuring that proper attribution practices are followed.
2025-01-14 15:33:24 +10:00
Zephyron 3f151c5111
nvdrv: Add MSVC compatibility for packed structs
Add conditional compilation directives to handle packed struct definitions
differently between MSVC and other compilers. MSVC uses #pragma pack
while GCC/Clang use __attribute__((packed)). This change affects:

- ZBCColorEntry
- ZBCDepthEntry
- IoctlZbcSetTable

The functionality remains the same, but ensures proper struct packing
across different compiler environments.
2025-01-08 21:16:04 +10:00
Zephyron 66b6d5b2da
core: Improve device memory and buffer queue handling
This commit makes several improvements to device memory management and buffer
queue handling:

DeviceMemoryManager:
- Add null pointer and size checks for ReadBlock
- Fill unmapped memory with a known pattern (0xCC) instead of zeros
- Add better error logging for invalid memory accesses
- Add null pointer check for source pointer in memcpy

BufferQueueProducer:
- Improve error handling in WaitForFreeSlotThenRelock
- Add proper abandoned state checking during wait conditions
- Clean up and simplify buffer scanning logic
- Improve logging messages with more descriptive information
- Remove redundant buffer count validation
- Fix potential infinite loop condition during wait

These changes improve stability and error handling while making the code more
maintainable and debuggable. The use of a known pattern for unmapped memory
helps identify uninitialized memory access issues.
2025-01-06 20:04:35 +10:00
Zephyron 83393a6c6b
service/am: Implement friend invitation storage channel
Implements TryPopFromFriendInvitationStorageChannel to properly handle
friend invitation data storage and retrieval. This includes:

- Add ResultNoData error code to am_results.h
- Add friend_invitation_storage_channel storage queue to Applet struct
- Implement proper data handling in TryPopFromFriendInvitationStorageChannel

The implementation now properly manages a queue of friend invitation data
and returns appropriate results based on data availability.
2025-01-06 16:57:45 +10:00
Zephyron 8f5e3516fe
nvdrv: Fix incorrect IoctlZbcSetTable structure size assertion
Resolves a build failure caused by a mismatch between the defined and expected size of the `IoctlZbcSetTable` structure in `nvhost_ctrl_gpu`. The `static_assert` incorrectly expected the size to be 44 bytes, while the actual size was 48 bytes.

Changes include:
- Updated `static_assert` to correctly reflect the 48-byte size of `IoctlZbcSetTable`.
- Verified packing and alignment to ensure compliance with hardware specifications.
- Reviewed and confirmed correctness of `u32` type definitions.

This fix addresses a regression introduced in commit 9be4bf9aa5, which implemented ZBCSetTable functionality, and ensures successful compilation and adherence to the ZBC table implementation's design.
2025-01-05 13:45:04 +10:00
Zephyron 9be4bf9aa5
nvdrv: Implement ZBCSetTable functionality
Implements basic Zero Bandwidth Clear (ZBC) table support in nvhost_ctrl_gpu.
This adds storage and validation for both color and depth clear values,
replacing the previous stub implementation. ZBC is a hardware optimization
technique used by NVIDIA GPUs to efficiently handle buffer clearing operations.

Changes include:
- Added ZBC table storage structures
- Implemented parameter validation
- Added separate handling for color and depth modes
- Improved debug logging
- Added documentation explaining ZBC functionality
2025-01-04 18:57:12 +10:00
Zephyron 468ace6b0b
core: Update copyright headers
- Update copyright headers to include Citron Homebrew Project
- Add 2025 to copyright years
2024-12-31 17:36:08 +10:00
Zephyron b3facaa6bb
chore: update project references and add Citron copyright
- Replaced all references to the old project name with Citron.
- Added Citron copyright information alongside existing notices in all files.
2024-12-31 17:07:49 +10:00
yuzubot 537296095a "Merge Tagged PR 13018" 2024-03-04 13:02:54 +00:00
liamwhite dc94882c90
Merge pull request #13135 from german77/hid-interface
service: hid: Migrate HidServer to new IPC
2024-02-27 12:26:26 -05:00
Liam c7174d5f61 general: fix asan errors 2024-02-26 19:28:49 -05:00
liamwhite 79edad2533
Merge pull request #13159 from liamwhite/web-error
core: enable error applet, add stubs for web applet
2024-02-26 12:44:55 -05:00
Liam d66ca8b731 video_core: make gpu context aware of rendering program 2024-02-26 11:16:14 -05:00
Liam 4050242cf3 ldn: return no connection from GetStateForMonitor 2024-02-24 22:56:08 -05:00
Liam fd718f350c ssl: add cert store 2024-02-24 22:56:05 -05:00
Liam 0d6fd12231 glue: load initial year setting as s32 2024-02-24 22:49:38 -05:00
Liam f297e98a9e acc: add account manager for acc:u1 2024-02-24 22:25:34 -05:00
Liam 637c54e205 fs: add stubs for online web applet 2024-02-24 22:25:34 -05:00