Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
173d5c2d3a | ||
|
|
52c1cef064 | ||
|
|
4efa5d7dd0 | ||
|
|
275da52305 | ||
|
|
30fac905af | ||
|
|
78f7218c4f | ||
|
|
09c6aa29dd | ||
|
|
1019bc54e6 | ||
|
|
96631d8225 | ||
|
|
d32dd0f04a | ||
|
|
ddfc16731f | ||
|
|
26714c7f3b | ||
|
|
767e702a70 | ||
|
|
9d5e652fbd | ||
|
|
1d39e06f32 | ||
|
|
21b7884653 | ||
|
|
14ad2f0ba0 | ||
|
|
fcc7ce49d9 | ||
|
|
f98c7cba98 | ||
|
|
496adb0018 | ||
|
|
09074798cd | ||
|
|
e256261b80 | ||
|
|
47218f0da8 | ||
|
|
409a48ec73 | ||
|
|
0c93cefd39 | ||
|
|
0bbc907907 | ||
|
|
4a4a1f0e87 | ||
|
|
705dd95375 | ||
|
|
2d5751356b | ||
|
|
b140834b7e | ||
|
|
e3d2af6b3f | ||
|
|
c17ad1e0e3 | ||
|
|
6145b3b72c | ||
|
|
aba7e4ca7d | ||
|
|
4cc5e9cdfd | ||
|
|
ca0308c7ca | ||
|
|
1d908295fe | ||
|
|
277bd101c5 | ||
|
|
3dce23773a | ||
|
|
4489513f7c | ||
|
|
5eabca7f04 | ||
|
|
a73e0e8f16 | ||
|
|
2161365f4f | ||
|
|
258a83684e | ||
|
|
d2a757c39e | ||
|
|
6cf5205a28 | ||
|
|
b9c90b9234 | ||
|
|
94e18b8c93 | ||
|
|
4e92687cab | ||
|
|
2a0b99d9f9 | ||
|
|
d1f3c4904b | ||
|
|
92321ccbc8 | ||
|
|
db3004e844 | ||
|
|
3e97e4addf | ||
|
|
4b7b33809f | ||
|
|
e81a1ce5a8 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -91,7 +91,11 @@ dkms.conf
|
|||||||
**/out
|
**/out
|
||||||
**/build
|
**/build
|
||||||
**/build_nintendo_nx_arm64
|
**/build_nintendo_nx_arm64
|
||||||
|
**/build_nintendo_nx_arm64_armv8a
|
||||||
**/build_nintendo_nx_arm
|
**/build_nintendo_nx_arm
|
||||||
|
**/build_nintendo_nx_arm_armv8a
|
||||||
|
**/build_nintendo_nx_arm_armv7a
|
||||||
|
**/build_nintendo_nx_arm_armv4t
|
||||||
**/build_nintendo_nx_x64
|
**/build_nintendo_nx_x64
|
||||||
**/build_nintendo_nx_x86
|
**/build_nintendo_nx_x86
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -112,6 +112,7 @@ dist-no-debug: all
|
|||||||
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000042
|
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000042
|
||||||
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000420
|
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000420
|
||||||
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000B240
|
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000B240
|
||||||
|
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D609
|
||||||
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D623
|
mkdir -p atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D623
|
||||||
cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000008/exefs.nsp
|
cp stratosphere/boot2/boot2.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000008/exefs.nsp
|
||||||
cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000000D/exefs.nsp
|
cp stratosphere/dmnt/dmnt.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000000D/exefs.nsp
|
||||||
@@ -125,6 +126,7 @@ dist-no-debug: all
|
|||||||
cp stratosphere/pgl/pgl.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000042/exefs.nsp
|
cp stratosphere/pgl/pgl.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000042/exefs.nsp
|
||||||
cp stratosphere/LogManager/LogManager.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000420/exefs.nsp
|
cp stratosphere/LogManager/LogManager.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/0100000000000420/exefs.nsp
|
||||||
cp stratosphere/htc/htc.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000B240/exefs.nsp
|
cp stratosphere/htc/htc.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000B240/exefs.nsp
|
||||||
|
cp stratosphere/dmnt.gen2/dmnt.gen2.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D609/exefs.nsp
|
||||||
cp stratosphere/TioServer/TioServer.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D623/exefs.nsp
|
cp stratosphere/TioServer/TioServer.nsp atmosphere-$(AMSVER)/stratosphere_romfs/atmosphere/contents/010000000000D623/exefs.nsp
|
||||||
@build_romfs atmosphere-$(AMSVER)/stratosphere_romfs atmosphere-$(AMSVER)/atmosphere/stratosphere.romfs
|
@build_romfs atmosphere-$(AMSVER)/stratosphere_romfs atmosphere-$(AMSVER)/atmosphere/stratosphere.romfs
|
||||||
rm -r atmosphere-$(AMSVER)/stratosphere_romfs
|
rm -r atmosphere-$(AMSVER)/stratosphere_romfs
|
||||||
|
|||||||
@@ -1,4 +1,73 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
## 1.2.6
|
||||||
|
+ Support was added for 13.2.1.
|
||||||
|
+ A number of minor issues were fixed and improvements were made, including:
|
||||||
|
+ A minor performance improvement was implemented in service table dispatch by sorting and binary-searching the service command table instead of using linear search.
|
||||||
|
+ Static initialization logic in Atmosphere was made much more regular.
|
||||||
|
+ General system stability improvements to enhance the user's experience.
|
||||||
|
## 1.2.5
|
||||||
|
+ Support was added for 13.2.0.
|
||||||
|
+ A number of minor issues were fixed and improvements were made, including:
|
||||||
|
+ A bug was fixed that caused `mesosphère` to underreport the total memory size by 8MB for certain games which use newer system-resource-size memory management.
|
||||||
|
+ This caused FIFA 19 to crash, and possibly other issues.
|
||||||
|
+ Memory management changes were made to `sm` that save 0x5000 of memory.
|
||||||
|
+ A microoptimization was made to the way `mesosphère` manages updating the debug register for hardware single-step support.
|
||||||
|
+ Support was fixed for enabling `usb!usb30_force_enabled` on 13.0.0+.
|
||||||
|
+ The work-in-progress unit testing framework was updated to use doctest instead of catch2.
|
||||||
|
+ General system stability improvements to enhance the user's experience.
|
||||||
|
## 1.2.4
|
||||||
|
+ Changes were made to the way fs.mitm builds images when providing a layeredfs romfs.
|
||||||
|
+ Cache management (to avoid unnecessary rebuild) was revised, to add a grace period of ~500ms-1s between process closing romfs image and ams.mitm needing to rebuild if romfs is re-opened.
|
||||||
|
+ This makes our cache much more effective, previously we were re-building romfs several times.
|
||||||
|
+ RomFS image ownership was overhauled, with a new reference-counting implementation added (used to implement the above grace period).
|
||||||
|
+ Certain games (e.g. Puyo Puyo Tetris 2, probably others) were sensitive to this timing, and could use access patterns which would trigger creation of romfs image while previous romfs image was in the middle of destructor.
|
||||||
|
+ This could cause a fatal error, because the destructor for the old image could run simultaneously with building the new image.
|
||||||
|
+ This also provides a speedup versus the 1.2.3 code, with Animal Crossing now taking ~8 fewer seconds to get past the Nintendo Switch logo.
|
||||||
|
+ General system stability improvements to enhance the user's experience.
|
||||||
|
## 1.2.3
|
||||||
|
+ Because ams.TMA is taking longer to develop than expected, experimental support for Atmosphère's gdbstub as a standalone is now available.
|
||||||
|
+ To enable it, set `atmosphere!enable_standalone_gdbstub` = u8!0x1 in system_settings.ini.
|
||||||
|
+ The standalone also requires `atmosphere!enable_htc` = u8!0x0, but this should be the case for everyone since ams.TMA isn't actually usable yet.
|
||||||
|
+ Once enabled, open the devkitPro provided-gdb (`aarch64-none-elf-gdb` for 64-bit or `arm-none-eabi-gdb` for 32-bit).
|
||||||
|
+ The standalone stub exposes itself on port 22225 -- so the command to connect is `target extended-remote <ip address>:22225`.
|
||||||
|
+ Type `info os processes` to get a list of process IDs that can be attached to.
|
||||||
|
+ The stub should work on both system programs, games, and homebrew -- but please note that debugging certain processes (like sockets) can cause hang due to the stub using them itself.
|
||||||
|
+ Software break-points, hardware break-points, hardware watch-points, and hardware single-step are all supported/implemented.
|
||||||
|
+ The following monitor commands are currently supported:
|
||||||
|
+ `monitor get info`: Get process info, address space layout, and information on modules.
|
||||||
|
+ `monitor get mappings`: Get all memory mappings.
|
||||||
|
+ `monitor get mapping <addr>`: Get the memory mapping for a specific address.
|
||||||
|
+ `monitor wait application`: Causes the stub to wait for an application to be launched. The next application will be started suspended.
|
||||||
|
+ User is expected to send `attach <pid>` after launching, which will cause attach-on-first-instruction. Failure to attach may cause system instability, this probably needs work.
|
||||||
|
+ **Please Note**: The GDBstub is new and may have bugs/need work. If you find issues, please report them to SciresM#0524 -- all help finding/fixing bugs is appreciated, here.
|
||||||
|
+ Generally speaking, if you would like to report information about fixes needed/discuss development of the gdbstub, join ReSwitched's #dev-support channel.
|
||||||
|
+ Changes were made to the way fs.mitm builds images when providing a layeredfs romfs.
|
||||||
|
+ Animal Crossing's 2.0.0 update contains >99000 files, and has tables so big that we ran out of memory even after the optimizations made in 0.10.5.
|
||||||
|
+ Previously, we used fixed-sized 0x40000 work buffers for file/directory tables and simultaneously built hash/content tables in one loop over files/directories.
|
||||||
|
+ We now iterate over the file/directory tables multiple times, first once to determine the hash table indices, then repeatedly to build hash tables, then once to build content tables.
|
||||||
|
+ We also now allow smaller-than-0x40000 work buffers, trying half-as-big buffers until allocation succeeds (or work buffer would be <0x4000, which is a safeguard against truly horrible performance).
|
||||||
|
+ There is a slight speed penalty to these changes, but it's on the order of seconds for the worst case (Animal Crossing) and trivial for most games with reasonable tables.
|
||||||
|
+ If you encounter a game that exhausts ams.mitm's memory (crashing it) when loading layeredfs mods, please contact `SciresM#0524`.
|
||||||
|
+ It's really hard to imagine any game being worse than Animal Crossing, but if it happens again I will drop everything to fix it as usual.
|
||||||
|
+ `creport` now attempts to parse symbol tables if present.
|
||||||
|
+ If a game executable has a symbol for a given address, the function-relative-offset will now be printed after the module-relative-offset.
|
||||||
|
+ General system stability improvements to enhance the user's experience.
|
||||||
|
## 1.2.2
|
||||||
|
+ A number of fixes were made to Atmosphère's implementation of the new "sprofile" service added in 13.0.0.
|
||||||
|
+ Nintendo is finally transmitting data over the internet to certain consoles, which has allowed for validating our service implementation.
|
||||||
|
+ Unfortunately, there were several problems, and if your console began trying to use the new services atmosphere would show a fatal error with code 0xCAF6 (sprofile::ResultInvalidState()).
|
||||||
|
+ With actual test data in hand, a test program was written and it was verified that our implementation can successfully import/access profile data now.
|
||||||
|
+ Hopefully there are no more issues, and I sincerely apologize for anyone who got an 0xCAF6 fatal due to this.
|
||||||
|
+ A number of minor improvements were made to `mesosphère`, including:
|
||||||
|
+ KThread::GetContextForSchedulerLoop was implemented in assembly (using static assertions to verify offset-of-context-in-struct is correct).
|
||||||
|
+ This saves an unnecessary function call in the middle of the scheduler hot loop, replacing it with an addition instruction, which should improve microperformance.
|
||||||
|
+ Mesosphere's hardware maintenance instructions were audited via a script and now directly match Nintendo's kernels.
|
||||||
|
+ Notably, this inserts a missing instruction synchronization barrier when validating that slab heaps may be constructed.
|
||||||
|
+ This missing ISB could cause an abort on certain (see: particularly sensitive) hardware on boot if the relevant codepath was speculatively executed (it normally only executes on game launch...)
|
||||||
|
+ The SVC handlers for performing light IPC (normally unused) from 32-bit process were fixed in Mesosphere.
|
||||||
|
+ A bug was fixed that would cause the register x27 to be overwritten with the contents of x26 when returning from a user exception handler.
|
||||||
|
+ A bug was fixed that would cause the kernel to use the userland stack pointer instead of the kernel stack pointer while generating an error report for a kernel abort.
|
||||||
|
+ General system stability improvements to enhance the user's experience.
|
||||||
## 1.2.1
|
## 1.2.1
|
||||||
+ Support was implemented for 13.1.0.
|
+ Support was implemented for 13.1.0.
|
||||||
+ `mesosphère` was updated to reflect the kernel behavioral changes made in 13.1.0.
|
+ `mesosphère` was updated to reflect the kernel behavioral changes made in 13.1.0.
|
||||||
|
|||||||
@@ -249,6 +249,8 @@ namespace ams::nxboot {
|
|||||||
return ams::TargetFirmware_12_1_0;
|
return ams::TargetFirmware_12_1_0;
|
||||||
} else if (std::memcmp(package1 + 0x10, "20210805", 8) == 0) {
|
} else if (std::memcmp(package1 + 0x10, "20210805", 8) == 0) {
|
||||||
return ams::TargetFirmware_13_0_0;
|
return ams::TargetFirmware_13_0_0;
|
||||||
|
} else if (std::memcmp(package1 + 0x10, "20220105", 8) == 0) {
|
||||||
|
return ams::TargetFirmware_13_2_1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
[subrepo]
|
[subrepo]
|
||||||
remote = https://github.com/Atmosphere-NX/Atmosphere-libs
|
remote = https://github.com/Atmosphere-NX/Atmosphere-libs
|
||||||
branch = master
|
branch = master
|
||||||
commit = 13c6987cc43d0b9a874e87e3ce8eaffd1c72fa69
|
commit = 0d161b8588aa6482b84f3c44dd001055b01a047f
|
||||||
parent = cb38b0b929f332a52ceeee5c27cb0fd83ff03433
|
parent = 4efa5d7dd0bfbdf89a6261af0aef3878ca784b05
|
||||||
method = merge
|
method = merge
|
||||||
cmdver = 0.4.1
|
cmdver = 0.4.1
|
||||||
|
|||||||
11
libraries/config/arch/armv4t/arch.mk
Normal file
11
libraries/config/arch/armv4t/arch.mk
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
ifeq ($(strip $(DEVKITPRO)),)
|
||||||
|
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITPRO)/devkitARM/base_rules
|
||||||
|
|
||||||
|
export ATMOSPHERE_DEFINES += -DATMOSPHERE_ARCH_ARM_V4T
|
||||||
|
export ATMOSPHERE_SETTINGS +=
|
||||||
|
export ATMOSPHERE_CFLAGS +=
|
||||||
|
export ATMOSPHERE_CXXFLAGS +=
|
||||||
|
export ATMOSPHERE_ASFLAGS +=
|
||||||
11
libraries/config/arch/armv8a/arch.mk
Normal file
11
libraries/config/arch/armv8a/arch.mk
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
ifeq ($(strip $(DEVKITPRO)),)
|
||||||
|
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITPRO)/devkitA64/base_rules
|
||||||
|
|
||||||
|
export ATMOSPHERE_DEFINES += -DATMOSPHERE_ARCH_ARM_V8A
|
||||||
|
export ATMOSPHERE_SETTINGS +=
|
||||||
|
export ATMOSPHERE_CFLAGS +=
|
||||||
|
export ATMOSPHERE_CXXFLAGS +=
|
||||||
|
export ATMOSPHERE_ASFLAGS +=
|
||||||
@@ -39,6 +39,9 @@ export ATMOSPHERE_ARCH_NAME := arm64
|
|||||||
export ATMOSPHERE_BOARD_NAME := nintendo_nx
|
export ATMOSPHERE_BOARD_NAME := nintendo_nx
|
||||||
export ATMOSPHERE_OS_NAME := horizon
|
export ATMOSPHERE_OS_NAME := horizon
|
||||||
|
|
||||||
|
export ATMOSPHERE_SUB_ARCH_DIR = armv8a
|
||||||
|
export ATMOSPHERE_SUB_ARCH_NAME = armv8a
|
||||||
|
|
||||||
export ATMOSPHERE_CPU_EXTENSIONS := arm_crypto_extension aarch64_crypto_extension
|
export ATMOSPHERE_CPU_EXTENSIONS := arm_crypto_extension aarch64_crypto_extension
|
||||||
else ifeq ($(ATMOSPHERE_CPU),arm7tdmi)
|
else ifeq ($(ATMOSPHERE_CPU),arm7tdmi)
|
||||||
export ATMOSPHERE_ARCH_DIR := arm
|
export ATMOSPHERE_ARCH_DIR := arm
|
||||||
@@ -49,6 +52,9 @@ export ATMOSPHERE_ARCH_NAME := arm
|
|||||||
export ATMOSPHERE_BOARD_NAME := nintendo_nx
|
export ATMOSPHERE_BOARD_NAME := nintendo_nx
|
||||||
export ATMOSPHERE_OS_NAME := horizon
|
export ATMOSPHERE_OS_NAME := horizon
|
||||||
|
|
||||||
|
export ATMOSPHERE_SUB_ARCH_DIR = armv4t
|
||||||
|
export ATMOSPHERE_SUB_ARCH_NAME = armv4t
|
||||||
|
|
||||||
export ATMOSPHERE_CPU_EXTENSIONS :=
|
export ATMOSPHERE_CPU_EXTENSIONS :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -64,6 +70,9 @@ export ATMOSPHERE_ARCH_NAME := arm64
|
|||||||
export ATMOSPHERE_BOARD_NAME := qemu_virt
|
export ATMOSPHERE_BOARD_NAME := qemu_virt
|
||||||
export ATMOSPHERE_OS_NAME := horizon
|
export ATMOSPHERE_OS_NAME := horizon
|
||||||
|
|
||||||
|
export ATMOSPHERE_SUB_ARCH_DIR = armv8a
|
||||||
|
export ATMOSPHERE_SUB_ARCH_NAME = armv8a
|
||||||
|
|
||||||
export ATMOSPHERE_CPU_EXTENSIONS := arm_crypto_extension aarch64_crypto_extension
|
export ATMOSPHERE_CPU_EXTENSIONS := arm_crypto_extension aarch64_crypto_extension
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -85,14 +94,27 @@ export ATMOSPHERE_BOARD_MAKE_DIR := $(ATMOSPHERE_CONFIG_MAKE_DIR)/board/$(ATMOSP
|
|||||||
export ATMOSPHERE_OS_MAKE_DIR := $(ATMOSPHERE_CONFIG_MAKE_DIR)/os/$(ATMOSPHERE_OS_DIR)
|
export ATMOSPHERE_OS_MAKE_DIR := $(ATMOSPHERE_CONFIG_MAKE_DIR)/os/$(ATMOSPHERE_OS_DIR)
|
||||||
export ATMOSPHERE_CPU_MAKE_DIR := $(ATMOSPHERE_ARCH_MAKE_DIR)/cpu/$(ATMOSPHERE_CPU_DIR)
|
export ATMOSPHERE_CPU_MAKE_DIR := $(ATMOSPHERE_ARCH_MAKE_DIR)/cpu/$(ATMOSPHERE_CPU_DIR)
|
||||||
|
|
||||||
|
ifneq ($(strip $(ATMOSPHERE_SUB_ARCH_NAME)),)
|
||||||
|
export ATMOSPHERE_LIBRARY_DIR := lib_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)_$(ATMOSPHERE_SUB_ARCH_NAME)
|
||||||
|
export ATMOSPHERE_BUILD_DIR := build_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)_$(ATMOSPHERE_SUB_ARCH_NAME)
|
||||||
|
else
|
||||||
export ATMOSPHERE_LIBRARY_DIR := lib_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)
|
export ATMOSPHERE_LIBRARY_DIR := lib_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)
|
||||||
export ATMOSPHERE_BUILD_DIR := build_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)
|
export ATMOSPHERE_BUILD_DIR := build_$(ATMOSPHERE_BOARD_NAME)_$(ATMOSPHERE_ARCH_NAME)
|
||||||
|
endif
|
||||||
|
|
||||||
include $(ATMOSPHERE_ARCH_MAKE_DIR)/arch.mk
|
include $(ATMOSPHERE_ARCH_MAKE_DIR)/arch.mk
|
||||||
include $(ATMOSPHERE_BOARD_MAKE_DIR)/board.mk
|
include $(ATMOSPHERE_BOARD_MAKE_DIR)/board.mk
|
||||||
include $(ATMOSPHERE_OS_MAKE_DIR)/os.mk
|
include $(ATMOSPHERE_OS_MAKE_DIR)/os.mk
|
||||||
include $(ATMOSPHERE_CPU_MAKE_DIR)/cpu.mk
|
include $(ATMOSPHERE_CPU_MAKE_DIR)/cpu.mk
|
||||||
|
|
||||||
|
|
||||||
|
ifneq ($(strip $(ATMOSPHERE_SUB_ARCH_NAME)),)
|
||||||
|
export ATMOSPHERE_SUB_ARCH_MAKE_DIR := $(ATMOSPHERE_CONFIG_MAKE_DIR)/arch/$(ATMOSPHERE_SUB_ARCH_DIR)
|
||||||
|
|
||||||
|
include $(ATMOSPHERE_SUB_ARCH_MAKE_DIR)/arch.mk
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# get atmosphere git revision information
|
# get atmosphere git revision information
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
@@ -125,12 +147,20 @@ DATA := data
|
|||||||
INCLUDES := include
|
INCLUDES := include
|
||||||
|
|
||||||
GENERAL_SOURCE_DIRS=$1 $(foreach d,$(filter-out $1/arch $1/board $1/os $1/cpu $1,$(wildcard $1/*)),$(if $(wildcard $d/.),$(filter-out $d,$(call GENERAL_SOURCE_DIRS,$d)) $d,))
|
GENERAL_SOURCE_DIRS=$1 $(foreach d,$(filter-out $1/arch $1/board $1/os $1/cpu $1,$(wildcard $1/*)),$(if $(wildcard $d/.),$(filter-out $d,$(call GENERAL_SOURCE_DIRS,$d)) $d,))
|
||||||
|
|
||||||
SPECIFIC_SOURCE_DIRS=$(if $(wildcard $1/$2/$3/.*),$1/$2/$3 $(call DIR_WILDCARD,$1/$2/$3),$(if $(wildcard $1/$2/generic/.*), $1/$2/generic $(call DIR_WILDCARD,$1/$2/generic),))
|
SPECIFIC_SOURCE_DIRS=$(if $(wildcard $1/$2/$3/.*),$1/$2/$3 $(call DIR_WILDCARD,$1/$2/$3),$(if $(wildcard $1/$2/generic/.*), $1/$2/generic $(call DIR_WILDCARD,$1/$2/generic),))
|
||||||
|
|
||||||
|
ifneq ($(strip $(ATMOSPHERE_SUB_ARCH_NAME)),)
|
||||||
|
SPECIFIC_SOURCE_DIRS_ARCH=$(if $(wildcard $1/$2/$3/.*),$1/$2/$3 $(call DIR_WILDCARD,$1/$2/$3),$(if $(wildcard $1/$2/$4/.*),$1/$2/$4 $(call DIR_WILDCARD,$1/$2/$4),$(if $(wildcard $1/$2/generic/.*), $1/$2/generic $(call DIR_WILDCARD,$1/$2/generic),)))
|
||||||
|
else
|
||||||
|
SPECIFIC_SOURCE_DIRS_ARCH=$(if $(wildcard $1/$2/$3/.*),$1/$2/$3 $(call DIR_WILDCARD,$1/$2/$3),$(if $(wildcard $1/$2/generic/.*), $1/$2/generic $(call DIR_WILDCARD,$1/$2/generic),))
|
||||||
|
endif
|
||||||
|
|
||||||
UNFILTERED_SOURCE_DIRS=$1 $(foreach d,$(wildcard $1/*),$(if $(wildcard $d/.),$(call DIR_WILDCARD,$d) $d,))
|
UNFILTERED_SOURCE_DIRS=$1 $(foreach d,$(wildcard $1/*),$(if $(wildcard $d/.),$(call DIR_WILDCARD,$d) $d,))
|
||||||
|
|
||||||
ALL_SOURCE_DIRS=$(foreach d,$(call GENERAL_SOURCE_DIRS,$1), \
|
ALL_SOURCE_DIRS=$(foreach d,$(call GENERAL_SOURCE_DIRS,$1), \
|
||||||
$d \
|
$d \
|
||||||
$(call SPECIFIC_SOURCE_DIRS,$d,arch,$(ATMOSPHERE_ARCH_DIR)) \
|
$(call SPECIFIC_SOURCE_DIRS_ARCH,$d,arch,$(ATMOSPHERE_ARCH_DIR),$(ATMOSPHERE_SUB_ARCH_DIR)) \
|
||||||
$(call SPECIFIC_SOURCE_DIRS,$d,board,$(ATMOSPHERE_BOARD_DIR)) \
|
$(call SPECIFIC_SOURCE_DIRS,$d,board,$(ATMOSPHERE_BOARD_DIR)) \
|
||||||
$(call SPECIFIC_SOURCE_DIRS,$d,os,$(ATMOSPHERE_OS_DIR)) \
|
$(call SPECIFIC_SOURCE_DIRS,$d,os,$(ATMOSPHERE_OS_DIR)) \
|
||||||
$(call SPECIFIC_SOURCE_DIRS,$d,cpu,$(ATMOSPHERE_ARCH_DIR)/$(ATMOSPHERE_CPU_DIR)) \
|
$(call SPECIFIC_SOURCE_DIRS,$d,cpu,$(ATMOSPHERE_ARCH_DIR)/$(ATMOSPHERE_CPU_DIR)) \
|
||||||
@@ -147,7 +177,7 @@ FIND_SOURCE_FILES=$(foreach dir,$1,$(filter-out $(notdir $(wildcard $(dir)/*.arc
|
|||||||
$(notdir $(wildcard $(dir)/*.os.*.$2)) \
|
$(notdir $(wildcard $(dir)/*.os.*.$2)) \
|
||||||
$(notdir $(wildcard $(dir)/.cpu.*.$2)), \
|
$(notdir $(wildcard $(dir)/.cpu.*.$2)), \
|
||||||
$(notdir $(wildcard $(dir)/*.$2)))) \
|
$(notdir $(wildcard $(dir)/*.$2)))) \
|
||||||
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),arch,$(ATMOSPHERE_ARCH_NAME),$2)) \
|
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES_EX,$(dir),arch,$(ATMOSPHERE_ARCH_NAME) $(ATMOSPHERE_SUB_ARCH_NAME),$2)) \
|
||||||
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),board,$(ATMOSPHERE_BOARD_NAME),$2)) \
|
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),board,$(ATMOSPHERE_BOARD_NAME),$2)) \
|
||||||
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),os,$(ATMOSPHERE_OS_NAME),$2)) \
|
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES,$(dir),os,$(ATMOSPHERE_OS_NAME),$2)) \
|
||||||
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES_EX,$(dir),cpu,$(ATMOSPHERE_CPU_NAME) $(ATMOSPHERE_CPU_EXTENSIONS),$2))
|
$(foreach dir,$1,$(call FIND_SPECIFIC_SOURCE_FILES_EX,$(dir),cpu,$(ATMOSPHERE_CPU_NAME) $(ATMOSPHERE_CPU_EXTENSIONS),$2))
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ namespace ams::pkg2 {
|
|||||||
|
|
||||||
constexpr inline int PayloadCount = 3;
|
constexpr inline int PayloadCount = 3;
|
||||||
|
|
||||||
constexpr inline int MinimumValidDataVersion = 0; /* We allow older package2 to load; this value is currently 0x13 in Nintendo's code. */
|
constexpr inline int MinimumValidDataVersion = 0; /* We allow older package2 to load; this value is currently 0x14 in Nintendo's code. */
|
||||||
constexpr inline int CurrentBootloaderVersion = 0xF;
|
constexpr inline int CurrentBootloaderVersion = 0x10;
|
||||||
|
|
||||||
struct Package2Meta {
|
struct Package2Meta {
|
||||||
using Magic = util::FourCC<'P','K','2','1'>;
|
using Magic = util::FourCC<'P','K','2','1'>;
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ namespace ams::fuse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr const TargetFirmware FuseVersionIncrementFirmwares[] = {
|
constexpr const TargetFirmware FuseVersionIncrementFirmwares[] = {
|
||||||
|
TargetFirmware_13_2_1,
|
||||||
TargetFirmware_12_0_2,
|
TargetFirmware_12_0_2,
|
||||||
TargetFirmware_11_0_0,
|
TargetFirmware_11_0_0,
|
||||||
TargetFirmware_10_0_0,
|
TargetFirmware_10_0_0,
|
||||||
|
|||||||
@@ -93,3 +93,4 @@
|
|||||||
|
|
||||||
/* Deferred includes. */
|
/* Deferred includes. */
|
||||||
#include <mesosphere/kern_k_auto_object_impls.hpp>
|
#include <mesosphere/kern_k_auto_object_impls.hpp>
|
||||||
|
#include <mesosphere/kern_k_scheduler_impls.hpp>
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ namespace ams::kern::arch::arm {
|
|||||||
PriorityLevel_Scheduler = 2,
|
PriorityLevel_Scheduler = 2,
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
static inline u32 s_mask[cpu::NumCores];
|
static constinit inline u32 s_mask[cpu::NumCores];
|
||||||
private:
|
private:
|
||||||
volatile GicDistributor *m_gicd;
|
volatile GicDistributor *m_gicd;
|
||||||
volatile GicCpuInterface *m_gicc;
|
volatile GicCpuInterface *m_gicc;
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ namespace ams::kern::arch::arm64::init {
|
|||||||
|
|
||||||
/* Invalidate the entire tlb. */
|
/* Invalidate the entire tlb. */
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
cpu::InvalidateEntireTlb();
|
cpu::InvalidateEntireTlbInnerShareable();
|
||||||
|
|
||||||
/* Copy data, if we should. */
|
/* Copy data, if we should. */
|
||||||
const u64 negative_block_size_for_mask = static_cast<u64>(-static_cast<s64>(block_size));
|
const u64 negative_block_size_for_mask = static_cast<u64>(-static_cast<s64>(block_size));
|
||||||
@@ -350,7 +350,6 @@ namespace ams::kern::arch::arm64::init {
|
|||||||
/* If we don't already have an L2 table, we need to make a new one. */
|
/* If we don't already have an L2 table, we need to make a new one. */
|
||||||
if (!l1_entry->IsTable()) {
|
if (!l1_entry->IsTable()) {
|
||||||
KPhysicalAddress new_table = AllocateNewPageTable(allocator);
|
KPhysicalAddress new_table = AllocateNewPageTable(allocator);
|
||||||
ClearNewPageTable(new_table);
|
|
||||||
*l1_entry = L1PageTableEntry(PageTableEntry::TableTag{}, new_table, attr.IsPrivilegedExecuteNever());
|
*l1_entry = L1PageTableEntry(PageTableEntry::TableTag{}, new_table, attr.IsPrivilegedExecuteNever());
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
}
|
}
|
||||||
@@ -361,12 +360,12 @@ namespace ams::kern::arch::arm64::init {
|
|||||||
if (util::IsAligned(GetInteger(virt_addr), L2ContiguousBlockSize) && util::IsAligned(GetInteger(phys_addr), L2ContiguousBlockSize) && size >= L2ContiguousBlockSize) {
|
if (util::IsAligned(GetInteger(virt_addr), L2ContiguousBlockSize) && util::IsAligned(GetInteger(phys_addr), L2ContiguousBlockSize) && size >= L2ContiguousBlockSize) {
|
||||||
for (size_t i = 0; i < L2ContiguousBlockSize / L2BlockSize; i++) {
|
for (size_t i = 0; i < L2ContiguousBlockSize / L2BlockSize; i++) {
|
||||||
l2_entry[i] = L2PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, attr, PageTableEntry::SoftwareReservedBit_None, true);
|
l2_entry[i] = L2PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, attr, PageTableEntry::SoftwareReservedBit_None, true);
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
|
||||||
|
|
||||||
virt_addr += L2BlockSize;
|
virt_addr += L2BlockSize;
|
||||||
phys_addr += L2BlockSize;
|
phys_addr += L2BlockSize;
|
||||||
size -= L2BlockSize;
|
size -= L2BlockSize;
|
||||||
}
|
}
|
||||||
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +383,6 @@ namespace ams::kern::arch::arm64::init {
|
|||||||
/* If we don't already have an L3 table, we need to make a new one. */
|
/* If we don't already have an L3 table, we need to make a new one. */
|
||||||
if (!l2_entry->IsTable()) {
|
if (!l2_entry->IsTable()) {
|
||||||
KPhysicalAddress new_table = AllocateNewPageTable(allocator);
|
KPhysicalAddress new_table = AllocateNewPageTable(allocator);
|
||||||
ClearNewPageTable(new_table);
|
|
||||||
*l2_entry = L2PageTableEntry(PageTableEntry::TableTag{}, new_table, attr.IsPrivilegedExecuteNever());
|
*l2_entry = L2PageTableEntry(PageTableEntry::TableTag{}, new_table, attr.IsPrivilegedExecuteNever());
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
}
|
}
|
||||||
@@ -395,12 +393,12 @@ namespace ams::kern::arch::arm64::init {
|
|||||||
if (util::IsAligned(GetInteger(virt_addr), L3ContiguousBlockSize) && util::IsAligned(GetInteger(phys_addr), L3ContiguousBlockSize) && size >= L3ContiguousBlockSize) {
|
if (util::IsAligned(GetInteger(virt_addr), L3ContiguousBlockSize) && util::IsAligned(GetInteger(phys_addr), L3ContiguousBlockSize) && size >= L3ContiguousBlockSize) {
|
||||||
for (size_t i = 0; i < L3ContiguousBlockSize / L3BlockSize; i++) {
|
for (size_t i = 0; i < L3ContiguousBlockSize / L3BlockSize; i++) {
|
||||||
l3_entry[i] = L3PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, attr, PageTableEntry::SoftwareReservedBit_None, true);
|
l3_entry[i] = L3PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, attr, PageTableEntry::SoftwareReservedBit_None, true);
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
|
||||||
|
|
||||||
virt_addr += L3BlockSize;
|
virt_addr += L3BlockSize;
|
||||||
phys_addr += L3BlockSize;
|
phys_addr += L3BlockSize;
|
||||||
size -= L3BlockSize;
|
size -= L3BlockSize;
|
||||||
}
|
}
|
||||||
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
/* TODO: Different header for this? */
|
/* TODO: Different header for this? */
|
||||||
#define AMS_KERN_NUM_SUPERVISOR_CALLS 0xC0
|
#define AMS_KERN_NUM_SUPERVISOR_CALLS 0xC0
|
||||||
|
|
||||||
|
/* ams::kern::KThread, https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp */
|
||||||
|
#define THREAD_THREAD_CONTEXT 0xD0
|
||||||
|
|
||||||
/* ams::kern::KThread::StackParameters, https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp */
|
/* ams::kern::KThread::StackParameters, https://github.com/Atmosphere-NX/Atmosphere/blob/master/libraries/libmesosphere/include/mesosphere/kern_k_thread.hpp */
|
||||||
#define THREAD_STACK_PARAMETERS_SIZE 0x30
|
#define THREAD_STACK_PARAMETERS_SIZE 0x30
|
||||||
#define THREAD_STACK_PARAMETERS_SVC_PERMISSION 0x00
|
#define THREAD_STACK_PARAMETERS_SVC_PERMISSION 0x00
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ namespace ams::kern::arch::arm64::cpu {
|
|||||||
__asm__ __volatile__("isb" ::: "memory");
|
__asm__ __volatile__("isb" ::: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE void EnsureInstructionConsistencyInnerShareable() {
|
||||||
|
DataSynchronizationBarrierInnerShareable();
|
||||||
|
InstructionMemoryBarrier();
|
||||||
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void EnsureInstructionConsistency() {
|
ALWAYS_INLINE void EnsureInstructionConsistency() {
|
||||||
DataSynchronizationBarrier();
|
DataSynchronizationBarrier();
|
||||||
InstructionMemoryBarrier();
|
InstructionMemoryBarrier();
|
||||||
@@ -177,7 +182,6 @@ namespace ams::kern::arch::arm64::cpu {
|
|||||||
NOINLINE void SynchronizeAllCores();
|
NOINLINE void SynchronizeAllCores();
|
||||||
|
|
||||||
/* Cache management helpers. */
|
/* Cache management helpers. */
|
||||||
void ClearPageToZeroImpl(void *);
|
|
||||||
void StoreEntireCacheForInit();
|
void StoreEntireCacheForInit();
|
||||||
void FlushEntireCacheForInit();
|
void FlushEntireCacheForInit();
|
||||||
|
|
||||||
@@ -190,10 +194,16 @@ namespace ams::kern::arch::arm64::cpu {
|
|||||||
|
|
||||||
void InvalidateEntireInstructionCache();
|
void InvalidateEntireInstructionCache();
|
||||||
|
|
||||||
ALWAYS_INLINE void ClearPageToZero(void *page) {
|
ALWAYS_INLINE void ClearPageToZero(void * const page) {
|
||||||
MESOSPHERE_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(page), PageSize));
|
MESOSPHERE_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(page), PageSize));
|
||||||
MESOSPHERE_ASSERT(page != nullptr);
|
MESOSPHERE_ASSERT(page != nullptr);
|
||||||
ClearPageToZeroImpl(page);
|
|
||||||
|
uintptr_t cur = reinterpret_cast<uintptr_t>(__builtin_assume_aligned(page, PageSize));
|
||||||
|
const uintptr_t last = cur + PageSize - DataCacheLineSize;
|
||||||
|
|
||||||
|
for (/* ... */; cur <= last; cur += DataCacheLineSize) {
|
||||||
|
__asm__ __volatile__("dc zva, %[cur]" :: [cur]"r"(cur) : "memory");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void InvalidateTlbByAsid(u32 asid) {
|
ALWAYS_INLINE void InvalidateTlbByAsid(u32 asid) {
|
||||||
@@ -213,6 +223,11 @@ namespace ams::kern::arch::arm64::cpu {
|
|||||||
EnsureInstructionConsistency();
|
EnsureInstructionConsistency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE void InvalidateEntireTlbInnerShareable() {
|
||||||
|
__asm__ __volatile__("tlbi vmalle1is" ::: "memory");
|
||||||
|
EnsureInstructionConsistencyInnerShareable();
|
||||||
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE void InvalidateEntireTlbDataOnly() {
|
ALWAYS_INLINE void InvalidateEntireTlbDataOnly() {
|
||||||
__asm__ __volatile__("tlbi vmalle1is" ::: "memory");
|
__asm__ __volatile__("tlbi vmalle1is" ::: "memory");
|
||||||
DataSynchronizationBarrier();
|
DataSynchronizationBarrier();
|
||||||
|
|||||||
@@ -105,35 +105,48 @@ namespace ams::kern::arch::arm64 {
|
|||||||
Result UnbindLocal(s32 irq);
|
Result UnbindLocal(s32 irq);
|
||||||
Result ClearGlobal(s32 irq);
|
Result ClearGlobal(s32 irq);
|
||||||
Result ClearLocal(s32 irq);
|
Result ClearLocal(s32 irq);
|
||||||
public:
|
private:
|
||||||
static ALWAYS_INLINE u32 DisableInterrupts() {
|
[[nodiscard]] static ALWAYS_INLINE u32 GetInterruptsEnabledState() {
|
||||||
u64 intr_state;
|
u64 intr_state;
|
||||||
__asm__ __volatile__("mrs %[intr_state], daif\n"
|
__asm__ __volatile__("mrs %[intr_state], daif\n"
|
||||||
"msr daifset, #2"
|
"ubfx %[intr_state], %[intr_state], #7, #1"
|
||||||
: [intr_state]"=r"(intr_state)
|
: [intr_state]"=r"(intr_state)
|
||||||
:: "memory");
|
:: "memory");
|
||||||
return intr_state;
|
return intr_state;
|
||||||
}
|
}
|
||||||
|
public:
|
||||||
|
static ALWAYS_INLINE void EnableInterrupts() {
|
||||||
|
__asm__ __volatile__("msr daifclr, #2" ::: "memory");
|
||||||
|
}
|
||||||
|
|
||||||
static ALWAYS_INLINE u32 EnableInterrupts() {
|
static ALWAYS_INLINE void DisableInterrupts() {
|
||||||
u64 intr_state;
|
__asm__ __volatile__("msr daifset, #2" ::: "memory");
|
||||||
__asm__ __volatile__("mrs %[intr_state], daif\n"
|
}
|
||||||
"msr daifclr, #2"
|
|
||||||
: [intr_state]"=r"(intr_state)
|
[[nodiscard]] static ALWAYS_INLINE u32 GetInterruptsEnabledStateAndDisableInterrupts() {
|
||||||
:: "memory");
|
const auto intr_state = GetInterruptsEnabledState();
|
||||||
|
DisableInterrupts();
|
||||||
|
return intr_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static ALWAYS_INLINE u32 GetInterruptsEnabledStateAndEnableInterrupts() {
|
||||||
|
const auto intr_state = GetInterruptsEnabledState();
|
||||||
|
EnableInterrupts();
|
||||||
return intr_state;
|
return intr_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ALWAYS_INLINE void RestoreInterrupts(u32 intr_state) {
|
static ALWAYS_INLINE void RestoreInterrupts(u32 intr_state) {
|
||||||
u64 cur_state;
|
u64 tmp;
|
||||||
__asm__ __volatile__("mrs %[cur_state], daif" : [cur_state]"=r"(cur_state));
|
__asm__ __volatile__("mrs %[tmp], daif\n"
|
||||||
__asm__ __volatile__("msr daif, %[intr_state]" :: [intr_state]"r"((cur_state & ~0x80ul) | (intr_state & 0x80)));
|
"bfi %[tmp], %[intr_state], #7, #1\n"
|
||||||
|
"msr daif, %[tmp]"
|
||||||
|
: [tmp]"=&r"(tmp)
|
||||||
|
: [intr_state]"r"(intr_state)
|
||||||
|
: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
static ALWAYS_INLINE bool AreInterruptsEnabled() {
|
static ALWAYS_INLINE bool AreInterruptsEnabled() {
|
||||||
u64 intr_state;
|
return GetInterruptsEnabledState() == 0;
|
||||||
__asm__ __volatile__("mrs %[intr_state], daif" : [intr_state]"=r"(intr_state));
|
|
||||||
return (intr_state & 0x80) == 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -219,27 +219,27 @@ namespace ams::kern::arch::arm64 {
|
|||||||
|
|
||||||
Result ChangePermissions(KProcessAddress virt_addr, size_t num_pages, PageTableEntry entry_template, DisableMergeAttribute disable_merge_attr, bool refresh_mapping, PageLinkedList *page_list, bool reuse_ll);
|
Result ChangePermissions(KProcessAddress virt_addr, size_t num_pages, PageTableEntry entry_template, DisableMergeAttribute disable_merge_attr, bool refresh_mapping, PageLinkedList *page_list, bool reuse_ll);
|
||||||
|
|
||||||
static void PteDataSynchronizationBarrier() {
|
static ALWAYS_INLINE void PteDataSynchronizationBarrier() {
|
||||||
cpu::DataSynchronizationBarrierInnerShareable();
|
cpu::DataSynchronizationBarrierInnerShareable();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ClearPageTable(KVirtualAddress table) {
|
static ALWAYS_INLINE void ClearPageTable(KVirtualAddress table) {
|
||||||
cpu::ClearPageToZero(GetVoidPointer(table));
|
cpu::ClearPageToZero(GetVoidPointer(table));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTableUpdated() const {
|
ALWAYS_INLINE void OnTableUpdated() const {
|
||||||
cpu::InvalidateTlbByAsid(m_asid);
|
cpu::InvalidateTlbByAsid(m_asid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnKernelTableUpdated() const {
|
ALWAYS_INLINE void OnKernelTableUpdated() const {
|
||||||
cpu::InvalidateEntireTlbDataOnly();
|
cpu::InvalidateEntireTlbDataOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnKernelTableSinglePageUpdated(KProcessAddress virt_addr) const {
|
ALWAYS_INLINE void OnKernelTableSinglePageUpdated(KProcessAddress virt_addr) const {
|
||||||
cpu::InvalidateTlbByVaDataOnly(virt_addr);
|
cpu::InvalidateTlbByVaDataOnly(virt_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoteUpdated() const {
|
ALWAYS_INLINE void NoteUpdated() const {
|
||||||
cpu::DataSynchronizationBarrier();
|
cpu::DataSynchronizationBarrier();
|
||||||
|
|
||||||
if (this->IsKernel()) {
|
if (this->IsKernel()) {
|
||||||
@@ -249,7 +249,7 @@ namespace ams::kern::arch::arm64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NoteSingleKernelPageUpdated(KProcessAddress virt_addr) const {
|
ALWAYS_INLINE void NoteSingleKernelPageUpdated(KProcessAddress virt_addr) const {
|
||||||
MESOSPHERE_ASSERT(this->IsKernel());
|
MESOSPHERE_ASSERT(this->IsKernel());
|
||||||
|
|
||||||
cpu::DataSynchronizationBarrier();
|
cpu::DataSynchronizationBarrier();
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace ams::kern::arch::arm64 {
|
|||||||
|
|
||||||
/* Select L1 cache. */
|
/* Select L1 cache. */
|
||||||
cpu::SetCsselrEl1(0);
|
cpu::SetCsselrEl1(0);
|
||||||
|
cpu::InstructionMemoryBarrier();
|
||||||
|
|
||||||
/* Check that the L1 cache is not direct-mapped. */
|
/* Check that the L1 cache is not direct-mapped. */
|
||||||
return cpu::CacheSizeIdRegisterAccessor().GetAssociativity() != 0;
|
return cpu::CacheSizeIdRegisterAccessor().GetAssociativity() != 0;
|
||||||
|
|||||||
@@ -40,6 +40,12 @@
|
|||||||
/* of the right side, and so this does not actually cost any space. */
|
/* of the right side, and so this does not actually cost any space. */
|
||||||
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
#define MESOSPHERE_ENABLE_DEVIRTUALIZED_DYNAMIC_CAST
|
||||||
|
|
||||||
|
/* NOTE: This enables usage of KDebug handles as parameter for svc::GetInfo */
|
||||||
|
/* calls which require a process parameter. This enables a debugger to obtain */
|
||||||
|
/* address space/layout information, for example. However, it changes abi, and so */
|
||||||
|
/* this define allows toggling the extension. */
|
||||||
|
#define MESOSPHERE_ENABLE_GET_INFO_OF_DEBUG_PROCESS
|
||||||
|
|
||||||
/* NOTE: This uses currently-reserved bits inside the MapRange capability */
|
/* NOTE: This uses currently-reserved bits inside the MapRange capability */
|
||||||
/* in order to support large physical addresses (40-bit instead of 36). */
|
/* in order to support large physical addresses (40-bit instead of 36). */
|
||||||
/* This is toggleable in order to disable it if N ever uses those bits. */
|
/* This is toggleable in order to disable it if N ever uses those bits. */
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace ams::kern {
|
|||||||
return m_slab_heap->Allocate(m_page_allocator);
|
return m_slab_heap->Allocate(m_page_allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free(T *t) const {
|
ALWAYS_INLINE void Free(T *t) const {
|
||||||
m_slab_heap->Free(t);
|
m_slab_heap->Free(t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ namespace ams::kern {
|
|||||||
KThread *m_idle_thread;
|
KThread *m_idle_thread;
|
||||||
util::Atomic<KThread *> m_current_thread;
|
util::Atomic<KThread *> m_current_thread;
|
||||||
public:
|
public:
|
||||||
constexpr KScheduler() : m_state(), m_is_active(false), m_core_id(0), m_last_context_switch_time(0), m_idle_thread(nullptr), m_current_thread(nullptr)
|
constexpr KScheduler() : m_state(), m_is_active(false), m_core_id(0), m_last_context_switch_time(0), m_idle_thread(nullptr), m_current_thread(nullptr) {
|
||||||
{
|
|
||||||
m_state.needs_scheduling = true;
|
m_state.needs_scheduling = true;
|
||||||
m_state.interrupt_task_runnable = false;
|
m_state.interrupt_task_runnable = false;
|
||||||
m_state.should_count_idle = false;
|
m_state.should_count_idle = false;
|
||||||
@@ -211,18 +210,6 @@ namespace ams::kern {
|
|||||||
static consteval bool ValidateAssemblyOffsets();
|
static consteval bool ValidateAssemblyOffsets();
|
||||||
};
|
};
|
||||||
|
|
||||||
consteval bool KScheduler::ValidateAssemblyOffsets() {
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.needs_scheduling) == KSCHEDULER_NEEDS_SCHEDULING);
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_runnable) == KSCHEDULER_INTERRUPT_TASK_RUNNABLE);
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.highest_priority_thread) == KSCHEDULER_HIGHEST_PRIORITY_THREAD);
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.idle_thread_stack) == KSCHEDULER_IDLE_THREAD_STACK);
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.prev_thread) == KSCHEDULER_PREVIOUS_THREAD);
|
|
||||||
static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_manager) == KSCHEDULER_INTERRUPT_TASK_MANAGER);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
static_assert(KScheduler::ValidateAssemblyOffsets());
|
|
||||||
|
|
||||||
class KScopedSchedulerLock : KScopedLock<KScheduler::LockType> {
|
class KScopedSchedulerLock : KScopedLock<KScheduler::LockType> {
|
||||||
public:
|
public:
|
||||||
explicit ALWAYS_INLINE KScopedSchedulerLock() : KScopedLock(KScheduler::s_scheduler_lock) { /* ... */ }
|
explicit ALWAYS_INLINE KScopedSchedulerLock() : KScopedLock(KScheduler::s_scheduler_lock) { /* ... */ }
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <mesosphere/kern_common.hpp>
|
||||||
|
#include <mesosphere/kern_k_scheduler.hpp>
|
||||||
|
#include <mesosphere/kern_select_interrupt_manager.hpp>
|
||||||
|
|
||||||
|
namespace ams::kern {
|
||||||
|
|
||||||
|
/* NOTE: This header is included after all main headers. */
|
||||||
|
consteval bool KScheduler::ValidateAssemblyOffsets() {
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.needs_scheduling) == KSCHEDULER_NEEDS_SCHEDULING);
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_runnable) == KSCHEDULER_INTERRUPT_TASK_RUNNABLE);
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.highest_priority_thread) == KSCHEDULER_HIGHEST_PRIORITY_THREAD);
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.idle_thread_stack) == KSCHEDULER_IDLE_THREAD_STACK);
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.prev_thread) == KSCHEDULER_PREVIOUS_THREAD);
|
||||||
|
static_assert(AMS_OFFSETOF(KScheduler, m_state.interrupt_task_manager) == KSCHEDULER_INTERRUPT_TASK_MANAGER);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static_assert(KScheduler::ValidateAssemblyOffsets());
|
||||||
|
|
||||||
|
ALWAYS_INLINE void KScheduler::RescheduleOtherCores(u64 cores_needing_scheduling) {
|
||||||
|
if (const u64 core_mask = cores_needing_scheduling & ~(1ul << m_core_id); core_mask != 0) {
|
||||||
|
cpu::DataSynchronizationBarrier();
|
||||||
|
Kernel::GetInterruptManager().SendInterProcessorInterrupt(KInterruptName_Scheduler, core_mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -405,8 +405,6 @@ namespace ams::kern {
|
|||||||
constexpr ThreadState GetState() const { return static_cast<ThreadState>(m_thread_state & ThreadState_Mask); }
|
constexpr ThreadState GetState() const { return static_cast<ThreadState>(m_thread_state & ThreadState_Mask); }
|
||||||
constexpr ThreadState GetRawState() const { return m_thread_state; }
|
constexpr ThreadState GetRawState() const { return m_thread_state; }
|
||||||
|
|
||||||
NOINLINE KThreadContext *GetContextForSchedulerLoop();
|
|
||||||
|
|
||||||
constexpr uintptr_t GetConditionVariableKey() const { return m_condvar_key; }
|
constexpr uintptr_t GetConditionVariableKey() const { return m_condvar_key; }
|
||||||
constexpr uintptr_t GetAddressArbiterKey() const { return m_condvar_key; }
|
constexpr uintptr_t GetAddressArbiterKey() const { return m_condvar_key; }
|
||||||
|
|
||||||
@@ -624,9 +622,7 @@ namespace ams::kern {
|
|||||||
void OnTimer();
|
void OnTimer();
|
||||||
void DoWorkerTaskImpl();
|
void DoWorkerTaskImpl();
|
||||||
public:
|
public:
|
||||||
static constexpr bool IsConditionVariableThreadTreeValid() {
|
static consteval bool IsKThreadStructurallyValid();
|
||||||
return ConditionVariableThreadTreeTraits::IsValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
static KThread *GetThreadFromId(u64 thread_id);
|
static KThread *GetThreadFromId(u64 thread_id);
|
||||||
static Result GetThreadList(s32 *out_num_threads, ams::kern::svc::KUserPointer<u64 *> out_thread_ids, s32 max_out_count);
|
static Result GetThreadList(s32 *out_num_threads, ams::kern::svc::KUserPointer<u64 *> out_thread_ids, s32 max_out_count);
|
||||||
@@ -634,7 +630,18 @@ namespace ams::kern {
|
|||||||
using ConditionVariableThreadTreeType = ConditionVariableThreadTree;
|
using ConditionVariableThreadTreeType = ConditionVariableThreadTree;
|
||||||
};
|
};
|
||||||
static_assert(alignof(KThread) == 0x10);
|
static_assert(alignof(KThread) == 0x10);
|
||||||
static_assert(KThread::IsConditionVariableThreadTreeValid());
|
|
||||||
|
consteval bool KThread::IsKThreadStructurallyValid() {
|
||||||
|
/* Check that the condition variable tree is valid. */
|
||||||
|
static_assert(ConditionVariableThreadTreeTraits::IsValid());
|
||||||
|
|
||||||
|
/* Check that the assembly offsets are valid. */
|
||||||
|
static_assert(AMS_OFFSETOF(KThread, m_thread_context) == THREAD_THREAD_CONTEXT);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static_assert(KThread::IsKThreadStructurallyValid());
|
||||||
|
|
||||||
class KScopedDisableDispatch {
|
class KScopedDisableDispatch {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace ams::kern {
|
|||||||
private:
|
private:
|
||||||
u32 m_prev_intr_state;
|
u32 m_prev_intr_state;
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE KScopedInterruptDisable() : m_prev_intr_state(KInterruptManager::DisableInterrupts()) { /* ... */ }
|
ALWAYS_INLINE KScopedInterruptDisable() : m_prev_intr_state(KInterruptManager::GetInterruptsEnabledStateAndDisableInterrupts()) { /* ... */ }
|
||||||
ALWAYS_INLINE ~KScopedInterruptDisable() { KInterruptManager::RestoreInterrupts(m_prev_intr_state); }
|
ALWAYS_INLINE ~KScopedInterruptDisable() { KInterruptManager::RestoreInterrupts(m_prev_intr_state); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ namespace ams::kern {
|
|||||||
private:
|
private:
|
||||||
u32 m_prev_intr_state;
|
u32 m_prev_intr_state;
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE KScopedInterruptEnable() : m_prev_intr_state(KInterruptManager::EnableInterrupts()) { /* ... */ }
|
ALWAYS_INLINE KScopedInterruptEnable() : m_prev_intr_state(KInterruptManager::GetInterruptsEnabledStateAndEnableInterrupts()) { /* ... */ }
|
||||||
ALWAYS_INLINE ~KScopedInterruptEnable() { KInterruptManager::RestoreInterrupts(m_prev_intr_state); }
|
ALWAYS_INLINE ~KScopedInterruptEnable() { KInterruptManager::RestoreInterrupts(m_prev_intr_state); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace ams::kern::arch::arm64::cpu {
|
|||||||
|
|
||||||
class KPerformanceCounterInterruptHandler : public KInterruptHandler {
|
class KPerformanceCounterInterruptHandler : public KInterruptHandler {
|
||||||
private:
|
private:
|
||||||
static inline KLightLock s_lock;
|
static constinit inline KLightLock s_lock;
|
||||||
private:
|
private:
|
||||||
u64 m_counter;
|
u64 m_counter;
|
||||||
s32 m_which;
|
s32 m_which;
|
||||||
|
|||||||
@@ -61,139 +61,3 @@ _ZN3ams4kern4arch5arm643cpu23SynchronizeAllCoresImplEPii:
|
|||||||
5:
|
5:
|
||||||
stlr wzr, [x0]
|
stlr wzr, [x0]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
/* ams::kern::arch::arm64::cpu::ClearPageToZero(void *) */
|
|
||||||
.section .text._ZN3ams4kern4arch5arm643cpu19ClearPageToZeroImplEPv, "ax", %progbits
|
|
||||||
.global _ZN3ams4kern4arch5arm643cpu19ClearPageToZeroImplEPv
|
|
||||||
.type _ZN3ams4kern4arch5arm643cpu19ClearPageToZeroImplEPv, %function
|
|
||||||
_ZN3ams4kern4arch5arm643cpu19ClearPageToZeroImplEPv:
|
|
||||||
/* Efficiently clear the page using dc zva. */
|
|
||||||
dc zva, x0
|
|
||||||
add x8, x0, #0x040
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x080
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x0c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x100
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x140
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x180
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x1c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x200
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x240
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x280
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x2c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x300
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x340
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x380
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x3c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x400
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x440
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x480
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x4c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x500
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x540
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x580
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x5c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x600
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x640
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x680
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x6c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x700
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x740
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x780
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x7c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x800
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x840
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x880
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x8c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x900
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x940
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x980
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0x9c0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xa00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xa40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xa80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xac0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xb00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xb40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xb80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xbc0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xc00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xc40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xc80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xcc0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xd00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xd40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xd80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xdc0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xe00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xe40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xe80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xec0
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xf00
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xf40
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xf80
|
|
||||||
dc zva, x8
|
|
||||||
add x8, x0, #0xfc0
|
|
||||||
dc zva, x8
|
|
||||||
ret
|
|
||||||
@@ -225,7 +225,7 @@ namespace ams::kern::arch::arm64 {
|
|||||||
if (AMS_UNLIKELY(GetCurrentThread().IsSingleStep())) {
|
if (AMS_UNLIKELY(GetCurrentThread().IsSingleStep())) {
|
||||||
GetCurrentThread().ClearSingleStep();
|
GetCurrentThread().ClearSingleStep();
|
||||||
cpu::MonitorDebugSystemControlRegisterAccessor().SetSoftwareStep(false).Store();
|
cpu::MonitorDebugSystemControlRegisterAccessor().SetSoftwareStep(false).Store();
|
||||||
cpu::EnsureInstructionConsistency();
|
cpu::InstructionMemoryBarrier();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ namespace ams::kern::arch::arm64 {
|
|||||||
if (user_mode) {
|
if (user_mode) {
|
||||||
KThread *cur_thread = GetCurrentThreadPointer();
|
KThread *cur_thread = GetCurrentThreadPointer();
|
||||||
if (cur_thread->IsTerminationRequested()) {
|
if (cur_thread->IsTerminationRequested()) {
|
||||||
KScopedInterruptEnable ei;
|
EnableInterrupts();
|
||||||
cur_thread->Exit();
|
cur_thread->Exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,13 +212,14 @@ namespace ams::kern::arch::arm64 {
|
|||||||
|
|
||||||
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
||||||
|
|
||||||
KScopedInterruptDisable di;
|
|
||||||
|
|
||||||
if (KInterruptController::IsGlobal(irq)) {
|
if (KInterruptController::IsGlobal(irq)) {
|
||||||
|
KScopedInterruptDisable di;
|
||||||
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
||||||
return this->BindGlobal(handler, irq, core_id, priority, manual_clear, level);
|
return this->BindGlobal(handler, irq, core_id, priority, manual_clear, level);
|
||||||
} else {
|
} else {
|
||||||
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
||||||
|
|
||||||
|
KScopedInterruptDisable di;
|
||||||
return this->BindLocal(handler, irq, priority, manual_clear);
|
return this->BindLocal(handler, irq, priority, manual_clear);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,13 +229,16 @@ namespace ams::kern::arch::arm64 {
|
|||||||
|
|
||||||
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
||||||
|
|
||||||
KScopedInterruptDisable di;
|
|
||||||
|
|
||||||
if (KInterruptController::IsGlobal(irq)) {
|
if (KInterruptController::IsGlobal(irq)) {
|
||||||
|
KScopedInterruptDisable di;
|
||||||
|
|
||||||
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
||||||
return this->UnbindGlobal(irq);
|
return this->UnbindGlobal(irq);
|
||||||
} else {
|
} else {
|
||||||
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
||||||
|
|
||||||
|
KScopedInterruptDisable di;
|
||||||
return this->UnbindLocal(irq);
|
return this->UnbindLocal(irq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,13 +248,15 @@ namespace ams::kern::arch::arm64 {
|
|||||||
|
|
||||||
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
R_UNLESS(KInterruptController::IsGlobal(irq) || KInterruptController::IsLocal(irq), svc::ResultOutOfRange());
|
||||||
|
|
||||||
KScopedInterruptDisable di;
|
|
||||||
|
|
||||||
if (KInterruptController::IsGlobal(irq)) {
|
if (KInterruptController::IsGlobal(irq)) {
|
||||||
|
KScopedInterruptDisable di;
|
||||||
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
KScopedSpinLock lk(this->GetGlobalInterruptLock());
|
||||||
return this->ClearGlobal(irq);
|
return this->ClearGlobal(irq);
|
||||||
} else {
|
} else {
|
||||||
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
MESOSPHERE_ASSERT(core_id == GetCurrentCoreId());
|
||||||
|
|
||||||
|
KScopedInterruptDisable di;
|
||||||
return this->ClearLocal(irq);
|
return this->ClearLocal(irq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,10 +169,10 @@ namespace ams::kern::arch::arm64 {
|
|||||||
m_manager = std::addressof(Kernel::GetSystemPageTableManager());
|
m_manager = std::addressof(Kernel::GetSystemPageTableManager());
|
||||||
|
|
||||||
/* Allocate a page for ttbr. */
|
/* Allocate a page for ttbr. */
|
||||||
|
/* NOTE: It is a postcondition of page table manager allocation that the page is all-zero. */
|
||||||
const u64 asid_tag = (static_cast<u64>(m_asid) << 48ul);
|
const u64 asid_tag = (static_cast<u64>(m_asid) << 48ul);
|
||||||
const KVirtualAddress page = m_manager->Allocate();
|
const KVirtualAddress page = m_manager->Allocate();
|
||||||
MESOSPHERE_ASSERT(page != Null<KVirtualAddress>);
|
MESOSPHERE_ASSERT(page != Null<KVirtualAddress>);
|
||||||
cpu::ClearPageToZero(GetVoidPointer(page));
|
|
||||||
m_ttbr = GetInteger(KPageTableBase::GetLinearMappedPhysicalAddress(page)) | asid_tag;
|
m_ttbr = GetInteger(KPageTableBase::GetLinearMappedPhysicalAddress(page)) | asid_tag;
|
||||||
|
|
||||||
/* Initialize the base page table. */
|
/* Initialize the base page table. */
|
||||||
@@ -1058,7 +1058,7 @@ namespace ams::kern::arch::arm64 {
|
|||||||
auto sw_reserved_bits = PageTableEntry::EncodeSoftwareReservedBits(head_entry->IsHeadMergeDisabled(), head_entry->IsHeadAndBodyMergeDisabled(), tail_entry->IsTailMergeDisabled());
|
auto sw_reserved_bits = PageTableEntry::EncodeSoftwareReservedBits(head_entry->IsHeadMergeDisabled(), head_entry->IsHeadAndBodyMergeDisabled(), tail_entry->IsTailMergeDisabled());
|
||||||
|
|
||||||
/* Merge! */
|
/* Merge! */
|
||||||
PteDataSynchronizationBarrier();
|
/* NOTE: As of 13.1.0, Nintendo does not do: PteDataSynchronizationBarrier(); */
|
||||||
*l1_entry = L1PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, PageTableEntry(entry_template), sw_reserved_bits, false);
|
*l1_entry = L1PageTableEntry(PageTableEntry::BlockTag{}, phys_addr, PageTableEntry(entry_template), sw_reserved_bits, false);
|
||||||
|
|
||||||
/* Note that we updated. */
|
/* Note that we updated. */
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ _ZN3ams4kern3svc25CallReturnFromException64Ev:
|
|||||||
stp x20, x21, [sp, #(EXCEPTION_CONTEXT_X20_X21)]
|
stp x20, x21, [sp, #(EXCEPTION_CONTEXT_X20_X21)]
|
||||||
stp x22, x23, [sp, #(EXCEPTION_CONTEXT_X22_X23)]
|
stp x22, x23, [sp, #(EXCEPTION_CONTEXT_X22_X23)]
|
||||||
stp x24, x25, [sp, #(EXCEPTION_CONTEXT_X24_X25)]
|
stp x24, x25, [sp, #(EXCEPTION_CONTEXT_X24_X25)]
|
||||||
stp x26, x26, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
stp x26, x27, [sp, #(EXCEPTION_CONTEXT_X26_X27)]
|
||||||
stp x28, x29, [sp, #(EXCEPTION_CONTEXT_X28_X29)]
|
stp x28, x29, [sp, #(EXCEPTION_CONTEXT_X28_X29)]
|
||||||
|
|
||||||
/* Call ams::kern::arch::arm64::ReturnFromException(result). */
|
/* Call ams::kern::arch::arm64::ReturnFromException(result). */
|
||||||
|
|||||||
@@ -50,10 +50,6 @@ _ZN3ams4kern3svc26CallSendSyncRequestLight64Ev:
|
|||||||
.global _ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev
|
.global _ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev
|
||||||
.type _ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev, %function
|
.type _ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev, %function
|
||||||
_ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev:
|
_ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev:
|
||||||
/* Load x4-x7 from where the svc handler stores them. */
|
|
||||||
ldp x4, x5, [sp, #(8 * 0)]
|
|
||||||
ldp x6, x7, [sp, #(8 * 2)]
|
|
||||||
|
|
||||||
/* Allocate space for the light ipc data. */
|
/* Allocate space for the light ipc data. */
|
||||||
sub sp, sp, #(4 * 8)
|
sub sp, sp, #(4 * 8)
|
||||||
|
|
||||||
@@ -78,13 +74,8 @@ _ZN3ams4kern3svc32CallSendSyncRequestLight64From32Ev:
|
|||||||
/* Free the stack space for the light ipc data. */
|
/* Free the stack space for the light ipc data. */
|
||||||
add sp, sp, #(4 * 8)
|
add sp, sp, #(4 * 8)
|
||||||
|
|
||||||
/* Save x4-x7 to where the svc handler stores them. */
|
|
||||||
stp x4, x5, [sp, #(8 * 0)]
|
|
||||||
stp x6, x7, [sp, #(8 * 2)]
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
/* ams::kern::svc::CallReplyAndReceiveLight64() */
|
/* ams::kern::svc::CallReplyAndReceiveLight64() */
|
||||||
.section .text._ZN3ams4kern3svc26CallReplyAndReceiveLight64Ev, "ax", %progbits
|
.section .text._ZN3ams4kern3svc26CallReplyAndReceiveLight64Ev, "ax", %progbits
|
||||||
.global _ZN3ams4kern3svc26CallReplyAndReceiveLight64Ev
|
.global _ZN3ams4kern3svc26CallReplyAndReceiveLight64Ev
|
||||||
@@ -121,10 +112,6 @@ _ZN3ams4kern3svc26CallReplyAndReceiveLight64Ev:
|
|||||||
.global _ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev
|
.global _ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev
|
||||||
.type _ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev, %function
|
.type _ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev, %function
|
||||||
_ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev:
|
_ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev:
|
||||||
/* Load x4-x7 from where the svc handler stores them. */
|
|
||||||
ldp x4, x5, [sp, #(8 * 0)]
|
|
||||||
ldp x6, x7, [sp, #(8 * 2)]
|
|
||||||
|
|
||||||
/* Allocate space for the light ipc data. */
|
/* Allocate space for the light ipc data. */
|
||||||
sub sp, sp, #(4 * 8)
|
sub sp, sp, #(4 * 8)
|
||||||
|
|
||||||
@@ -149,8 +136,4 @@ _ZN3ams4kern3svc32CallReplyAndReceiveLight64From32Ev:
|
|||||||
/* Free the stack space for the light ipc data. */
|
/* Free the stack space for the light ipc data. */
|
||||||
add sp, sp, #(4 * 8)
|
add sp, sp, #(4 * 8)
|
||||||
|
|
||||||
/* Save x4-x7 to where the svc handler stores them. */
|
|
||||||
stp x4, x5, [sp, #(8 * 0)]
|
|
||||||
stp x6, x7, [sp, #(8 * 2)]
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace ams::kern::svc {
|
|||||||
|
|
||||||
/* Set omit-frame-pointer to prevent GCC from emitting MOV X29, SP instructions. */
|
/* Set omit-frame-pointer to prevent GCC from emitting MOV X29, SP instructions. */
|
||||||
#pragma GCC push_options
|
#pragma GCC push_options
|
||||||
#pragma GCC optimize ("-O2")
|
#pragma GCC optimize ("-O3")
|
||||||
#pragma GCC optimize ("omit-frame-pointer")
|
#pragma GCC optimize ("omit-frame-pointer")
|
||||||
|
|
||||||
AMS_SVC_FOREACH_KERN_DEFINITION(DECLARE_SVC_STRUCT, _)
|
AMS_SVC_FOREACH_KERN_DEFINITION(DECLARE_SVC_STRUCT, _)
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
ams::svc::DeviceName_Hda,
|
ams::svc::DeviceName_Hda,
|
||||||
ams::svc::DeviceName_Isp2,
|
ams::svc::DeviceName_Isp2,
|
||||||
ams::svc::DeviceName_Sata,
|
ams::svc::DeviceName_Sata,
|
||||||
|
ams::svc::DeviceName_Vi,
|
||||||
ams::svc::DeviceName_XusbHost,
|
ams::svc::DeviceName_XusbHost,
|
||||||
ams::svc::DeviceName_XusbDev,
|
ams::svc::DeviceName_XusbDev,
|
||||||
ams::svc::DeviceName_Tsec,
|
ams::svc::DeviceName_Tsec,
|
||||||
@@ -548,11 +549,11 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
|
|
||||||
/* Print the interrupt. */
|
/* Print the interrupt. */
|
||||||
{
|
{
|
||||||
constexpr auto GetBits = [] ALWAYS_INLINE_LAMBDA (u32 value, size_t ofs, size_t count) {
|
constexpr auto GetBits = [](u32 value, size_t ofs, size_t count) ALWAYS_INLINE_LAMBDA {
|
||||||
return (value >> ofs) & ((1u << count) - 1);
|
return (value >> ofs) & ((1u << count) - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto GetBit = [GetBits] ALWAYS_INLINE_LAMBDA (u32 value, size_t ofs) {
|
constexpr auto GetBit = [GetBits](u32 value, size_t ofs) ALWAYS_INLINE_LAMBDA {
|
||||||
return (value >> ofs) & 1u;
|
return (value >> ofs) & 1u;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -656,9 +657,8 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
MESOSPHERE_ASSERT(IsValidPhysicalAddress(table_phys_addr));
|
MESOSPHERE_ASSERT(IsValidPhysicalAddress(table_phys_addr));
|
||||||
Kernel::GetSystemPageTableManager().Open(table_virt_addr, 1);
|
Kernel::GetSystemPageTableManager().Open(table_virt_addr, 1);
|
||||||
|
|
||||||
/* Clear the page and save it. */
|
/* Save the page. Note that it is a pre-condition that the page is cleared, when allocated from the system page table manager. */
|
||||||
/* NOTE: Nintendo does not check the result of StoreDataCache. */
|
/* NOTE: Nintendo does not check the result of StoreDataCache. */
|
||||||
cpu::ClearPageToZero(GetVoidPointer(table_virt_addr));
|
|
||||||
cpu::StoreDataCache(GetVoidPointer(table_virt_addr), PageDirectorySize);
|
cpu::StoreDataCache(GetVoidPointer(table_virt_addr), PageDirectorySize);
|
||||||
g_reserved_table_phys_addr = table_phys_addr;
|
g_reserved_table_phys_addr = table_phys_addr;
|
||||||
|
|
||||||
|
|||||||
@@ -341,7 +341,9 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
|
|
||||||
/* Restore pmu registers. */
|
/* Restore pmu registers. */
|
||||||
cpu::SetPmUserEnrEl0(0);
|
cpu::SetPmUserEnrEl0(0);
|
||||||
cpu::PerformanceMonitorsControlRegisterAccessor().SetEventCounterReset(true).SetCycleCounterReset(true).Store();
|
cpu::PerformanceMonitorsControlRegisterAccessor(0).SetEventCounterReset(true).SetCycleCounterReset(true).Store();
|
||||||
|
cpu::EnsureInstructionConsistency();
|
||||||
|
|
||||||
cpu::SetPmOvsClrEl0(static_cast<u64>(static_cast<u32>(~u32())));
|
cpu::SetPmOvsClrEl0(static_cast<u64>(static_cast<u32>(~u32())));
|
||||||
cpu::SetPmIntEnClrEl1(static_cast<u64>(static_cast<u32>(~u32())));
|
cpu::SetPmIntEnClrEl1(static_cast<u64>(static_cast<u32>(~u32())));
|
||||||
cpu::SetPmCntEnClrEl0(static_cast<u64>(static_cast<u32>(~u32())));
|
cpu::SetPmCntEnClrEl0(static_cast<u64>(static_cast<u32>(~u32())));
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
|
|
||||||
size_t KSystemControl::Init::GetApplicationPoolSize() {
|
size_t KSystemControl::Init::GetApplicationPoolSize() {
|
||||||
/* Get the base pool size. */
|
/* Get the base pool size. */
|
||||||
const size_t base_pool_size = [] ALWAYS_INLINE_LAMBDA () -> size_t {
|
const size_t base_pool_size = []() ALWAYS_INLINE_LAMBDA -> size_t {
|
||||||
switch (GetMemoryArrangeForInit()) {
|
switch (GetMemoryArrangeForInit()) {
|
||||||
case smc::MemoryArrangement_4GB:
|
case smc::MemoryArrangement_4GB:
|
||||||
default:
|
default:
|
||||||
@@ -336,7 +336,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
|
|
||||||
size_t KSystemControl::Init::GetAppletPoolSize() {
|
size_t KSystemControl::Init::GetAppletPoolSize() {
|
||||||
/* Get the base pool size. */
|
/* Get the base pool size. */
|
||||||
const size_t base_pool_size = [] ALWAYS_INLINE_LAMBDA () -> size_t {
|
const size_t base_pool_size = []() ALWAYS_INLINE_LAMBDA -> size_t {
|
||||||
switch (GetMemoryArrangeForInit()) {
|
switch (GetMemoryArrangeForInit()) {
|
||||||
case smc::MemoryArrangement_4GB:
|
case smc::MemoryArrangement_4GB:
|
||||||
default:
|
default:
|
||||||
@@ -490,7 +490,7 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
|
|
||||||
|
|
||||||
if (AMS_LIKELY(s_initialized_random_generator)) {
|
if (AMS_LIKELY(s_initialized_random_generator)) {
|
||||||
return KSystemControlBase::GenerateUniformRange(min, max, [] ALWAYS_INLINE_LAMBDA () -> u64 { return s_random_generator.GenerateRandomU64(); });
|
return KSystemControlBase::GenerateUniformRange(min, max, []() ALWAYS_INLINE_LAMBDA -> u64 { return s_random_generator.GenerateRandomU64(); });
|
||||||
} else {
|
} else {
|
||||||
return KSystemControlBase::GenerateUniformRange(min, max, GenerateRandomU64FromSmc);
|
return KSystemControlBase::GenerateUniformRange(min, max, GenerateRandomU64FromSmc);
|
||||||
}
|
}
|
||||||
@@ -680,4 +680,4 @@ namespace ams::kern::board::nintendo::nx {
|
|||||||
Kernel::GetMemoryManager().Close(KPageTable::GetHeapPhysicalAddress(address), size / PageSize);
|
Kernel::GetMemoryManager().Close(KPageTable::GetHeapPhysicalAddress(address), size / PageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace ams::kern {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr std::tuple<KMemoryState, const char *> MemoryStateNames[] = {
|
constexpr const std::pair<KMemoryState, const char *> MemoryStateNames[] = {
|
||||||
{KMemoryState_Free , "----- Free -----"},
|
{KMemoryState_Free , "----- Free -----"},
|
||||||
{KMemoryState_Io , "Io "},
|
{KMemoryState_Io , "Io "},
|
||||||
{KMemoryState_Static , "Static "},
|
{KMemoryState_Static , "Static "},
|
||||||
@@ -41,6 +41,7 @@ namespace ams::kern {
|
|||||||
{KMemoryState_Kernel , "Kernel "},
|
{KMemoryState_Kernel , "Kernel "},
|
||||||
{KMemoryState_GeneratedCode , "GeneratedCode "},
|
{KMemoryState_GeneratedCode , "GeneratedCode "},
|
||||||
{KMemoryState_CodeOut , "CodeOut "},
|
{KMemoryState_CodeOut , "CodeOut "},
|
||||||
|
{KMemoryState_Coverage , "Coverage "},
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const char *GetMemoryStateName(KMemoryState state) {
|
constexpr const char *GetMemoryStateName(KMemoryState state) {
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ namespace ams::kern {
|
|||||||
static_assert(KMemoryManager::Pool_Secure == KMemoryManager::Pool_System);
|
static_assert(KMemoryManager::Pool_Secure == KMemoryManager::Pool_System);
|
||||||
|
|
||||||
/* Get Secure pool size. */
|
/* Get Secure pool size. */
|
||||||
const size_t secure_pool_size = [] ALWAYS_INLINE_LAMBDA (auto target_firmware) -> size_t {
|
const size_t secure_pool_size = [](auto target_firmware) ALWAYS_INLINE_LAMBDA -> size_t {
|
||||||
constexpr size_t LegacySecureKernelSize = 8_MB; /* KPageBuffer pages, other small kernel allocations. */
|
constexpr size_t LegacySecureKernelSize = 8_MB; /* KPageBuffer pages, other small kernel allocations. */
|
||||||
constexpr size_t LegacySecureMiscSize = 1_MB; /* Miscellaneous pages for secure process mapping. */
|
constexpr size_t LegacySecureMiscSize = 1_MB; /* Miscellaneous pages for secure process mapping. */
|
||||||
constexpr size_t LegacySecureHeapSize = 24_MB; /* Heap pages for secure process mapping (fs). */
|
constexpr size_t LegacySecureHeapSize = 24_MB; /* Heap pages for secure process mapping (fs). */
|
||||||
@@ -274,4 +274,4 @@ namespace ams::kern {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2398,7 +2398,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
@@ -2484,7 +2484,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
@@ -2943,7 +2943,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
@@ -3023,7 +3023,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
@@ -3092,7 +3092,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
@@ -3172,7 +3172,7 @@ namespace ams::kern {
|
|||||||
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
size_t cur_size = next_entry.block_size - (GetInteger(cur_addr) & (next_entry.block_size - 1));
|
||||||
size_t tot_size = cur_size;
|
size_t tot_size = cur_size;
|
||||||
|
|
||||||
auto PerformCopy = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
auto PerformCopy = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* Ensure the address is linear mapped. */
|
/* Ensure the address is linear mapped. */
|
||||||
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
R_UNLESS(IsLinearMappedPhysicalAddress(cur_addr), svc::ResultInvalidCurrentMemory());
|
||||||
|
|
||||||
|
|||||||
@@ -893,7 +893,7 @@ namespace ams::kern {
|
|||||||
size_t KProcess::GetTotalUserPhysicalMemorySize() const {
|
size_t KProcess::GetTotalUserPhysicalMemorySize() const {
|
||||||
/* Get the amount of free and used size. */
|
/* Get the amount of free and used size. */
|
||||||
const size_t free_size = m_resource_limit->GetFreeValue(ams::svc::LimitableResource_PhysicalMemoryMax);
|
const size_t free_size = m_resource_limit->GetFreeValue(ams::svc::LimitableResource_PhysicalMemoryMax);
|
||||||
const size_t used_size = this->GetUsedNonSystemUserPhysicalMemorySize();
|
const size_t used_size = this->GetUsedUserPhysicalMemorySize();
|
||||||
const size_t max_size = m_max_process_memory;
|
const size_t max_size = m_max_process_memory;
|
||||||
|
|
||||||
if (used_size + free_size > max_size) {
|
if (used_size + free_size > max_size) {
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
#include <mesosphere.hpp>
|
#include <mesosphere.hpp>
|
||||||
|
|
||||||
namespace ams::kern {
|
#pragma GCC push_options
|
||||||
|
#pragma GCC optimize ("-O3")
|
||||||
|
|
||||||
#pragma GCC push_options
|
namespace ams::kern {
|
||||||
#pragma GCC optimize ("-O3")
|
|
||||||
|
|
||||||
bool KScheduler::s_scheduler_update_needed;
|
bool KScheduler::s_scheduler_update_needed;
|
||||||
KScheduler::LockType KScheduler::s_scheduler_lock;
|
KScheduler::LockType KScheduler::s_scheduler_lock;
|
||||||
@@ -79,13 +79,6 @@ namespace ams::kern {
|
|||||||
RescheduleCurrentCore();
|
RescheduleCurrentCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::RescheduleOtherCores(u64 cores_needing_scheduling) {
|
|
||||||
if (const u64 core_mask = cores_needing_scheduling & ~(1ul << m_core_id); core_mask != 0) {
|
|
||||||
cpu::DataSynchronizationBarrier();
|
|
||||||
Kernel::GetInterruptManager().SendInterProcessorInterrupt(KInterruptName_Scheduler, core_mask);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 KScheduler::UpdateHighestPriorityThread(KThread *highest_thread) {
|
u64 KScheduler::UpdateHighestPriorityThread(KThread *highest_thread) {
|
||||||
if (KThread *prev_highest_thread = m_state.highest_priority_thread; AMS_LIKELY(prev_highest_thread != highest_thread)) {
|
if (KThread *prev_highest_thread = m_state.highest_priority_thread; AMS_LIKELY(prev_highest_thread != highest_thread)) {
|
||||||
if (AMS_LIKELY(prev_highest_thread != nullptr)) {
|
if (AMS_LIKELY(prev_highest_thread != nullptr)) {
|
||||||
@@ -254,6 +247,17 @@ namespace ams::kern {
|
|||||||
|
|
||||||
MESOSPHERE_KTRACE_THREAD_SWITCH(next_thread);
|
MESOSPHERE_KTRACE_THREAD_SWITCH(next_thread);
|
||||||
|
|
||||||
|
#if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP)
|
||||||
|
/* Ensure the single-step bit in mdscr reflects the correct single-step state for the new thread. */
|
||||||
|
/* NOTE: Per ARM docs, changing the single-step bit requires a "context synchronization event" to */
|
||||||
|
/* be sure that our new configuration takes. However, there are three types of synchronization event: */
|
||||||
|
/* Taking an exception, returning from an exception, and ISB. The single-step bit change only matters */
|
||||||
|
/* in EL0...which implies a return-from-exception has occurred since we set the bit. Thus, forcing */
|
||||||
|
/* an ISB is unnecessary, and we can modify the register safely and be confident it will affect the next */
|
||||||
|
/* userland instruction executed. */
|
||||||
|
cpu::MonitorDebugSystemControlRegisterAccessor().SetSoftwareStep(next_thread->IsSingleStep()).Store();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Switch the current process, if we're switching processes. */
|
/* Switch the current process, if we're switching processes. */
|
||||||
if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) {
|
if (KProcess *next_process = next_thread->GetOwnerProcess(); next_process != cur_process) {
|
||||||
KProcess::Switch(cur_process, next_process);
|
KProcess::Switch(cur_process, next_process);
|
||||||
@@ -594,6 +598,6 @@ namespace ams::kern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC pop_options
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
#include <mesosphere.hpp>
|
#include <mesosphere.hpp>
|
||||||
|
|
||||||
namespace ams::kern {
|
#pragma GCC push_options
|
||||||
|
#pragma GCC optimize ("-O3")
|
||||||
|
|
||||||
#pragma GCC push_options
|
namespace ams::kern {
|
||||||
#pragma GCC optimize ("-O3")
|
|
||||||
|
|
||||||
namespace ipc {
|
namespace ipc {
|
||||||
|
|
||||||
@@ -1385,8 +1385,6 @@ namespace ams::kern {
|
|||||||
this->NotifyAvailable(svc::ResultSessionClosed());
|
this->NotifyAvailable(svc::ResultSessionClosed());
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC pop_options
|
|
||||||
|
|
||||||
void KServerSession::Dump() {
|
void KServerSession::Dump() {
|
||||||
MESOSPHERE_ASSERT_THIS();
|
MESOSPHERE_ASSERT_THIS();
|
||||||
|
|
||||||
@@ -1420,3 +1418,5 @@ namespace ams::kern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ namespace ams::kern {
|
|||||||
s_initialized_random_generator = true;
|
s_initialized_random_generator = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return KSystemControlBase::GenerateUniformRange(min, max, [] ALWAYS_INLINE_LAMBDA () -> u64 { return s_random_generator.GenerateRandomU64(); });
|
return KSystemControlBase::GenerateUniformRange(min, max, []() ALWAYS_INLINE_LAMBDA -> u64 { return s_random_generator.GenerateRandomU64(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/* System Initialization. */
|
/* System Initialization. */
|
||||||
@@ -194,7 +194,7 @@ namespace ams::kern {
|
|||||||
KScopedInterruptDisable intr_disable;
|
KScopedInterruptDisable intr_disable;
|
||||||
KScopedSpinLock lk(s_random_lock);
|
KScopedSpinLock lk(s_random_lock);
|
||||||
|
|
||||||
return KSystemControlBase::GenerateUniformRange(min, max, [] ALWAYS_INLINE_LAMBDA () -> u64 { return s_random_generator.GenerateRandomU64(); });
|
return KSystemControlBase::GenerateUniformRange(min, max, []() ALWAYS_INLINE_LAMBDA -> u64 { return s_random_generator.GenerateRandomU64(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 KSystemControlBase::GenerateRandomU64() {
|
u64 KSystemControlBase::GenerateRandomU64() {
|
||||||
@@ -292,4 +292,4 @@ namespace ams::kern {
|
|||||||
Kernel::GetMemoryManager().Close(KPageTable::GetHeapPhysicalAddress(address), size / PageSize);
|
Kernel::GetMemoryManager().Close(KPageTable::GetHeapPhysicalAddress(address), size / PageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1183,7 +1183,7 @@ namespace ams::kern {
|
|||||||
KScopedSchedulerLock sl;
|
KScopedSchedulerLock sl;
|
||||||
|
|
||||||
/* Determine if this is the first termination request. */
|
/* Determine if this is the first termination request. */
|
||||||
const bool first_request = [&] ALWAYS_INLINE_LAMBDA () -> bool {
|
const bool first_request = [&]() ALWAYS_INLINE_LAMBDA -> bool {
|
||||||
/* Perform an atomic compare-and-swap from false to true. */
|
/* Perform an atomic compare-and-swap from false to true. */
|
||||||
bool expected = false;
|
bool expected = false;
|
||||||
return m_termination_requested.CompareExchangeStrong(expected, true);
|
return m_termination_requested.CompareExchangeStrong(expected, true);
|
||||||
@@ -1315,10 +1315,6 @@ namespace ams::kern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KThreadContext *KThread::GetContextForSchedulerLoop() {
|
|
||||||
return std::addressof(this->GetContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
KThread *KThread::GetThreadFromId(u64 thread_id) {
|
KThread *KThread::GetThreadFromId(u64 thread_id) {
|
||||||
/* Lock the list. */
|
/* Lock the list. */
|
||||||
KThread::ListAccessor accessor;
|
KThread::ListAccessor accessor;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace ams::kern::svc {
|
|||||||
/* Check whether the address is aligned. */
|
/* Check whether the address is aligned. */
|
||||||
const bool aligned = util::IsAligned(phys_addr, PageSize);
|
const bool aligned = util::IsAligned(phys_addr, PageSize);
|
||||||
|
|
||||||
auto QueryIoMappingFromPageTable = [&] ALWAYS_INLINE_LAMBDA (uint64_t phys_addr, size_t size) -> Result {
|
auto QueryIoMappingFromPageTable = [&](uint64_t phys_addr, size_t size) ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
/* The size must be non-zero. */
|
/* The size must be non-zero. */
|
||||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||||
|
|
||||||
|
|||||||
@@ -277,6 +277,9 @@ namespace ams::kern::svc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result WriteDebugProcessMemory(ams::svc::Handle debug_handle, uintptr_t buffer, uintptr_t address, size_t size) {
|
Result WriteDebugProcessMemory(ams::svc::Handle debug_handle, uintptr_t buffer, uintptr_t address, size_t size) {
|
||||||
|
/* Only allow invoking the svc on development hardware. */
|
||||||
|
R_UNLESS(KTargetSystem::IsDebugMode(), svc::ResultNotImplemented());
|
||||||
|
|
||||||
/* Validate address / size. */
|
/* Validate address / size. */
|
||||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||||
R_UNLESS((address < address + size), svc::ResultInvalidCurrentMemory());
|
R_UNLESS((address < address + size), svc::ResultInvalidCurrentMemory());
|
||||||
|
|||||||
@@ -38,6 +38,80 @@ namespace ams::kern::svc {
|
|||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result GetInfoImpl(u64 *out, ams::svc::InfoType info_type, KProcess *process) {
|
||||||
|
switch (info_type) {
|
||||||
|
case ams::svc::InfoType_CoreMask:
|
||||||
|
*out = process->GetCoreMask();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_PriorityMask:
|
||||||
|
*out = process->GetPriorityMask();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_AliasRegionAddress:
|
||||||
|
*out = GetInteger(process->GetPageTable().GetAliasRegionStart());
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_AliasRegionSize:
|
||||||
|
*out = process->GetPageTable().GetAliasRegionSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_HeapRegionAddress:
|
||||||
|
*out = GetInteger(process->GetPageTable().GetHeapRegionStart());
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_HeapRegionSize:
|
||||||
|
*out = process->GetPageTable().GetHeapRegionSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_TotalMemorySize:
|
||||||
|
*out = process->GetTotalUserPhysicalMemorySize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_UsedMemorySize:
|
||||||
|
*out = process->GetUsedUserPhysicalMemorySize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_AslrRegionAddress:
|
||||||
|
*out = GetInteger(process->GetPageTable().GetAliasCodeRegionStart());
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_AslrRegionSize:
|
||||||
|
*out = process->GetPageTable().GetAliasCodeRegionSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_StackRegionAddress:
|
||||||
|
*out = GetInteger(process->GetPageTable().GetStackRegionStart());
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_StackRegionSize:
|
||||||
|
*out = process->GetPageTable().GetStackRegionSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_SystemResourceSizeTotal:
|
||||||
|
*out = process->GetTotalSystemResourceSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_SystemResourceSizeUsed:
|
||||||
|
*out = process->GetUsedSystemResourceSize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_ProgramId:
|
||||||
|
*out = process->GetProgramId();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_UserExceptionContextAddress:
|
||||||
|
*out = GetInteger(process->GetProcessLocalRegionAddress());
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
||||||
|
*out = process->GetTotalNonSystemUserPhysicalMemorySize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
||||||
|
*out = process->GetUsedNonSystemUserPhysicalMemorySize();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_IsApplication:
|
||||||
|
*out = process->IsApplication();
|
||||||
|
break;
|
||||||
|
case ams::svc::InfoType_FreeThreadCount:
|
||||||
|
if (KResourceLimit *resource_limit = process->GetResourceLimit(); resource_limit != nullptr) {
|
||||||
|
const auto current_value = resource_limit->GetCurrentValue(ams::svc::LimitableResource_ThreadCountMax);
|
||||||
|
const auto limit_value = resource_limit->GetLimitValue(ams::svc::LimitableResource_ThreadCountMax);
|
||||||
|
*out = limit_value - current_value;
|
||||||
|
} else {
|
||||||
|
*out = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
Result GetInfo(u64 *out, ams::svc::InfoType info_type, ams::svc::Handle handle, u64 info_subtype) {
|
Result GetInfo(u64 *out, ams::svc::InfoType info_type, ams::svc::Handle handle, u64 info_subtype) {
|
||||||
switch (info_type) {
|
switch (info_type) {
|
||||||
case ams::svc::InfoType_CoreMask:
|
case ams::svc::InfoType_CoreMask:
|
||||||
@@ -66,77 +140,34 @@ namespace ams::kern::svc {
|
|||||||
|
|
||||||
/* Get the process from its handle. */
|
/* Get the process from its handle. */
|
||||||
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(handle);
|
KScopedAutoObject process = GetCurrentProcess().GetHandleTable().GetObject<KProcess>(handle);
|
||||||
|
|
||||||
|
#if defined(MESOSPHERE_ENABLE_GET_INFO_OF_DEBUG_PROCESS)
|
||||||
|
/* If we the process is valid, use it. */
|
||||||
|
if (process.IsNotNull()) {
|
||||||
|
return GetInfoImpl(out, info_type, process.GetPointerUnsafe());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, as a mesosphere extension check if we were passed a usable KDebug. */
|
||||||
|
KScopedAutoObject debug = GetCurrentProcess().GetHandleTable().GetObject<KDebug>(handle);
|
||||||
|
R_UNLESS(debug.IsNotNull(), svc::ResultInvalidHandle());
|
||||||
|
|
||||||
|
/* Get the process from the debug object. */
|
||||||
|
/* TODO: ResultInvalidHandle()? */
|
||||||
|
R_UNLESS(debug->IsAttached(), svc::ResultProcessTerminated());
|
||||||
|
R_UNLESS(debug->OpenProcess(), svc::ResultProcessTerminated());
|
||||||
|
|
||||||
|
/* Close the process when we're done. */
|
||||||
|
ON_SCOPE_EXIT { debug->CloseProcess(); };
|
||||||
|
|
||||||
|
/* Return the info. */
|
||||||
|
return GetInfoImpl(out, info_type, debug->GetProcessUnsafe());
|
||||||
|
#else
|
||||||
|
/* Verify that the process is valid. */
|
||||||
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
R_UNLESS(process.IsNotNull(), svc::ResultInvalidHandle());
|
||||||
|
|
||||||
switch (info_type) {
|
/* Return the relevant info. */
|
||||||
case ams::svc::InfoType_CoreMask:
|
return GetInfoImpl(out, info_type, process.GetPointerUnsafe());
|
||||||
*out = process->GetCoreMask();
|
#endif
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_PriorityMask:
|
|
||||||
*out = process->GetPriorityMask();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_AliasRegionAddress:
|
|
||||||
*out = GetInteger(process->GetPageTable().GetAliasRegionStart());
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_AliasRegionSize:
|
|
||||||
*out = process->GetPageTable().GetAliasRegionSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_HeapRegionAddress:
|
|
||||||
*out = GetInteger(process->GetPageTable().GetHeapRegionStart());
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_HeapRegionSize:
|
|
||||||
*out = process->GetPageTable().GetHeapRegionSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_TotalMemorySize:
|
|
||||||
*out = process->GetTotalUserPhysicalMemorySize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_UsedMemorySize:
|
|
||||||
*out = process->GetUsedUserPhysicalMemorySize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_AslrRegionAddress:
|
|
||||||
*out = GetInteger(process->GetPageTable().GetAliasCodeRegionStart());
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_AslrRegionSize:
|
|
||||||
*out = process->GetPageTable().GetAliasCodeRegionSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_StackRegionAddress:
|
|
||||||
*out = GetInteger(process->GetPageTable().GetStackRegionStart());
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_StackRegionSize:
|
|
||||||
*out = process->GetPageTable().GetStackRegionSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_SystemResourceSizeTotal:
|
|
||||||
*out = process->GetTotalSystemResourceSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_SystemResourceSizeUsed:
|
|
||||||
*out = process->GetUsedSystemResourceSize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_ProgramId:
|
|
||||||
*out = process->GetProgramId();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_UserExceptionContextAddress:
|
|
||||||
*out = GetInteger(process->GetProcessLocalRegionAddress());
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_TotalNonSystemMemorySize:
|
|
||||||
*out = process->GetTotalNonSystemUserPhysicalMemorySize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
|
||||||
*out = process->GetUsedNonSystemUserPhysicalMemorySize();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_IsApplication:
|
|
||||||
*out = process->IsApplication();
|
|
||||||
break;
|
|
||||||
case ams::svc::InfoType_FreeThreadCount:
|
|
||||||
if (KResourceLimit *resource_limit = process->GetResourceLimit(); resource_limit != nullptr) {
|
|
||||||
const auto current_value = resource_limit->GetCurrentValue(ams::svc::LimitableResource_ThreadCountMax);
|
|
||||||
const auto limit_value = resource_limit->GetLimitValue(ams::svc::LimitableResource_ThreadCountMax);
|
|
||||||
*out = limit_value - current_value;
|
|
||||||
} else {
|
|
||||||
*out = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ams::svc::InfoType_DebuggerAttached:
|
case ams::svc::InfoType_DebuggerAttached:
|
||||||
|
|||||||
@@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
#include <mesosphere.hpp>
|
#include <mesosphere.hpp>
|
||||||
|
|
||||||
namespace ams::kern::svc {
|
#pragma GCC push_options
|
||||||
|
#pragma GCC optimize ("-O3")
|
||||||
|
|
||||||
#pragma GCC push_options
|
namespace ams::kern::svc {
|
||||||
#pragma GCC optimize ("-O3")
|
|
||||||
|
|
||||||
/* ============================= Common ============================= */
|
/* ============================= Common ============================= */
|
||||||
|
|
||||||
@@ -315,6 +315,6 @@ namespace ams::kern::svc {
|
|||||||
return ReplyAndReceiveWithUserBuffer(out_index, message_buffer, message_buffer_size, handles, num_handles, reply_target, timeout_ns);
|
return ReplyAndReceiveWithUserBuffer(out_index, message_buffer, message_buffer_size, handles, num_handles, reply_target, timeout_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma GCC pop_options
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ namespace ams::kern::svc {
|
|||||||
KResourceLimit *process_resource_limit = resource_limit.IsNotNull() ? resource_limit.GetPointerUnsafe() : std::addressof(Kernel::GetSystemResourceLimit());
|
KResourceLimit *process_resource_limit = resource_limit.IsNotNull() ? resource_limit.GetPointerUnsafe() : std::addressof(Kernel::GetSystemResourceLimit());
|
||||||
|
|
||||||
/* Get the pool for the process. */
|
/* Get the pool for the process. */
|
||||||
const auto pool = [] ALWAYS_INLINE_LAMBDA (u32 flags) -> KMemoryManager::Pool {
|
const auto pool = [](u32 flags) ALWAYS_INLINE_LAMBDA -> KMemoryManager::Pool {
|
||||||
if (GetTargetFirmware() >= TargetFirmware_5_0_0) {
|
if (GetTargetFirmware() >= TargetFirmware_5_0_0) {
|
||||||
switch (flags & ams::svc::CreateProcessFlag_PoolPartitionMask) {
|
switch (flags & ams::svc::CreateProcessFlag_PoolPartitionMask) {
|
||||||
case ams::svc::CreateProcessFlag_PoolPartitionApplication:
|
case ams::svc::CreateProcessFlag_PoolPartitionApplication:
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace ams::impl {
|
|||||||
AMS_DEFINE_SYSTEM_THREAD(-7, mitm, InitializeThread);
|
AMS_DEFINE_SYSTEM_THREAD(-7, mitm, InitializeThread);
|
||||||
AMS_DEFINE_SYSTEM_THREAD(-1, mitm_sf, QueryServerProcessThread);
|
AMS_DEFINE_SYSTEM_THREAD(-1, mitm_sf, QueryServerProcessThread);
|
||||||
AMS_DEFINE_SYSTEM_THREAD(16, mitm_fs, RomFileSystemInitializeThread);
|
AMS_DEFINE_SYSTEM_THREAD(16, mitm_fs, RomFileSystemInitializeThread);
|
||||||
|
AMS_DEFINE_SYSTEM_THREAD(16, mitm_fs, RomFileSystemFinalizeThread);
|
||||||
AMS_DEFINE_SYSTEM_THREAD(21, mitm, DebugThrowThread);
|
AMS_DEFINE_SYSTEM_THREAD(21, mitm, DebugThrowThread);
|
||||||
AMS_DEFINE_SYSTEM_THREAD(21, mitm_sysupdater, IpcServer);
|
AMS_DEFINE_SYSTEM_THREAD(21, mitm_sysupdater, IpcServer);
|
||||||
AMS_DEFINE_SYSTEM_THREAD(21, mitm_sysupdater, AsyncPrepareSdCardUpdateTask);
|
AMS_DEFINE_SYSTEM_THREAD(21, mitm_sysupdater, AsyncPrepareSdCardUpdateTask);
|
||||||
|
|||||||
@@ -118,12 +118,12 @@ namespace ams::fssystem {
|
|||||||
|
|
||||||
/* Copy API. */
|
/* Copy API. */
|
||||||
Result CopyFile(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size);
|
Result CopyFile(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size);
|
||||||
NX_INLINE Result CopyFile(fs::fsa::IFileSystem *fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size) {
|
ALWAYS_INLINE Result CopyFile(fs::fsa::IFileSystem *fs, const char *dst_parent_path, const char *src_path, const fs::DirectoryEntry *dir_ent, void *work_buf, size_t work_buf_size) {
|
||||||
return CopyFile(fs, fs, dst_parent_path, src_path, dir_ent, work_buf, work_buf_size);
|
return CopyFile(fs, fs, dst_parent_path, src_path, dir_ent, work_buf, work_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size);
|
Result CopyDirectoryRecursively(fs::fsa::IFileSystem *dst_fs, fs::fsa::IFileSystem *src_fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size);
|
||||||
NX_INLINE Result CopyDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) {
|
ALWAYS_INLINE Result CopyDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *dst_path, const char *src_path, void *work_buf, size_t work_buf_size) {
|
||||||
return CopyDirectoryRecursively(fs, fs, dst_path, src_path, work_buf, work_buf_size);
|
return CopyDirectoryRecursively(fs, fs, dst_path, src_path, work_buf, work_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,11 +148,11 @@ namespace ams::fssystem {
|
|||||||
Result EnsureDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path);
|
Result EnsureDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path);
|
||||||
Result EnsureParentDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path);
|
Result EnsureParentDirectoryRecursively(fs::fsa::IFileSystem *fs, const char *path);
|
||||||
|
|
||||||
template<typename F>
|
template<s64 RetryMilliSeconds = 100>
|
||||||
NX_INLINE Result RetryFinitelyForTargetLocked(F f) {
|
ALWAYS_INLINE Result RetryFinitelyForTargetLocked(auto f) {
|
||||||
/* Retry up to 10 times, 100ms between retries. */
|
/* Retry up to 10 times, 100ms between retries. */
|
||||||
constexpr s32 MaxRetryCount = 10;
|
constexpr s32 MaxRetryCount = 10;
|
||||||
constexpr TimeSpan RetryWaitTime = TimeSpan::FromMilliSeconds(100);
|
constexpr TimeSpan RetryWaitTime = TimeSpan::FromMilliSeconds(RetryMilliSeconds);
|
||||||
|
|
||||||
s32 remaining_retries = MaxRetryCount;
|
s32 remaining_retries = MaxRetryCount;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ namespace ams::hos {
|
|||||||
Version_12_0_3 = ::ams::TargetFirmware_12_0_3,
|
Version_12_0_3 = ::ams::TargetFirmware_12_0_3,
|
||||||
Version_12_1_0 = ::ams::TargetFirmware_12_1_0,
|
Version_12_1_0 = ::ams::TargetFirmware_12_1_0,
|
||||||
Version_13_0_0 = ::ams::TargetFirmware_13_0_0,
|
Version_13_0_0 = ::ams::TargetFirmware_13_0_0,
|
||||||
|
Version_13_1_0 = ::ams::TargetFirmware_13_1_0,
|
||||||
|
Version_13_2_0 = ::ams::TargetFirmware_13_2_0,
|
||||||
|
Version_13_2_1 = ::ams::TargetFirmware_13_2_1,
|
||||||
|
|
||||||
Version_Current = ::ams::TargetFirmware_Current,
|
Version_Current = ::ams::TargetFirmware_Current,
|
||||||
|
|
||||||
|
|||||||
@@ -62,20 +62,16 @@ namespace ams::settings {
|
|||||||
|
|
||||||
char name[MaxLength];
|
char name[MaxLength];
|
||||||
|
|
||||||
static constexpr LanguageCode Encode(const char *name, size_t name_size) {
|
static constexpr LanguageCode Encode(util::string_view name) {
|
||||||
LanguageCode out{};
|
LanguageCode out{};
|
||||||
for (size_t i = 0; i < MaxLength && i < name_size; i++) {
|
for (size_t i = 0; i < MaxLength && i < name.size(); i++) {
|
||||||
out.name[i] = name[i];
|
out.name[i] = name[i];
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr LanguageCode Encode(const char *name) {
|
|
||||||
return Encode(name, std::strlen(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<Language Lang>
|
template<Language Lang>
|
||||||
static constexpr inline LanguageCode EncodeLanguage = [] {
|
static constexpr inline LanguageCode EncodeLanguage() {
|
||||||
if constexpr (false) { /* ... */ }
|
if constexpr (false) { /* ... */ }
|
||||||
#define AMS_MATCH_LANGUAGE(lang, enc) else if constexpr (Lang == Language_##lang) { return LanguageCode::Encode(enc); }
|
#define AMS_MATCH_LANGUAGE(lang, enc) else if constexpr (Lang == Language_##lang) { return LanguageCode::Encode(enc); }
|
||||||
AMS_MATCH_LANGUAGE(Japanese, "ja")
|
AMS_MATCH_LANGUAGE(Japanese, "ja")
|
||||||
@@ -98,28 +94,28 @@ namespace ams::settings {
|
|||||||
AMS_MATCH_LANGUAGE(TraditionalChinese, "zh-Hant")
|
AMS_MATCH_LANGUAGE(TraditionalChinese, "zh-Hant")
|
||||||
#undef AMS_MATCH_LANGUAGE
|
#undef AMS_MATCH_LANGUAGE
|
||||||
else { static_assert(Lang != Language_Japanese); }
|
else { static_assert(Lang != Language_Japanese); }
|
||||||
}();
|
}
|
||||||
|
|
||||||
static constexpr inline LanguageCode Encode(const Language language) {
|
static constexpr inline LanguageCode Encode(const Language language) {
|
||||||
constexpr LanguageCode EncodedLanguages[Language_Count] = {
|
constexpr LanguageCode EncodedLanguages[Language_Count] = {
|
||||||
EncodeLanguage<Language_Japanese>,
|
EncodeLanguage<Language_Japanese>(),
|
||||||
EncodeLanguage<Language_AmericanEnglish>,
|
EncodeLanguage<Language_AmericanEnglish>(),
|
||||||
EncodeLanguage<Language_French>,
|
EncodeLanguage<Language_French>(),
|
||||||
EncodeLanguage<Language_German>,
|
EncodeLanguage<Language_German>(),
|
||||||
EncodeLanguage<Language_Italian>,
|
EncodeLanguage<Language_Italian>(),
|
||||||
EncodeLanguage<Language_Spanish>,
|
EncodeLanguage<Language_Spanish>(),
|
||||||
EncodeLanguage<Language_Chinese>,
|
EncodeLanguage<Language_Chinese>(),
|
||||||
EncodeLanguage<Language_Korean>,
|
EncodeLanguage<Language_Korean>(),
|
||||||
EncodeLanguage<Language_Dutch>,
|
EncodeLanguage<Language_Dutch>(),
|
||||||
EncodeLanguage<Language_Portuguese>,
|
EncodeLanguage<Language_Portuguese>(),
|
||||||
EncodeLanguage<Language_Russian>,
|
EncodeLanguage<Language_Russian>(),
|
||||||
EncodeLanguage<Language_Taiwanese>,
|
EncodeLanguage<Language_Taiwanese>(),
|
||||||
EncodeLanguage<Language_BritishEnglish>,
|
EncodeLanguage<Language_BritishEnglish>(),
|
||||||
EncodeLanguage<Language_CanadianFrench>,
|
EncodeLanguage<Language_CanadianFrench>(),
|
||||||
EncodeLanguage<Language_LatinAmericanSpanish>,
|
EncodeLanguage<Language_LatinAmericanSpanish>(),
|
||||||
/* 4.0.0+ */
|
/* 4.0.0+ */
|
||||||
EncodeLanguage<Language_SimplifiedChinese>,
|
EncodeLanguage<Language_SimplifiedChinese>(),
|
||||||
EncodeLanguage<Language_TraditionalChinese>,
|
EncodeLanguage<Language_TraditionalChinese>(),
|
||||||
};
|
};
|
||||||
return EncodedLanguages[language];
|
return EncodedLanguages[language];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ namespace ams::sf::cmif {
|
|||||||
|
|
||||||
void DisposeImpl();
|
void DisposeImpl();
|
||||||
|
|
||||||
virtual void AddReference() {
|
virtual void AddReference() override {
|
||||||
ServiceObjectImplBase2::AddReferenceImpl();
|
ServiceObjectImplBase2::AddReferenceImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Release() {
|
virtual void Release() override {
|
||||||
if (ServiceObjectImplBase2::ReleaseImpl()) {
|
if (ServiceObjectImplBase2::ReleaseImpl()) {
|
||||||
this->DisposeImpl();
|
this->DisposeImpl();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,16 +53,32 @@ namespace ams::sf::cmif {
|
|||||||
u32 cmd_id;
|
u32 cmd_id;
|
||||||
Result (*handler)(CmifOutHeader **out_header_ptr, ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data);
|
Result (*handler)(CmifOutHeader **out_header_ptr, ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data);
|
||||||
|
|
||||||
constexpr inline bool Matches(u32 cmd_id, hos::Version hosver) const {
|
constexpr inline bool MatchesVersion(hos::Version hosver) const {
|
||||||
const bool min_valid = this->hosver_low == hos::Version_Min;
|
const bool min_valid = this->hosver_low == hos::Version_Min;
|
||||||
const bool max_valid = this->hosver_high == hos::Version_Max;
|
const bool max_valid = this->hosver_high == hos::Version_Max;
|
||||||
|
|
||||||
return this->cmd_id == cmd_id && (min_valid || this->hosver_low <= hosver) && (max_valid || hosver <= this->hosver_high);
|
return (min_valid || this->hosver_low <= hosver) && (max_valid || hosver <= this->hosver_high);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline bool Matches(u32 cmd_id, hos::Version hosver) const {
|
||||||
|
return this->cmd_id == cmd_id && this->MatchesVersion(hosver);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline decltype(handler) GetHandler() const {
|
constexpr inline decltype(handler) GetHandler() const {
|
||||||
return this->handler;
|
return this->handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr inline bool operator>(const ServiceCommandMeta &rhs) const {
|
||||||
|
if (this->cmd_id > rhs.cmd_id) {
|
||||||
|
return true;
|
||||||
|
} else if (this->cmd_id == rhs.cmd_id && this->hosver_low > rhs.hosver_low) {
|
||||||
|
return true;
|
||||||
|
} else if (this->cmd_id == rhs.cmd_id && this->hosver_low == rhs.hosver_low && this->hosver_high == rhs.hosver_high){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
static_assert(util::is_pod<ServiceCommandMeta>::value && sizeof(ServiceCommandMeta) == 0x18, "sizeof(ServiceCommandMeta)");
|
static_assert(util::is_pod<ServiceCommandMeta>::value && sizeof(ServiceCommandMeta) == 0x18, "sizeof(ServiceCommandMeta)");
|
||||||
|
|
||||||
|
|||||||
@@ -85,16 +85,41 @@ namespace ams::sf::impl {
|
|||||||
constexpr const auto &BaseEntries = ::ams::sf::cmif::ServiceDispatchTraits<BASECLASS>::DispatchTable.GetEntries(); \
|
constexpr const auto &BaseEntries = ::ams::sf::cmif::ServiceDispatchTraits<BASECLASS>::DispatchTable.GetEntries(); \
|
||||||
constexpr size_t BaseSize = BaseEntries.size(); \
|
constexpr size_t BaseSize = BaseEntries.size(); \
|
||||||
\
|
\
|
||||||
std::array<::ams::sf::cmif::ServiceCommandMeta, BaseSize + CurSize> combined_entries{}; \
|
constexpr size_t CombinedSize = BaseSize + CurSize; \
|
||||||
for (size_t i = 0; i < BaseSize; ++i) { \
|
\
|
||||||
combined_entries[i] = BaseEntries[i]; \
|
std::array<size_t, CombinedSize> map{}; \
|
||||||
|
for (size_t i = 0; i < CombinedSize; ++i) { map[i] = i; } \
|
||||||
|
\
|
||||||
|
for (size_t i = 1; i < CombinedSize; ++i) { \
|
||||||
|
size_t j = i; \
|
||||||
|
while (j > 0) { \
|
||||||
|
const auto li = map[j]; \
|
||||||
|
const auto ri = map[j - 1]; \
|
||||||
|
\
|
||||||
|
const auto &lhs = (li < BaseSize) ? BaseEntries[li] : cur_entries[li - BaseSize]; \
|
||||||
|
const auto &rhs = (ri < BaseSize) ? BaseEntries[ri] : cur_entries[ri - BaseSize]; \
|
||||||
|
\
|
||||||
|
if (!(rhs > lhs)) { \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
std::swap(map[j], map[j - 1]); \
|
||||||
|
\
|
||||||
|
--j; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
for (size_t i = 0; i < CurSize; ++i) { \
|
\
|
||||||
combined_entries[BaseSize + i] = cur_entries[i]; \
|
std::array<::ams::sf::cmif::ServiceCommandMeta, CombinedSize> combined_entries{}; \
|
||||||
|
for (size_t i = 0; i < CombinedSize; ++i) { \
|
||||||
|
if (map[i] < BaseSize) { \
|
||||||
|
combined_entries[i] = BaseEntries[map[i]]; \
|
||||||
|
} else { \
|
||||||
|
combined_entries[i] = cur_entries[map[i] - BaseSize]; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return ::ams::sf::cmif::ServiceDispatchTable { combined_entries }; \
|
return ::ams::sf::cmif::ServiceDispatchTable { combined_entries }; \
|
||||||
} () \
|
}() \
|
||||||
}; \
|
}; \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace ams::sf {
|
|||||||
return lmem::FreeToExpHeap(m_handle, buffer);
|
return lmem::FreeToExpHeap(m_handle, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsEqualImpl(const MemoryResource &resource) const {
|
virtual bool IsEqualImpl(const MemoryResource &resource) const override {
|
||||||
return this == std::addressof(resource);
|
return this == std::addressof(resource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -76,9 +76,9 @@ namespace ams::sf {
|
|||||||
return lmem::FreeToUnitHeap(m_handle, buffer);
|
return lmem::FreeToUnitHeap(m_handle, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsEqualImpl(const MemoryResource &resource) const {
|
virtual bool IsEqualImpl(const MemoryResource &resource) const override {
|
||||||
return this == std::addressof(resource);
|
return this == std::addressof(resource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ namespace ams::sf {
|
|||||||
return m_standard_allocator->Free(buffer);
|
return m_standard_allocator->Free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool IsEqualImpl(const MemoryResource &resource) const {
|
virtual bool IsEqualImpl(const MemoryResource &resource) const override {
|
||||||
return this == std::addressof(resource);
|
return this == std::addressof(resource);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace ams::sf {
|
|||||||
public:
|
public:
|
||||||
class Object;
|
class Object;
|
||||||
using Allocator = StatelessDummyAllocator;
|
using Allocator = StatelessDummyAllocator;
|
||||||
using StatelessAllocator = typename Policy::StatelessAllocator<Object>;
|
using StatelessAllocator = typename Policy::template StatelessAllocator<Object>;
|
||||||
|
|
||||||
class Object final : private ::ams::sf::impl::ServiceObjectImplBase2, public Base {
|
class Object final : private ::ams::sf::impl::ServiceObjectImplBase2, public Base {
|
||||||
NON_COPYABLE(Object);
|
NON_COPYABLE(Object);
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ namespace ams::sm {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr ServiceName Encode(const char *name) {
|
static constexpr ServiceName Encode(util::string_view name) {
|
||||||
return Encode(name, std::strlen(name));
|
return Encode(name.data(), name.size());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace ams::socket {
|
|||||||
|
|
||||||
s32 Shutdown(s32 desc, ShutdownMethod how);
|
s32 Shutdown(s32 desc, ShutdownMethod how);
|
||||||
|
|
||||||
|
s32 Socket(Family domain, Type type, Protocol protocol);
|
||||||
s32 SocketExempt(Family domain, Type type, Protocol protocol);
|
s32 SocketExempt(Family domain, Type type, Protocol protocol);
|
||||||
|
|
||||||
s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len);
|
s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len);
|
||||||
|
|||||||
@@ -57,4 +57,42 @@ namespace ams::socket {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SystemConfigLightDefault : public Config {
|
||||||
|
public:
|
||||||
|
static constexpr size_t DefaultTcpInitialSendBufferSize = 16_KB;
|
||||||
|
static constexpr size_t DefaultTcpInitialReceiveBufferSize = 16_KB;
|
||||||
|
static constexpr size_t DefaultTcpAutoSendBufferSizeMax = 0_KB;
|
||||||
|
static constexpr size_t DefaultTcpAutoReceiveBufferSizeMax = 0_KB;
|
||||||
|
static constexpr size_t DefaultUdpSendBufferSize = 9_KB;
|
||||||
|
static constexpr size_t DefaultUdpReceiveBufferSize = 42240;
|
||||||
|
static constexpr auto DefaultSocketBufferEfficiency = 2;
|
||||||
|
static constexpr auto DefaultConcurrency = 2;
|
||||||
|
static constexpr size_t DefaultAllocatorPoolSize = 64_KB;
|
||||||
|
|
||||||
|
static constexpr size_t PerTcpSocketWorstCaseMemoryPoolSize = [] {
|
||||||
|
constexpr size_t WorstCaseTcpSendBufferSize = AlignMss(std::max(DefaultTcpInitialSendBufferSize, DefaultTcpAutoSendBufferSizeMax));
|
||||||
|
constexpr size_t WorstCaseTcpReceiveBufferSize = AlignMss(std::max(DefaultTcpInitialReceiveBufferSize, DefaultTcpAutoReceiveBufferSizeMax));
|
||||||
|
|
||||||
|
return util::AlignUp(WorstCaseTcpSendBufferSize * DefaultSocketBufferEfficiency + WorstCaseTcpReceiveBufferSize * DefaultSocketBufferEfficiency, os::MemoryPageSize);
|
||||||
|
}();
|
||||||
|
|
||||||
|
static constexpr size_t PerUdpSocketWorstCaseMemoryPoolSize = [] {
|
||||||
|
constexpr size_t WorstCaseUdpSendBufferSize = AlignMss(DefaultUdpSendBufferSize);
|
||||||
|
constexpr size_t WorstCaseUdpReceiveBufferSize = AlignMss(DefaultUdpReceiveBufferSize);
|
||||||
|
|
||||||
|
return util::AlignUp(WorstCaseUdpSendBufferSize * DefaultSocketBufferEfficiency + WorstCaseUdpReceiveBufferSize * DefaultSocketBufferEfficiency, os::MemoryPageSize);
|
||||||
|
}();
|
||||||
|
public:
|
||||||
|
constexpr SystemConfigLightDefault(void *mp, size_t mp_sz, size_t ap, int c=DefaultConcurrency)
|
||||||
|
: Config(mp, mp_sz, ap,
|
||||||
|
DefaultTcpInitialSendBufferSize, DefaultTcpInitialReceiveBufferSize,
|
||||||
|
DefaultTcpAutoSendBufferSizeMax, DefaultTcpAutoReceiveBufferSizeMax,
|
||||||
|
DefaultUdpSendBufferSize, DefaultUdpReceiveBufferSize,
|
||||||
|
DefaultSocketBufferEfficiency, c)
|
||||||
|
{
|
||||||
|
/* Mark as system. */
|
||||||
|
m_system = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace ams::spl::impl {
|
|||||||
|
|
||||||
Result AllocateAesKeySlot(s32 *out_keyslot);
|
Result AllocateAesKeySlot(s32 *out_keyslot);
|
||||||
Result DeallocateAesKeySlot(s32 keyslot);
|
Result DeallocateAesKeySlot(s32 keyslot);
|
||||||
Result TestAesKeySlot(s32 *out_index, s32 keyslot);
|
Result TestAesKeySlot(s32 *out_index, bool *out_virtual, s32 keyslot);
|
||||||
|
|
||||||
os::SystemEvent *GetAesKeySlotAvailableEvent();
|
os::SystemEvent *GetAesKeySlotAvailableEvent();
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace ams::time {
|
|||||||
AMS_ASSERT(rhs.IsValid());
|
AMS_ASSERT(rhs.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto ToUint64 = [] ALWAYS_INLINE_LAMBDA (const time::CalendarTime &time) {
|
constexpr auto ToUint64 = [](const time::CalendarTime &time) ALWAYS_INLINE_LAMBDA {
|
||||||
return (static_cast<u64>(time.year) << 40) |
|
return (static_cast<u64>(time.year) << 40) |
|
||||||
(static_cast<u64>(time.month) << 32) |
|
(static_cast<u64>(time.month) << 32) |
|
||||||
(static_cast<u64>(time.day) << 24) |
|
(static_cast<u64>(time.day) << 24) |
|
||||||
|
|||||||
@@ -40,12 +40,28 @@ namespace ams::tipc::impl {
|
|||||||
#define AMS_TIPC_IMPL_EXTRACT_SYNC_METHOD_ARGUMENTS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
#define AMS_TIPC_IMPL_EXTRACT_SYNC_METHOD_ARGUMENTS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
||||||
using NAME##ArgumentsType = ::ams::tipc::impl::SyncFunctionArgsType<&NAME##ArgumentsFunctionHolder::f>;
|
using NAME##ArgumentsType = ::ams::tipc::impl::SyncFunctionArgsType<&NAME##ArgumentsFunctionHolder::f>;
|
||||||
|
|
||||||
|
#define AMS_TIPC_IMPL_GET_MAXIMUM_REQUEST_SIZE(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
||||||
|
, ::ams::tipc::impl::CommandMetaInfo<CMD_ID + 0x10, NAME##ArgumentsType>::InMessageTotalSize
|
||||||
|
|
||||||
|
#define AMS_TIPC_IMPL_GET_MAXIMUM_RESPONSE_SIZE(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
||||||
|
, ::ams::tipc::impl::CommandMetaInfo<CMD_ID + 0x10, NAME##ArgumentsType>::OutMessageTotalSize
|
||||||
|
|
||||||
#define AMS_TIPC_IMPL_DEFINE_INTERFACE(BASECLASS, CLASSNAME, CMD_MACRO) \
|
#define AMS_TIPC_IMPL_DEFINE_INTERFACE(BASECLASS, CLASSNAME, CMD_MACRO) \
|
||||||
class CLASSNAME : public BASECLASS { \
|
class CLASSNAME : public BASECLASS { \
|
||||||
private: \
|
private: \
|
||||||
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_DEFINE_SYNC_METHOD_HOLDER) \
|
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_DEFINE_SYNC_METHOD_HOLDER) \
|
||||||
public: \
|
public: \
|
||||||
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_EXTRACT_SYNC_METHOD_ARGUMENTS) \
|
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_EXTRACT_SYNC_METHOD_ARGUMENTS) \
|
||||||
|
public: \
|
||||||
|
static constexpr size_t MaximumRequestSize = std::max<size_t>({ \
|
||||||
|
0 \
|
||||||
|
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_GET_MAXIMUM_REQUEST_SIZE) \
|
||||||
|
}); \
|
||||||
|
\
|
||||||
|
static constexpr size_t MaximumResponseSize = std::max<size_t>({ \
|
||||||
|
0 \
|
||||||
|
CMD_MACRO(CLASSNAME, AMS_TIPC_IMPL_GET_MAXIMUM_RESPONSE_SIZE) \
|
||||||
|
}); \
|
||||||
};
|
};
|
||||||
|
|
||||||
#define AMS_TIPC_IMPL_DEFINE_CONCEPT_HELPERS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
#define AMS_TIPC_IMPL_DEFINE_CONCEPT_HELPERS(CLASSNAME, CMD_ID, RETURN, NAME, ARGS, ARGNAMES, VERSION_MIN, VERSION_MAX) \
|
||||||
|
|||||||
@@ -319,6 +319,9 @@ namespace ams::tipc::impl {
|
|||||||
static constexpr auto OutMessageResultIndex = svc::ipc::MessageBuffer::GetRawDataIndex(OutMessageHeader, OutSpecialHeader);
|
static constexpr auto OutMessageResultIndex = svc::ipc::MessageBuffer::GetRawDataIndex(OutMessageHeader, OutSpecialHeader);
|
||||||
static constexpr auto OutMessageRawDataIndex = OutMessageResultIndex + 1;
|
static constexpr auto OutMessageRawDataIndex = OutMessageResultIndex + 1;
|
||||||
|
|
||||||
|
static constexpr size_t InMessageTotalSize = (InMessageRawDataIndex * sizeof(u32)) + InDataSize;
|
||||||
|
static constexpr size_t OutMessageTotalSize = (OutMessageRawDataIndex * sizeof(u32)) + OutDataSize;
|
||||||
|
|
||||||
/* Construction of argument serialization structs. */
|
/* Construction of argument serialization structs. */
|
||||||
private:
|
private:
|
||||||
template<typename>
|
template<typename>
|
||||||
@@ -472,7 +475,7 @@ namespace ams::tipc::impl {
|
|||||||
using OutRawHolderType = OutRawHolder<CommandMeta::OutDataSize, CommandMeta::OutDataAlign, CommandMeta::OutMessageRawDataIndex>;
|
using OutRawHolderType = OutRawHolder<CommandMeta::OutDataSize, CommandMeta::OutDataAlign, CommandMeta::OutMessageRawDataIndex>;
|
||||||
using OutHandleHolderType = OutHandleHolder<CommandMeta::NumOutMoveHandles, CommandMeta::NumOutCopyHandles, CommandMeta::OutMessageHandleIndex>;
|
using OutHandleHolderType = OutHandleHolder<CommandMeta::NumOutMoveHandles, CommandMeta::NumOutCopyHandles, CommandMeta::OutMessageHandleIndex>;
|
||||||
private:
|
private:
|
||||||
static consteval u64 GetMessageHeaderForCheck(const svc::ipc::MessageBuffer::MessageHeader &header) {
|
static constexpr u64 GetMessageHeaderForCheck(const svc::ipc::MessageBuffer::MessageHeader &header) {
|
||||||
using Value = util::BitPack32::Field<0, BITSIZEOF(util::BitPack32)>;
|
using Value = util::BitPack32::Field<0, BITSIZEOF(util::BitPack32)>;
|
||||||
|
|
||||||
const util::BitPack32 *data = header.GetData();
|
const util::BitPack32 *data = header.GetData();
|
||||||
@@ -482,7 +485,7 @@ namespace ams::tipc::impl {
|
|||||||
return static_cast<u64>(lower) | (static_cast<u64>(upper) << BITSIZEOF(u32));
|
return static_cast<u64>(lower) | (static_cast<u64>(upper) << BITSIZEOF(u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
static consteval u32 GetSpecialHeaderForCheck(const svc::ipc::MessageBuffer::SpecialHeader &header) {
|
static constexpr u32 GetSpecialHeaderForCheck(const svc::ipc::MessageBuffer::SpecialHeader &header) {
|
||||||
using Value = util::BitPack32::Field<0, BITSIZEOF(util::BitPack32)>;
|
using Value = util::BitPack32::Field<0, BITSIZEOF(util::BitPack32)>;
|
||||||
|
|
||||||
return header.GetHeader()->Get<Value>();
|
return header.GetHeader()->Get<Value>();
|
||||||
|
|||||||
@@ -44,16 +44,17 @@ namespace ams::tipc {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeferrableBase : public impl::DeferrableBaseTag {
|
class DeferrableBaseImpl : public impl::DeferrableBaseTag {
|
||||||
private:
|
private:
|
||||||
DeferralManagerBase *m_deferral_manager;
|
DeferralManagerBase *m_deferral_manager;
|
||||||
ObjectHolder m_object_holder;
|
ObjectHolder m_object_holder;
|
||||||
uintptr_t m_resume_key;
|
uintptr_t m_resume_key;
|
||||||
u8 m_message_buffer[svc::ipc::MessageBufferSize];
|
const u32 m_message_buffer_size;
|
||||||
|
u8 m_message_buffer_base[0];
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE DeferrableBase() : m_deferral_manager(nullptr), m_object_holder(), m_resume_key() { /* ... */ }
|
ALWAYS_INLINE DeferrableBaseImpl(u32 mb_size) : m_deferral_manager(nullptr), m_object_holder(), m_resume_key(), m_message_buffer_size(mb_size) { /* ... */ }
|
||||||
|
|
||||||
~DeferrableBase();
|
~DeferrableBaseImpl();
|
||||||
|
|
||||||
ALWAYS_INLINE void SetDeferralManager(DeferralManagerBase *manager, os::NativeHandle reply_target, ServiceObjectBase *object) {
|
ALWAYS_INLINE void SetDeferralManager(DeferralManagerBase *manager, os::NativeHandle reply_target, ServiceObjectBase *object) {
|
||||||
m_deferral_manager = manager;
|
m_deferral_manager = manager;
|
||||||
@@ -67,7 +68,7 @@ namespace ams::tipc {
|
|||||||
template<IsResumeKey ResumeKey>
|
template<IsResumeKey ResumeKey>
|
||||||
ALWAYS_INLINE void RegisterRetry(ResumeKey key) {
|
ALWAYS_INLINE void RegisterRetry(ResumeKey key) {
|
||||||
m_resume_key = ConvertToInternalResumeKey(key);
|
m_resume_key = ConvertToInternalResumeKey(key);
|
||||||
std::memcpy(m_message_buffer, svc::ipc::GetMessageBuffer(), sizeof(m_message_buffer));
|
std::memcpy(m_message_buffer_base, svc::ipc::GetMessageBuffer(), m_message_buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<IsResumeKey ResumeKey, typename F>
|
template<IsResumeKey ResumeKey, typename F>
|
||||||
@@ -85,11 +86,49 @@ namespace ams::tipc {
|
|||||||
m_resume_key = 0;
|
m_resume_key = 0;
|
||||||
|
|
||||||
/* Restore message buffer. */
|
/* Restore message buffer. */
|
||||||
std::memcpy(svc::ipc::GetMessageBuffer(), m_message_buffer, sizeof(m_message_buffer));
|
std::memcpy(svc::ipc::GetMessageBuffer(), m_message_buffer_base, m_message_buffer_size);
|
||||||
|
|
||||||
/* Process the request. */
|
/* Process the request. */
|
||||||
return port_manager->ProcessDeferredRequest(m_object_holder);
|
return port_manager->ProcessDeferredRequest(m_object_holder);
|
||||||
}
|
}
|
||||||
|
protected:
|
||||||
|
static consteval size_t GetMessageBufferOffsetBase();
|
||||||
|
};
|
||||||
|
static_assert(std::is_standard_layout<DeferrableBaseImpl>::value);
|
||||||
|
|
||||||
|
template<size_t _MessageBufferRequiredSize>
|
||||||
|
class DeferrableBaseImplWithBuffer : public DeferrableBaseImpl {
|
||||||
|
private:
|
||||||
|
static constexpr size_t MessageBufferRequiredSize = _MessageBufferRequiredSize;
|
||||||
|
private:
|
||||||
|
u8 m_message_buffer[MessageBufferRequiredSize];
|
||||||
|
public:
|
||||||
|
DeferrableBaseImplWithBuffer();
|
||||||
|
private:
|
||||||
|
static consteval size_t GetMessageBufferOffset();
|
||||||
|
};
|
||||||
|
|
||||||
|
consteval size_t DeferrableBaseImpl::GetMessageBufferOffsetBase() {
|
||||||
|
return AMS_OFFSETOF(DeferrableBaseImpl, m_message_buffer_base);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t _MessageBufferRequiredSize>
|
||||||
|
consteval size_t DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>::GetMessageBufferOffset() {
|
||||||
|
return AMS_OFFSETOF(DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>, m_message_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t _MessageBufferRequiredSize>
|
||||||
|
ALWAYS_INLINE DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>::DeferrableBaseImplWithBuffer() : DeferrableBaseImpl(MessageBufferRequiredSize) {
|
||||||
|
static_assert(GetMessageBufferOffsetBase() == GetMessageBufferOffset());
|
||||||
|
static_assert(sizeof(DeferrableBaseImplWithBuffer<_MessageBufferRequiredSize>) >= sizeof(DeferrableBaseImpl) + MessageBufferRequiredSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Interface, size_t MaximumDefaultRequestSize = 0>
|
||||||
|
class DeferrableBase : public DeferrableBaseImplWithBuffer<std::max(Interface::MaximumRequestSize, MaximumDefaultRequestSize)> {
|
||||||
|
private:
|
||||||
|
using BaseImpl = DeferrableBaseImplWithBuffer<std::max(Interface::MaximumRequestSize, MaximumDefaultRequestSize)>;
|
||||||
|
public:
|
||||||
|
using BaseImpl::BaseImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -100,11 +139,11 @@ namespace ams::tipc {
|
|||||||
NON_MOVEABLE(DeferralManagerBase);
|
NON_MOVEABLE(DeferralManagerBase);
|
||||||
private:
|
private:
|
||||||
size_t m_object_count;
|
size_t m_object_count;
|
||||||
DeferrableBase *m_objects_base[0];
|
DeferrableBaseImpl *m_objects_base[0];
|
||||||
public:
|
public:
|
||||||
ALWAYS_INLINE DeferralManagerBase() : m_object_count(0) { /* ... */ }
|
ALWAYS_INLINE DeferralManagerBase() : m_object_count(0) { /* ... */ }
|
||||||
|
|
||||||
void AddObject(DeferrableBase &object, os::NativeHandle reply_target, ServiceObjectBase *service_object) {
|
void AddObject(DeferrableBaseImpl &object, os::NativeHandle reply_target, ServiceObjectBase *service_object) {
|
||||||
/* Set ourselves as the manager for the object. */
|
/* Set ourselves as the manager for the object. */
|
||||||
object.SetDeferralManager(this, reply_target, service_object);
|
object.SetDeferralManager(this, reply_target, service_object);
|
||||||
|
|
||||||
@@ -113,7 +152,7 @@ namespace ams::tipc {
|
|||||||
m_objects_base[m_object_count++] = std::addressof(object);
|
m_objects_base[m_object_count++] = std::addressof(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveObject(DeferrableBase *object) {
|
void RemoveObject(DeferrableBaseImpl *object) {
|
||||||
/* If the object is present, remove it. */
|
/* If the object is present, remove it. */
|
||||||
for (size_t i = 0; i < m_object_count; ++i) {
|
for (size_t i = 0; i < m_object_count; ++i) {
|
||||||
if (m_objects_base[i] == object) {
|
if (m_objects_base[i] == object) {
|
||||||
@@ -148,7 +187,7 @@ namespace ams::tipc {
|
|||||||
};
|
};
|
||||||
static_assert(std::is_standard_layout<DeferralManagerBase>::value);
|
static_assert(std::is_standard_layout<DeferralManagerBase>::value);
|
||||||
|
|
||||||
inline DeferrableBase::~DeferrableBase() {
|
inline DeferrableBaseImpl::~DeferrableBaseImpl() {
|
||||||
AMS_ASSUME(m_deferral_manager != nullptr);
|
AMS_ASSUME(m_deferral_manager != nullptr);
|
||||||
m_deferral_manager->RemoveObject(this);
|
m_deferral_manager->RemoveObject(this);
|
||||||
}
|
}
|
||||||
@@ -156,7 +195,7 @@ namespace ams::tipc {
|
|||||||
template<size_t N> requires (N > 0)
|
template<size_t N> requires (N > 0)
|
||||||
class DeferralManager final : public DeferralManagerBase {
|
class DeferralManager final : public DeferralManagerBase {
|
||||||
private:
|
private:
|
||||||
DeferrableBase *m_objects[N];
|
DeferrableBaseImpl *m_objects[N];
|
||||||
public:
|
public:
|
||||||
DeferralManager();
|
DeferralManager();
|
||||||
private:
|
private:
|
||||||
@@ -167,15 +206,15 @@ namespace ams::tipc {
|
|||||||
return AMS_OFFSETOF(DeferralManagerBase, m_objects_base);
|
return AMS_OFFSETOF(DeferralManagerBase, m_objects_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N> requires (N > 0)
|
||||||
consteval size_t DeferralManager<N>::GetObjectPointersOffset() {
|
consteval size_t DeferralManager<N>::GetObjectPointersOffset() {
|
||||||
return AMS_OFFSETOF(DeferralManager<N>, m_objects);
|
return AMS_OFFSETOF(DeferralManager<N>, m_objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N> requires (N > 0)
|
||||||
inline DeferralManager<N>::DeferralManager() : DeferralManagerBase() {
|
inline DeferralManager<N>::DeferralManager() : DeferralManagerBase() {
|
||||||
static_assert(GetObjectPointersOffset() == GetObjectPointersOffsetBase());
|
static_assert(GetObjectPointersOffset() == GetObjectPointersOffsetBase());
|
||||||
static_assert(sizeof(DeferralManager<N>) == sizeof(DeferralManagerBase) + N * sizeof(DeferrableBase *));
|
static_assert(sizeof(DeferralManager<N>) == sizeof(DeferralManagerBase) + N * sizeof(DeferrableBaseImpl *));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ namespace ams::tipc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Try to reply/receive. */
|
/* Try to reply/receive. */
|
||||||
const Result result = [&] ALWAYS_INLINE_LAMBDA () -> Result {
|
const Result result = [&]() ALWAYS_INLINE_LAMBDA -> Result {
|
||||||
os::MultiWaitHolderType *signaled_holder = nullptr;
|
os::MultiWaitHolderType *signaled_holder = nullptr;
|
||||||
ON_SCOPE_EXIT { AMS_ABORT_UNLESS(signaled_holder == nullptr); };
|
ON_SCOPE_EXIT { AMS_ABORT_UNLESS(signaled_holder == nullptr); };
|
||||||
return m_object_manager->ReplyAndReceive(std::addressof(signaled_holder), out_object, reply_target, std::addressof(m_multi_wait));
|
return m_object_manager->ReplyAndReceive(std::addressof(signaled_holder), out_object, reply_target, std::addressof(m_multi_wait));
|
||||||
@@ -747,7 +747,7 @@ namespace ams::tipc {
|
|||||||
using PortManager = PortManagerImpl;
|
using PortManager = PortManagerImpl;
|
||||||
private:
|
private:
|
||||||
PortManager m_port_manager;
|
PortManager m_port_manager;
|
||||||
PortInfo::Allocator m_port_allocator;
|
typename PortInfo::Allocator m_port_allocator;
|
||||||
public:
|
public:
|
||||||
constexpr ServerManagerImpl() : m_port_manager(), m_port_allocator() { /* ... */ }
|
constexpr ServerManagerImpl() : m_port_manager(), m_port_allocator() { /* ... */ }
|
||||||
|
|
||||||
|
|||||||
@@ -18,41 +18,28 @@
|
|||||||
#include <vapours.hpp>
|
#include <vapours.hpp>
|
||||||
#include <stratosphere/os/os_sdk_mutex.hpp>
|
#include <stratosphere/os/os_sdk_mutex.hpp>
|
||||||
|
|
||||||
#define AMS_SINGLETON_TRAITS(_CLASSNAME_) \
|
#define AMS_SINGLETON_TRAITS(_CLASSNAME_) \
|
||||||
private: \
|
private: \
|
||||||
NON_COPYABLE(_CLASSNAME_); \
|
NON_COPYABLE(_CLASSNAME_); \
|
||||||
NON_MOVEABLE(_CLASSNAME_); \
|
NON_MOVEABLE(_CLASSNAME_); \
|
||||||
private: \
|
private: \
|
||||||
_CLASSNAME_ (); \
|
_CLASSNAME_ (); \
|
||||||
public: \
|
public: \
|
||||||
static _CLASSNAME_ &GetInstance() { \
|
static _CLASSNAME_ &GetInstance() { \
|
||||||
/* Declare singleton instance variables. */ \
|
AMS_FUNCTION_LOCAL_STATIC(_CLASSNAME_, s_singleton_instance); \
|
||||||
static constinit ::ams::util::TypedStorage<_CLASSNAME_> s_singleton_storage; \
|
\
|
||||||
static constinit ::ams::os::SdkMutex s_singleton_mutex; \
|
return s_singleton_instance; \
|
||||||
static constinit bool s_initialized_singleton = false; \
|
|
||||||
\
|
|
||||||
/* Ensure the instance is created. */ \
|
|
||||||
if (AMS_UNLIKELY(!s_initialized_singleton)) { \
|
|
||||||
std::scoped_lock lk(s_singleton_mutex); \
|
|
||||||
\
|
|
||||||
if (AMS_LIKELY(!s_initialized_singleton)) { \
|
|
||||||
new (::ams::util::GetPointer(s_singleton_storage)) _CLASSNAME_; \
|
|
||||||
s_initialized_singleton = true; \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
return ::ams::util::GetReference(s_singleton_storage); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AMS_CONSTINIT_SINGLETON_TRAITS(_CLASSNAME_) \
|
#define AMS_CONSTINIT_SINGLETON_TRAITS(_CLASSNAME_) \
|
||||||
private: \
|
private: \
|
||||||
NON_COPYABLE(_CLASSNAME_); \
|
NON_COPYABLE(_CLASSNAME_); \
|
||||||
NON_MOVEABLE(_CLASSNAME_); \
|
NON_MOVEABLE(_CLASSNAME_); \
|
||||||
private: \
|
private: \
|
||||||
constexpr _CLASSNAME_ () = default; \
|
constexpr _CLASSNAME_ () = default; \
|
||||||
public: \
|
public: \
|
||||||
static _CLASSNAME_ &GetInstance() { \
|
static _CLASSNAME_ &GetInstance() { \
|
||||||
/* Declare singleton instance variables. */ \
|
/* Declare singleton instance variables. */ \
|
||||||
static constinit _CLASSNAME_ s_singleton_instance; \
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(_CLASSNAME_, s_singleton_instance); \
|
||||||
return s_singleton_instance; \
|
return s_singleton_instance; \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,6 +188,12 @@ namespace ams::boot2 {
|
|||||||
return enable_htc != 0;
|
return enable_htc != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsStandaloneGdbstubEnabled() {
|
||||||
|
u8 enable_gdbstub = 0;
|
||||||
|
settings::fwdbg::GetSettingsItemValue(std::addressof(enable_gdbstub), sizeof(enable_gdbstub), "atmosphere", "enable_standalone_gdbstub");
|
||||||
|
return enable_gdbstub != 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsAtmosphereLogManagerEnabled() {
|
bool IsAtmosphereLogManagerEnabled() {
|
||||||
/* If htc is enabled, ams log manager is enabled. */
|
/* If htc is enabled, ams log manager is enabled. */
|
||||||
if (IsHtcEnabled()) {
|
if (IsHtcEnabled()) {
|
||||||
@@ -403,6 +409,9 @@ namespace ams::boot2 {
|
|||||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Htc, ncm::StorageId::None), 0);
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Htc, ncm::StorageId::None), 0);
|
||||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Cs, ncm::StorageId::None), 0);
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Cs, ncm::StorageId::None), 0);
|
||||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::DmntGen2, ncm::StorageId::None), 0);
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::DmntGen2, ncm::StorageId::None), 0);
|
||||||
|
} else if (IsStandaloneGdbstubEnabled()) {
|
||||||
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::DmntGen2, ncm::StorageId::None), 0);
|
||||||
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0);
|
||||||
} else {
|
} else {
|
||||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Dmnt, ncm::StorageId::None), 0);
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Dmnt, ncm::StorageId::None), 0);
|
||||||
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0);
|
LaunchProgram(nullptr, ncm::ProgramLocation::Make(ncm::SystemProgramId::Tma, ncm::StorageId::BuiltInSystem), 0);
|
||||||
|
|||||||
@@ -73,18 +73,7 @@ namespace ams::erpt::srv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IsProductionMode() {
|
bool IsProductionMode() {
|
||||||
static constinit bool s_initialized = false;
|
AMS_FUNCTION_LOCAL_STATIC(bool, s_is_prod_mode, IsProductionModeImpl());
|
||||||
static constinit bool s_is_prod_mode = true;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
s_is_prod_mode = IsProductionModeImpl();
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_is_prod_mode;
|
return s_is_prod_mode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,8 @@ namespace ams::fs {
|
|||||||
Result DeleteSystemSaveData(SaveDataSpaceId space_id, SystemSaveDataId id, UserId user_id) {
|
Result DeleteSystemSaveData(SaveDataSpaceId space_id, SystemSaveDataId id, UserId user_id) {
|
||||||
const auto attribute = SaveDataAttribute::Make(ncm::InvalidProgramId, SaveDataType::System, user_id, id);
|
const auto attribute = SaveDataAttribute::Make(ncm::InvalidProgramId, SaveDataType::System, user_id, id);
|
||||||
|
|
||||||
/* TODO: Libnx binding for DeleteSaveDataFileSystemBySaveDataAttribute */
|
static_assert(sizeof(attribute) == sizeof(::FsSaveDataAttribute));
|
||||||
AMS_UNUSED(space_id, attribute);
|
return fsDeleteSaveDataFileSystemBySaveDataAttribute(static_cast<::FsSaveDataSpaceId>(space_id), reinterpret_cast<const ::FsSaveDataAttribute *>(std::addressof(attribute)));
|
||||||
AMS_ABORT();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetSaveDataFlags(u32 *out, SaveDataId id) {
|
Result GetSaveDataFlags(u32 *out, SaveDataId id) {
|
||||||
|
|||||||
@@ -112,13 +112,13 @@ namespace ams::fssystem {
|
|||||||
NcaCryptoConfiguration g_nca_crypto_configuration_prod;
|
NcaCryptoConfiguration g_nca_crypto_configuration_prod;
|
||||||
|
|
||||||
constexpr inline s32 KeySlotCacheEntryCount = 3;
|
constexpr inline s32 KeySlotCacheEntryCount = 3;
|
||||||
KeySlotCache g_key_slot_cache;
|
constinit KeySlotCache g_key_slot_cache;
|
||||||
util::optional<KeySlotCacheEntry> g_key_slot_cache_entry[KeySlotCacheEntryCount];
|
constinit util::optional<KeySlotCacheEntry> g_key_slot_cache_entry[KeySlotCacheEntryCount];
|
||||||
|
|
||||||
spl::AccessKey &GetNcaKekAccessKey(s32 key_type) {
|
spl::AccessKey &GetNcaKekAccessKey(s32 key_type) {
|
||||||
static spl::AccessKey s_nca_kek_access_key_array[KeyAreaEncryptionKeyCount] = {};
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(spl::AccessKey, s_nca_kek_access_key_array[KeyAreaEncryptionKeyCount]);
|
||||||
static spl::AccessKey s_nca_header_kek_access_key = {};
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(spl::AccessKey, s_nca_header_kek_access_key);
|
||||||
static spl::AccessKey s_invalid_nca_kek_access_key = {};
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(spl::AccessKey, s_invalid_nca_kek_access_key);
|
||||||
|
|
||||||
if (key_type > static_cast<s32>(KeyType::NcaHeaderKey) || IsInvalidKeyTypeValue(key_type)) {
|
if (key_type > static_cast<s32>(KeyType::NcaHeaderKey) || IsInvalidKeyTypeValue(key_type)) {
|
||||||
return s_invalid_nca_kek_access_key;
|
return s_invalid_nca_kek_access_key;
|
||||||
|
|||||||
@@ -26,42 +26,20 @@ namespace ams::gpio::driver::impl {
|
|||||||
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
|
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
|
||||||
|
|
||||||
gpio::driver::IGpioDriver::List &GetGpioDriverList() {
|
gpio::driver::IGpioDriver::List &GetGpioDriverList() {
|
||||||
static constinit gpio::driver::IGpioDriver::List s_gpio_driver_list;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(gpio::driver::IGpioDriver::List, s_gpio_driver_list);
|
||||||
return s_gpio_driver_list;
|
return s_gpio_driver_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
|
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
|
||||||
static constinit util::TypedStorage<ddsf::EventHandlerManager> s_interrupt_handler_manager;
|
AMS_FUNCTION_LOCAL_STATIC(ddsf::EventHandlerManager, s_interrupt_handler_manager);
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
return s_interrupt_handler_manager;
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
util::ConstructAt(s_interrupt_handler_manager);
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_interrupt_handler_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
||||||
static constinit util::TypedStorage<ddsf::DeviceCodeEntryManager> s_device_code_entry_manager;
|
AMS_FUNCTION_LOCAL_STATIC(ddsf::DeviceCodeEntryManager, s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
return s_device_code_entry_manager;
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
util::ConstructAt(s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_device_code_entry_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptThreadFunction(void *arg) {
|
void InterruptThreadFunction(void *arg) {
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ namespace ams::htclow::ctrl {
|
|||||||
/* Lock ourselves. */
|
/* Lock ourselves. */
|
||||||
std::scoped_lock lk(m_mutex);
|
std::scoped_lock lk(m_mutex);
|
||||||
|
|
||||||
auto IsSupportedServiceChannel = [] ALWAYS_INLINE_LAMBDA (const impl::ChannelInternalType &channel, const impl::ChannelInternalType *supported, int num_supported) -> bool {
|
auto IsSupportedServiceChannel = [](const impl::ChannelInternalType &channel, const impl::ChannelInternalType *supported, int num_supported) ALWAYS_INLINE_LAMBDA -> bool {
|
||||||
for (auto i = 0; i < num_supported; ++i) {
|
for (auto i = 0; i < num_supported; ++i) {
|
||||||
if (channel.module_id == supported[i].module_id && channel.channel_id == supported[i].channel_id) {
|
if (channel.module_id == supported[i].module_id && channel.channel_id == supported[i].channel_id) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -95,16 +95,17 @@ namespace ams::i2c::driver::board::nintendo::nx {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constinit util::TypedStorage<impl::I2cBusAccessorManager> g_bus_accessor_manager;
|
||||||
|
constinit util::TypedStorage<impl::I2cDevicePropertyManager> g_device_manager;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialize() {
|
void Initialize() {
|
||||||
static constinit util::TypedStorage<impl::I2cBusAccessorManager> s_bus_accessor_manager;
|
/* Initialize managers. */
|
||||||
static constinit util::TypedStorage<impl::I2cDevicePropertyManager> s_device_manager;
|
util::ConstructAt(g_bus_accessor_manager, ddsf::GetMemoryResource());
|
||||||
|
util::ConstructAt(g_device_manager, ddsf::GetMemoryResource());
|
||||||
|
|
||||||
util::ConstructAt(s_bus_accessor_manager, ddsf::GetMemoryResource());
|
return Initialize(util::GetReference(g_bus_accessor_manager), util::GetReference(g_device_manager));
|
||||||
util::ConstructAt(s_device_manager, ddsf::GetMemoryResource());
|
|
||||||
|
|
||||||
return Initialize(util::GetReference(s_bus_accessor_manager), util::GetReference(s_device_manager));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,25 +24,14 @@ namespace ams::i2c::driver::impl {
|
|||||||
constinit int g_init_count = 0;
|
constinit int g_init_count = 0;
|
||||||
|
|
||||||
i2c::driver::II2cDriver::List &GetI2cDriverList() {
|
i2c::driver::II2cDriver::List &GetI2cDriverList() {
|
||||||
static constinit i2c::driver::II2cDriver::List s_driver_list;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(i2c::driver::II2cDriver::List, s_driver_list);
|
||||||
return s_driver_list;
|
return s_driver_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
||||||
static constinit util::TypedStorage<ddsf::DeviceCodeEntryManager> s_device_code_entry_manager;
|
AMS_FUNCTION_LOCAL_STATIC(ddsf::DeviceCodeEntryManager, s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
return s_device_code_entry_manager;
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
util::ConstructAt(s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_device_code_entry_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ extern "C" {
|
|||||||
constinit u32 __nx_fs_num_sessions = 1;
|
constinit u32 __nx_fs_num_sessions = 1;
|
||||||
constinit u32 __nx_applet_type = AppletType_None;
|
constinit u32 __nx_applet_type = AppletType_None;
|
||||||
|
|
||||||
|
constinit bool __nx_fsdev_support_cwd = false;
|
||||||
|
|
||||||
extern int __system_argc;
|
extern int __system_argc;
|
||||||
extern char** __system_argv;
|
extern char** __system_argv;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ namespace ams::lm::srv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EventLogTransmitter &EventLogTransmitter::GetDefaultInstance() {
|
EventLogTransmitter &EventLogTransmitter::GetDefaultInstance() {
|
||||||
static constinit EventLogTransmitter s_default_event_log_transmitter(DefaultFlushFunction);
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(EventLogTransmitter, s_default_event_log_transmitter, DefaultFlushFunction);
|
||||||
|
|
||||||
return s_default_event_log_transmitter;
|
return s_default_event_log_transmitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,10 @@ namespace ams::lm::srv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool DefaultFlushFunction(const u8 *data, size_t size) {
|
bool DefaultFlushFunction(const u8 *data, size_t size) {
|
||||||
|
/* Declare persistent clock-updated state storage. */
|
||||||
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(bool, s_is_user_system_clock_updated, false);
|
||||||
|
|
||||||
/* Update clock. */
|
/* Update clock. */
|
||||||
static constinit bool s_is_user_system_clock_updated = false;
|
|
||||||
if (!s_is_user_system_clock_updated) {
|
if (!s_is_user_system_clock_updated) {
|
||||||
UpdateUserSystemClock(data, size);
|
UpdateUserSystemClock(data, size);
|
||||||
s_is_user_system_clock_updated = true;
|
s_is_user_system_clock_updated = true;
|
||||||
@@ -84,8 +86,8 @@ namespace ams::lm::srv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogBuffer &LogBuffer::GetDefaultInstance() {
|
LogBuffer &LogBuffer::GetDefaultInstance() {
|
||||||
static constinit u8 s_default_buffers[128_KB * 2];
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(u8, s_default_buffers[128_KB * 2]);
|
||||||
static constinit LogBuffer s_default_log_buffer(s_default_buffers, sizeof(s_default_buffers), DefaultFlushFunction);
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(LogBuffer, s_default_log_buffer, s_default_buffers, sizeof(s_default_buffers), DefaultFlushFunction);
|
||||||
|
|
||||||
return s_default_log_buffer;
|
return s_default_log_buffer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@
|
|||||||
namespace ams::lm::srv {
|
namespace ams::lm::srv {
|
||||||
|
|
||||||
CustomSinkBuffer &LogGetterImpl::GetBuffer() {
|
CustomSinkBuffer &LogGetterImpl::GetBuffer() {
|
||||||
static constinit u8 s_buffer[32_KB];
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(u8, s_buffer[32_KB]);
|
||||||
static constinit CustomSinkBuffer s_custom_sink_buffer(s_buffer, sizeof(s_buffer), FlushFunction);
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(CustomSinkBuffer, s_custom_sink_buffer, s_buffer, sizeof(s_buffer), FlushFunction);
|
||||||
|
|
||||||
return s_custom_sink_buffer;
|
return s_custom_sink_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ namespace ams::lm::srv {
|
|||||||
size_t carry_size;
|
size_t carry_size;
|
||||||
bool ends_with_text_log;
|
bool ends_with_text_log;
|
||||||
};
|
};
|
||||||
static constinit PreviousPacketContext s_previous_packet_context = {};
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(PreviousPacketContext, s_previous_packet_context);
|
||||||
|
|
||||||
/* Get the packet header. */
|
/* Get the packet header. */
|
||||||
auto *header = static_cast<const impl::LogPacketHeader *>(buffer);
|
auto *header = static_cast<const impl::LogPacketHeader *>(buffer);
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ namespace ams::ncm {
|
|||||||
out_orphaned[i] = true;
|
out_orphaned[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto IsOrphanedContent = [] ALWAYS_INLINE_LAMBDA (const sf::InArray<ContentId> &list, const ncm::ContentId &id) -> util::optional<size_t> {
|
auto IsOrphanedContent = [](const sf::InArray<ContentId> &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA -> util::optional<size_t> {
|
||||||
/* Check if any input content ids match our found content id. */
|
/* Check if any input content ids match our found content id. */
|
||||||
for (size_t i = 0; i < list.GetSize(); i++) {
|
for (size_t i = 0; i < list.GetSize(); i++) {
|
||||||
if (list[i] == id) {
|
if (list[i] == id) {
|
||||||
|
|||||||
@@ -635,7 +635,7 @@ namespace ams::ncm {
|
|||||||
for (s32 i = 0; i < count; i++) {
|
for (s32 i = 0; i < count; i++) {
|
||||||
R_UNLESS(!this->IsCancelRequested(), ncm::ResultCreatePlaceHolderCancelled());
|
R_UNLESS(!this->IsCancelRequested(), ncm::ResultCreatePlaceHolderCancelled());
|
||||||
|
|
||||||
static constinit os::SdkMutex s_placeholder_mutex;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(os::SdkMutex, s_placeholder_mutex);
|
||||||
std::scoped_lock lk(s_placeholder_mutex);
|
std::scoped_lock lk(s_placeholder_mutex);
|
||||||
|
|
||||||
InstallContentMeta content_meta;
|
InstallContentMeta content_meta;
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ namespace ams::ncm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HeapState &GetHeapState() {
|
HeapState &GetHeapState() {
|
||||||
static HeapState s_heap_state = {};
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(HeapState, s_heap_state);
|
||||||
|
|
||||||
return s_heap_state;
|
return s_heap_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,26 @@ namespace ams::os::impl {
|
|||||||
/* Get the thread impl object from libnx. */
|
/* Get the thread impl object from libnx. */
|
||||||
ThreadImpl *thread_impl = ::threadGetSelf();
|
ThreadImpl *thread_impl = ::threadGetSelf();
|
||||||
|
|
||||||
|
/* Hack around libnx's main thread, to ensure stratosphere thread type consistency. */
|
||||||
|
{
|
||||||
|
auto *tlr = reinterpret_cast<uintptr_t *>(svc::GetThreadLocalRegion());
|
||||||
|
for (size_t i = sizeof(svc::ThreadLocalRegion) / sizeof(uintptr_t); i > 0; --i) {
|
||||||
|
if (auto *candidate = reinterpret_cast<ThreadImpl *>(tlr[i - 1]); candidate == thread_impl) {
|
||||||
|
ThreadImpl *embedded_thread = std::addressof(main_thread->thread_impl_storage);
|
||||||
|
|
||||||
|
*embedded_thread = *thread_impl;
|
||||||
|
|
||||||
|
if (embedded_thread->next) {
|
||||||
|
embedded_thread->next->prev_next = std::addressof(embedded_thread->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_impl = embedded_thread;
|
||||||
|
tlr[i-1] = reinterpret_cast<uintptr_t>(thread_impl);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the thread priority. */
|
/* Get the thread priority. */
|
||||||
s32 horizon_priority;
|
s32 horizon_priority;
|
||||||
R_ABORT_UNLESS(svc::GetThreadPriority(std::addressof(horizon_priority), thread_impl->handle));
|
R_ABORT_UNLESS(svc::GetThreadPriority(std::addressof(horizon_priority), thread_impl->handle));
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace ams::osdbg::impl {
|
|||||||
static_assert(AMS_OFFSETOF(ThreadLocalRegionIlp32, tls) == 0x1C0);
|
static_assert(AMS_OFFSETOF(ThreadLocalRegionIlp32, tls) == 0x1C0);
|
||||||
|
|
||||||
struct LibnxThreadVars {
|
struct LibnxThreadVars {
|
||||||
static constexpr u32 Magic = util::FourCC<'!','T','V','$'>::Code;
|
static constexpr u32 Magic = util::ReverseFourCC<'!','T','V','$'>::Code;
|
||||||
|
|
||||||
u32 magic;
|
u32 magic;
|
||||||
::Handle handle;
|
::Handle handle;
|
||||||
@@ -69,11 +69,11 @@ namespace ams::osdbg::impl {
|
|||||||
volatile u16 disable_counter;
|
volatile u16 disable_counter;
|
||||||
volatile u16 interrupt_flag;
|
volatile u16 interrupt_flag;
|
||||||
u32 reserved0;
|
u32 reserved0;
|
||||||
u64 tls[(0x1E0 - 0x108) / sizeof(u64)];
|
u64 tls[(0x200 - sizeof(LibnxThreadVars) - 0x108) / sizeof(u64)];
|
||||||
LibnxThreadVars thread_vars;
|
LibnxThreadVars thread_vars;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ThreadLocalRegionLibnx) == sizeof(svc::ThreadLocalRegion));
|
static_assert(sizeof(ThreadLocalRegionLibnx) == sizeof(svc::ThreadLocalRegion));
|
||||||
static_assert(AMS_OFFSETOF(ThreadLocalRegionLibnx, thread_vars) == 0x1E0);
|
static_assert(AMS_OFFSETOF(ThreadLocalRegionLibnx, thread_vars) == 0x200 - sizeof(LibnxThreadVars));
|
||||||
|
|
||||||
struct LibnxThreadEntryArgs {
|
struct LibnxThreadEntryArgs {
|
||||||
u64 t;
|
u64 t;
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ namespace ams::osdbg {
|
|||||||
} else {
|
} else {
|
||||||
/* Special-case libnx threads. */
|
/* Special-case libnx threads. */
|
||||||
if (thread_info->_thread_type_type == ThreadTypeType_Libnx) {
|
if (thread_info->_thread_type_type == ThreadTypeType_Libnx) {
|
||||||
util::TSNPrintf(dst, os::ThreadNameLengthMax, "libnx Thread_0x%p", reinterpret_cast<void *>(thread_info->_thread_type));
|
util::TSNPrintf(dst, os::ThreadNameLengthMax, "libnx Thread_0x%010lx", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
|
||||||
} else {
|
} else {
|
||||||
util::TSNPrintf(dst, os::ThreadNameLengthMax, "Thread_0x%p", reinterpret_cast<void *>(thread_info->_thread_type));
|
util::TSNPrintf(dst, os::ThreadNameLengthMax, "Thread_0x%010lx", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
|
|||||||
@@ -20,60 +20,44 @@ namespace ams::powctl::impl {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
os::ThreadType g_interrupt_thread;
|
constinit os::ThreadType g_interrupt_thread;
|
||||||
|
|
||||||
constexpr inline size_t InterruptThreadStackSize = os::MemoryPageSize;
|
constexpr inline size_t InterruptThreadStackSize = os::MemoryPageSize;
|
||||||
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
|
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
|
||||||
|
|
||||||
constinit u8 g_unit_heap_memory[2_KB];
|
|
||||||
constinit lmem::HeapHandle g_unit_heap_handle;
|
|
||||||
constinit sf::UnitHeapMemoryResource g_unit_heap_memory_resource;
|
|
||||||
|
|
||||||
IPowerControlDriver::List &GetDriverList() {
|
IPowerControlDriver::List &GetDriverList() {
|
||||||
static constinit IPowerControlDriver::List s_driver_list;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(IPowerControlDriver::List, s_driver_list);
|
||||||
return s_driver_list;
|
return s_driver_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
|
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
|
||||||
static constinit util::TypedStorage<ddsf::EventHandlerManager> s_interrupt_handler_manager;
|
AMS_FUNCTION_LOCAL_STATIC(ddsf::EventHandlerManager, s_interrupt_handler_manager);
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
return s_interrupt_handler_manager;
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
util::ConstructAt(s_interrupt_handler_manager);
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_interrupt_handler_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
||||||
static constinit util::TypedStorage<ddsf::DeviceCodeEntryManager> s_device_code_entry_manager;
|
class DeviceCodeEntryManagerWithUnitHeap {
|
||||||
static constinit bool s_initialized = false;
|
private:
|
||||||
static constinit os::SdkMutex s_mutex;
|
u8 m_heap_memory[2_KB];
|
||||||
|
sf::UnitHeapMemoryResource m_memory_resource;
|
||||||
|
util::TypedStorage<ddsf::DeviceCodeEntryManager> m_manager;
|
||||||
|
public:
|
||||||
|
DeviceCodeEntryManagerWithUnitHeap() {
|
||||||
|
/* Initialize the memory resource. */
|
||||||
|
m_memory_resource.Attach(lmem::CreateUnitHeap(m_heap_memory, sizeof(m_heap_memory), sizeof(ddsf::DeviceCodeEntryHolder), lmem::CreateOption_ThreadSafe));
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
/* Construct the entry manager. */
|
||||||
std::scoped_lock lk(s_mutex);
|
util::ConstructAt(m_manager, std::addressof(m_memory_resource));
|
||||||
|
}
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
ALWAYS_INLINE operator ddsf::DeviceCodeEntryManager &() {
|
||||||
/* Initialize the entry code heap. */
|
return util::GetReference(m_manager);
|
||||||
g_unit_heap_handle = lmem::CreateUnitHeap(g_unit_heap_memory, sizeof(g_unit_heap_memory), sizeof(ddsf::DeviceCodeEntryHolder), lmem::CreateOption_ThreadSafe);
|
}
|
||||||
|
};
|
||||||
|
AMS_FUNCTION_LOCAL_STATIC(DeviceCodeEntryManagerWithUnitHeap, s_device_code_entry_manager_holder);
|
||||||
|
|
||||||
/* Initialize the entry code memory resource. */
|
return s_device_code_entry_manager_holder;
|
||||||
g_unit_heap_memory_resource.Attach(g_unit_heap_handle);
|
|
||||||
|
|
||||||
/* Make the entry manager using the newly initialized memory resource. */
|
|
||||||
util::ConstructAt(s_device_code_entry_manager, std::addressof(g_unit_heap_memory_resource));
|
|
||||||
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_device_code_entry_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterruptThreadFunction(void *arg) {
|
void InterruptThreadFunction(void *arg) {
|
||||||
|
|||||||
@@ -24,25 +24,14 @@ namespace ams::pwm::driver::impl {
|
|||||||
constinit int g_init_count = 0;
|
constinit int g_init_count = 0;
|
||||||
|
|
||||||
pwm::driver::IPwmDriver::List &GetPwmDriverList() {
|
pwm::driver::IPwmDriver::List &GetPwmDriverList() {
|
||||||
static constinit pwm::driver::IPwmDriver::List s_driver_list;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(pwm::driver::IPwmDriver::List, s_driver_list);
|
||||||
return s_driver_list;
|
return s_driver_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
|
||||||
static constinit util::TypedStorage<ddsf::DeviceCodeEntryManager> s_device_code_entry_manager;
|
AMS_FUNCTION_LOCAL_STATIC(ddsf::DeviceCodeEntryManager, s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
return s_device_code_entry_manager;
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
util::ConstructAt(s_device_code_entry_manager, ddsf::GetDeviceCodeEntryHolderMemoryResource());
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return util::GetReference(s_device_code_entry_manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,14 +289,8 @@ namespace ams::settings::impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lmem::HeapHandle &GetHeapHandle() {
|
lmem::HeapHandle &GetHeapHandle() {
|
||||||
static constinit bool s_is_initialized = false;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(u8, s_heap_memory[HeapMemorySize]);
|
||||||
static constinit lmem::HeapHandle s_heap_handle;
|
AMS_FUNCTION_LOCAL_STATIC(lmem::HeapHandle, s_heap_handle, lmem::CreateExpHeap(s_heap_memory, sizeof(s_heap_memory), lmem::CreateOption_ThreadSafe));
|
||||||
static constinit u8 s_heap_memory[HeapMemorySize];
|
|
||||||
|
|
||||||
if (!s_is_initialized) {
|
|
||||||
s_heap_handle = lmem::CreateExpHeap(s_heap_memory, sizeof(s_heap_memory), lmem::CreateOption_None);
|
|
||||||
s_is_initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_heap_handle;
|
return s_heap_handle;
|
||||||
}
|
}
|
||||||
@@ -314,24 +308,15 @@ namespace ams::settings::impl {
|
|||||||
AMS_ASSERT(out != nullptr);
|
AMS_ASSERT(out != nullptr);
|
||||||
|
|
||||||
/* Declare static instance variables. */
|
/* Declare static instance variables. */
|
||||||
static constinit util::TypedStorage<Map> s_storage = {};
|
AMS_FUNCTION_LOCAL_STATIC(Map, s_map);
|
||||||
static constinit bool s_is_initialized = false;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(bool, s_is_map_loaded, false);
|
||||||
static constinit bool s_is_loaded = false;
|
|
||||||
|
|
||||||
/* Get pointer to the map. */
|
/* Get pointer to the map. */
|
||||||
Map *map = util::GetPointer(s_storage);
|
Map * const map = std::addressof(s_map);
|
||||||
|
|
||||||
/* Construct the map, if we haven't already. */
|
|
||||||
if (AMS_UNLIKELY(!s_is_initialized)) {
|
|
||||||
/* Construct the instance. */
|
|
||||||
util::ConstructAt(s_storage);
|
|
||||||
|
|
||||||
/* Note that we constructed. */
|
|
||||||
s_is_initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* TODO: Mutex? */
|
||||||
/* Load the map, if we haven't already. */
|
/* Load the map, if we haven't already. */
|
||||||
if (AMS_UNLIKELY(!s_is_loaded)) {
|
if (AMS_UNLIKELY(!s_is_map_loaded)) {
|
||||||
/* Attempt to load the map, allowing for failure if acceptable. */
|
/* Attempt to load the map, allowing for failure if acceptable. */
|
||||||
const auto result = LoadKeyValueStoreMap(map);
|
const auto result = LoadKeyValueStoreMap(map);
|
||||||
|
|
||||||
@@ -340,7 +325,7 @@ namespace ams::settings::impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Note that the map is loaded. */
|
/* Note that the map is loaded. */
|
||||||
s_is_loaded = true;
|
s_is_map_loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the output pointer. */
|
/* Set the output pointer. */
|
||||||
@@ -425,26 +410,13 @@ namespace ams::settings::impl {
|
|||||||
AMS_ASSERT(out_data != nullptr);
|
AMS_ASSERT(out_data != nullptr);
|
||||||
|
|
||||||
/* Declare static instance variables. */
|
/* Declare static instance variables. */
|
||||||
static constinit util::TypedStorage<SystemData> s_storage = {};
|
AMS_FUNCTION_LOCAL_STATIC(SystemData, s_data, id, GetSystemDataMountName<T>());
|
||||||
static constinit bool s_initialized = false;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(bool, s_mounted, false);
|
||||||
static constinit bool s_mounted = false;
|
|
||||||
|
|
||||||
/* Get pointer to the system data. */
|
/* Get pointer to the system data. */
|
||||||
SystemData *data = util::GetPointer(s_storage);
|
SystemData *data = std::addressof(s_data);
|
||||||
|
|
||||||
/* Construct the system data, if we haven't already. */
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
|
||||||
/* Construct the instance. */
|
|
||||||
util::ConstructAt(s_storage);
|
|
||||||
|
|
||||||
/* Setup system data. */
|
|
||||||
data->SetSystemDataId(id);
|
|
||||||
data->SetMountName(GetSystemDataMountName<T>());
|
|
||||||
|
|
||||||
/* Note that we constructed. */
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* TODO: Mutex? */
|
||||||
/* Mount the system data, if we haven't already. */
|
/* Mount the system data, if we haven't already. */
|
||||||
if (AMS_UNLIKELY(!s_mounted)) {
|
if (AMS_UNLIKELY(!s_mounted)) {
|
||||||
/* Mount the system data. */
|
/* Mount the system data. */
|
||||||
@@ -464,28 +436,11 @@ namespace ams::settings::impl {
|
|||||||
AMS_ASSERT(out_data != nullptr);
|
AMS_ASSERT(out_data != nullptr);
|
||||||
|
|
||||||
/* Declare static instance variables. */
|
/* Declare static instance variables. */
|
||||||
static constinit util::TypedStorage<SystemSaveData> s_storage = {};
|
AMS_FUNCTION_LOCAL_STATIC(SystemSaveData, s_data, SystemSaveDataId, SystemSaveDataSize, SystemSaveDataJournalSize, SystemSaveDataFlags, SystemSaveDataMountName);
|
||||||
static constinit bool s_initialized = false;
|
AMS_FUNCTION_LOCAL_STATIC_CONSTINIT(bool, s_mounted, false);
|
||||||
static constinit bool s_mounted = false;
|
|
||||||
|
|
||||||
/* Get pointer to the system data. */
|
/* Get pointer to the system save data. */
|
||||||
SystemSaveData *data = util::GetPointer(s_storage);
|
SystemSaveData *data = std::addressof(s_data);
|
||||||
|
|
||||||
/* Construct the system data, if we haven't already. */
|
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
|
||||||
/* Construct the instance. */
|
|
||||||
util::ConstructAt(s_storage);
|
|
||||||
|
|
||||||
/* Setup system data. */
|
|
||||||
data->SetSystemSaveDataId(SystemSaveDataId);
|
|
||||||
data->SetTotalSize(SystemSaveDataSize);
|
|
||||||
data->SetJournalSize(SystemSaveDataJournalSize);
|
|
||||||
data->SetFlags(SystemSaveDataFlags);
|
|
||||||
data->SetMountName(SystemSaveDataMountName);
|
|
||||||
|
|
||||||
/* Note that we constructed. */
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Mount the system data, if we haven't already. */
|
/* Mount the system data, if we haven't already. */
|
||||||
if (AMS_UNLIKELY(!s_mounted)) {
|
if (AMS_UNLIKELY(!s_mounted)) {
|
||||||
|
|||||||
@@ -56,27 +56,33 @@ namespace ams::settings::impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SplConfig GetSplConfig() {
|
SplConfig GetSplConfig() {
|
||||||
static constinit bool s_is_initialized = false;
|
class SplConfigHolder {
|
||||||
static constinit SplConfig s_config;
|
NON_COPYABLE(SplConfigHolder);
|
||||||
|
NON_MOVEABLE(SplConfigHolder);
|
||||||
|
private:
|
||||||
|
SplConfig m_config;
|
||||||
|
public:
|
||||||
|
SplConfigHolder() {
|
||||||
|
/* Initialize spl. */
|
||||||
|
spl::Initialize();
|
||||||
|
ON_SCOPE_EXIT { spl::Finalize(); };
|
||||||
|
|
||||||
if (!s_is_initialized) {
|
/* Create the config. */
|
||||||
/* Initialize spl. */
|
m_config = {
|
||||||
spl::Initialize();
|
.is_development = spl::IsDevelopment(),
|
||||||
ON_SCOPE_EXIT { spl::Finalize(); };
|
.hardware_type = ConvertToSplHardwareType(spl::GetHardwareType()),
|
||||||
|
.is_quest = IsSplRetailInteractiveDisplayStateEnabled(spl::GetRetailInteractiveDisplayState()),
|
||||||
|
.device_id_low = spl::GetDeviceIdLow(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the config. */
|
ALWAYS_INLINE operator SplConfig() {
|
||||||
s_config = {
|
return m_config;
|
||||||
.is_development = spl::IsDevelopment(),
|
}
|
||||||
.hardware_type = ConvertToSplHardwareType(spl::GetHardwareType()),
|
};
|
||||||
.is_quest = IsSplRetailInteractiveDisplayStateEnabled(spl::GetRetailInteractiveDisplayState()),
|
|
||||||
.device_id_low = spl::GetDeviceIdLow(),
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Mark as initialized. */
|
AMS_FUNCTION_LOCAL_STATIC(SplConfigHolder, s_config_holder);
|
||||||
s_is_initialized = true;
|
return s_config_holder;
|
||||||
}
|
|
||||||
|
|
||||||
return s_config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,27 +25,9 @@ namespace ams::settings::impl {
|
|||||||
StaticObject();
|
StaticObject();
|
||||||
public:
|
public:
|
||||||
static T &Get() {
|
static T &Get() {
|
||||||
/* Declare static instance variables. */
|
AMS_FUNCTION_LOCAL_STATIC(T, s_object);
|
||||||
static constinit util::TypedStorage<T> s_storage = {};
|
|
||||||
static constinit bool s_initialized = false;
|
|
||||||
static constinit os::SdkMutex s_mutex;
|
|
||||||
|
|
||||||
/* If we haven't already done so, construct the instance. */
|
return s_object;
|
||||||
if (AMS_UNLIKELY(!s_initialized)) {
|
|
||||||
std::scoped_lock lk(s_mutex);
|
|
||||||
|
|
||||||
/* Check that we didn't concurrently construct the instance. */
|
|
||||||
if (AMS_LIKELY(!s_initialized)) {
|
|
||||||
/* Construct the instance. */
|
|
||||||
util::ConstructAt(s_storage);
|
|
||||||
|
|
||||||
/* Note that we constructed. */
|
|
||||||
s_initialized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the constructed instance. */
|
|
||||||
return util::GetReference(s_storage);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ namespace ams::settings::impl {
|
|||||||
public:
|
public:
|
||||||
SystemData() : m_system_data_id(), m_mount_name(), m_file_path() { /* ... */ }
|
SystemData() : m_system_data_id(), m_mount_name(), m_file_path() { /* ... */ }
|
||||||
|
|
||||||
|
SystemData(ncm::SystemDataId id, const char *mn) : SystemData() {
|
||||||
|
this->SetSystemDataId(id);
|
||||||
|
this->SetMountName(mn);
|
||||||
|
}
|
||||||
|
|
||||||
void SetSystemDataId(ncm::SystemDataId id);
|
void SetSystemDataId(ncm::SystemDataId id);
|
||||||
void SetMountName(const char *name);
|
void SetMountName(const char *name);
|
||||||
Result Mount();
|
Result Mount();
|
||||||
|
|||||||
@@ -30,6 +30,14 @@ namespace ams::settings::impl {
|
|||||||
public:
|
public:
|
||||||
SystemSaveData() : m_system_save_data_id(0), m_save_data_space_id(fs::SaveDataSpaceId::System), m_total_size(0), m_journal_size(0), m_flags(0) { /* ... */ }
|
SystemSaveData() : m_system_save_data_id(0), m_save_data_space_id(fs::SaveDataSpaceId::System), m_total_size(0), m_journal_size(0), m_flags(0) { /* ... */ }
|
||||||
|
|
||||||
|
SystemSaveData(u64 id, s64 total_size, s64 journal_size, u32 flags, const char *mn) : SystemSaveData() {
|
||||||
|
this->SetSystemSaveDataId(id);
|
||||||
|
this->SetTotalSize(total_size);
|
||||||
|
this->SetJournalSize(journal_size);
|
||||||
|
this->SetFlags(flags);
|
||||||
|
this->SetMountName(mn);
|
||||||
|
}
|
||||||
|
|
||||||
void SetSystemSaveDataId(u64 id);
|
void SetSystemSaveDataId(u64 id);
|
||||||
void SetTotalSize(s64 size);
|
void SetTotalSize(s64 size);
|
||||||
void SetJournalSize(s64 size);
|
void SetJournalSize(s64 size);
|
||||||
|
|||||||
@@ -17,6 +17,65 @@
|
|||||||
|
|
||||||
namespace ams::sf::cmif {
|
namespace ams::sf::cmif {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
ALWAYS_INLINE decltype(ServiceCommandMeta::handler) FindCommandHandlerByBinarySearch(const ServiceCommandMeta *entries, const size_t entry_count, const u32 cmd_id, const hos::Version hos_version) {
|
||||||
|
/* Binary search for the handler. */
|
||||||
|
ssize_t lo = 0;
|
||||||
|
ssize_t hi = entry_count - 1;
|
||||||
|
while (lo <= hi) {
|
||||||
|
const size_t mid = (lo + hi) / 2;
|
||||||
|
if (entries[mid].cmd_id < cmd_id) {
|
||||||
|
lo = mid + 1;
|
||||||
|
} else if (entries[mid].cmd_id > cmd_id) {
|
||||||
|
hi = mid - 1;
|
||||||
|
} else {
|
||||||
|
/* Find start. */
|
||||||
|
size_t start = mid;
|
||||||
|
while (start > 0 && entries[start - 1].cmd_id == cmd_id) {
|
||||||
|
--start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find end. */
|
||||||
|
size_t end = mid + 1;
|
||||||
|
while (end < entry_count && entries[end].cmd_id == cmd_id) {
|
||||||
|
++end;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t idx = start; idx < end; ++idx) {
|
||||||
|
if (entries[idx].MatchesVersion(hos_version)) {
|
||||||
|
return entries[idx].GetHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE decltype(ServiceCommandMeta::handler) FindCommandHandlerByLinearSearch(const ServiceCommandMeta *entries, const size_t entry_count, const u32 cmd_id, const hos::Version hos_version) {
|
||||||
|
for (size_t i = 0; i < entry_count; ++i) {
|
||||||
|
if (entries[i].Matches(cmd_id, hos_version)) {
|
||||||
|
return entries[i].GetHandler();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE decltype(ServiceCommandMeta::handler) FindCommandHandler(const ServiceCommandMeta *entries, const size_t entry_count, const u32 cmd_id, const hos::Version hos_version) {
|
||||||
|
if (entry_count >= 8) {
|
||||||
|
return FindCommandHandlerByBinarySearch(entries, entry_count, cmd_id, hos_version);
|
||||||
|
} else {
|
||||||
|
return FindCommandHandlerByLinearSearch(entries, entry_count, cmd_id, hos_version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Result impl::ServiceDispatchTableBase::ProcessMessageImpl(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data, const ServiceCommandMeta *entries, const size_t entry_count) const {
|
Result impl::ServiceDispatchTableBase::ProcessMessageImpl(ServiceDispatchContext &ctx, const cmif::PointerAndSize &in_raw_data, const ServiceCommandMeta *entries, const size_t entry_count) const {
|
||||||
/* Get versioning info. */
|
/* Get versioning info. */
|
||||||
const auto hos_version = hos::GetVersion();
|
const auto hos_version = hos::GetVersion();
|
||||||
@@ -30,13 +89,7 @@ namespace ams::sf::cmif {
|
|||||||
const u32 cmd_id = in_header->command_id;
|
const u32 cmd_id = in_header->command_id;
|
||||||
|
|
||||||
/* Find a handler. */
|
/* Find a handler. */
|
||||||
decltype(ServiceCommandMeta::handler) cmd_handler = nullptr;
|
const auto cmd_handler = FindCommandHandler(entries, entry_count, cmd_id, hos_version);
|
||||||
for (size_t i = 0; i < entry_count; i++) {
|
|
||||||
if (entries[i].Matches(cmd_id, hos_version)) {
|
|
||||||
cmd_handler = entries[i].GetHandler();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
R_UNLESS(cmd_handler != nullptr, sf::cmif::ResultUnknownCommandId());
|
R_UNLESS(cmd_handler != nullptr, sf::cmif::ResultUnknownCommandId());
|
||||||
|
|
||||||
/* Invoke handler. */
|
/* Invoke handler. */
|
||||||
@@ -73,13 +126,7 @@ namespace ams::sf::cmif {
|
|||||||
const u32 cmd_id = in_header->command_id;
|
const u32 cmd_id = in_header->command_id;
|
||||||
|
|
||||||
/* Find a handler. */
|
/* Find a handler. */
|
||||||
decltype(ServiceCommandMeta::handler) cmd_handler = nullptr;
|
const auto cmd_handler = FindCommandHandler(entries, entry_count, cmd_id, hos_version);
|
||||||
for (size_t i = 0; i < entry_count; i++) {
|
|
||||||
if (entries[i].Matches(cmd_id, hos_version)) {
|
|
||||||
cmd_handler = entries[i].GetHandler();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we didn't find a handler, forward the request. */
|
/* If we didn't find a handler, forward the request. */
|
||||||
if (cmd_handler == nullptr) {
|
if (cmd_handler == nullptr) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace ams::socket::impl {
|
|||||||
|
|
||||||
s32 Shutdown(s32 desc, ShutdownMethod how);
|
s32 Shutdown(s32 desc, ShutdownMethod how);
|
||||||
|
|
||||||
|
s32 Socket(Family domain, Type type, Protocol protocol);
|
||||||
s32 SocketExempt(Family domain, Type type, Protocol protocol);
|
s32 SocketExempt(Family domain, Type type, Protocol protocol);
|
||||||
|
|
||||||
s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len);
|
s32 Accept(s32 desc, SockAddr *out_address, SockLenT *out_addr_len);
|
||||||
|
|||||||
@@ -206,6 +206,8 @@ namespace ams::socket::impl {
|
|||||||
|
|
||||||
/* TODO: socket::resolver::EnableResolverCalls()? Not necessary in our case (htc), but consider calling it. */
|
/* TODO: socket::resolver::EnableResolverCalls()? Not necessary in our case (htc), but consider calling it. */
|
||||||
|
|
||||||
|
g_initialized = true;
|
||||||
|
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,6 +424,22 @@ namespace ams::socket::impl {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 Socket(Family domain, Type type, Protocol protocol) {
|
||||||
|
/* Check pre-conditions. */
|
||||||
|
AMS_ABORT_UNLESS(IsInitialized());
|
||||||
|
|
||||||
|
/* Perform the call. */
|
||||||
|
Errno error = Errno::ESuccess;
|
||||||
|
int result = ::bsdSocket(static_cast<int>(domain), static_cast<int>(type), static_cast<int>(protocol));
|
||||||
|
TranslateResultToBsdError(error, result);
|
||||||
|
|
||||||
|
if (result < 0) {
|
||||||
|
socket::impl::SetLastError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
s32 SocketExempt(Family domain, Type type, Protocol protocol) {
|
s32 SocketExempt(Family domain, Type type, Protocol protocol) {
|
||||||
/* Check pre-conditions. */
|
/* Check pre-conditions. */
|
||||||
AMS_ABORT_UNLESS(IsInitialized());
|
AMS_ABORT_UNLESS(IsInitialized());
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ namespace ams::socket {
|
|||||||
return impl::Shutdown(desc, how);
|
return impl::Shutdown(desc, how);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s32 Socket(Family domain, Type type, Protocol protocol) {
|
||||||
|
return impl::Socket(domain, type, protocol);
|
||||||
|
}
|
||||||
|
|
||||||
s32 SocketExempt(Family domain, Type type, Protocol protocol) {
|
s32 SocketExempt(Family domain, Type type, Protocol protocol) {
|
||||||
return impl::SocketExempt(domain, type, protocol);
|
return impl::SocketExempt(domain, type, protocol);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -729,9 +729,10 @@ namespace ams::spl::impl {
|
|||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result TestAesKeySlot(s32 *out_index, s32 keyslot) {
|
Result TestAesKeySlot(s32 *out_index, bool *out_virtual, s32 keyslot) {
|
||||||
if (g_is_physical_keyslot_allowed && IsPhysicalAesKeySlot(keyslot)) {
|
if (g_is_physical_keyslot_allowed && IsPhysicalAesKeySlot(keyslot)) {
|
||||||
*out_index = keyslot;
|
*out_index = keyslot;
|
||||||
|
*out_virtual = false;
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -740,7 +741,8 @@ namespace ams::spl::impl {
|
|||||||
const s32 index = GetVirtualAesKeySlotIndex(keyslot);
|
const s32 index = GetVirtualAesKeySlotIndex(keyslot);
|
||||||
R_UNLESS(g_is_aes_keyslot_allocated[index], spl::ResultInvalidKeySlot());
|
R_UNLESS(g_is_aes_keyslot_allocated[index], spl::ResultInvalidKeySlot());
|
||||||
|
|
||||||
*out_index = index;
|
*out_index = index;
|
||||||
|
*out_virtual = true;
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "sprofile_srv_i_profile_importer.hpp"
|
#include "sprofile_srv_i_profile_importer.hpp"
|
||||||
|
|
||||||
#define AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO(C, H) \
|
#define AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO(C, H) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 100, Result, OpenProfileImporter, (sf::Out<sf::SharedPointer<::ams::sprofile::IProfileImporter>> out), (out)) \
|
AMS_SF_METHOD_INFO(C, H, 100, Result, OpenProfileImporter, (sf::Out<sf::SharedPointer<::ams::sprofile::IProfileImporter>> out), (out)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 200, Result, GetMetadataEntryData, (sf::Out<u32> out_count, const sf::OutArray<sprofile::srv::ProfileMetadataEntryData> &out, const sprofile::srv::ProfileMetadataForImportMetadata &arg), (out_count, out, arg)) \
|
AMS_SF_METHOD_INFO(C, H, 200, Result, GetImportableProfileUrls, (sf::Out<u32> out_count, const sf::OutArray<sprofile::srv::ProfileUrl> &out, const sprofile::srv::ProfileMetadataForImportMetadata &arg), (out_count, out, arg)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 201, Result, IsUpdateNeeded, (sf::Out<bool> out, sprofile::Identifier revision_key), (out, revision_key)) \
|
AMS_SF_METHOD_INFO(C, H, 201, Result, IsUpdateNeeded, (sf::Out<bool> out, sprofile::Identifier revision_key), (out, revision_key)) \
|
||||||
AMS_SF_METHOD_INFO(C, H, 2000, Result, Reset, (), ())
|
AMS_SF_METHOD_INFO(C, H, 2000, Result, Reset, (), ())
|
||||||
|
|
||||||
AMS_SF_DEFINE_INTERFACE(ams::sprofile, ISprofileServiceForBgAgent, AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO)
|
AMS_SF_DEFINE_INTERFACE(ams::sprofile, ISprofileServiceForBgAgent, AMS_SPROFILE_I_SPROFILE_SERVICE_FOR_BG_AGENT_INTERFACE_INFO)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user