Compare commits
52 Commits
1.6.1-prer
...
1800_suppo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cd3d29770 | ||
|
|
f860590d5f | ||
|
|
e6cf70a18a | ||
|
|
b4d453882d | ||
|
|
05df389d30 | ||
|
|
23d6014f91 | ||
|
|
496f8bf45e | ||
|
|
4974a98ec6 | ||
|
|
1f44a9c4bf | ||
|
|
6113ffa191 | ||
|
|
48e86f0406 | ||
|
|
bf3203da0f | ||
|
|
af7a200865 | ||
|
|
cfb12deb51 | ||
|
|
4aac5f0082 | ||
|
|
f5a9d1d6e8 | ||
|
|
5e63792a67 | ||
|
|
8cacb07d5f | ||
|
|
4301e948cc | ||
|
|
c331216f99 | ||
|
|
b12e89d0a9 | ||
|
|
83b3b09e73 | ||
|
|
c8c76bf8f8 | ||
|
|
0220f67085 | ||
|
|
615f8a3ef3 | ||
|
|
000e382c42 | ||
|
|
3627356d4b | ||
|
|
72b0fe6c1c | ||
|
|
e919b80fa2 | ||
|
|
fc16f28d0c | ||
|
|
e09ba765a1 | ||
|
|
3217df147e | ||
|
|
1fa41c3e2a | ||
|
|
db3dc4ebd2 | ||
|
|
742fd16080 | ||
|
|
812b2aeb4c | ||
|
|
46a4357882 | ||
|
|
872c18c501 | ||
|
|
afc0e14556 | ||
|
|
f7bf379cfe | ||
|
|
9f26419b1a | ||
|
|
1b057d48c6 | ||
|
|
0c3afff4d3 | ||
|
|
274f6b63f2 | ||
|
|
2ed8450446 | ||
|
|
60974a5f4e | ||
|
|
fa384fd920 | ||
|
|
3f19db0d96 | ||
|
|
a84f725e21 | ||
|
|
7f61dfdb8d | ||
|
|
c44da84869 | ||
|
|
7f4450f930 |
@@ -27,7 +27,6 @@ This software is licensed under the terms of the GPLv2, with exemptions for spec
|
||||
You can find a copy of the license in the [LICENSE file](LICENSE).
|
||||
|
||||
Exemptions:
|
||||
* The [yuzu Nintendo Switch emulator](https://github.com/yuzu-emu/yuzu) and the [Ryujinx Team and Contributors](https://github.com/orgs/Ryujinx) are exempt from GPLv2 licensing. They are permitted, each at their individual discretion, to instead license any source code authored for the Atmosphère project as either GPLv2 or later or the [MIT license](https://github.com/Atmosphere-NX/Atmosphere/blob/master/docs/licensing_exemptions/MIT_LICENSE). In doing so, they may alter, supplement, or entirely remove the copyright notice for each file they choose to relicense. Neither the Atmosphère project nor its individual contributors shall assert their moral rights against any of the aforementioned projects.
|
||||
* [Nintendo](https://github.com/Nintendo) is exempt from GPLv2 licensing and may (at its option) instead license any source code authored for the Atmosphère project under the Zero-Clause BSD license.
|
||||
|
||||
Credits
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
# Changelog
|
||||
## 1.6.2
|
||||
+ Support was finished for 17.0.0.
|
||||
+ `erpt` was updated to support the latest official behavior.
|
||||
+ `jpegdec` was updated to support the latest official behavior.
|
||||
+ `pm` was updated to support the latest official behavior.
|
||||
+ General system stability improvements to enhance the user's experience.
|
||||
## 1.6.1
|
||||
+ An improved solution to [the problem that would cause consoles which had previously re-built their SYSTEM partition to brick on update-to-17.0.0](https://gist.github.com/SciresM/2ddb708c812ed585c4d99f54e25205ff) was added.
|
||||
+ In particular, booting atmosphère will now automatically detect the problem and unbrick any consoles which have fallen into this state.
|
||||
|
||||
2
emummc/README.md
vendored
2
emummc/README.md
vendored
@@ -2,7 +2,7 @@
|
||||
*A SDMMC driver replacement for Nintendo's Filesystem Services, by **m4xw***
|
||||
|
||||
### Supported Horizon Versions
|
||||
**1.0.0 - 17.0.0**
|
||||
**1.0.0 - 18.0.0**
|
||||
|
||||
## Features
|
||||
* Arbitrary SDMMC backend selection
|
||||
|
||||
8
emummc/source/FS/FS_offsets.c
vendored
8
emummc/source/FS/FS_offsets.c
vendored
@@ -69,6 +69,8 @@
|
||||
#include "offsets/1603_exfat.h"
|
||||
#include "offsets/1700.h"
|
||||
#include "offsets/1700_exfat.h"
|
||||
#include "offsets/1800.h"
|
||||
#include "offsets/1800_exfat.h"
|
||||
#include "../utils/fatal.h"
|
||||
|
||||
#define GET_OFFSET_STRUCT_NAME(vers) g_offsets##vers
|
||||
@@ -149,6 +151,8 @@ DEFINE_OFFSET_STRUCT(_1603);
|
||||
DEFINE_OFFSET_STRUCT(_1603_EXFAT);
|
||||
DEFINE_OFFSET_STRUCT(_1700);
|
||||
DEFINE_OFFSET_STRUCT(_1700_EXFAT);
|
||||
DEFINE_OFFSET_STRUCT(_1800);
|
||||
DEFINE_OFFSET_STRUCT(_1800_EXFAT);
|
||||
|
||||
const fs_offsets_t *get_fs_offsets(enum FS_VER version) {
|
||||
switch (version) {
|
||||
@@ -258,6 +262,10 @@ const fs_offsets_t *get_fs_offsets(enum FS_VER version) {
|
||||
return &(GET_OFFSET_STRUCT_NAME(_1700));
|
||||
case FS_VER_17_0_0_EXFAT:
|
||||
return &(GET_OFFSET_STRUCT_NAME(_1700_EXFAT));
|
||||
case FS_VER_18_0_0:
|
||||
return &(GET_OFFSET_STRUCT_NAME(_1800));
|
||||
case FS_VER_18_0_0_EXFAT:
|
||||
return &(GET_OFFSET_STRUCT_NAME(_1800_EXFAT));
|
||||
default:
|
||||
fatal_abort(Fatal_UnknownVersion);
|
||||
}
|
||||
|
||||
3
emummc/source/FS/FS_versions.h
vendored
3
emummc/source/FS/FS_versions.h
vendored
@@ -101,6 +101,9 @@ enum FS_VER
|
||||
FS_VER_17_0_0,
|
||||
FS_VER_17_0_0_EXFAT,
|
||||
|
||||
FS_VER_18_0_0,
|
||||
FS_VER_18_0_0_EXFAT,
|
||||
|
||||
FS_VER_MAX,
|
||||
};
|
||||
|
||||
|
||||
59
emummc/source/FS/offsets/1800.h
vendored
Normal file
59
emummc/source/FS/offsets/1800.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2019 m4xw <m4x@m4xw.net>
|
||||
* Copyright (c) 2019 Atmosphere-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/>.
|
||||
*/
|
||||
#ifndef __FS_1800_H__
|
||||
#define __FS_1800_H__
|
||||
|
||||
// Accessor vtable getters
|
||||
#define FS_OFFSET_1800_SDMMC_ACCESSOR_GC 0x18AB00
|
||||
#define FS_OFFSET_1800_SDMMC_ACCESSOR_SD 0x18C800
|
||||
#define FS_OFFSET_1800_SDMMC_ACCESSOR_NAND 0x18AFE0
|
||||
|
||||
// Hooks
|
||||
#define FS_OFFSET_1800_SDMMC_WRAPPER_READ 0x186A50
|
||||
#define FS_OFFSET_1800_SDMMC_WRAPPER_WRITE 0x186AB0
|
||||
#define FS_OFFSET_1800_RTLD 0x2A3A4
|
||||
#define FS_OFFSET_1800_RTLD_DESTINATION ((uintptr_t)(INT64_C(-0x44)))
|
||||
|
||||
#define FS_OFFSET_1800_CLKRST_SET_MIN_V_CLK_RATE 0x1A77D0
|
||||
|
||||
// Misc funcs
|
||||
#define FS_OFFSET_1800_LOCK_MUTEX 0x17FCC0
|
||||
#define FS_OFFSET_1800_UNLOCK_MUTEX 0x17FD10
|
||||
|
||||
#define FS_OFFSET_1800_SDMMC_WRAPPER_CONTROLLER_OPEN 0x186A10
|
||||
#define FS_OFFSET_1800_SDMMC_WRAPPER_CONTROLLER_CLOSE 0x186A30
|
||||
|
||||
// Misc Data
|
||||
#define FS_OFFSET_1800_SD_MUTEX 0xFD13F0
|
||||
#define FS_OFFSET_1800_NAND_MUTEX 0xFCCB28
|
||||
#define FS_OFFSET_1800_ACTIVE_PARTITION 0xFCCB68
|
||||
#define FS_OFFSET_1800_SDMMC_DAS_HANDLE 0xFB1950
|
||||
|
||||
// NOPs
|
||||
#define FS_OFFSET_1800_SD_DAS_INIT 0x28F24
|
||||
|
||||
// Nintendo Paths
|
||||
#define FS_OFFSET_1800_NINTENDO_PATHS \
|
||||
{ \
|
||||
{.opcode_reg = 3, .adrp_offset = 0x00068B08, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 3, .adrp_offset = 0x000758DC, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 4, .adrp_offset = 0x0007C77C, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 4, .adrp_offset = 0x000905C4, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 0, .adrp_offset = 0, .add_rel_offset = 0}, \
|
||||
}
|
||||
|
||||
#endif // __FS_1800_H__
|
||||
59
emummc/source/FS/offsets/1800_exfat.h
vendored
Normal file
59
emummc/source/FS/offsets/1800_exfat.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2019 m4xw <m4x@m4xw.net>
|
||||
* Copyright (c) 2019 Atmosphere-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/>.
|
||||
*/
|
||||
#ifndef __FS_1800_EXFAT_H__
|
||||
#define __FS_1800_EXFAT_H__
|
||||
|
||||
// Accessor vtable getters
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_ACCESSOR_GC 0x195B90
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_ACCESSOR_SD 0x197890
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_ACCESSOR_NAND 0x196070
|
||||
|
||||
// Hooks
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_WRAPPER_READ 0x191AE0
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_WRAPPER_WRITE 0x191B40
|
||||
#define FS_OFFSET_1800_EXFAT_RTLD 0x2A3A4
|
||||
#define FS_OFFSET_1800_EXFAT_RTLD_DESTINATION ((uintptr_t)(INT64_C(-0x44)))
|
||||
|
||||
#define FS_OFFSET_1800_EXFAT_CLKRST_SET_MIN_V_CLK_RATE 0x1B2860
|
||||
|
||||
// Misc funcs
|
||||
#define FS_OFFSET_1800_EXFAT_LOCK_MUTEX 0x18AD50
|
||||
#define FS_OFFSET_1800_EXFAT_UNLOCK_MUTEX 0x18ADA0
|
||||
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_WRAPPER_CONTROLLER_OPEN 0x191AA0
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_WRAPPER_CONTROLLER_CLOSE 0x191AC0
|
||||
|
||||
// Misc Data
|
||||
#define FS_OFFSET_1800_EXFAT_SD_MUTEX 0xFE33F0
|
||||
#define FS_OFFSET_1800_EXFAT_NAND_MUTEX 0xFDEB28
|
||||
#define FS_OFFSET_1800_EXFAT_ACTIVE_PARTITION 0xFDEB68
|
||||
#define FS_OFFSET_1800_EXFAT_SDMMC_DAS_HANDLE 0xFBE950
|
||||
|
||||
// NOPs
|
||||
#define FS_OFFSET_1800_EXFAT_SD_DAS_INIT 0x28F24
|
||||
|
||||
// Nintendo Paths
|
||||
#define FS_OFFSET_1800_EXFAT_NINTENDO_PATHS \
|
||||
{ \
|
||||
{.opcode_reg = 3, .adrp_offset = 0x00068B08, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 3, .adrp_offset = 0x000758DC, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 4, .adrp_offset = 0x0007C77C, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 4, .adrp_offset = 0x000905C4, .add_rel_offset = 0x00000004}, \
|
||||
{.opcode_reg = 0, .adrp_offset = 0, .add_rel_offset = 0}, \
|
||||
}
|
||||
|
||||
#endif // __FS_1800_EXFAT_H__
|
||||
@@ -85,10 +85,10 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
/* We can get away with only including latest because exosphere supports newer-than-expected master key in engine. */
|
||||
/* TODO: Update on next change of keys. */
|
||||
/* Mariko Development Master Kek Source. */
|
||||
.byte 0x43, 0xDB, 0x9D, 0x88, 0xDB, 0x38, 0xE9, 0xBF, 0x3D, 0xD7, 0x83, 0x39, 0xEF, 0xB1, 0x4F, 0xA7
|
||||
.byte 0xE4, 0x45, 0xD0, 0x14, 0xA0, 0xE5, 0xE9, 0x4B, 0xFE, 0x76, 0xF4, 0x29, 0x41, 0xBB, 0x64, 0xED
|
||||
|
||||
/* Mariko Production Master Kek Source. */
|
||||
.byte 0x8D, 0xEE, 0x9E, 0x11, 0x36, 0x3A, 0x9B, 0x0A, 0x6A, 0xC7, 0xBB, 0xE9, 0xD1, 0x03, 0xF7, 0x80
|
||||
.byte 0x4F, 0x41, 0x3C, 0x3B, 0xFB, 0x6A, 0x01, 0x2A, 0x68, 0x9F, 0x83, 0xE9, 0x53, 0xBD, 0x16, 0xD2
|
||||
|
||||
/* Development Master Key Vectors. */
|
||||
.byte 0x46, 0x22, 0xB4, 0x51, 0x9A, 0x7E, 0xA7, 0x7F, 0x62, 0xA1, 0x1F, 0x8F, 0xC5, 0x3A, 0xDB, 0xFE /* Zeroes encrypted with Master Key 00. */
|
||||
@@ -108,6 +108,7 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
.byte 0xD6, 0x80, 0x98, 0xC0, 0xFA, 0xC7, 0x13, 0xCB, 0x93, 0xD2, 0x0B, 0x82, 0x4C, 0xA1, 0x7B, 0x8D /* Master key 0D encrypted with Master key 0E. */
|
||||
.byte 0x78, 0x66, 0x19, 0xBD, 0x86, 0xE7, 0xC1, 0x09, 0x9B, 0x6F, 0x92, 0xB2, 0x58, 0x7D, 0xCF, 0x26 /* Master key 0E encrypted with Master key 0F. */
|
||||
.byte 0x39, 0x1E, 0x7E, 0xF8, 0x7E, 0x73, 0xEA, 0x6F, 0xAF, 0x00, 0x3A, 0xB4, 0xAA, 0xB8, 0xB7, 0x59 /* Master key 0F encrypted with Master key 10. */
|
||||
.byte 0x0C, 0x75, 0x39, 0x15, 0x53, 0xEA, 0x81, 0x11, 0xA3, 0xE0, 0xDC, 0x3D, 0x0E, 0x76, 0xC6, 0xB8 /* Master key 10 encrypted with Master key 11. */
|
||||
|
||||
/* Production Master Key Vectors. */
|
||||
.byte 0x0C, 0xF0, 0x59, 0xAC, 0x85, 0xF6, 0x26, 0x65, 0xE1, 0xE9, 0x19, 0x55, 0xE6, 0xF2, 0x67, 0x3D /* Zeroes encrypted with Master Key 00. */
|
||||
@@ -127,6 +128,7 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
.byte 0xB1, 0x81, 0xA6, 0x0D, 0x72, 0xC7, 0xEE, 0x15, 0x21, 0xF3, 0xC0, 0xB5, 0x6B, 0x61, 0x6D, 0xE7 /* Master key 0D encrypted with Master key 0E. */
|
||||
.byte 0xAF, 0x11, 0x4C, 0x67, 0x17, 0x7A, 0x52, 0x43, 0xF7, 0x70, 0x2F, 0xC7, 0xEF, 0x81, 0x72, 0x16 /* Master key 0E encrypted with Master key 0F. */
|
||||
.byte 0x25, 0x12, 0x8B, 0xCB, 0xB5, 0x46, 0xA1, 0xF8, 0xE0, 0x52, 0x15, 0xB7, 0x0B, 0x57, 0x00, 0xBD /* Master key 0F encrypted with Master key 10. */
|
||||
.byte 0x58, 0x15, 0xD2, 0xF6, 0x8A, 0xE8, 0x19, 0xAB, 0xFB, 0x2D, 0x52, 0x9D, 0xE7, 0x55, 0xF3, 0x93 /* Master key 10 encrypted with Master key 11. */
|
||||
|
||||
/* Device Master Key Source Sources. */
|
||||
.byte 0x8B, 0x4E, 0x1C, 0x22, 0x42, 0x07, 0xC8, 0x73, 0x56, 0x94, 0x08, 0x8B, 0xCC, 0x47, 0x0F, 0x5D /* 4.0.0 Device Master Key Source Source. */
|
||||
@@ -143,6 +145,7 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
.byte 0x5E, 0xC9, 0xC5, 0x0A, 0xD0, 0x5F, 0x8B, 0x7B, 0xA7, 0x39, 0xEA, 0xBC, 0x60, 0x0F, 0x74, 0xE6 /* 15.0.0 Device Master Key Source Source. */
|
||||
.byte 0xEA, 0x90, 0x6E, 0xA8, 0xAE, 0x92, 0x99, 0x64, 0x36, 0xC1, 0xF3, 0x1C, 0xC6, 0x32, 0x83, 0x8C /* 16.0.0 Device Master Key Source Source. */
|
||||
.byte 0xDA, 0xB9, 0xD6, 0x77, 0x52, 0x2D, 0x1F, 0x78, 0x73, 0xC9, 0x98, 0x5B, 0x06, 0xFE, 0xA0, 0x52 /* 17.0.0 Device Master Key Source Source. */
|
||||
.byte 0x14, 0xF5, 0xA5, 0xD0, 0x73, 0x6D, 0x44, 0x80, 0x5F, 0x31, 0x5A, 0x8F, 0x1E, 0xD4, 0x0D, 0x63 /* 18.0.0 Device Master Key Source Source. */
|
||||
|
||||
/* Development Device Master Kek Sources. */
|
||||
.byte 0xD6, 0xBD, 0x9F, 0xC6, 0x18, 0x09, 0xE1, 0x96, 0x20, 0x39, 0x60, 0xD2, 0x89, 0x83, 0x31, 0x34 /* 4.0.0 Device Master Kek Source. */
|
||||
@@ -159,6 +162,7 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
.byte 0xAE, 0x05, 0x48, 0x65, 0xAB, 0x17, 0x9D, 0x3D, 0x51, 0xB7, 0x56, 0xBD, 0x9B, 0x0B, 0x5B, 0x6E /* 15.0.0 Device Master Kek Source. */
|
||||
.byte 0xFF, 0xF6, 0x4B, 0x0F, 0xFF, 0x0D, 0xC0, 0x4F, 0x56, 0x8A, 0x40, 0x74, 0x67, 0xC5, 0xFE, 0x9F /* 16.0.0 Device Master Kek Source. */
|
||||
.byte 0x4E, 0xCE, 0x7B, 0x2A, 0xEA, 0x2E, 0x3D, 0x16, 0xD5, 0x2A, 0xDE, 0xF6, 0xF8, 0x6A, 0x7D, 0x43 /* 17.0.0 Device Master Kek Source. */
|
||||
.byte 0x3B, 0x00, 0x89, 0xD7, 0xA9, 0x9E, 0xB7, 0x70, 0x86, 0x00, 0xC3, 0x49, 0x52, 0x8C, 0xA4, 0xAF /* 18.0.0 Device Master Kek Source. */
|
||||
|
||||
/* Production Device Master Kek Sources. */
|
||||
.byte 0x88, 0x62, 0x34, 0x6E, 0xFA, 0xF7, 0xD8, 0x3F, 0xE1, 0x30, 0x39, 0x50, 0xF0, 0xB7, 0x5D, 0x5D /* 4.0.0 Device Master Kek Source. */
|
||||
@@ -175,3 +179,4 @@ _ZN3ams6secmon4boot15VolatileKeyDataE:
|
||||
.byte 0x7C, 0x30, 0xED, 0x8B, 0x39, 0x25, 0x2C, 0x08, 0x8F, 0x48, 0xDC, 0x28, 0xE6, 0x1A, 0x6B, 0x49 /* 15.0.0 Device Master Kek Source. */
|
||||
.byte 0xF0, 0xF3, 0xFF, 0x52, 0x75, 0x2F, 0xBA, 0x4D, 0x09, 0x72, 0x30, 0x89, 0xA9, 0xDF, 0xFE, 0x1F /* 16.0.0 Device Master Kek Source. */
|
||||
.byte 0x21, 0xD6, 0x35, 0xF1, 0x0F, 0x7A, 0xF0, 0x5D, 0xDF, 0x79, 0x1C, 0x7A, 0xE4, 0x32, 0x82, 0x9E /* 17.0.0 Device Master Kek Source. */
|
||||
.byte 0xE7, 0x85, 0x8C, 0xA2, 0xF4, 0x49, 0xCB, 0x07, 0xD1, 0x8E, 0x48, 0x1B, 0xE8, 0x1E, 0x28, 0x3B /* 18.0.0 Device Master Kek Source. */
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace ams::secmon::boot {
|
||||
}
|
||||
|
||||
/* Check that the key generation is one that we can use. */
|
||||
static_assert(pkg1::KeyGeneration_Count == 17);
|
||||
static_assert(pkg1::KeyGeneration_Count == 18);
|
||||
if (key_generation >= pkg1::KeyGeneration_Count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace ams::nxboot::loader {
|
||||
}
|
||||
|
||||
void Uncompress(void *dst, size_t dst_size, const void *src, size_t src_size) {
|
||||
/* Create an execute a decompressor. */
|
||||
/* Create and execute a decompressor. */
|
||||
Lz4Uncompressor(dst, dst_size, src, src_size).Uncompress();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,17 +23,17 @@ namespace ams::nxboot {
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 MarikoMasterKekSource[se::AesBlockSize] = {
|
||||
/* TODO: Update on next change of keys. */
|
||||
0x8D, 0xEE, 0x9E, 0x11, 0x36, 0x3A, 0x9B, 0x0A, 0x6A, 0xC7, 0xBB, 0xE9, 0xD1, 0x03, 0xF7, 0x80
|
||||
0x4F, 0x41, 0x3C, 0x3B, 0xFB, 0x6A, 0x01, 0x2A, 0x68, 0x9F, 0x83, 0xE9, 0x53, 0xBD, 0x16, 0xD2
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 MarikoMasterKekSourceDev[se::AesBlockSize] = {
|
||||
/* TODO: Update on next change of keys. */
|
||||
0x43, 0xDB, 0x9D, 0x88, 0xDB, 0x38, 0xE9, 0xBF, 0x3D, 0xD7, 0x83, 0x39, 0xEF, 0xB1, 0x4F, 0xA7
|
||||
0xE4, 0x45, 0xD0, 0x14, 0xA0, 0xE5, 0xE9, 0x4B, 0xFE, 0x76, 0xF4, 0x29, 0x41, 0xBB, 0x64, 0xED
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 EristaMasterKekSource[se::AesBlockSize] = {
|
||||
/* TODO: Update on next change of keys. */
|
||||
0x71, 0xB9, 0xA6, 0xC0, 0xFF, 0x97, 0x6B, 0x0C, 0xB4, 0x40, 0xB9, 0xD5, 0x81, 0x5D, 0x81, 0x90
|
||||
0x00, 0x04, 0x5D, 0xF0, 0x4D, 0xCD, 0x14, 0xA3, 0x1C, 0xBF, 0xDE, 0x48, 0x55, 0xBA, 0x35, 0xC1
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 KeyblobKeySource[se::AesBlockSize] = {
|
||||
@@ -71,6 +71,7 @@ namespace ams::nxboot {
|
||||
{ 0x5E, 0xC9, 0xC5, 0x0A, 0xD0, 0x5F, 0x8B, 0x7B, 0xA7, 0x39, 0xEA, 0xBC, 0x60, 0x0F, 0x74, 0xE6 }, /* 15.0.0 Device Master Key Source Source. */
|
||||
{ 0xEA, 0x90, 0x6E, 0xA8, 0xAE, 0x92, 0x99, 0x64, 0x36, 0xC1, 0xF3, 0x1C, 0xC6, 0x32, 0x83, 0x8C }, /* 16.0.0 Device Master Key Source Source. */
|
||||
{ 0xDA, 0xB9, 0xD6, 0x77, 0x52, 0x2D, 0x1F, 0x78, 0x73, 0xC9, 0x98, 0x5B, 0x06, 0xFE, 0xA0, 0x52 }, /* 17.0.0 Device Master Key Source Source. */
|
||||
{ 0x14, 0xF5, 0xA5, 0xD0, 0x73, 0x6D, 0x44, 0x80, 0x5F, 0x31, 0x5A, 0x8F, 0x1E, 0xD4, 0x0D, 0x63 }, /* 18.0.0 Device Master Key Source Source. */
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 DeviceMasterKekSources[pkg1::OldDeviceMasterKeyCount][se::AesBlockSize] = {
|
||||
@@ -88,6 +89,7 @@ namespace ams::nxboot {
|
||||
{ 0x7C, 0x30, 0xED, 0x8B, 0x39, 0x25, 0x2C, 0x08, 0x8F, 0x48, 0xDC, 0x28, 0xE6, 0x1A, 0x6B, 0x49 }, /* 15.0.0 Device Master Kek Source. */
|
||||
{ 0xF0, 0xF3, 0xFF, 0x52, 0x75, 0x2F, 0xBA, 0x4D, 0x09, 0x72, 0x30, 0x89, 0xA9, 0xDF, 0xFE, 0x1F }, /* 16.0.0 Device Master Kek Source. */
|
||||
{ 0x21, 0xD6, 0x35, 0xF1, 0x0F, 0x7A, 0xF0, 0x5D, 0xDF, 0x79, 0x1C, 0x7A, 0xE4, 0x32, 0x82, 0x9E }, /* 17.0.0 Device Master Kek Source. */
|
||||
{ 0xE7, 0x85, 0x8C, 0xA2, 0xF4, 0x49, 0xCB, 0x07, 0xD1, 0x8E, 0x48, 0x1B, 0xE8, 0x1E, 0x28, 0x3B }, /* 18.0.0 Device Master Kek Source. */
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 DeviceMasterKekSourcesDev[pkg1::OldDeviceMasterKeyCount][se::AesBlockSize] = {
|
||||
@@ -105,6 +107,7 @@ namespace ams::nxboot {
|
||||
{ 0xAE, 0x05, 0x48, 0x65, 0xAB, 0x17, 0x9D, 0x3D, 0x51, 0xB7, 0x56, 0xBD, 0x9B, 0x0B, 0x5B, 0x6E }, /* 15.0.0 Device Master Kek Source. */
|
||||
{ 0xFF, 0xF6, 0x4B, 0x0F, 0xFF, 0x0D, 0xC0, 0x4F, 0x56, 0x8A, 0x40, 0x74, 0x67, 0xC5, 0xFE, 0x9F }, /* 16.0.0 Device Master Kek Source. */
|
||||
{ 0x4E, 0xCE, 0x7B, 0x2A, 0xEA, 0x2E, 0x3D, 0x16, 0xD5, 0x2A, 0xDE, 0xF6, 0xF8, 0x6A, 0x7D, 0x43 }, /* 17.0.0 Device Master Kek Source. */
|
||||
{ 0x3B, 0x00, 0x89, 0xD7, 0xA9, 0x9E, 0xB7, 0x70, 0x86, 0x00, 0xC3, 0x49, 0x52, 0x8C, 0xA4, 0xAF }, /* 18.0.0 Device Master Kek Source. */
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 MasterKeySources[pkg1::KeyGeneration_Count][se::AesBlockSize] = {
|
||||
@@ -125,6 +128,7 @@ namespace ams::nxboot {
|
||||
{ 0xB1, 0x81, 0xA6, 0x0D, 0x72, 0xC7, 0xEE, 0x15, 0x21, 0xF3, 0xC0, 0xB5, 0x6B, 0x61, 0x6D, 0xE7 }, /* Master key 0D encrypted with Master key 0E. */
|
||||
{ 0xAF, 0x11, 0x4C, 0x67, 0x17, 0x7A, 0x52, 0x43, 0xF7, 0x70, 0x2F, 0xC7, 0xEF, 0x81, 0x72, 0x16 }, /* Master key 0E encrypted with Master key 0F. */
|
||||
{ 0x25, 0x12, 0x8B, 0xCB, 0xB5, 0x46, 0xA1, 0xF8, 0xE0, 0x52, 0x15, 0xB7, 0x0B, 0x57, 0x00, 0xBD }, /* Master key 0F encrypted with Master key 10. */
|
||||
{ 0x58, 0x15, 0xD2, 0xF6, 0x8A, 0xE8, 0x19, 0xAB, 0xFB, 0x2D, 0x52, 0x9D, 0xE7, 0x55, 0xF3, 0x93 }, /* Master key 10 encrypted with Master key 11. */
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constexpr inline const u8 MasterKeySourcesDev[pkg1::KeyGeneration_Count][se::AesBlockSize] = {
|
||||
@@ -145,6 +149,7 @@ namespace ams::nxboot {
|
||||
{ 0xD6, 0x80, 0x98, 0xC0, 0xFA, 0xC7, 0x13, 0xCB, 0x93, 0xD2, 0x0B, 0x82, 0x4C, 0xA1, 0x7B, 0x8D }, /* Master key 0D encrypted with Master key 0E. */
|
||||
{ 0x78, 0x66, 0x19, 0xBD, 0x86, 0xE7, 0xC1, 0x09, 0x9B, 0x6F, 0x92, 0xB2, 0x58, 0x7D, 0xCF, 0x26 }, /* Master key 0E encrypted with Master key 0F. */
|
||||
{ 0x39, 0x1E, 0x7E, 0xF8, 0x7E, 0x73, 0xEA, 0x6F, 0xAF, 0x00, 0x3A, 0xB4, 0xAA, 0xB8, 0xB7, 0x59 }, /* Master key 0F encrypted with Master key 10. */
|
||||
{ 0x0C, 0x75, 0x39, 0x15, 0x53, 0xEA, 0x81, 0x11, 0xA3, 0xE0, 0xDC, 0x3D, 0x0E, 0x76, 0xC6, 0xB8 }, /* Master key 10 encrypted with Master key 11. */
|
||||
};
|
||||
|
||||
alignas(se::AesBlockSize) constinit u8 MasterKeys[pkg1::OldMasterKeyCount][se::AesBlockSize] = {};
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
/* Check that the key generation is one that we can use. */
|
||||
static_assert(pkg1::KeyGeneration_Count == 17);
|
||||
static_assert(pkg1::KeyGeneration_Count == 18);
|
||||
if (key_generation >= pkg1::KeyGeneration_Count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -259,6 +259,8 @@ namespace ams::nxboot {
|
||||
return ams::TargetFirmware_16_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20230906", 8) == 0) {
|
||||
return ams::TargetFirmware_17_0_0;
|
||||
} else if (std::memcmp(package1 + 0x10, "20240207", 8) == 0) {
|
||||
return ams::TargetFirmware_18_0_0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -171,6 +171,9 @@ namespace ams::nxboot {
|
||||
FsVersion_17_0_0,
|
||||
FsVersion_17_0_0_Exfat,
|
||||
|
||||
FsVersion_18_0_0,
|
||||
FsVersion_18_0_0_Exfat,
|
||||
|
||||
FsVersion_Count,
|
||||
};
|
||||
|
||||
@@ -254,6 +257,9 @@ namespace ams::nxboot {
|
||||
|
||||
{ 0x27, 0x07, 0x3B, 0xF0, 0xA1, 0xB8, 0xCE, 0x61 }, /* FsVersion_17_0_0 */
|
||||
{ 0xEE, 0x0F, 0x4B, 0xAC, 0x6D, 0x1F, 0xFC, 0x4B }, /* FsVersion_17_0_0_Exfat */
|
||||
|
||||
{ 0x79, 0x5F, 0x5A, 0x5E, 0xB0, 0xC6, 0x77, 0x9E }, /* FsVersion_18_0_0 */
|
||||
{ 0x1E, 0x2C, 0x64, 0xB1, 0xCC, 0xE2, 0x78, 0x24 }, /* FsVersion_18_0_0_Exfat */
|
||||
};
|
||||
|
||||
const InitialProcessBinaryHeader *FindInitialProcessBinary(const pkg2::Package2Header *header, const u8 *data, ams::TargetFirmware target_firmware) {
|
||||
@@ -385,15 +391,6 @@ namespace ams::nxboot {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
InitialProcessMeta *FindInitialProcess(const se::Sha256Hash &hash) {
|
||||
for (InitialProcessMeta *cur = std::addressof(g_initial_process_meta); cur != nullptr; cur = cur->next) {
|
||||
if (std::memcmp(std::addressof(cur->kip_hash), std::addressof(hash), sizeof(hash)) == 0) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
u32 GetPatchSegments(const InitialProcessHeader *kip, u32 offset, size_t size) {
|
||||
/* Create segment mask. */
|
||||
u32 segments = 0;
|
||||
@@ -474,78 +471,6 @@ namespace ams::nxboot {
|
||||
meta->patches_tail = new_patch;
|
||||
}
|
||||
|
||||
void AddIps24PatchToKip(InitialProcessMeta *meta, const u8 *ips, s32 size) {
|
||||
while (size > 0) {
|
||||
/* Read offset, stopping at EOF */
|
||||
const u32 offset = (static_cast<u32>(ips[0]) << 16) | (static_cast<u32>(ips[1]) << 8) | (static_cast<u32>(ips[2]) << 0);
|
||||
if (offset == 0x454F46) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read size. */
|
||||
const u16 cur_size = (static_cast<u32>(ips[3]) << 8) | (static_cast<u32>(ips[4]) << 0);
|
||||
|
||||
if (cur_size > 0) {
|
||||
/* Add patch. */
|
||||
AddPatch(meta, offset, ips + 5, cur_size, false);
|
||||
|
||||
/* Advance. */
|
||||
ips += (5 + cur_size);
|
||||
size -= (5 + cur_size);
|
||||
} else {
|
||||
/* Read RLE size */
|
||||
const u16 rle_size = (static_cast<u32>(ips[5]) << 8) | (static_cast<u32>(ips[6]) << 0);
|
||||
|
||||
/* Add patch. */
|
||||
AddPatch(meta, offset, ips + 7, rle_size, true);
|
||||
|
||||
/* Advance. */
|
||||
ips += 8;
|
||||
size -= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddIps32PatchToKip(InitialProcessMeta *meta, const u8 *ips, s32 size) {
|
||||
while (size > 0) {
|
||||
/* Read offset, stopping at EOF */
|
||||
const u32 offset = (static_cast<u32>(ips[0]) << 24) | (static_cast<u32>(ips[1]) << 16) | (static_cast<u32>(ips[2]) << 8) | (static_cast<u32>(ips[3]) << 0);
|
||||
if (offset == 0x45454F46) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read size. */
|
||||
const u16 cur_size = (static_cast<u32>(ips[4]) << 8) | (static_cast<u32>(ips[5]) << 0);
|
||||
|
||||
if (cur_size > 0) {
|
||||
/* Add patch. */
|
||||
AddPatch(meta, offset, ips + 6, cur_size, false);
|
||||
|
||||
/* Advance. */
|
||||
ips += (6 + cur_size);
|
||||
size -= (6 + cur_size);
|
||||
} else {
|
||||
/* Read RLE size */
|
||||
const u16 rle_size = (static_cast<u32>(ips[6]) << 8) | (static_cast<u32>(ips[7]) << 0);
|
||||
|
||||
/* Add patch. */
|
||||
AddPatch(meta, offset, ips + 8, rle_size, true);
|
||||
|
||||
/* Advance. */
|
||||
ips += 9;
|
||||
size -= 9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AddIpsPatchToKip(InitialProcessMeta *meta, const u8 *ips, s32 size) {
|
||||
if (std::memcmp(ips, "PATCH", 5) == 0) {
|
||||
AddIps24PatchToKip(meta, ips + 5, size - 5);
|
||||
} else if (std::memcmp(ips, "IPS32", 5) == 0) {
|
||||
AddIps32PatchToKip(meta, ips + 5, size - 5);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr const u8 NogcPatch0[] = {
|
||||
0x80
|
||||
};
|
||||
@@ -698,6 +623,14 @@ namespace ams::nxboot {
|
||||
AddPatch(fs_meta, 0x195FA9, NogcPatch0, sizeof(NogcPatch0));
|
||||
AddPatch(fs_meta, 0x170060, NogcPatch1, sizeof(NogcPatch1));
|
||||
break;
|
||||
case FsVersion_18_0_0:
|
||||
AddPatch(fs_meta, 0x18AF49, NogcPatch0, sizeof(NogcPatch0));
|
||||
AddPatch(fs_meta, 0x164B50, NogcPatch1, sizeof(NogcPatch1));
|
||||
break;
|
||||
case FsVersion_18_0_0_Exfat:
|
||||
AddPatch(fs_meta, 0x195FD9, NogcPatch0, sizeof(NogcPatch0));
|
||||
AddPatch(fs_meta, 0x16FBE0, NogcPatch1, sizeof(NogcPatch1));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -891,106 +824,6 @@ namespace ams::nxboot {
|
||||
}
|
||||
|
||||
/* TODO ams.tma2: add mount_host patches. */
|
||||
|
||||
/* Add generic patches. */
|
||||
{
|
||||
/* Create patch path. */
|
||||
char patch_path[0x220];
|
||||
std::memcpy(patch_path, "sdmc:/atmosphere/kip_patches", 0x1D);
|
||||
|
||||
fs::DirectoryHandle patch_root_dir;
|
||||
if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(patch_root_dir), patch_path))) {
|
||||
ON_SCOPE_EXIT { fs::CloseDirectory(patch_root_dir); };
|
||||
|
||||
s64 count;
|
||||
fs::DirectoryEntry entries[1];
|
||||
while (R_SUCCEEDED(fs::ReadDirectory(std::addressof(count), entries, patch_root_dir, util::size(entries))) && count > 0) {
|
||||
/* Check that dir is a dir. */
|
||||
if (fs::GetEntryType(entries[0]) != fs::DirectoryEntryType_Directory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* For compatibility, ignore the old "default_nogc" patches. */
|
||||
if (std::strcmp(entries[0].file_name, "default_nogc") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Get filename length. */
|
||||
const int dir_len = std::strlen(entries[0].file_name);
|
||||
|
||||
/* Adjust patch path. */
|
||||
patch_path[0x1C] = '/';
|
||||
std::memcpy(patch_path + 0x1D, entries[0].file_name, dir_len + 1);
|
||||
|
||||
/* Try to open the patch subdirectory. */
|
||||
fs::DirectoryHandle patch_dir;
|
||||
if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(patch_dir), patch_path))) {
|
||||
ON_SCOPE_EXIT { fs::CloseDirectory(patch_dir); };
|
||||
|
||||
/* Read patches. */
|
||||
while (R_SUCCEEDED(fs::ReadDirectory(std::addressof(count), entries, patch_dir, util::size(entries))) && count > 0) {
|
||||
/* Check that file is a file. */
|
||||
if (fs::GetEntryType(entries[0]) != fs::DirectoryEntryType_File) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Get filename length. */
|
||||
const int name_len = std::strlen(entries[0].file_name);
|
||||
|
||||
/* Adjust patch path. */
|
||||
patch_path[0x1D + dir_len] = '/';
|
||||
std::memcpy(patch_path + 0x1D + dir_len + 1, entries[0].file_name, name_len + 1);
|
||||
|
||||
/* Check that file is "{hex}.ips" file. */
|
||||
const int path_len = 0x1D + dir_len + 1 + name_len;
|
||||
if (name_len != 0x44 || std::memcmp(patch_path + path_len - 4, ".ips", 5) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check that the filename is hex. */
|
||||
bool valid_name = true;
|
||||
se::Sha256Hash patch_name = {};
|
||||
u32 shift = 4;
|
||||
for (int i = 0; i < name_len - 4; ++i) {
|
||||
const char c = entries[0].file_name[i];
|
||||
|
||||
u8 val;
|
||||
if ('0' <= c && c <= '9') {
|
||||
val = (c - '0');
|
||||
} else if ('a' <= c && c <= 'f') {
|
||||
val = (c - 'a') + 10;
|
||||
} else if ('A' <= c && c <= 'F') {
|
||||
val = (c - 'A') + 10;
|
||||
} else {
|
||||
valid_name = false;
|
||||
break;
|
||||
}
|
||||
|
||||
patch_name.bytes[i >> 1] |= val << shift;
|
||||
shift ^= 4;
|
||||
}
|
||||
|
||||
/* Ignore invalid patches. */
|
||||
if (!valid_name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Find kip for the patch. */
|
||||
auto *kip_meta = FindInitialProcess(patch_name);
|
||||
if (kip_meta == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Read the ips patch. */
|
||||
s64 file_size;
|
||||
if (u8 *ips = static_cast<u8 *>(ReadFile(std::addressof(file_size), patch_path)); ips != nullptr) {
|
||||
AddIpsPatchToKip(kip_meta, ips, static_cast<s32>(file_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the fs version we're using. */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[subrepo]
|
||||
remote = https://github.com/Atmosphere-NX/Atmosphere-libs
|
||||
branch = master
|
||||
commit = 965e05b3cc5ea74de7e3071c3554135e828ce42e
|
||||
parent = 183f3e0d7e0c620d213be53c66d9156f55389be2
|
||||
commit = bfc55834869fe24f8d94550bc6909a65ae7d35c2
|
||||
parent = 742fd16080bce8cd664d6244304a771f82e8aa04
|
||||
method = merge
|
||||
cmdver = 0.4.1
|
||||
|
||||
@@ -66,7 +66,7 @@ endif
|
||||
|
||||
|
||||
ifeq ($(ATMOSPHERE_BOARD),nx-hac-001)
|
||||
export LDFLAGS = -specs=$(ATMOSPHERE_LIBRARIES_DIR)/libstratosphere/stratosphere.specs -specs=$(DEVKITPRO)/libnx/switch.specs $(CXXFLAGS) $(CXXWRAPS) $(CXXREQUIRED) -Wl,-Map,$(notdir $*.map)
|
||||
export LDFLAGS = -specs=$(ATMOSPHERE_LIBRARIES_DIR)/libstratosphere/stratosphere.specs -specs=$(DEVKITPRO)/libnx/switch.specs $(CXXFLAGS) $(CXXWRAPS) $(CXXREQUIRED) -Wl,-Map,$(notdir $*.map) -Wl,-z,relro,-z,now
|
||||
else ifeq ($(ATMOSPHERE_OS_NAME),macos)
|
||||
export LDFLAGS = $(CXXFLAGS) $(CXXWRAPS) $(CXXREQUIRED) -Wl,-map,$(notdir $@.map)
|
||||
else
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace ams::pkg1 {
|
||||
KeyGeneration_15_0_0 = 0x0E,
|
||||
KeyGeneration_16_0_0 = 0x0F,
|
||||
KeyGeneration_17_0_0 = 0x10,
|
||||
KeyGeneration_18_0_0 = 0x11,
|
||||
|
||||
KeyGeneration_Count,
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace ams::pkg2 {
|
||||
constexpr inline int PayloadCount = 3;
|
||||
|
||||
constexpr inline int MinimumValidDataVersion = 0; /* We allow older package2 to load; this value is currently 0x18 in Nintendo's code. */
|
||||
constexpr inline int CurrentBootloaderVersion = 0x14;
|
||||
constexpr inline int CurrentBootloaderVersion = 0x15;
|
||||
|
||||
struct Package2Meta {
|
||||
using Magic = util::FourCC<'P','K','2','1'>;
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace ams::kern::arch::arm64 {
|
||||
}
|
||||
|
||||
NOINLINE Result InitializeForKernel(void *table, KVirtualAddress start, KVirtualAddress end);
|
||||
NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit);
|
||||
NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit);
|
||||
Result Finalize();
|
||||
private:
|
||||
Result MapL1Blocks(KProcessAddress virt_addr, KPhysicalAddress phys_addr, size_t num_pages, PageTableEntry entry_template, bool disable_head_merge, PageLinkedList *page_list, bool reuse_ll);
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace ams::kern::arch::arm64 {
|
||||
KPhysicalAddress phys_addr;
|
||||
size_t block_size;
|
||||
u8 sw_reserved_bits;
|
||||
u8 attr;
|
||||
|
||||
constexpr bool IsHeadMergeDisabled() const { return (this->sw_reserved_bits & PageTableEntry::SoftwareReservedBit_DisableMergeHead) != 0; }
|
||||
constexpr bool IsHeadAndBodyMergeDisabled() const { return (this->sw_reserved_bits & PageTableEntry::SoftwareReservedBit_DisableMergeHeadAndBody) != 0; }
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace ams::kern::arch::arm64 {
|
||||
m_page_table.Activate(id);
|
||||
}
|
||||
|
||||
Result Initialize(ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
R_RETURN(m_page_table.InitializeForProcess(as_type, enable_aslr, enable_das_merge, from_back, pool, code_address, code_size, system_resource, resource_limit));
|
||||
Result Initialize(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
R_RETURN(m_page_table.InitializeForProcess(flags, from_back, pool, code_address, code_size, system_resource, resource_limit));
|
||||
}
|
||||
|
||||
void Finalize() { m_page_table.Finalize(); }
|
||||
@@ -110,12 +110,12 @@ namespace ams::kern::arch::arm64 {
|
||||
R_RETURN(m_page_table.MapRegion(region_type, perm));
|
||||
}
|
||||
|
||||
Result MapInsecureMemory(KProcessAddress address, size_t size) {
|
||||
R_RETURN(m_page_table.MapInsecureMemory(address, size));
|
||||
Result MapInsecurePhysicalMemory(KProcessAddress address, size_t size) {
|
||||
R_RETURN(m_page_table.MapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
Result UnmapInsecureMemory(KProcessAddress address, size_t size) {
|
||||
R_RETURN(m_page_table.UnmapInsecureMemory(address, size));
|
||||
Result UnmapInsecurePhysicalMemory(KProcessAddress address, size_t size) {
|
||||
R_RETURN(m_page_table.UnmapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
Result MapPageGroup(KProcessAddress addr, const KPageGroup &pg, KMemoryState state, KMemoryPermission perm) {
|
||||
@@ -316,6 +316,8 @@ namespace ams::kern::arch::arm64 {
|
||||
size_t GetKernelMapRegionSize() const { return m_page_table.GetKernelMapRegionSize(); }
|
||||
size_t GetAliasCodeRegionSize() const { return m_page_table.GetAliasCodeRegionSize(); }
|
||||
|
||||
size_t GetAliasRegionExtraSize() const { return m_page_table.GetAliasRegionExtraSize(); }
|
||||
|
||||
size_t GetNormalMemorySize() const { return m_page_table.GetNormalMemorySize(); }
|
||||
|
||||
size_t GetCodeSize() const { return m_page_table.GetCodeSize(); }
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
#pragma once
|
||||
#include <mesosphere/kern_common.hpp>
|
||||
#include <mesosphere/kern_select_cpu.hpp>
|
||||
#include <mesosphere/kern_select_interrupt_manager.hpp>
|
||||
|
||||
namespace ams::kern::arch::arm64::smc {
|
||||
|
||||
template<int SmcId, bool DisableInterrupt>
|
||||
template<int SmcId>
|
||||
void SecureMonitorCall(u64 *buf) {
|
||||
/* Load arguments into registers. */
|
||||
register u64 x0 asm("x0") = buf[0];
|
||||
@@ -32,34 +31,18 @@ namespace ams::kern::arch::arm64::smc {
|
||||
register u64 x6 asm("x6") = buf[6];
|
||||
register u64 x7 asm("x7") = buf[7];
|
||||
|
||||
/* Backup the current thread pointer. */
|
||||
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
||||
|
||||
/* Perform the call. */
|
||||
if constexpr (DisableInterrupt) {
|
||||
KScopedInterruptDisable di;
|
||||
__asm__ __volatile__("smc %c[smc_id]"
|
||||
: "+r"(x0), "+r"(x1), "+r"(x2), "+r"(x3), "+r"(x4), "+r"(x5), "+r"(x6), "+r"(x7)
|
||||
: [smc_id]"i"(SmcId)
|
||||
: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "cc", "memory"
|
||||
);
|
||||
|
||||
/* Backup the current thread pointer. */
|
||||
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
||||
|
||||
__asm__ __volatile__("smc %c[smc_id]"
|
||||
: "+r"(x0), "+r"(x1), "+r"(x2), "+r"(x3), "+r"(x4), "+r"(x5), "+r"(x6), "+r"(x7)
|
||||
: [smc_id]"i"(SmcId)
|
||||
: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "cc", "memory"
|
||||
);
|
||||
|
||||
/* Restore the current thread pointer into X18. */
|
||||
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
||||
} else {
|
||||
/* Backup the current thread pointer. */
|
||||
const uintptr_t current_thread_pointer_value = cpu::GetCurrentThreadPointerValue();
|
||||
|
||||
__asm__ __volatile__("smc %c[smc_id]"
|
||||
: "+r"(x0), "+r"(x1), "+r"(x2), "+r"(x3), "+r"(x4), "+r"(x5), "+r"(x6), "+r"(x7)
|
||||
: [smc_id]"i"(SmcId)
|
||||
: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "cc", "memory"
|
||||
);
|
||||
|
||||
/* Restore the current thread pointer into X18. */
|
||||
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
||||
}
|
||||
/* Restore the current thread pointer into X18. */
|
||||
cpu::SetCurrentThreadPointerValue(current_thread_pointer_value);
|
||||
|
||||
/* Store arguments to output. */
|
||||
buf[0] = x0;
|
||||
@@ -78,18 +61,18 @@ namespace ams::kern::arch::arm64::smc {
|
||||
PsciFunction_CpuOn = 0xC4000003,
|
||||
};
|
||||
|
||||
template<int SmcId, bool DisableInterrupt>
|
||||
template<int SmcId>
|
||||
u64 PsciCall(PsciFunction function, u64 x1 = 0, u64 x2 = 0, u64 x3 = 0, u64 x4 = 0, u64 x5 = 0, u64 x6 = 0, u64 x7 = 0) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { function, x1, x2, x3, x4, x5, x6, x7 } };
|
||||
|
||||
SecureMonitorCall<SmcId, DisableInterrupt>(args.r);
|
||||
SecureMonitorCall<SmcId>(args.r);
|
||||
|
||||
return args.r[0];
|
||||
}
|
||||
|
||||
template<int SmcId, bool DisableInterrupt>
|
||||
template<int SmcId>
|
||||
u64 CpuOn(u64 core_id, uintptr_t entrypoint, uintptr_t arg) {
|
||||
return PsciCall<SmcId, DisableInterrupt>(PsciFunction_CpuOn, core_id, entrypoint, arg);
|
||||
return PsciCall<SmcId>(PsciFunction_CpuOn, core_id, entrypoint, arg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace ams::kern {
|
||||
struct InitialProcessBinaryLayout {
|
||||
uintptr_t address;
|
||||
uintptr_t _08;
|
||||
uintptr_t kern_address;
|
||||
};
|
||||
|
||||
struct InitialProcessBinaryLayoutWithSize {
|
||||
|
||||
@@ -358,7 +358,7 @@ namespace ams::kern {
|
||||
void Detach() {
|
||||
/* Close our object, if we have one. */
|
||||
if (T * const object = m_object; AMS_LIKELY(object != nullptr)) {
|
||||
/* Set our object to a debug sentinel value, which will cause crash if accessed. */
|
||||
/* Set our object to a debug sentinel value, which will cause a crash if accessed. */
|
||||
m_object = reinterpret_cast<T *>(1);
|
||||
|
||||
/* Close reference to our object. */
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace ams::kern {
|
||||
};
|
||||
|
||||
constexpr KMemoryPermission ConvertToKMemoryPermission(ams::svc::MemoryPermission perm) {
|
||||
return static_cast<KMemoryPermission>((util::ToUnderlying(perm) & KMemoryPermission_UserMask) | KMemoryPermission_KernelRead | ((util::ToUnderlying(perm) & KMemoryPermission_UserWrite) << KMemoryPermission_KernelShift) | (perm == ams::svc::MemoryPermission_None ? KMemoryPermission_NotMapped : KMemoryPermission_None));
|
||||
return static_cast<KMemoryPermission>((util::ToUnderlying(perm) & KMemoryPermission_UserMask) | KMemoryPermission_KernelRead | ((util::ToUnderlying(perm) & ams::svc::MemoryPermission_Write) ? KMemoryPermission_KernelWrite : KMemoryPermission_None) | (perm == ams::svc::MemoryPermission_None ? KMemoryPermission_NotMapped : KMemoryPermission_None));
|
||||
}
|
||||
|
||||
enum KMemoryAttribute : u8 {
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace ams::kern {
|
||||
}
|
||||
}
|
||||
|
||||
Result AllocatePageGroupImpl(KPageGroup *out, size_t num_pages, Pool pool, Direction dir, bool unoptimized, bool random);
|
||||
Result AllocatePageGroupImpl(KPageGroup *out, size_t num_pages, Pool pool, Direction dir, bool unoptimized, bool random, s32 min_heap_index);
|
||||
public:
|
||||
KMemoryManager()
|
||||
: m_pool_locks(), m_pool_managers_head(), m_pool_managers_tail(), m_managers(), m_num_managers(), m_optimized_process_ids(), m_has_optimized_process()
|
||||
@@ -199,7 +199,7 @@ namespace ams::kern {
|
||||
NOINLINE void FinalizeOptimizedMemory(u64 process_id, Pool pool);
|
||||
|
||||
NOINLINE KPhysicalAddress AllocateAndOpenContinuous(size_t num_pages, size_t align_pages, u32 option);
|
||||
NOINLINE Result AllocateAndOpen(KPageGroup *out, size_t num_pages, u32 option);
|
||||
NOINLINE Result AllocateAndOpen(KPageGroup *out, size_t num_pages, size_t align_pages, u32 option);
|
||||
NOINLINE Result AllocateForProcess(KPageGroup *out, size_t num_pages, u32 option, u64 process_id, u8 fill_pattern);
|
||||
|
||||
Pool GetPool(KPhysicalAddress address) const {
|
||||
|
||||
@@ -145,6 +145,8 @@ namespace ams::kern {
|
||||
|
||||
bool IsEquivalentTo(const KPageGroup &rhs) const;
|
||||
|
||||
Result CopyRangeTo(KPageGroup &out, size_t offset, size_t size) const;
|
||||
|
||||
ALWAYS_INLINE bool operator==(const KPageGroup &rhs) const {
|
||||
return this->IsEquivalentTo(rhs);
|
||||
}
|
||||
|
||||
@@ -62,18 +62,21 @@ namespace ams::kern {
|
||||
KPhysicalAddress m_address;
|
||||
size_t m_size;
|
||||
bool m_heap;
|
||||
u8 m_attr;
|
||||
public:
|
||||
constexpr MemoryRange() : m_address(Null<KPhysicalAddress>), m_size(0), m_heap(false) { /* ... */ }
|
||||
constexpr MemoryRange() : m_address(Null<KPhysicalAddress>), m_size(0), m_heap(false), m_attr(0) { /* ... */ }
|
||||
|
||||
void Set(KPhysicalAddress address, size_t size, bool heap) {
|
||||
void Set(KPhysicalAddress address, size_t size, bool heap, u8 attr) {
|
||||
m_address = address;
|
||||
m_size = size;
|
||||
m_heap = heap;
|
||||
m_attr = attr;
|
||||
}
|
||||
|
||||
constexpr KPhysicalAddress GetAddress() const { return m_address; }
|
||||
constexpr size_t GetSize() const { return m_size; }
|
||||
constexpr bool IsHeap() const { return m_heap; }
|
||||
constexpr u8 GetAttribute() const { return m_attr; }
|
||||
|
||||
void Open();
|
||||
void Close();
|
||||
@@ -86,6 +89,15 @@ namespace ams::kern {
|
||||
MemoryFillValue_Heap = 'Z',
|
||||
};
|
||||
|
||||
enum RegionType {
|
||||
RegionType_KernelMap = 0,
|
||||
RegionType_Stack = 1,
|
||||
RegionType_Alias = 2,
|
||||
RegionType_Heap = 3,
|
||||
|
||||
RegionType_Count,
|
||||
};
|
||||
|
||||
enum OperationType {
|
||||
OperationType_Map = 0,
|
||||
OperationType_MapGroup = 1,
|
||||
@@ -165,15 +177,9 @@ namespace ams::kern {
|
||||
private:
|
||||
KProcessAddress m_address_space_start;
|
||||
KProcessAddress m_address_space_end;
|
||||
KProcessAddress m_heap_region_start;
|
||||
KProcessAddress m_heap_region_end;
|
||||
KProcessAddress m_region_starts[RegionType_Count];
|
||||
KProcessAddress m_region_ends[RegionType_Count];
|
||||
KProcessAddress m_current_heap_end;
|
||||
KProcessAddress m_alias_region_start;
|
||||
KProcessAddress m_alias_region_end;
|
||||
KProcessAddress m_stack_region_start;
|
||||
KProcessAddress m_stack_region_end;
|
||||
KProcessAddress m_kernel_map_region_start;
|
||||
KProcessAddress m_kernel_map_region_end;
|
||||
KProcessAddress m_alias_code_region_start;
|
||||
KProcessAddress m_alias_code_region_end;
|
||||
KProcessAddress m_code_region_start;
|
||||
@@ -183,6 +189,7 @@ namespace ams::kern {
|
||||
size_t m_mapped_unsafe_physical_memory;
|
||||
size_t m_mapped_insecure_memory;
|
||||
size_t m_mapped_ipc_server_memory;
|
||||
size_t m_alias_region_extra_size;
|
||||
mutable KLightLock m_general_lock;
|
||||
mutable KLightLock m_map_physical_memory_lock;
|
||||
KLightLock m_device_map_lock;
|
||||
@@ -203,12 +210,12 @@ namespace ams::kern {
|
||||
MemoryFillValue m_stack_fill_value;
|
||||
public:
|
||||
constexpr explicit KPageTableBase(util::ConstantInitializeTag)
|
||||
: m_address_space_start(Null<KProcessAddress>), m_address_space_end(Null<KProcessAddress>), m_heap_region_start(Null<KProcessAddress>),
|
||||
m_heap_region_end(Null<KProcessAddress>), m_current_heap_end(Null<KProcessAddress>), m_alias_region_start(Null<KProcessAddress>),
|
||||
m_alias_region_end(Null<KProcessAddress>), m_stack_region_start(Null<KProcessAddress>), m_stack_region_end(Null<KProcessAddress>),
|
||||
m_kernel_map_region_start(Null<KProcessAddress>), m_kernel_map_region_end(Null<KProcessAddress>), m_alias_code_region_start(Null<KProcessAddress>),
|
||||
: m_address_space_start(Null<KProcessAddress>), m_address_space_end(Null<KProcessAddress>),
|
||||
m_region_starts{Null<KProcessAddress>, Null<KProcessAddress>, Null<KProcessAddress>, Null<KProcessAddress>},
|
||||
m_region_ends{Null<KProcessAddress>, Null<KProcessAddress>, Null<KProcessAddress>, Null<KProcessAddress>},
|
||||
m_current_heap_end(Null<KProcessAddress>), m_alias_code_region_start(Null<KProcessAddress>),
|
||||
m_alias_code_region_end(Null<KProcessAddress>), m_code_region_start(Null<KProcessAddress>), m_code_region_end(Null<KProcessAddress>),
|
||||
m_max_heap_size(), m_mapped_physical_memory_size(), m_mapped_unsafe_physical_memory(), m_mapped_insecure_memory(), m_mapped_ipc_server_memory(),
|
||||
m_max_heap_size(), m_mapped_physical_memory_size(), m_mapped_unsafe_physical_memory(), m_mapped_insecure_memory(), m_mapped_ipc_server_memory(), m_alias_region_extra_size(),
|
||||
m_general_lock(), m_map_physical_memory_lock(), m_device_map_lock(), m_impl(util::ConstantInitialize), m_memory_block_manager(util::ConstantInitialize),
|
||||
m_allocate_option(), m_address_space_width(), m_is_kernel(), m_enable_aslr(), m_enable_device_address_space_merge(),
|
||||
m_memory_block_slab_manager(), m_block_info_manager(), m_resource_limit(), m_cached_physical_linear_region(), m_cached_physical_heap_region(),
|
||||
@@ -220,7 +227,7 @@ namespace ams::kern {
|
||||
explicit KPageTableBase() { /* ... */ }
|
||||
|
||||
NOINLINE Result InitializeForKernel(bool is_64_bit, void *table, KVirtualAddress start, KVirtualAddress end);
|
||||
NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool enable_device_address_space_merge, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit);
|
||||
NOINLINE Result InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit);
|
||||
|
||||
void Finalize();
|
||||
|
||||
@@ -236,7 +243,7 @@ namespace ams::kern {
|
||||
}
|
||||
|
||||
constexpr bool IsInAliasRegion(KProcessAddress addr, size_t size) const {
|
||||
return this->Contains(addr, size) && m_alias_region_start <= addr && addr + size - 1 <= m_alias_region_end - 1;
|
||||
return this->Contains(addr, size) && m_region_starts[RegionType_Alias] <= addr && addr + size - 1 <= m_region_ends[RegionType_Alias] - 1;
|
||||
}
|
||||
|
||||
bool IsInUnsafeAliasRegion(KProcessAddress addr, size_t size) const {
|
||||
@@ -328,7 +335,7 @@ namespace ams::kern {
|
||||
|
||||
Result QueryMappingImpl(KProcessAddress *out, KPhysicalAddress address, size_t size, ams::svc::MemoryState state) const;
|
||||
|
||||
Result AllocateAndMapPagesImpl(PageLinkedList *page_list, KProcessAddress address, size_t num_pages, KMemoryPermission perm);
|
||||
Result AllocateAndMapPagesImpl(PageLinkedList *page_list, KProcessAddress address, size_t num_pages, const KPageProperties &properties);
|
||||
Result MapPageGroupImpl(PageLinkedList *page_list, KProcessAddress address, const KPageGroup &pg, const KPageProperties properties, bool reuse_ll);
|
||||
|
||||
void RemapPageGroup(PageLinkedList *page_list, KProcessAddress address, size_t size, const KPageGroup &pg);
|
||||
@@ -387,8 +394,8 @@ namespace ams::kern {
|
||||
Result UnmapIoRegion(KProcessAddress dst_address, KPhysicalAddress phys_addr, size_t size, ams::svc::MemoryMapping mapping);
|
||||
Result MapStatic(KPhysicalAddress phys_addr, size_t size, KMemoryPermission perm);
|
||||
Result MapRegion(KMemoryRegionType region_type, KMemoryPermission perm);
|
||||
Result MapInsecureMemory(KProcessAddress address, size_t size);
|
||||
Result UnmapInsecureMemory(KProcessAddress address, size_t size);
|
||||
Result MapInsecurePhysicalMemory(KProcessAddress address, size_t size);
|
||||
Result UnmapInsecurePhysicalMemory(KProcessAddress address, size_t size);
|
||||
|
||||
Result MapPages(KProcessAddress *out_addr, size_t num_pages, size_t alignment, KPhysicalAddress phys_addr, KProcessAddress region_start, size_t region_num_pages, KMemoryState state, KMemoryPermission perm) {
|
||||
R_RETURN(this->MapPages(out_addr, num_pages, alignment, phys_addr, true, region_start, region_num_pages, state, perm));
|
||||
@@ -479,24 +486,30 @@ namespace ams::kern {
|
||||
}
|
||||
public:
|
||||
KProcessAddress GetAddressSpaceStart() const { return m_address_space_start; }
|
||||
KProcessAddress GetHeapRegionStart() const { return m_heap_region_start; }
|
||||
KProcessAddress GetAliasRegionStart() const { return m_alias_region_start; }
|
||||
KProcessAddress GetStackRegionStart() const { return m_stack_region_start; }
|
||||
KProcessAddress GetKernelMapRegionStart() const { return m_kernel_map_region_start; }
|
||||
|
||||
KProcessAddress GetHeapRegionStart() const { return m_region_starts[RegionType_Heap]; }
|
||||
KProcessAddress GetAliasRegionStart() const { return m_region_starts[RegionType_Alias]; }
|
||||
KProcessAddress GetStackRegionStart() const { return m_region_starts[RegionType_Stack]; }
|
||||
KProcessAddress GetKernelMapRegionStart() const { return m_region_starts[RegionType_KernelMap]; }
|
||||
|
||||
KProcessAddress GetAliasCodeRegionStart() const { return m_alias_code_region_start; }
|
||||
|
||||
size_t GetAddressSpaceSize() const { return m_address_space_end - m_address_space_start; }
|
||||
size_t GetHeapRegionSize() const { return m_heap_region_end - m_heap_region_start; }
|
||||
size_t GetAliasRegionSize() const { return m_alias_region_end - m_alias_region_start; }
|
||||
size_t GetStackRegionSize() const { return m_stack_region_end - m_stack_region_start; }
|
||||
size_t GetKernelMapRegionSize() const { return m_kernel_map_region_end - m_kernel_map_region_start; }
|
||||
size_t GetAddressSpaceSize() const { return m_address_space_end - m_address_space_start; }
|
||||
|
||||
size_t GetHeapRegionSize() const { return m_region_ends[RegionType_Heap] - m_region_starts[RegionType_Heap]; }
|
||||
size_t GetAliasRegionSize() const { return m_region_ends[RegionType_Alias] - m_region_starts[RegionType_Alias]; }
|
||||
size_t GetStackRegionSize() const { return m_region_ends[RegionType_Stack] - m_region_starts[RegionType_Stack]; }
|
||||
size_t GetKernelMapRegionSize() const { return m_region_ends[RegionType_KernelMap] - m_region_starts[RegionType_KernelMap]; }
|
||||
|
||||
size_t GetAliasCodeRegionSize() const { return m_alias_code_region_end - m_alias_code_region_start; }
|
||||
|
||||
size_t GetAliasRegionExtraSize() const { return m_alias_region_extra_size; }
|
||||
|
||||
size_t GetNormalMemorySize() const {
|
||||
/* Lock the table. */
|
||||
KScopedLightLock lk(m_general_lock);
|
||||
|
||||
return (m_current_heap_end - m_heap_region_start) + m_mapped_physical_memory_size;
|
||||
return (m_current_heap_end - m_region_starts[RegionType_Heap]) + m_mapped_physical_memory_size;
|
||||
}
|
||||
|
||||
size_t GetCodeSize() const;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace ams::kern {
|
||||
static size_t GetRealMemorySize();
|
||||
static size_t GetIntendedMemorySize();
|
||||
static KPhysicalAddress GetKernelPhysicalBaseAddress(KPhysicalAddress base_address);
|
||||
static void GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out);
|
||||
static void GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out, KPhysicalAddress kern_base_address);
|
||||
static bool ShouldIncreaseThreadResourceLimit();
|
||||
static void TurnOnCpu(u64 core_id, const ams::kern::init::KInitArguments *args);
|
||||
static size_t GetApplicationPoolSize();
|
||||
|
||||
@@ -223,6 +223,13 @@ namespace ams::kern::arch::arm64 {
|
||||
type = ams::svc::ExceptionType_InstructionAbort;
|
||||
break;
|
||||
case EsrEc_DataAbortEl0:
|
||||
/* If esr.IFSC is "Alignment Fault", return UnalignedData instead of DataAbort. */
|
||||
if ((esr & 0x3F) == 0b100001) {
|
||||
type = ams::svc::ExceptionType_UnalignedData;
|
||||
} else {
|
||||
type = ams::svc::ExceptionType_DataAbort;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
type = ams::svc::ExceptionType_DataAbort;
|
||||
break;
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace ams::kern::arch::arm64 {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
/* Set the watchkpoint. */
|
||||
/* Set the watchpoint. */
|
||||
switch (name) {
|
||||
case ams::svc::HardwareBreakPointRegisterName_D0: MESOSPHERE_SET_HW_WATCH_POINT( 0, flags, value); break;
|
||||
case ams::svc::HardwareBreakPointRegisterName_D1: MESOSPHERE_SET_HW_WATCH_POINT( 1, flags, value); break;
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace ams::kern::arch::arm64 {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KPageTable::InitializeForProcess(ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
Result KPageTable::InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
/* Get an ASID */
|
||||
m_asid = g_asid_manager.Reserve();
|
||||
ON_RESULT_FAILURE { g_asid_manager.Release(m_asid); };
|
||||
@@ -222,10 +222,10 @@ namespace ams::kern::arch::arm64 {
|
||||
ON_RESULT_FAILURE_2 { m_manager->Free(new_table); };
|
||||
|
||||
/* Initialize our base table. */
|
||||
const size_t as_width = GetAddressSpaceWidth(as_type);
|
||||
const size_t as_width = GetAddressSpaceWidth(flags);
|
||||
const KProcessAddress as_start = 0;
|
||||
const KProcessAddress as_end = (1ul << as_width);
|
||||
R_TRY(KPageTableBase::InitializeForProcess(as_type, enable_aslr, enable_das_merge, from_back, pool, GetVoidPointer(new_table), as_start, as_end, code_address, code_size, system_resource, resource_limit));
|
||||
R_TRY(KPageTableBase::InitializeForProcess(flags, from_back, pool, GetVoidPointer(new_table), as_start, as_end, code_address, code_size, system_resource, resource_limit));
|
||||
|
||||
/* Note that we've updated the table (since we created it). */
|
||||
this->NoteUpdated();
|
||||
@@ -258,7 +258,7 @@ namespace ams::kern::arch::arm64 {
|
||||
|
||||
/* Begin the traversal. */
|
||||
TraversalContext context;
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0 };
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0, .attr = 0 };
|
||||
bool cur_valid = false;
|
||||
TraversalEntry next_entry;
|
||||
bool next_valid;
|
||||
@@ -268,7 +268,9 @@ namespace ams::kern::arch::arm64 {
|
||||
|
||||
/* Iterate over entries. */
|
||||
while (true) {
|
||||
if ((!next_valid && !cur_valid) || (next_valid && cur_valid && next_entry.phys_addr == cur_entry.phys_addr + cur_entry.block_size)) {
|
||||
/* NOTE: Nintendo really does check next_entry.attr == (cur_entry.attr != 0)...but attr is always zero as of 18.0.0, and this is "probably" for the new console or debug-only anyway, */
|
||||
/* so we'll implement the weird logic verbatim even though it doesn't match the GetContiguousRange logic. */
|
||||
if ((!next_valid && !cur_valid) || (next_valid && cur_valid && next_entry.phys_addr == cur_entry.phys_addr + cur_entry.block_size && next_entry.attr == (cur_entry.attr ? 1 : 0))) {
|
||||
cur_entry.block_size += next_entry.block_size;
|
||||
} else {
|
||||
if (cur_valid && IsHeapPhysicalAddressForFinalize(cur_entry.phys_addr)) {
|
||||
|
||||
@@ -46,12 +46,14 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->block_size = L3BlockSize;
|
||||
}
|
||||
out_entry->sw_reserved_bits = l3_entry->GetSoftwareReservedBits();
|
||||
out_entry->attr = 0;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
out_entry->phys_addr = Null<KPhysicalAddress>;
|
||||
out_entry->block_size = L3BlockSize;
|
||||
out_entry->sw_reserved_bits = 0;
|
||||
out_entry->attr = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +71,7 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->block_size = L2BlockSize;
|
||||
}
|
||||
out_entry->sw_reserved_bits = l2_entry->GetSoftwareReservedBits();
|
||||
out_entry->attr = 0;
|
||||
|
||||
/* Set the output context. */
|
||||
out_context->l3_entry = nullptr;
|
||||
@@ -79,6 +82,8 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->phys_addr = Null<KPhysicalAddress>;
|
||||
out_entry->block_size = L2BlockSize;
|
||||
out_entry->sw_reserved_bits = 0;
|
||||
out_entry->attr = 0;
|
||||
|
||||
out_context->l3_entry = nullptr;
|
||||
return false;
|
||||
}
|
||||
@@ -108,6 +113,8 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->phys_addr = Null<KPhysicalAddress>;
|
||||
out_entry->block_size = L1BlockSize;
|
||||
out_entry->sw_reserved_bits = 0;
|
||||
out_entry->attr = 0;
|
||||
|
||||
out_context->l2_entry = nullptr;
|
||||
out_context->l3_entry = nullptr;
|
||||
return false;
|
||||
@@ -119,6 +126,7 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->phys_addr = Null<KPhysicalAddress>;
|
||||
out_entry->block_size = L1BlockSize;
|
||||
out_entry->sw_reserved_bits = 0;
|
||||
out_entry->attr = 0;
|
||||
out_context->l1_entry = m_table + m_num_entries;
|
||||
out_context->l2_entry = nullptr;
|
||||
out_context->l3_entry = nullptr;
|
||||
@@ -220,6 +228,7 @@ namespace ams::kern::arch::arm64 {
|
||||
out_entry->phys_addr = Null<KPhysicalAddress>;
|
||||
out_entry->block_size = L1BlockSize;
|
||||
out_entry->sw_reserved_bits = 0;
|
||||
out_entry->attr = 0;
|
||||
context->l1_entry = m_table + m_num_entries;
|
||||
context->l2_entry = nullptr;
|
||||
context->l3_entry = nullptr;
|
||||
|
||||
@@ -68,7 +68,8 @@ _ZN3ams4kern4arch5arm6412SvcHandler64Ev:
|
||||
|
||||
/* Check if our disable count allows us to call SVCs. */
|
||||
mrs x10, tpidrro_el0
|
||||
ldrh w10, [x10, #(THREAD_LOCAL_REGION_DISABLE_COUNT)]
|
||||
add x10, x10, #(THREAD_LOCAL_REGION_DISABLE_COUNT)
|
||||
ldtrh w10, [x10]
|
||||
cbz w10, 1f
|
||||
|
||||
/* It might not, so check the stack params to see if we must not allow the SVC. */
|
||||
@@ -352,7 +353,8 @@ _ZN3ams4kern4arch5arm6412SvcHandler32Ev:
|
||||
|
||||
/* Check if our disable count allows us to call SVCs. */
|
||||
mrs x10, tpidrro_el0
|
||||
ldrh w10, [x10, #(THREAD_LOCAL_REGION_DISABLE_COUNT)]
|
||||
add x10, x10, #(THREAD_LOCAL_REGION_DISABLE_COUNT)
|
||||
ldtrh w10, [x10]
|
||||
cbz w10, 1f
|
||||
|
||||
/* It might not, so check the stack params to see if we must not allow the SVC. */
|
||||
|
||||
@@ -142,10 +142,10 @@ namespace ams::kern::svc {
|
||||
/* Get the target firmware. */
|
||||
const auto target_fw = kern::GetTargetFirmware();
|
||||
|
||||
/* 10.0.0 broke the ABI for QueryIoMapping. */
|
||||
/* 10.0.0 broke the ABI for QueryIoMapping, and renamed it to QueryMemoryMapping. */
|
||||
if (target_fw < TargetFirmware_10_0_0) {
|
||||
if (table_64) { ::ams::kern::svc::PatchSvcTableEntry(table_64, svc::SvcId_QueryIoMapping, LegacyQueryIoMapping::Call64); }
|
||||
if (table_64_from_32) { ::ams::kern::svc::PatchSvcTableEntry(table_64_from_32, svc::SvcId_QueryIoMapping, LegacyQueryIoMapping::Call64From32); }
|
||||
if (table_64) { ::ams::kern::svc::PatchSvcTableEntry(table_64, svc::SvcId_QueryMemoryMapping, LegacyQueryIoMapping::Call64); }
|
||||
if (table_64_from_32) { ::ams::kern::svc::PatchSvcTableEntry(table_64_from_32, svc::SvcId_QueryMemoryMapping, LegacyQueryIoMapping::Call64From32); }
|
||||
}
|
||||
|
||||
/* 6.0.0 broke the ABI for GetFutureThreadInfo, and renamed it to GetDebugFutureThreadInfo. */
|
||||
|
||||
@@ -296,7 +296,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
/* TODO: Move this into a header for the MC in general. */
|
||||
constexpr u32 MemoryControllerConfigurationRegister = 0x70019050;
|
||||
u32 config_value;
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(smc::init::ReadWriteRegister(&config_value, MemoryControllerConfigurationRegister, 0, 0));
|
||||
smc::init::ReadWriteRegister(std::addressof(config_value), MemoryControllerConfigurationRegister, 0, 0);
|
||||
return static_cast<size_t>(config_value & 0x3FFF) << 20;
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ namespace ams::kern::board::nintendo::nx {
|
||||
}
|
||||
|
||||
void KSystemControl::Init::CpuOnImpl(u64 core_id, uintptr_t entrypoint, uintptr_t arg) {
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((::ams::kern::arch::arm64::smc::CpuOn<smc::SmcId_Supervisor, false>(core_id, entrypoint, arg)) == 0);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((::ams::kern::arch::arm64::smc::CpuOn<smc::SmcId_Supervisor>(core_id, entrypoint, arg)) == 0);
|
||||
}
|
||||
|
||||
/* Randomness for Initialization. */
|
||||
@@ -601,8 +601,9 @@ namespace ams::kern::board::nintendo::nx {
|
||||
|
||||
if (g_call_smc_on_panic) {
|
||||
/* If we should, instruct the secure monitor to display a panic screen. */
|
||||
smc::Panic(0xF00);
|
||||
smc::ShowError(0xF00);
|
||||
}
|
||||
|
||||
AMS_INFINITE_LOOP();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
enum FunctionId : u32 {
|
||||
FunctionId_GetConfig = 0xC3000004,
|
||||
FunctionId_GenerateRandomBytes = 0xC3000005,
|
||||
FunctionId_Panic = 0xC3000006,
|
||||
FunctionId_ShowError = 0xC3000006,
|
||||
FunctionId_ConfigureCarveout = 0xC3000007,
|
||||
FunctionId_ReadWriteRegister = 0xC3000008,
|
||||
|
||||
@@ -51,122 +51,187 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
FunctionId_SetConfig = 0xC3000409,
|
||||
};
|
||||
|
||||
constexpr size_t GenerateRandomBytesSizeMax = sizeof(::ams::svc::lp64::SecureMonitorArguments) - sizeof(::ams::svc::lp64::SecureMonitorArguments{}.r[0]);
|
||||
|
||||
/* Global lock for generate random bytes. */
|
||||
constinit KSpinLock g_generate_random_lock;
|
||||
|
||||
bool TryGetConfigImpl(u64 *out, size_t num_qwords, ConfigItem config_item) {
|
||||
/* Create the arguments .*/
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GetConfig, static_cast<u32>(config_item) } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* If successful, copy the output. */
|
||||
const bool success = static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
if (AMS_LIKELY(success)) {
|
||||
for (size_t i = 0; i < num_qwords && i < 7; i++) {
|
||||
out[i] = args.r[1 + i];
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SetConfigImpl(ConfigItem config_item, u64 value) {
|
||||
/* Create the arguments .*/
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_SetConfig, static_cast<u32>(config_item), 0, value } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* Return whether the call was successful. */
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
}
|
||||
|
||||
bool ReadWriteRegisterImpl(u32 *out, u64 address, u32 mask, u32 value) {
|
||||
/* Create the arguments .*/
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ReadWriteRegister, address, mask, value } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* Unconditionally write the output. */
|
||||
*out = static_cast<u32>(args.r[1]);
|
||||
|
||||
/* Return whether the call was successful. */
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
}
|
||||
|
||||
bool GenerateRandomBytesImpl(void *dst, size_t size) {
|
||||
/* Create the arguments. */
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GenerateRandomBytes, size } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* If successful, copy the output. */
|
||||
const bool success = static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
if (AMS_LIKELY(success)) {
|
||||
std::memcpy(dst, std::addressof(args.r[1]), size);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ConfigureCarveoutImpl(size_t which, uintptr_t address, size_t size) {
|
||||
/* Create the arguments .*/
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ConfigureCarveout, static_cast<u64>(which), static_cast<u64>(address), static_cast<u64>(size) } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* Return whether the call was successful. */
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
}
|
||||
|
||||
bool ShowErrorImpl(u32 color) {
|
||||
/* Create the arguments .*/
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ShowError, color } };
|
||||
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor>(args.r);
|
||||
|
||||
/* Return whether the call was successful. */
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
}
|
||||
|
||||
void CallSecureMonitorFromUserImpl(ams::svc::lp64::SecureMonitorArguments *args) {
|
||||
/* Call into the secure monitor. */
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_User>(args->r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* SMC functionality needed for init. */
|
||||
namespace init {
|
||||
|
||||
void GetConfig(u64 *out, size_t num_qwords, ConfigItem config_item) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GetConfig, static_cast<u32>(config_item) } };
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, false>(args.r);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.r[0]) == SmcResult::Success));
|
||||
|
||||
for (size_t i = 0; i < num_qwords && i < 7; i++) {
|
||||
out[i] = args.r[1 + i];
|
||||
}
|
||||
/* Ensure we successfully get the config. */
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(TryGetConfigImpl(out, num_qwords, config_item));
|
||||
}
|
||||
|
||||
void GenerateRandomBytes(void *dst, size_t size) {
|
||||
/* Call SmcGenerateRandomBytes() */
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GenerateRandomBytes, size } };
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(size <= sizeof(args) - sizeof(args.r[0]));
|
||||
/* Check that the size is valid. */
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(0 < size && size <= GenerateRandomBytesSizeMax);
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, false>(args.r);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.r[0]) == SmcResult::Success));
|
||||
|
||||
/* Copy output. */
|
||||
std::memcpy(dst, std::addressof(args.r[1]), size);
|
||||
/* Ensure we successfully generate the random bytes. */
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(GenerateRandomBytesImpl(dst, size));
|
||||
}
|
||||
|
||||
bool ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ReadWriteRegister, address, mask, value } };
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, false>(args.r);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.r[0]) == SmcResult::Success));
|
||||
|
||||
*out = args.r[1];
|
||||
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
void ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value) {
|
||||
/* Ensure we successfully access the register. */
|
||||
MESOSPHERE_INIT_ABORT_UNLESS(ReadWriteRegisterImpl(out, address, mask, value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool TryGetConfig(u64 *out, size_t num_qwords, ConfigItem config_item) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GetConfig, static_cast<u32>(config_item) } };
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
if (AMS_UNLIKELY(static_cast<SmcResult>(args.r[0]) != SmcResult::Success)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num_qwords && i < 7; i++) {
|
||||
out[i] = args.r[1 + i];
|
||||
}
|
||||
|
||||
return true;
|
||||
/* Get the config. */
|
||||
return TryGetConfigImpl(out, num_qwords, config_item);
|
||||
}
|
||||
|
||||
void GetConfig(u64 *out, size_t num_qwords, ConfigItem config_item) {
|
||||
/* Ensure we successfully get the config. */
|
||||
MESOSPHERE_ABORT_UNLESS(TryGetConfig(out, num_qwords, config_item));
|
||||
}
|
||||
|
||||
bool SetConfig(ConfigItem config_item, u64 value) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_SetConfig, static_cast<u32>(config_item), 0, value } };
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
/* Set the config. */
|
||||
return SetConfigImpl(config_item, value);
|
||||
}
|
||||
|
||||
bool ReadWriteRegister(u32 *out, ams::svc::PhysicalAddress address, u32 mask, u32 value) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ReadWriteRegister, address, mask, value } };
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
|
||||
*out = static_cast<u32>(args.r[1]);
|
||||
return static_cast<SmcResult>(args.r[0]) == SmcResult::Success;
|
||||
/* Access the register. */
|
||||
return ReadWriteRegisterImpl(out, address, mask, value);
|
||||
}
|
||||
|
||||
void ConfigureCarveout(size_t which, uintptr_t address, size_t size) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_ConfigureCarveout, static_cast<u64>(which), static_cast<u64>(address), static_cast<u64>(size) } };
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
|
||||
MESOSPHERE_ABORT_UNLESS((static_cast<SmcResult>(args.r[0]) == SmcResult::Success));
|
||||
/* Ensure that we successfully configure the carveout. */
|
||||
MESOSPHERE_ABORT_UNLESS(ConfigureCarveoutImpl(which, address, size));
|
||||
}
|
||||
|
||||
void GenerateRandomBytes(void *dst, size_t size) {
|
||||
/* Setup for call. */
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_GenerateRandomBytes, size } };
|
||||
MESOSPHERE_ABORT_UNLESS(size <= sizeof(args) - sizeof(args.r[0]));
|
||||
/* Check that the size is valid. */
|
||||
MESOSPHERE_ABORT_UNLESS(0 < size && size <= GenerateRandomBytesSizeMax);
|
||||
|
||||
/* Make call. */
|
||||
{
|
||||
KScopedInterruptDisable intr_disable;
|
||||
KScopedSpinLock lk(g_generate_random_lock);
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
}
|
||||
MESOSPHERE_ABORT_UNLESS((static_cast<SmcResult>(args.r[0]) == SmcResult::Success));
|
||||
/* Acquire the exclusive right to generate random bytes. */
|
||||
KScopedSpinLock lk(g_generate_random_lock);
|
||||
|
||||
/* Copy output. */
|
||||
std::memcpy(dst, std::addressof(args.r[1]), size);
|
||||
/* Ensure we successfully generate the random bytes. */
|
||||
MESOSPHERE_ABORT_UNLESS(GenerateRandomBytesImpl(dst, size));
|
||||
}
|
||||
|
||||
void NORETURN Panic(u32 color) {
|
||||
ams::svc::lp64::SecureMonitorArguments args = { { FunctionId_Panic, color } };
|
||||
void ShowError(u32 color) {
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_Supervisor, true>(args.r);
|
||||
|
||||
AMS_INFINITE_LOOP();
|
||||
/* Ensure we successfully show the error. */
|
||||
MESOSPHERE_ABORT_UNLESS(ShowErrorImpl(color));
|
||||
}
|
||||
|
||||
void CallSecureMonitorFromUser(ams::svc::lp64::SecureMonitorArguments *args) {
|
||||
::ams::kern::arch::arm64::smc::SecureMonitorCall<SmcId_User, true>(args->r);
|
||||
/* Disable interrupts. */
|
||||
KScopedInterruptDisable di;
|
||||
|
||||
/* Perform the call. */
|
||||
CallSecureMonitorFromUserImpl(args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,7 +111,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
|
||||
bool SetConfig(ConfigItem config_item, u64 value);
|
||||
|
||||
void NORETURN Panic(u32 color);
|
||||
void ShowError(u32 color);
|
||||
|
||||
void CallSecureMonitorFromUser(ams::svc::lp64::SecureMonitorArguments *args);
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace ams::kern::board::nintendo::nx::smc {
|
||||
|
||||
void GetConfig(u64 *out, size_t num_qwords, ConfigItem config_item);
|
||||
void GenerateRandomBytes(void *dst, size_t size);
|
||||
bool ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value);
|
||||
void ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace ams::kern {
|
||||
{
|
||||
/* Allocate the previously unreserved pages. */
|
||||
KPageGroup unreserve_pg(Kernel::GetSystemSystemResource().GetBlockInfoManagerPointer());
|
||||
MESOSPHERE_R_ABORT_UNLESS(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(unreserve_pg), unreserved_size / PageSize, KMemoryManager::EncodeOption(dst_pool, KMemoryManager::Direction_FromFront)));
|
||||
MESOSPHERE_R_ABORT_UNLESS(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(unreserve_pg), unreserved_size / PageSize, 1, KMemoryManager::EncodeOption(dst_pool, KMemoryManager::Direction_FromFront)));
|
||||
|
||||
/* Add the previously reserved pages. */
|
||||
if (src_pool == dst_pool && binary_pages != 0) {
|
||||
@@ -173,7 +173,7 @@ namespace ams::kern {
|
||||
/* If the pool is the same, we need to use the workaround page group. */
|
||||
if (src_pool == dst_pool) {
|
||||
/* Allocate a new, usable group for the process. */
|
||||
MESOSPHERE_R_ABORT_UNLESS(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(workaround_pg), static_cast<size_t>(params.code_num_pages), KMemoryManager::EncodeOption(dst_pool, KMemoryManager::Direction_FromFront)));
|
||||
MESOSPHERE_R_ABORT_UNLESS(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(workaround_pg), static_cast<size_t>(params.code_num_pages), 1, KMemoryManager::EncodeOption(dst_pool, KMemoryManager::Direction_FromFront)));
|
||||
|
||||
/* Copy data from the working page group to the usable one. */
|
||||
auto work_it = pg.begin();
|
||||
|
||||
@@ -184,6 +184,11 @@ namespace ams::kern {
|
||||
case RegionType::NoMapping:
|
||||
break;
|
||||
case RegionType::KernelTraceBuffer:
|
||||
/* NOTE: This does not match official, but is used to make pre-processing hbl capabilities in userland unnecessary. */
|
||||
/* If ktrace isn't enabled, allow ktrace to succeed without mapping anything. */
|
||||
if constexpr (!ams::kern::IsKTraceEnabled) {
|
||||
break;
|
||||
}
|
||||
case RegionType::OnMemoryBootImage:
|
||||
case RegionType::DTB:
|
||||
R_TRY(f(MemoryRegions[static_cast<u32>(type)], perm));
|
||||
|
||||
@@ -107,7 +107,6 @@ namespace ams::kern {
|
||||
R_UNLESS(cur_sessions < max, svc::ResultOutOfSessions());
|
||||
new_sessions = cur_sessions + 1;
|
||||
} while (!m_num_sessions.CompareExchangeWeak<std::memory_order_relaxed>(cur_sessions, new_sessions));
|
||||
|
||||
}
|
||||
|
||||
/* Atomically update the peak session tracking. */
|
||||
@@ -182,7 +181,6 @@ namespace ams::kern {
|
||||
R_UNLESS(cur_sessions < max, svc::ResultOutOfSessions());
|
||||
new_sessions = cur_sessions + 1;
|
||||
} while (!m_num_sessions.CompareExchangeWeak<std::memory_order_relaxed>(cur_sessions, new_sessions));
|
||||
|
||||
}
|
||||
|
||||
/* Atomically update the peak session tracking. */
|
||||
|
||||
@@ -79,29 +79,7 @@ namespace ams::kern {
|
||||
|
||||
/* Create a page group representing the segment. */
|
||||
KPageGroup segment_pg(Kernel::GetSystemSystemResource().GetBlockInfoManagerPointer());
|
||||
if (size_t remaining_size = util::AlignUp(seg_size, PageSize); remaining_size != 0) {
|
||||
/* Find the pages whose data corresponds to the segment. */
|
||||
size_t cur_offset = 0;
|
||||
for (auto it = pg.begin(); it != pg.end() && remaining_size > 0; ++it) {
|
||||
/* Get the current size. */
|
||||
const size_t cur_size = it->GetSize();
|
||||
|
||||
/* Determine if the offset is in range. */
|
||||
const size_t rel_diff = seg_offset - cur_offset;
|
||||
const bool is_before = cur_offset <= seg_offset;
|
||||
cur_offset += cur_size;
|
||||
if (is_before && seg_offset < cur_offset) {
|
||||
/* It is, so add the block. */
|
||||
const size_t block_size = std::min<size_t>(cur_size - rel_diff, remaining_size);
|
||||
MESOSPHERE_R_ABORT_UNLESS(segment_pg.AddBlock(it->GetAddress() + rel_diff, block_size / PageSize));
|
||||
|
||||
/* Advance. */
|
||||
cur_offset = seg_offset + block_size;
|
||||
remaining_size -= block_size;
|
||||
seg_offset += block_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
MESOSPHERE_R_ABORT_UNLESS(pg.CopyRangeTo(segment_pg, seg_offset, util::AlignUp(seg_size, PageSize)));
|
||||
|
||||
/* Setup the new page group's memory so that we can load the segment. */
|
||||
{
|
||||
@@ -226,6 +204,9 @@ namespace ams::kern {
|
||||
const uintptr_t map_end = map_start + map_size;
|
||||
MESOSPHERE_ABORT_UNLESS(start_address == 0);
|
||||
|
||||
/* Default fields in parameter to zero. */
|
||||
*out = {};
|
||||
|
||||
/* Set fields in parameter. */
|
||||
out->code_address = map_start + start_address;
|
||||
out->code_num_pages = util::AlignUp(end_address - start_address, PageSize) / PageSize;
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace ams::kern {
|
||||
return allocated_block;
|
||||
}
|
||||
|
||||
Result KMemoryManager::AllocatePageGroupImpl(KPageGroup *out, size_t num_pages, Pool pool, Direction dir, bool unoptimized, bool random) {
|
||||
Result KMemoryManager::AllocatePageGroupImpl(KPageGroup *out, size_t num_pages, Pool pool, Direction dir, bool unoptimized, bool random, s32 min_heap_index) {
|
||||
/* Choose a heap based on our page size request. */
|
||||
const s32 heap_index = KPageHeap::GetBlockIndex(num_pages);
|
||||
R_UNLESS(0 <= heap_index, svc::ResultOutOfMemory());
|
||||
@@ -241,7 +241,7 @@ namespace ams::kern {
|
||||
};
|
||||
|
||||
/* Keep allocating until we've allocated all our pages. */
|
||||
for (s32 index = heap_index; index >= 0 && num_pages > 0; index--) {
|
||||
for (s32 index = heap_index; index >= min_heap_index && num_pages > 0; index--) {
|
||||
const size_t pages_per_alloc = KPageHeap::GetBlockNumPages(index);
|
||||
for (Impl *cur_manager = this->GetFirstManager(pool, dir); cur_manager != nullptr; cur_manager = this->GetNextManager(cur_manager, dir)) {
|
||||
while (num_pages >= pages_per_alloc) {
|
||||
@@ -274,7 +274,7 @@ namespace ams::kern {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KMemoryManager::AllocateAndOpen(KPageGroup *out, size_t num_pages, u32 option) {
|
||||
Result KMemoryManager::AllocateAndOpen(KPageGroup *out, size_t num_pages, size_t align_pages, u32 option) {
|
||||
MESOSPHERE_ASSERT(out != nullptr);
|
||||
MESOSPHERE_ASSERT(out->GetNumPages() == 0);
|
||||
|
||||
@@ -285,8 +285,11 @@ namespace ams::kern {
|
||||
const auto [pool, dir] = DecodeOption(option);
|
||||
KScopedLightLock lk(m_pool_locks[pool]);
|
||||
|
||||
/* Choose a heap based on our alignment size request. */
|
||||
const s32 heap_index = KPageHeap::GetAlignedBlockIndex(align_pages, align_pages);
|
||||
|
||||
/* Allocate the page group. */
|
||||
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, m_has_optimized_process[pool], true));
|
||||
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, m_has_optimized_process[pool], true, heap_index));
|
||||
|
||||
/* Open the first reference to the pages. */
|
||||
for (const auto &block : *out) {
|
||||
@@ -326,8 +329,11 @@ namespace ams::kern {
|
||||
const bool has_optimized = m_has_optimized_process[pool];
|
||||
const bool is_optimized = m_optimized_process_ids[pool] == process_id;
|
||||
|
||||
/* Always use the minimum alignment size. */
|
||||
const s32 heap_index = 0;
|
||||
|
||||
/* Allocate the page group. */
|
||||
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, has_optimized && !is_optimized, false));
|
||||
R_TRY(this->AllocatePageGroupImpl(out, num_pages, pool, dir, has_optimized && !is_optimized, false, heap_index));
|
||||
|
||||
/* Set whether we should optimize. */
|
||||
optimized = has_optimized && is_optimized;
|
||||
|
||||
@@ -84,6 +84,58 @@ namespace ams::kern {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KPageGroup::CopyRangeTo(KPageGroup &out, size_t range_offset, size_t range_size) const {
|
||||
/* Get the previous last block for the group. */
|
||||
KBlockInfo * const out_last = out.m_last_block;
|
||||
const auto out_last_addr = out_last != nullptr ? out_last->GetAddress() : Null<KPhysicalAddress>;
|
||||
const auto out_last_np = out_last != nullptr ? out_last->GetNumPages() : 0;
|
||||
|
||||
/* Ensure we cleanup the group on failure. */
|
||||
ON_RESULT_FAILURE {
|
||||
KBlockInfo *cur = out_last != nullptr ? out_last->GetNext() : out.m_first_block;
|
||||
while (cur != nullptr) {
|
||||
KBlockInfo *next = cur->GetNext();
|
||||
out.m_manager->Free(cur);
|
||||
cur = next;
|
||||
}
|
||||
|
||||
if (out_last != nullptr) {
|
||||
out_last->Initialize(out_last_addr, out_last_np);
|
||||
out_last->SetNext(nullptr);
|
||||
} else {
|
||||
out.m_first_block = nullptr;
|
||||
}
|
||||
out.m_last_block = out_last;
|
||||
};
|
||||
|
||||
/* Find the pages within the requested range. */
|
||||
size_t cur_offset = 0, remaining_size = range_size;
|
||||
for (auto it = this->begin(); it != this->end() && remaining_size > 0; ++it) {
|
||||
/* Get the current size. */
|
||||
const size_t cur_size = it->GetSize();
|
||||
|
||||
/* Determine if the offset is in range. */
|
||||
const size_t rel_diff = range_offset - cur_offset;
|
||||
const bool is_before = cur_offset <= range_offset;
|
||||
cur_offset += cur_size;
|
||||
if (is_before && range_offset < cur_offset) {
|
||||
/* It is, so add the block. */
|
||||
const size_t block_size = std::min<size_t>(cur_size - rel_diff, remaining_size);
|
||||
R_TRY(out.AddBlock(it->GetAddress() + rel_diff, block_size / PageSize));
|
||||
|
||||
/* Advance. */
|
||||
cur_offset = range_offset + block_size;
|
||||
remaining_size -= block_size;
|
||||
range_offset += block_size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that we successfully copied the range. */
|
||||
MESOSPHERE_ABORT_UNLESS(remaining_size == 0);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void KPageGroup::Open() const {
|
||||
auto &mm = Kernel::GetMemoryManager();
|
||||
|
||||
|
||||
@@ -97,15 +97,12 @@ namespace ams::kern {
|
||||
m_enable_aslr = true;
|
||||
m_enable_device_address_space_merge = false;
|
||||
|
||||
m_heap_region_start = 0;
|
||||
m_heap_region_end = 0;
|
||||
for (auto i = 0; i < RegionType_Count; ++i) {
|
||||
m_region_starts[i] = 0;
|
||||
m_region_ends[i] = 0;
|
||||
}
|
||||
|
||||
m_current_heap_end = 0;
|
||||
m_alias_region_start = 0;
|
||||
m_alias_region_end = 0;
|
||||
m_stack_region_start = 0;
|
||||
m_stack_region_end = 0;
|
||||
m_kernel_map_region_start = 0;
|
||||
m_kernel_map_region_end = 0;
|
||||
m_alias_code_region_start = 0;
|
||||
m_alias_code_region_end = 0;
|
||||
m_code_region_start = 0;
|
||||
@@ -115,6 +112,7 @@ namespace ams::kern {
|
||||
m_mapped_unsafe_physical_memory = 0;
|
||||
m_mapped_insecure_memory = 0;
|
||||
m_mapped_ipc_server_memory = 0;
|
||||
m_alias_region_extra_size = 0;
|
||||
|
||||
m_memory_block_slab_manager = Kernel::GetSystemSystemResource().GetMemoryBlockSlabManagerPointer();
|
||||
m_block_info_manager = Kernel::GetSystemSystemResource().GetBlockInfoManagerPointer();
|
||||
@@ -135,7 +133,7 @@ namespace ams::kern {
|
||||
R_RETURN(m_memory_block_manager.Initialize(m_address_space_start, m_address_space_end, m_memory_block_slab_manager));
|
||||
}
|
||||
|
||||
Result KPageTableBase::InitializeForProcess(ams::svc::CreateProcessFlag as_type, bool enable_aslr, bool enable_das_merge, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
Result KPageTableBase::InitializeForProcess(ams::svc::CreateProcessFlag flags, bool from_back, KMemoryManager::Pool pool, void *table, KProcessAddress start, KProcessAddress end, KProcessAddress code_address, size_t code_size, KSystemResource *system_resource, KResourceLimit *resource_limit) {
|
||||
/* Validate the region. */
|
||||
MESOSPHERE_ABORT_UNLESS(start <= code_address);
|
||||
MESOSPHERE_ABORT_UNLESS(code_address < code_address + code_size);
|
||||
@@ -149,13 +147,16 @@ namespace ams::kern {
|
||||
return KAddressSpaceInfo::GetAddressSpaceSize(m_address_space_width, type);
|
||||
};
|
||||
|
||||
/* Default to zero alias region extra size. */
|
||||
m_alias_region_extra_size = 0;
|
||||
|
||||
/* Set our width and heap/alias sizes. */
|
||||
m_address_space_width = GetAddressSpaceWidth(as_type);
|
||||
m_address_space_width = GetAddressSpaceWidth(flags);
|
||||
size_t alias_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Alias);
|
||||
size_t heap_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Heap);
|
||||
|
||||
/* Adjust heap/alias size if we don't have an alias region. */
|
||||
if ((as_type & ams::svc::CreateProcessFlag_AddressSpaceMask) == ams::svc::CreateProcessFlag_AddressSpace32BitWithoutAlias) {
|
||||
if ((flags & ams::svc::CreateProcessFlag_AddressSpaceMask) == ams::svc::CreateProcessFlag_AddressSpace32BitWithoutAlias) {
|
||||
heap_region_size += alias_region_size;
|
||||
alias_region_size = 0;
|
||||
}
|
||||
@@ -165,35 +166,57 @@ namespace ams::kern {
|
||||
KProcessAddress process_code_end;
|
||||
size_t stack_region_size;
|
||||
size_t kernel_map_region_size;
|
||||
KProcessAddress before_process_code_start, after_process_code_start;
|
||||
size_t before_process_code_size, after_process_code_size;
|
||||
if (m_address_space_width == 39) {
|
||||
alias_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Alias);
|
||||
heap_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Heap);
|
||||
stack_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Stack);
|
||||
kernel_map_region_size = GetSpaceSize(KAddressSpaceInfo::Type_MapSmall);
|
||||
m_code_region_start = GetSpaceStart(KAddressSpaceInfo::Type_Map39Bit);
|
||||
m_code_region_end = m_code_region_start + GetSpaceSize(KAddressSpaceInfo::Type_Map39Bit);
|
||||
m_alias_code_region_start = m_code_region_start;
|
||||
m_alias_code_region_end = m_code_region_end;
|
||||
process_code_start = util::AlignDown(GetInteger(code_address), RegionAlignment);
|
||||
process_code_end = util::AlignUp(GetInteger(code_address) + code_size, RegionAlignment);
|
||||
stack_region_size = GetSpaceSize(KAddressSpaceInfo::Type_Stack);
|
||||
kernel_map_region_size = GetSpaceSize(KAddressSpaceInfo::Type_MapSmall);
|
||||
|
||||
m_code_region_start = GetSpaceStart(KAddressSpaceInfo::Type_Map39Bit);
|
||||
m_code_region_end = m_code_region_start + GetSpaceSize(KAddressSpaceInfo::Type_Map39Bit);
|
||||
m_alias_code_region_start = m_code_region_start;
|
||||
m_alias_code_region_end = m_code_region_end;
|
||||
|
||||
process_code_start = util::AlignDown(GetInteger(code_address), RegionAlignment);
|
||||
process_code_end = util::AlignUp(GetInteger(code_address) + code_size, RegionAlignment);
|
||||
|
||||
before_process_code_start = m_code_region_start;
|
||||
before_process_code_size = process_code_start - before_process_code_start;
|
||||
after_process_code_start = process_code_end;
|
||||
after_process_code_size = m_code_region_end - process_code_end;
|
||||
|
||||
/* If we have a 39-bit address space and should, enable extra size to the alias region. */
|
||||
if (flags & ams::svc::CreateProcessFlag_EnableAliasRegionExtraSize) {
|
||||
/* Extra size is 1/8th of the address space. */
|
||||
m_alias_region_extra_size = (static_cast<size_t>(1) << m_address_space_width) / 8;
|
||||
|
||||
alias_region_size += m_alias_region_extra_size;
|
||||
}
|
||||
} else {
|
||||
stack_region_size = 0;
|
||||
kernel_map_region_size = 0;
|
||||
m_code_region_start = GetSpaceStart(KAddressSpaceInfo::Type_MapSmall);
|
||||
m_code_region_end = m_code_region_start + GetSpaceSize(KAddressSpaceInfo::Type_MapSmall);
|
||||
m_stack_region_start = m_code_region_start;
|
||||
m_alias_code_region_start = m_code_region_start;
|
||||
m_alias_code_region_end = GetSpaceStart(KAddressSpaceInfo::Type_MapLarge) + GetSpaceSize(KAddressSpaceInfo::Type_MapLarge);
|
||||
m_stack_region_end = m_code_region_end;
|
||||
m_kernel_map_region_start = m_code_region_start;
|
||||
m_kernel_map_region_end = m_code_region_end;
|
||||
process_code_start = m_code_region_start;
|
||||
process_code_end = m_code_region_end;
|
||||
stack_region_size = 0;
|
||||
kernel_map_region_size = 0;
|
||||
|
||||
m_code_region_start = GetSpaceStart(KAddressSpaceInfo::Type_MapSmall);
|
||||
m_code_region_end = m_code_region_start + GetSpaceSize(KAddressSpaceInfo::Type_MapSmall);
|
||||
m_alias_code_region_start = m_code_region_start;
|
||||
m_alias_code_region_end = GetSpaceStart(KAddressSpaceInfo::Type_MapLarge) + GetSpaceSize(KAddressSpaceInfo::Type_MapLarge);
|
||||
m_region_starts[RegionType_Stack] = m_code_region_start;
|
||||
m_region_ends[RegionType_Stack] = m_code_region_end;
|
||||
m_region_starts[RegionType_KernelMap] = m_code_region_start;
|
||||
m_region_ends[RegionType_KernelMap] = m_code_region_end;
|
||||
|
||||
process_code_start = m_code_region_start;
|
||||
process_code_end = m_code_region_end;
|
||||
|
||||
before_process_code_start = m_code_region_start;
|
||||
before_process_code_size = 0;
|
||||
after_process_code_start = GetSpaceStart(KAddressSpaceInfo::Type_MapLarge);
|
||||
after_process_code_size = GetSpaceSize(KAddressSpaceInfo::Type_MapLarge);
|
||||
}
|
||||
|
||||
/* Set other basic fields. */
|
||||
m_enable_aslr = enable_aslr;
|
||||
m_enable_device_address_space_merge = enable_das_merge;
|
||||
m_enable_aslr = (flags & ams::svc::CreateProcessFlag_EnableAslr) != 0;
|
||||
m_enable_device_address_space_merge = (flags & ams::svc::CreateProcessFlag_DisableDeviceAddressSpaceMerge) == 0;
|
||||
m_address_space_start = start;
|
||||
m_address_space_end = end;
|
||||
m_is_kernel = false;
|
||||
@@ -201,100 +224,285 @@ namespace ams::kern {
|
||||
m_block_info_manager = system_resource->GetBlockInfoManagerPointer();
|
||||
m_resource_limit = resource_limit;
|
||||
|
||||
/* Determine the region we can place our undetermineds in. */
|
||||
KProcessAddress alloc_start;
|
||||
size_t alloc_size;
|
||||
if ((GetInteger(process_code_start) - GetInteger(m_code_region_start)) >= (GetInteger(end) - GetInteger(process_code_end))) {
|
||||
alloc_start = m_code_region_start;
|
||||
alloc_size = GetInteger(process_code_start) - GetInteger(m_code_region_start);
|
||||
} else {
|
||||
alloc_start = process_code_end;
|
||||
alloc_size = GetInteger(end) - GetInteger(process_code_end);
|
||||
}
|
||||
const size_t needed_size = (alias_region_size + heap_region_size + stack_region_size + kernel_map_region_size);
|
||||
R_UNLESS(alloc_size >= needed_size, svc::ResultOutOfMemory());
|
||||
/* Set up our undetermined regions. */
|
||||
{
|
||||
/* Declare helper structure for layout process. */
|
||||
struct RegionLayoutInfo {
|
||||
size_t size;
|
||||
RegionType type;
|
||||
s32 alloc_index; /* 0 for before process code, 1 for after process code */
|
||||
};
|
||||
|
||||
const size_t remaining_size = alloc_size - needed_size;
|
||||
/* Create region layout info array, and add regions to it. */
|
||||
RegionLayoutInfo region_layouts[RegionType_Count] = {};
|
||||
size_t num_regions = 0;
|
||||
|
||||
/* Determine random placements for each region. */
|
||||
size_t alias_rnd = 0, heap_rnd = 0, stack_rnd = 0, kmap_rnd = 0;
|
||||
if (enable_aslr) {
|
||||
alias_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment;
|
||||
heap_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment;
|
||||
stack_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment;
|
||||
kmap_rnd = KSystemControl::GenerateRandomRange(0, remaining_size / RegionAlignment) * RegionAlignment;
|
||||
}
|
||||
if (kernel_map_region_size > 0) { region_layouts[num_regions++] = { .size = kernel_map_region_size, .type = RegionType_KernelMap, .alloc_index = 0, }; }
|
||||
if (stack_region_size > 0) { region_layouts[num_regions++] = { .size = stack_region_size, .type = RegionType_Stack, .alloc_index = 0, }; }
|
||||
|
||||
/* Setup heap and alias regions. */
|
||||
m_alias_region_start = alloc_start + alias_rnd;
|
||||
m_alias_region_end = m_alias_region_start + alias_region_size;
|
||||
m_heap_region_start = alloc_start + heap_rnd;
|
||||
m_heap_region_end = m_heap_region_start + heap_region_size;
|
||||
region_layouts[num_regions++] = { .size = alias_region_size, .type = RegionType_Alias, .alloc_index = 0, };
|
||||
region_layouts[num_regions++] = { .size = heap_region_size, .type = RegionType_Heap, .alloc_index = 0, };
|
||||
|
||||
if (alias_rnd <= heap_rnd) {
|
||||
m_heap_region_start += alias_region_size;
|
||||
m_heap_region_end += alias_region_size;
|
||||
} else {
|
||||
m_alias_region_start += heap_region_size;
|
||||
m_alias_region_end += heap_region_size;
|
||||
}
|
||||
|
||||
/* Setup stack region. */
|
||||
if (stack_region_size) {
|
||||
m_stack_region_start = alloc_start + stack_rnd;
|
||||
m_stack_region_end = m_stack_region_start + stack_region_size;
|
||||
|
||||
if (alias_rnd < stack_rnd) {
|
||||
m_stack_region_start += alias_region_size;
|
||||
m_stack_region_end += alias_region_size;
|
||||
} else {
|
||||
m_alias_region_start += stack_region_size;
|
||||
m_alias_region_end += stack_region_size;
|
||||
/* Selection-sort the regions by size largest-to-smallest. */
|
||||
for (size_t i = 0; i < num_regions - 1; ++i) {
|
||||
for (size_t j = i + 1; j < num_regions; ++j) {
|
||||
if (region_layouts[i].size < region_layouts[j].size) {
|
||||
std::swap(region_layouts[i], region_layouts[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (heap_rnd < stack_rnd) {
|
||||
m_stack_region_start += heap_region_size;
|
||||
m_stack_region_end += heap_region_size;
|
||||
} else {
|
||||
m_heap_region_start += stack_region_size;
|
||||
m_heap_region_end += stack_region_size;
|
||||
}
|
||||
}
|
||||
/* Layout the regions. */
|
||||
constexpr auto AllocIndexCount = 2;
|
||||
KProcessAddress alloc_starts[AllocIndexCount] = { before_process_code_start, after_process_code_start };
|
||||
size_t alloc_sizes[AllocIndexCount] = { before_process_code_size, after_process_code_size };
|
||||
size_t alloc_counts[AllocIndexCount] = {};
|
||||
for (size_t i = 0; i < num_regions; ++i) {
|
||||
/* Get reference to the current region. */
|
||||
auto &cur_region = region_layouts[i];
|
||||
|
||||
/* Setup kernel map region. */
|
||||
if (kernel_map_region_size) {
|
||||
m_kernel_map_region_start = alloc_start + kmap_rnd;
|
||||
m_kernel_map_region_end = m_kernel_map_region_start + kernel_map_region_size;
|
||||
/* Determine where the current region should go. */
|
||||
cur_region.alloc_index = alloc_sizes[1] >= alloc_sizes[0] ? 1 : 0;
|
||||
++alloc_counts[cur_region.alloc_index];
|
||||
|
||||
if (alias_rnd < kmap_rnd) {
|
||||
m_kernel_map_region_start += alias_region_size;
|
||||
m_kernel_map_region_end += alias_region_size;
|
||||
} else {
|
||||
m_alias_region_start += kernel_map_region_size;
|
||||
m_alias_region_end += kernel_map_region_size;
|
||||
/* Check that the current region can fit. */
|
||||
R_UNLESS(alloc_sizes[cur_region.alloc_index] >= cur_region.size, svc::ResultOutOfMemory());
|
||||
|
||||
/* Update our remaining size tracking. */
|
||||
alloc_sizes[cur_region.alloc_index] -= cur_region.size;
|
||||
}
|
||||
|
||||
if (heap_rnd < kmap_rnd) {
|
||||
m_kernel_map_region_start += heap_region_size;
|
||||
m_kernel_map_region_end += heap_region_size;
|
||||
} else {
|
||||
m_heap_region_start += kernel_map_region_size;
|
||||
m_heap_region_end += kernel_map_region_size;
|
||||
/* Selection sort the regions to coalesce them by alloc index. */
|
||||
for (size_t i = 0; i < num_regions - 1; ++i) {
|
||||
for (size_t j = i + 1; j < num_regions; ++j) {
|
||||
if (region_layouts[i].alloc_index > region_layouts[j].alloc_index) {
|
||||
std::swap(region_layouts[i], region_layouts[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stack_region_size) {
|
||||
if (stack_rnd < kmap_rnd) {
|
||||
m_kernel_map_region_start += stack_region_size;
|
||||
m_kernel_map_region_end += stack_region_size;
|
||||
/* Layout the regions for each alloc index. */
|
||||
for (auto cur_alloc_index = 0; cur_alloc_index < AllocIndexCount; ++cur_alloc_index) {
|
||||
/* If there are no regions to place, continue. */
|
||||
const size_t cur_alloc_count = alloc_counts[cur_alloc_index];
|
||||
if (cur_alloc_count == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Determine the starting region index for the current alloc index. */
|
||||
size_t cur_region_index = 0;
|
||||
for (size_t i = 0; i < num_regions; ++i) {
|
||||
if (region_layouts[i].alloc_index == cur_alloc_index) {
|
||||
cur_region_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If aslr is enabled, randomize the current region order. Otherwise, sort by type. */
|
||||
if (m_enable_aslr) {
|
||||
for (size_t i = 0; i < cur_alloc_count - 1; ++i) {
|
||||
std::swap(region_layouts[cur_region_index + i], region_layouts[cur_region_index + KSystemControl::GenerateRandomRange(i, cur_alloc_count - 1)]);
|
||||
}
|
||||
} else {
|
||||
m_stack_region_start += kernel_map_region_size;
|
||||
m_stack_region_end += kernel_map_region_size;
|
||||
for (size_t i = 0; i < cur_alloc_count - 1; ++i) {
|
||||
for (size_t j = i + 1; j < cur_alloc_count; ++j) {
|
||||
if (region_layouts[cur_region_index + i].type > region_layouts[cur_region_index + j].type) {
|
||||
std::swap(region_layouts[cur_region_index + i], region_layouts[cur_region_index + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine aslr offsets for the current space. */
|
||||
size_t aslr_offsets[RegionType_Count] = {};
|
||||
if (m_enable_aslr) {
|
||||
/* Generate the aslr offsets. */
|
||||
for (size_t i = 0; i < cur_alloc_count; ++i) {
|
||||
aslr_offsets[i] = KSystemControl::GenerateRandomRange(0, alloc_sizes[cur_alloc_index] / RegionAlignment) * RegionAlignment;
|
||||
}
|
||||
|
||||
/* Sort the aslr offsets. */
|
||||
for (size_t i = 0; i < cur_alloc_count - 1; ++i) {
|
||||
for (size_t j = i + 1; j < cur_alloc_count; ++j) {
|
||||
if (aslr_offsets[i] > aslr_offsets[j]) {
|
||||
std::swap(aslr_offsets[i], aslr_offsets[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate final region positions. */
|
||||
KProcessAddress prev_region_end = alloc_starts[cur_alloc_index];
|
||||
size_t prev_aslr_offset = 0;
|
||||
for (size_t i = 0; i < cur_alloc_count; ++i) {
|
||||
/* Get the current region. */
|
||||
auto &cur_region = region_layouts[cur_region_index + i];
|
||||
|
||||
/* Set the current region start/end. */
|
||||
m_region_starts[cur_region.type] = (aslr_offsets[i] - prev_aslr_offset) + GetInteger(prev_region_end);
|
||||
m_region_ends[cur_region.type] = m_region_starts[cur_region.type] + cur_region.size;
|
||||
|
||||
/* Update tracking variables. */
|
||||
prev_region_end = m_region_ends[cur_region.type];
|
||||
prev_aslr_offset = aslr_offsets[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* Declare helpers to check that regions are inside our address space. */
|
||||
const KProcessAddress process_code_last = process_code_end - 1;
|
||||
auto IsInAddressSpace = [&](KProcessAddress addr) ALWAYS_INLINE_LAMBDA { return m_address_space_start <= addr && addr <= m_address_space_end; };
|
||||
|
||||
/* Ensure that the KernelMap region is valid. */
|
||||
for (size_t k = 0; k < num_regions; ++k) {
|
||||
if (const auto &kmap_region = region_layouts[k]; kmap_region.type == RegionType_KernelMap) {
|
||||
/* If there's no kmap region, we have nothing to check. */
|
||||
if (kmap_region.size == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check that the kmap region is within our address space. */
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_starts[RegionType_KernelMap]));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_ends[RegionType_KernelMap]));
|
||||
|
||||
/* Check for overlap with process code. */
|
||||
const KProcessAddress kmap_start = m_region_starts[RegionType_KernelMap];
|
||||
const KProcessAddress kmap_last = m_region_ends[RegionType_KernelMap] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(kernel_map_region_size == 0 || kmap_last < process_code_start || process_code_last < kmap_start);
|
||||
|
||||
/* Check for overlap with stack. */
|
||||
for (size_t s = 0; s < num_regions; ++s) {
|
||||
if (const auto &stack_region = region_layouts[s]; stack_region.type == RegionType_Stack) {
|
||||
if (stack_region.size != 0) {
|
||||
const KProcessAddress stack_start = m_region_starts[RegionType_Stack];
|
||||
const KProcessAddress stack_last = m_region_ends[RegionType_Stack] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS((kernel_map_region_size == 0 && stack_region_size == 0) || kmap_last < stack_start || stack_last < kmap_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for overlap with alias. */
|
||||
for (size_t a = 0; a < num_regions; ++a) {
|
||||
if (const auto &alias_region = region_layouts[a]; alias_region.type == RegionType_Alias) {
|
||||
if (alias_region.size != 0) {
|
||||
const KProcessAddress alias_start = m_region_starts[RegionType_Alias];
|
||||
const KProcessAddress alias_last = m_region_ends[RegionType_Alias] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(kmap_last < alias_start || alias_last < kmap_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for overlap with heap. */
|
||||
for (size_t h = 0; h < num_regions; ++h) {
|
||||
if (const auto &heap_region = region_layouts[h]; heap_region.type == RegionType_Heap) {
|
||||
if (heap_region.size != 0) {
|
||||
const KProcessAddress heap_start = m_region_starts[RegionType_Heap];
|
||||
const KProcessAddress heap_last = m_region_ends[RegionType_Heap] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(kmap_last < heap_start || heap_last < kmap_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the Stack region is valid. */
|
||||
for (size_t s = 0; s < num_regions; ++s) {
|
||||
if (const auto &stack_region = region_layouts[s]; stack_region.type == RegionType_Stack) {
|
||||
/* If there's no stack region, we have nothing to check. */
|
||||
if (stack_region.size == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check that the stack region is within our address space. */
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_starts[RegionType_Stack]));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_ends[RegionType_Stack]));
|
||||
|
||||
/* Check for overlap with process code. */
|
||||
const KProcessAddress stack_start = m_region_starts[RegionType_Stack];
|
||||
const KProcessAddress stack_last = m_region_ends[RegionType_Stack] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(stack_region_size == 0 || stack_last < process_code_start || process_code_last < stack_start);
|
||||
|
||||
/* Check for overlap with alias. */
|
||||
for (size_t a = 0; a < num_regions; ++a) {
|
||||
if (const auto &alias_region = region_layouts[a]; alias_region.type == RegionType_Alias) {
|
||||
if (alias_region.size != 0) {
|
||||
const KProcessAddress alias_start = m_region_starts[RegionType_Alias];
|
||||
const KProcessAddress alias_last = m_region_ends[RegionType_Alias] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(stack_last < alias_start || alias_last < stack_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for overlap with heap. */
|
||||
for (size_t h = 0; h < num_regions; ++h) {
|
||||
if (const auto &heap_region = region_layouts[h]; heap_region.type == RegionType_Heap) {
|
||||
if (heap_region.size != 0) {
|
||||
const KProcessAddress heap_start = m_region_starts[RegionType_Heap];
|
||||
const KProcessAddress heap_last = m_region_ends[RegionType_Heap] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(stack_last < heap_start || heap_last < stack_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the Alias region is valid. */
|
||||
for (size_t a = 0; a < num_regions; ++a) {
|
||||
if (const auto &alias_region = region_layouts[a]; alias_region.type == RegionType_Alias) {
|
||||
/* If there's no alias region, we have nothing to check. */
|
||||
if (alias_region.size == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check that the alias region is within our address space. */
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_starts[RegionType_Alias]));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_ends[RegionType_Alias]));
|
||||
|
||||
/* Check for overlap with process code. */
|
||||
const KProcessAddress alias_start = m_region_starts[RegionType_Alias];
|
||||
const KProcessAddress alias_last = m_region_ends[RegionType_Alias] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(alias_last < process_code_start || process_code_last < alias_start);
|
||||
|
||||
/* Check for overlap with heap. */
|
||||
for (size_t h = 0; h < num_regions; ++h) {
|
||||
if (const auto &heap_region = region_layouts[h]; heap_region.type == RegionType_Heap) {
|
||||
if (heap_region.size != 0) {
|
||||
const KProcessAddress heap_start = m_region_starts[RegionType_Heap];
|
||||
const KProcessAddress heap_last = m_region_ends[RegionType_Heap] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(alias_last < heap_start || heap_last < alias_start);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check that the Heap region is valid. */
|
||||
for (size_t h = 0; h < num_regions; ++h) {
|
||||
if (const auto &heap_region = region_layouts[h]; heap_region.type == RegionType_Heap) {
|
||||
/* If there's no heap region, we have nothing to check. */
|
||||
if (heap_region.size == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check that the heap region is within our address space. */
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_starts[RegionType_Heap]));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_region_ends[RegionType_Heap]));
|
||||
|
||||
/* Check for overlap with process code. */
|
||||
const KProcessAddress heap_start = m_region_starts[RegionType_Heap];
|
||||
const KProcessAddress heap_last = m_region_ends[RegionType_Heap] - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(heap_last < process_code_start || process_code_last < heap_start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set heap and fill members. */
|
||||
m_current_heap_end = m_heap_region_start;
|
||||
m_current_heap_end = m_region_starts[RegionType_Heap];
|
||||
m_max_heap_size = 0;
|
||||
m_mapped_physical_memory_size = 0;
|
||||
m_mapped_unsafe_physical_memory = 0;
|
||||
@@ -309,32 +517,6 @@ namespace ams::kern {
|
||||
/* Set allocation option. */
|
||||
m_allocate_option = KMemoryManager::EncodeOption(pool, from_back ? KMemoryManager::Direction_FromBack : KMemoryManager::Direction_FromFront);
|
||||
|
||||
/* Ensure that we regions inside our address space. */
|
||||
auto IsInAddressSpace = [&](KProcessAddress addr) ALWAYS_INLINE_LAMBDA { return m_address_space_start <= addr && addr <= m_address_space_end; };
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_alias_region_start));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_alias_region_end));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_heap_region_start));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_heap_region_end));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_stack_region_start));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_stack_region_end));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_kernel_map_region_start));
|
||||
MESOSPHERE_ABORT_UNLESS(IsInAddressSpace(m_kernel_map_region_end));
|
||||
|
||||
/* Ensure that we selected regions that don't overlap. */
|
||||
const KProcessAddress alias_start = m_alias_region_start;
|
||||
const KProcessAddress alias_last = m_alias_region_end - 1;
|
||||
const KProcessAddress heap_start = m_heap_region_start;
|
||||
const KProcessAddress heap_last = m_heap_region_end - 1;
|
||||
const KProcessAddress stack_start = m_stack_region_start;
|
||||
const KProcessAddress stack_last = m_stack_region_end - 1;
|
||||
const KProcessAddress kmap_start = m_kernel_map_region_start;
|
||||
const KProcessAddress kmap_last = m_kernel_map_region_end - 1;
|
||||
MESOSPHERE_ABORT_UNLESS(alias_last < heap_start || heap_last < alias_start);
|
||||
MESOSPHERE_ABORT_UNLESS(alias_last < stack_start || stack_last < alias_start);
|
||||
MESOSPHERE_ABORT_UNLESS(alias_last < kmap_start || kmap_last < alias_start);
|
||||
MESOSPHERE_ABORT_UNLESS(heap_last < stack_start || stack_last < heap_start);
|
||||
MESOSPHERE_ABORT_UNLESS(heap_last < kmap_start || kmap_last < heap_start);
|
||||
|
||||
/* Initialize our implementation. */
|
||||
m_impl.InitializeForProcess(table, GetInteger(start), GetInteger(end));
|
||||
|
||||
@@ -374,16 +556,16 @@ namespace ams::kern {
|
||||
case ams::svc::MemoryState_Kernel:
|
||||
return m_address_space_start;
|
||||
case ams::svc::MemoryState_Normal:
|
||||
return m_heap_region_start;
|
||||
return m_region_starts[RegionType_Heap];
|
||||
case ams::svc::MemoryState_Ipc:
|
||||
case ams::svc::MemoryState_NonSecureIpc:
|
||||
case ams::svc::MemoryState_NonDeviceIpc:
|
||||
return m_alias_region_start;
|
||||
return m_region_starts[RegionType_Alias];
|
||||
case ams::svc::MemoryState_Stack:
|
||||
return m_stack_region_start;
|
||||
return m_region_starts[RegionType_Stack];
|
||||
case ams::svc::MemoryState_Static:
|
||||
case ams::svc::MemoryState_ThreadLocal:
|
||||
return m_kernel_map_region_start;
|
||||
return m_region_starts[RegionType_KernelMap];
|
||||
case ams::svc::MemoryState_Io:
|
||||
case ams::svc::MemoryState_Shared:
|
||||
case ams::svc::MemoryState_AliasCode:
|
||||
@@ -409,16 +591,16 @@ namespace ams::kern {
|
||||
case ams::svc::MemoryState_Kernel:
|
||||
return m_address_space_end - m_address_space_start;
|
||||
case ams::svc::MemoryState_Normal:
|
||||
return m_heap_region_end - m_heap_region_start;
|
||||
return m_region_ends[RegionType_Heap] - m_region_starts[RegionType_Heap];
|
||||
case ams::svc::MemoryState_Ipc:
|
||||
case ams::svc::MemoryState_NonSecureIpc:
|
||||
case ams::svc::MemoryState_NonDeviceIpc:
|
||||
return m_alias_region_end - m_alias_region_start;
|
||||
return m_region_ends[RegionType_Alias] - m_region_starts[RegionType_Alias];
|
||||
case ams::svc::MemoryState_Stack:
|
||||
return m_stack_region_end - m_stack_region_start;
|
||||
return m_region_ends[RegionType_Stack] - m_region_starts[RegionType_Stack];
|
||||
case ams::svc::MemoryState_Static:
|
||||
case ams::svc::MemoryState_ThreadLocal:
|
||||
return m_kernel_map_region_end - m_kernel_map_region_start;
|
||||
return m_region_ends[RegionType_KernelMap] - m_region_starts[RegionType_KernelMap];
|
||||
case ams::svc::MemoryState_Io:
|
||||
case ams::svc::MemoryState_Shared:
|
||||
case ams::svc::MemoryState_AliasCode:
|
||||
@@ -446,8 +628,8 @@ namespace ams::kern {
|
||||
const size_t region_size = this->GetRegionSize(state);
|
||||
|
||||
const bool is_in_region = region_start <= addr && addr < end && last <= region_start + region_size - 1;
|
||||
const bool is_in_heap = !(end <= m_heap_region_start || m_heap_region_end <= addr || m_heap_region_start == m_heap_region_end);
|
||||
const bool is_in_alias = !(end <= m_alias_region_start || m_alias_region_end <= addr || m_alias_region_start == m_alias_region_end);
|
||||
const bool is_in_heap = !(end <= m_region_starts[RegionType_Heap] || m_region_ends[RegionType_Heap] <= addr || m_region_starts[RegionType_Heap] == m_region_ends[RegionType_Heap]);
|
||||
const bool is_in_alias = !(end <= m_region_starts[RegionType_Alias] || m_region_ends[RegionType_Alias] <= addr || m_region_starts[RegionType_Alias] == m_region_ends[RegionType_Alias]);
|
||||
switch (state) {
|
||||
case ams::svc::MemoryState_Free:
|
||||
case ams::svc::MemoryState_Kernel:
|
||||
@@ -734,7 +916,7 @@ namespace ams::kern {
|
||||
|
||||
/* Begin traversal. */
|
||||
TraversalContext context;
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0 };
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0, .attr = 0 };
|
||||
bool cur_valid = false;
|
||||
TraversalEntry next_entry;
|
||||
bool next_valid;
|
||||
@@ -1072,7 +1254,7 @@ namespace ams::kern {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
|
||||
Result KPageTableBase::MapInsecurePhysicalMemory(KProcessAddress address, size_t size) {
|
||||
/* Get the insecure memory resource limit and pool. */
|
||||
auto * const insecure_resource_limit = KSystemControl::GetInsecureMemoryResourceLimit();
|
||||
const auto insecure_pool = static_cast<KMemoryManager::Pool>(KSystemControl::GetInsecureMemoryPool());
|
||||
@@ -1084,7 +1266,7 @@ namespace ams::kern {
|
||||
|
||||
/* Allocate pages for the insecure memory. */
|
||||
KPageGroup pg(m_block_info_manager);
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), size / PageSize, KMemoryManager::EncodeOption(insecure_pool, KMemoryManager::Direction_FromFront)));
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), size / PageSize, 1, KMemoryManager::EncodeOption(insecure_pool, KMemoryManager::Direction_FromFront)));
|
||||
|
||||
/* Close the opened pages when we're done with them. */
|
||||
/* If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed automatically. */
|
||||
@@ -1128,7 +1310,7 @@ namespace ams::kern {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result KPageTableBase::UnmapInsecureMemory(KProcessAddress address, size_t size) {
|
||||
Result KPageTableBase::UnmapInsecurePhysicalMemory(KProcessAddress address, size_t size) {
|
||||
/* Lock the table. */
|
||||
KScopedLightLock lk(m_general_lock);
|
||||
|
||||
@@ -1237,14 +1419,14 @@ namespace ams::kern {
|
||||
return this->GetSize(KMemoryState_AliasCodeData);
|
||||
}
|
||||
|
||||
Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList *page_list, KProcessAddress address, size_t num_pages, KMemoryPermission perm) {
|
||||
Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList *page_list, KProcessAddress address, size_t num_pages, const KPageProperties &properties) {
|
||||
MESOSPHERE_ASSERT(this->IsLockedByCurrentThread());
|
||||
|
||||
/* Create a page group to hold the pages we allocate. */
|
||||
KPageGroup pg(m_block_info_manager);
|
||||
|
||||
/* Allocate the pages. */
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, m_allocate_option));
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, 1, m_allocate_option));
|
||||
|
||||
/* Ensure that the page group is closed when we're done working with it. */
|
||||
ON_SCOPE_EXIT { pg.Close(); };
|
||||
@@ -1255,7 +1437,6 @@ namespace ams::kern {
|
||||
}
|
||||
|
||||
/* Map the pages. */
|
||||
const KPageProperties properties = { perm, false, false, DisableMergeAttribute_None };
|
||||
R_RETURN(this->Operate(page_list, address, num_pages, pg, properties, OperationType_MapGroup, false));
|
||||
}
|
||||
|
||||
@@ -1506,11 +1687,12 @@ namespace ams::kern {
|
||||
|
||||
/* Begin a traversal. */
|
||||
TraversalContext context;
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0 };
|
||||
TraversalEntry cur_entry = { .phys_addr = Null<KPhysicalAddress>, .block_size = 0, .sw_reserved_bits = 0, .attr = 0 };
|
||||
R_UNLESS(impl.BeginTraversal(std::addressof(cur_entry), std::addressof(context), address), svc::ResultInvalidCurrentMemory());
|
||||
|
||||
/* Traverse until we have enough size or we aren't contiguous any more. */
|
||||
const KPhysicalAddress phys_address = cur_entry.phys_addr;
|
||||
const u8 entry_attr = cur_entry.attr;
|
||||
size_t contig_size;
|
||||
for (contig_size = cur_entry.block_size - (GetInteger(phys_address) & (cur_entry.block_size - 1)); contig_size < size; contig_size += cur_entry.block_size) {
|
||||
if (!impl.ContinueTraversal(std::addressof(cur_entry), std::addressof(context))) {
|
||||
@@ -1519,6 +1701,9 @@ namespace ams::kern {
|
||||
if (cur_entry.phys_addr != phys_address + contig_size) {
|
||||
break;
|
||||
}
|
||||
if (cur_entry.attr != entry_attr) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Take the minimum size for our region. */
|
||||
@@ -1532,7 +1717,7 @@ namespace ams::kern {
|
||||
}
|
||||
|
||||
/* The memory is contiguous, so set the output range. */
|
||||
out->Set(phys_address, size, is_heap);
|
||||
out->Set(phys_address, size, is_heap, attr);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
@@ -1692,17 +1877,17 @@ namespace ams::kern {
|
||||
KScopedLightLock lk(m_general_lock);
|
||||
|
||||
/* Validate that setting heap size is possible at all. */
|
||||
R_UNLESS(!m_is_kernel, svc::ResultOutOfMemory());
|
||||
R_UNLESS(size <= static_cast<size_t>(m_heap_region_end - m_heap_region_start), svc::ResultOutOfMemory());
|
||||
R_UNLESS(size <= m_max_heap_size, svc::ResultOutOfMemory());
|
||||
R_UNLESS(!m_is_kernel, svc::ResultOutOfMemory());
|
||||
R_UNLESS(size <= static_cast<size_t>(m_region_ends[RegionType_Heap] - m_region_starts[RegionType_Heap]), svc::ResultOutOfMemory());
|
||||
R_UNLESS(size <= m_max_heap_size, svc::ResultOutOfMemory());
|
||||
|
||||
if (size < static_cast<size_t>(m_current_heap_end - m_heap_region_start)) {
|
||||
if (size < static_cast<size_t>(m_current_heap_end - m_region_starts[RegionType_Heap])) {
|
||||
/* The size being requested is less than the current size, so we need to free the end of the heap. */
|
||||
|
||||
/* Validate memory state. */
|
||||
size_t num_allocator_blocks;
|
||||
R_TRY(this->CheckMemoryState(std::addressof(num_allocator_blocks),
|
||||
m_heap_region_start + size, (m_current_heap_end - m_heap_region_start) - size,
|
||||
m_region_starts[RegionType_Heap] + size, (m_current_heap_end - m_region_starts[RegionType_Heap]) - size,
|
||||
KMemoryState_All, KMemoryState_Normal,
|
||||
KMemoryPermission_All, KMemoryPermission_UserReadWrite,
|
||||
KMemoryAttribute_All, KMemoryAttribute_None));
|
||||
@@ -1716,30 +1901,30 @@ namespace ams::kern {
|
||||
KScopedPageTableUpdater updater(this);
|
||||
|
||||
/* Unmap the end of the heap. */
|
||||
const size_t num_pages = ((m_current_heap_end - m_heap_region_start) - size) / PageSize;
|
||||
const size_t num_pages = ((m_current_heap_end - m_region_starts[RegionType_Heap]) - size) / PageSize;
|
||||
const KPageProperties unmap_properties = { KMemoryPermission_None, false, false, DisableMergeAttribute_None };
|
||||
R_TRY(this->Operate(updater.GetPageList(), m_heap_region_start + size, num_pages, Null<KPhysicalAddress>, false, unmap_properties, OperationType_Unmap, false));
|
||||
R_TRY(this->Operate(updater.GetPageList(), m_region_starts[RegionType_Heap] + size, num_pages, Null<KPhysicalAddress>, false, unmap_properties, OperationType_Unmap, false));
|
||||
|
||||
/* Release the memory from the resource limit. */
|
||||
m_resource_limit->Release(ams::svc::LimitableResource_PhysicalMemoryMax, num_pages * PageSize);
|
||||
|
||||
/* Apply the memory block update. */
|
||||
m_memory_block_manager.Update(std::addressof(allocator), m_heap_region_start + size, num_pages, KMemoryState_Free, KMemoryPermission_None, KMemoryAttribute_None, KMemoryBlockDisableMergeAttribute_None, size == 0 ? KMemoryBlockDisableMergeAttribute_Normal : KMemoryBlockDisableMergeAttribute_None);
|
||||
m_memory_block_manager.Update(std::addressof(allocator), m_region_starts[RegionType_Heap] + size, num_pages, KMemoryState_Free, KMemoryPermission_None, KMemoryAttribute_None, KMemoryBlockDisableMergeAttribute_None, size == 0 ? KMemoryBlockDisableMergeAttribute_Normal : KMemoryBlockDisableMergeAttribute_None);
|
||||
|
||||
/* Update the current heap end. */
|
||||
m_current_heap_end = m_heap_region_start + size;
|
||||
m_current_heap_end = m_region_starts[RegionType_Heap] + size;
|
||||
|
||||
/* Set the output. */
|
||||
*out = m_heap_region_start;
|
||||
*out = m_region_starts[RegionType_Heap];
|
||||
R_SUCCEED();
|
||||
} else if (size == static_cast<size_t>(m_current_heap_end - m_heap_region_start)) {
|
||||
} else if (size == static_cast<size_t>(m_current_heap_end - m_region_starts[RegionType_Heap])) {
|
||||
/* The size requested is exactly the current size. */
|
||||
*out = m_heap_region_start;
|
||||
*out = m_region_starts[RegionType_Heap];
|
||||
R_SUCCEED();
|
||||
} else {
|
||||
/* We have to allocate memory. Determine how much to allocate and where while the table is locked. */
|
||||
cur_address = m_current_heap_end;
|
||||
allocation_size = size - (m_current_heap_end - m_heap_region_start);
|
||||
allocation_size = size - (m_current_heap_end - m_region_starts[RegionType_Heap]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1749,7 +1934,7 @@ namespace ams::kern {
|
||||
|
||||
/* Allocate pages for the heap extension. */
|
||||
KPageGroup pg(m_block_info_manager);
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize, m_allocate_option));
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), allocation_size / PageSize, 1, m_allocate_option));
|
||||
|
||||
/* Close the opened pages when we're done with them. */
|
||||
/* If the mapping succeeds, each page will gain an extra reference, otherwise they will be freed automatically. */
|
||||
@@ -1782,20 +1967,20 @@ namespace ams::kern {
|
||||
|
||||
/* Map the pages. */
|
||||
const size_t num_pages = allocation_size / PageSize;
|
||||
const KPageProperties map_properties = { KMemoryPermission_UserReadWrite, false, false, (m_current_heap_end == m_heap_region_start) ? DisableMergeAttribute_DisableHead : DisableMergeAttribute_None };
|
||||
const KPageProperties map_properties = { KMemoryPermission_UserReadWrite, false, false, (m_current_heap_end == m_region_starts[RegionType_Heap]) ? DisableMergeAttribute_DisableHead : DisableMergeAttribute_None };
|
||||
R_TRY(this->Operate(updater.GetPageList(), m_current_heap_end, num_pages, pg, map_properties, OperationType_MapGroup, false));
|
||||
|
||||
/* We succeeded, so commit our memory reservation. */
|
||||
memory_reservation.Commit();
|
||||
|
||||
/* Apply the memory block update. */
|
||||
m_memory_block_manager.Update(std::addressof(allocator), m_current_heap_end, num_pages, KMemoryState_Normal, KMemoryPermission_UserReadWrite, KMemoryAttribute_None, m_heap_region_start == m_current_heap_end ? KMemoryBlockDisableMergeAttribute_Normal : KMemoryBlockDisableMergeAttribute_None, KMemoryBlockDisableMergeAttribute_None);
|
||||
m_memory_block_manager.Update(std::addressof(allocator), m_current_heap_end, num_pages, KMemoryState_Normal, KMemoryPermission_UserReadWrite, KMemoryAttribute_None, m_region_starts[RegionType_Heap] == m_current_heap_end ? KMemoryBlockDisableMergeAttribute_Normal : KMemoryBlockDisableMergeAttribute_None, KMemoryBlockDisableMergeAttribute_None);
|
||||
|
||||
/* Update the current heap end. */
|
||||
m_current_heap_end = m_heap_region_start + size;
|
||||
m_current_heap_end = m_region_starts[RegionType_Heap] + size;
|
||||
|
||||
/* Set the output. */
|
||||
*out = m_heap_region_start;
|
||||
*out = m_region_starts[RegionType_Heap];
|
||||
R_SUCCEED();
|
||||
}
|
||||
}
|
||||
@@ -1927,8 +2112,8 @@ namespace ams::kern {
|
||||
const KPhysicalAddress last = phys_addr + size - 1;
|
||||
|
||||
/* Get region extents. */
|
||||
const KProcessAddress region_start = m_kernel_map_region_start;
|
||||
const size_t region_size = m_kernel_map_region_end - m_kernel_map_region_start;
|
||||
const KProcessAddress region_start = m_region_starts[RegionType_KernelMap];
|
||||
const size_t region_size = m_region_ends[RegionType_KernelMap] - m_region_starts[RegionType_KernelMap];
|
||||
const size_t region_num_pages = region_size / PageSize;
|
||||
|
||||
MESOSPHERE_ASSERT(this->CanContain(region_start, region_size, state));
|
||||
@@ -2237,11 +2422,11 @@ namespace ams::kern {
|
||||
KScopedPageTableUpdater updater(this);
|
||||
|
||||
/* Perform mapping operation. */
|
||||
const KPageProperties properties = { perm, false, false, DisableMergeAttribute_DisableHead };
|
||||
if (is_pa_valid) {
|
||||
const KPageProperties properties = { perm, false, false, DisableMergeAttribute_DisableHead };
|
||||
R_TRY(this->Operate(updater.GetPageList(), addr, num_pages, phys_addr, true, properties, OperationType_Map, false));
|
||||
} else {
|
||||
R_TRY(this->AllocateAndMapPagesImpl(updater.GetPageList(), addr, num_pages, perm));
|
||||
R_TRY(this->AllocateAndMapPagesImpl(updater.GetPageList(), addr, num_pages, properties));
|
||||
}
|
||||
|
||||
/* Update the blocks. */
|
||||
@@ -2273,7 +2458,8 @@ namespace ams::kern {
|
||||
KScopedPageTableUpdater updater(this);
|
||||
|
||||
/* Map the pages. */
|
||||
R_TRY(this->AllocateAndMapPagesImpl(updater.GetPageList(), address, num_pages, perm));
|
||||
const KPageProperties properties = { perm, false, false, DisableMergeAttribute_DisableHead };
|
||||
R_TRY(this->AllocateAndMapPagesImpl(updater.GetPageList(), address, num_pages, properties));
|
||||
|
||||
/* Update the blocks. */
|
||||
m_memory_block_manager.Update(std::addressof(allocator), address, num_pages, state, perm, KMemoryAttribute_None, KMemoryBlockDisableMergeAttribute_Normal, KMemoryBlockDisableMergeAttribute_None);
|
||||
@@ -2812,7 +2998,7 @@ namespace ams::kern {
|
||||
MESOSPHERE_ABORT_UNLESS(src_page_table.GetPhysicalAddressLocked(std::addressof(phys_addr), address));
|
||||
|
||||
/* Determine the current read size. */
|
||||
const size_t cur_size = std::min<size_t>(last_address - address + 1, util::AlignDown(GetInteger(address) + PageSize, PageSize) - GetInteger(address));
|
||||
const size_t cur_size = std::min<size_t>(last_address - address + 1, PageSize - (GetInteger(address) & (PageSize - 1)));
|
||||
|
||||
/* Read. */
|
||||
R_TRY(dst_page_table.ReadIoMemoryImpl(dst, phys_addr, cur_size, state));
|
||||
@@ -2848,7 +3034,7 @@ namespace ams::kern {
|
||||
MESOSPHERE_ABORT_UNLESS(src_page_table.GetPhysicalAddressLocked(std::addressof(phys_addr), address));
|
||||
|
||||
/* Determine the current read size. */
|
||||
const size_t cur_size = std::min<size_t>(last_address - address + 1, util::AlignDown(GetInteger(address) + PageSize, PageSize) - GetInteger(address));
|
||||
const size_t cur_size = std::min<size_t>(last_address - address + 1, PageSize - (GetInteger(address) & (PageSize - 1)));
|
||||
|
||||
/* Read. */
|
||||
R_TRY(dst_page_table.WriteIoMemoryImpl(phys_addr, src, cur_size, state));
|
||||
@@ -3624,7 +3810,7 @@ namespace ams::kern {
|
||||
R_UNLESS(this->Contains(address, size), svc::ResultInvalidCurrentMemory());
|
||||
|
||||
/* Get the source permission. */
|
||||
const auto src_perm = static_cast<KMemoryPermission>((test_perm == KMemoryPermission_UserReadWrite) ? KMemoryPermission_KernelReadWrite | KMemoryPermission_NotMapped : KMemoryPermission_UserRead);
|
||||
const auto src_perm = static_cast<KMemoryPermission>((test_perm == KMemoryPermission_UserReadWrite) ? (KMemoryPermission_KernelReadWrite | KMemoryPermission_NotMapped) : KMemoryPermission_UserRead);
|
||||
|
||||
/* Get aligned extents. */
|
||||
const KProcessAddress aligned_src_start = util::AlignDown(GetInteger(address), PageSize);
|
||||
@@ -3720,8 +3906,8 @@ namespace ams::kern {
|
||||
MESOSPHERE_ASSERT(src_page_table.IsLockedByCurrentThread());
|
||||
|
||||
/* Check that we can theoretically map. */
|
||||
const KProcessAddress region_start = m_alias_region_start;
|
||||
const size_t region_size = m_alias_region_end - m_alias_region_start;
|
||||
const KProcessAddress region_start = m_region_starts[RegionType_Alias];
|
||||
const size_t region_size = m_region_ends[RegionType_Alias] - m_region_starts[RegionType_Alias];
|
||||
R_UNLESS(size < region_size, svc::ResultOutOfAddressSpace());
|
||||
|
||||
/* Get aligned source extents. */
|
||||
@@ -3953,7 +4139,7 @@ namespace ams::kern {
|
||||
const size_t src_map_size = src_map_end - src_map_start;
|
||||
|
||||
/* Ensure that we clean up appropriately if we fail after this. */
|
||||
const auto src_perm = static_cast<KMemoryPermission>((test_perm == KMemoryPermission_UserReadWrite) ? KMemoryPermission_KernelReadWrite | KMemoryPermission_NotMapped : KMemoryPermission_UserRead);
|
||||
const auto src_perm = static_cast<KMemoryPermission>((test_perm == KMemoryPermission_UserReadWrite) ? (KMemoryPermission_KernelReadWrite | KMemoryPermission_NotMapped) : KMemoryPermission_UserRead);
|
||||
ON_RESULT_FAILURE {
|
||||
if (src_map_end > src_map_start) {
|
||||
src_page_table.CleanupForIpcClientOnServerSetupFailure(updater.GetPageList(), src_map_start, src_map_size, src_perm);
|
||||
@@ -4488,7 +4674,7 @@ namespace ams::kern {
|
||||
}
|
||||
}
|
||||
|
||||
/* Map the papges. */
|
||||
/* Map the pages. */
|
||||
R_TRY(this->Operate(updater.GetPageList(), cur_address, map_pages, cur_pg, map_properties, OperationType_MapFirstGroup, false));
|
||||
}
|
||||
}
|
||||
@@ -4662,7 +4848,7 @@ namespace ams::kern {
|
||||
|
||||
/* Allocate the new memory. */
|
||||
const size_t num_pages = size / PageSize;
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, KMemoryManager::EncodeOption(KMemoryManager::Pool_Unsafe, KMemoryManager::Direction_FromFront)));
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(pg), num_pages, 1, KMemoryManager::EncodeOption(KMemoryManager::Pool_Unsafe, KMemoryManager::Direction_FromFront)));
|
||||
|
||||
/* Close the page group when we're done with it. */
|
||||
ON_SCOPE_EXIT { pg.Close(); };
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace ams::kern {
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for all children threads to terminate.*/
|
||||
/* Wait for all children threads to terminate. */
|
||||
while (true) {
|
||||
/* Get the next child. */
|
||||
KThread *cur_child = nullptr;
|
||||
@@ -298,10 +298,8 @@ namespace ams::kern {
|
||||
|
||||
/* Setup page table. */
|
||||
{
|
||||
const auto as_type = static_cast<ams::svc::CreateProcessFlag>(params.flags & ams::svc::CreateProcessFlag_AddressSpaceMask);
|
||||
const bool enable_aslr = (params.flags & ams::svc::CreateProcessFlag_EnableAslr) != 0;
|
||||
const bool enable_das_merge = (params.flags & ams::svc::CreateProcessFlag_DisableDeviceAddressSpaceMerge) == 0;
|
||||
R_TRY(m_page_table.Initialize(as_type, enable_aslr, enable_das_merge, !enable_aslr, pool, params.code_address, params.code_num_pages * PageSize, m_system_resource, res_limit));
|
||||
const bool from_back = (params.flags & ams::svc::CreateProcessFlag_EnableAslr) == 0;
|
||||
R_TRY(m_page_table.Initialize(static_cast<ams::svc::CreateProcessFlag>(params.flags), from_back, pool, params.code_address, params.code_num_pages * PageSize, m_system_resource, res_limit));
|
||||
}
|
||||
ON_RESULT_FAILURE_2 { m_page_table.Finalize(); };
|
||||
|
||||
@@ -379,10 +377,8 @@ namespace ams::kern {
|
||||
|
||||
/* Setup page table. */
|
||||
{
|
||||
const auto as_type = static_cast<ams::svc::CreateProcessFlag>(params.flags & ams::svc::CreateProcessFlag_AddressSpaceMask);
|
||||
const bool enable_aslr = (params.flags & ams::svc::CreateProcessFlag_EnableAslr) != 0;
|
||||
const bool enable_das_merge = (params.flags & ams::svc::CreateProcessFlag_DisableDeviceAddressSpaceMerge) == 0;
|
||||
R_TRY(m_page_table.Initialize(as_type, enable_aslr, enable_das_merge, !enable_aslr, pool, params.code_address, code_size, m_system_resource, res_limit));
|
||||
const bool from_back = (params.flags & ams::svc::CreateProcessFlag_EnableAslr) == 0;
|
||||
R_TRY(m_page_table.Initialize(static_cast<ams::svc::CreateProcessFlag>(params.flags), from_back, pool, params.code_address, code_size, m_system_resource, res_limit));
|
||||
}
|
||||
ON_RESULT_FAILURE_2 { m_page_table.Finalize(); };
|
||||
|
||||
@@ -467,7 +463,7 @@ namespace ams::kern {
|
||||
void KProcess::Exit() {
|
||||
MESOSPHERE_ASSERT_THIS();
|
||||
|
||||
/* Determine whether we need to start terminating */
|
||||
/* Determine whether we need to start terminating. */
|
||||
bool needs_terminate = false;
|
||||
{
|
||||
KScopedLightLock lk(m_state_lock);
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace ams::kern {
|
||||
|
||||
/* Cleanup the session list. */
|
||||
while (true) {
|
||||
/* Get the last session in the list */
|
||||
/* Get the last session in the list. */
|
||||
KServerSession *session = nullptr;
|
||||
{
|
||||
KScopedSchedulerLock sl;
|
||||
@@ -56,7 +56,7 @@ namespace ams::kern {
|
||||
|
||||
/* Cleanup the light session list. */
|
||||
while (true) {
|
||||
/* Get the last session in the list */
|
||||
/* Get the last session in the list. */
|
||||
KLightServerSession *session = nullptr;
|
||||
{
|
||||
KScopedSchedulerLock sl;
|
||||
|
||||
@@ -650,7 +650,7 @@ namespace ams::kern {
|
||||
const auto src_state = src_user ? KMemoryState_FlagReferenceCounted : KMemoryState_FlagLinearMapped;
|
||||
|
||||
/* Determine the source permission. User buffer should be unmapped + read, TLS should be user readable. */
|
||||
const KMemoryPermission src_perm = static_cast<KMemoryPermission>(src_user ? KMemoryPermission_NotMapped | KMemoryPermission_KernelRead : KMemoryPermission_UserRead);
|
||||
const KMemoryPermission src_perm = static_cast<KMemoryPermission>(src_user ? (KMemoryPermission_NotMapped | KMemoryPermission_KernelRead) : KMemoryPermission_UserRead);
|
||||
|
||||
/* Perform the fast part of the copy. */
|
||||
R_TRY(src_page_table.CopyMemoryFromLinearToKernel(reinterpret_cast<uintptr_t>(dst_msg_ptr) + offset_words, fast_size, src_message_buffer + offset_words,
|
||||
@@ -753,7 +753,7 @@ namespace ams::kern {
|
||||
/* Perform the pointer data copy. */
|
||||
const bool dst_heap = dst_user && dst_recv_list.IsToMessageBuffer();
|
||||
const auto dst_state = dst_heap ? KMemoryState_FlagReferenceCounted : KMemoryState_FlagLinearMapped;
|
||||
const KMemoryPermission dst_perm = static_cast<KMemoryPermission>(dst_heap ? KMemoryPermission_NotMapped | KMemoryPermission_KernelReadWrite : KMemoryPermission_UserReadWrite);
|
||||
const KMemoryPermission dst_perm = static_cast<KMemoryPermission>(dst_heap ? (KMemoryPermission_NotMapped | KMemoryPermission_KernelReadWrite) : KMemoryPermission_UserReadWrite);
|
||||
R_TRY(dst_page_table.CopyMemoryFromUserToLinear(recv_pointer, recv_size,
|
||||
dst_state, dst_state,
|
||||
dst_perm,
|
||||
@@ -911,7 +911,7 @@ namespace ams::kern {
|
||||
const auto dst_state = dst_user ? KMemoryState_FlagReferenceCounted : KMemoryState_FlagLinearMapped;
|
||||
|
||||
/* Determine the dst permission. User buffer should be unmapped + read, TLS should be user readable. */
|
||||
const KMemoryPermission dst_perm = static_cast<KMemoryPermission>(dst_user ? KMemoryPermission_NotMapped | KMemoryPermission_KernelReadWrite : KMemoryPermission_UserReadWrite);
|
||||
const KMemoryPermission dst_perm = static_cast<KMemoryPermission>(dst_user ? (KMemoryPermission_NotMapped | KMemoryPermission_KernelReadWrite) : KMemoryPermission_UserReadWrite);
|
||||
|
||||
/* Perform the fast part of the copy. */
|
||||
R_TRY(dst_page_table.CopyMemoryFromKernelToLinear(dst_message_buffer + offset_words, fast_size,
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ams::kern {
|
||||
R_UNLESS(memory_reservation.Succeeded(), svc::ResultLimitReached());
|
||||
|
||||
/* Allocate the memory. */
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(m_page_group), num_pages, owner->GetAllocateOption()));
|
||||
R_TRY(Kernel::GetMemoryManager().AllocateAndOpen(std::addressof(m_page_group), num_pages, 1, owner->GetAllocateOption()));
|
||||
|
||||
/* Commit our reservation. */
|
||||
memory_reservation.Commit();
|
||||
|
||||
@@ -46,10 +46,11 @@ namespace ams::kern {
|
||||
}
|
||||
}
|
||||
|
||||
void KSystemControlBase::Init::GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out) {
|
||||
void KSystemControlBase::Init::GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out, KPhysicalAddress kern_base_address) {
|
||||
*out = {
|
||||
.address = GetInteger(KSystemControl::Init::GetKernelPhysicalBaseAddress(ams::kern::MainMemoryAddress)) + KSystemControl::Init::GetIntendedMemorySize() - InitialProcessBinarySizeMax,
|
||||
._08 = 0,
|
||||
.address = GetInteger(KSystemControl::Init::GetKernelPhysicalBaseAddress(ams::kern::MainMemoryAddress)) + KSystemControl::Init::GetIntendedMemorySize() - InitialProcessBinarySizeMax,
|
||||
._08 = 0,
|
||||
.kern_address = GetInteger(kern_base_address),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ namespace ams::kern {
|
||||
|
||||
void KSystemControlBase::Init::CpuOnImpl(u64 core_id, uintptr_t entrypoint, uintptr_t arg) {
|
||||
#if defined(ATMOSPHERE_ARCH_ARM64)
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((::ams::kern::arch::arm64::smc::CpuOn<0, false>(core_id, entrypoint, arg)) == 0);
|
||||
MESOSPHERE_INIT_ABORT_UNLESS((::ams::kern::arch::arm64::smc::CpuOn<0>(core_id, entrypoint, arg)) == 0);
|
||||
#else
|
||||
AMS_INFINITE_LOOP();
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace ams::kern::svc {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result QueryIoMapping(uintptr_t *out_address, size_t *out_size, uint64_t phys_addr, size_t size) {
|
||||
Result QueryMemoryMapping(uintptr_t *out_address, size_t *out_size, uint64_t phys_addr, size_t size) {
|
||||
/* Declare variables we'll populate. */
|
||||
KProcessAddress found_address = Null<KProcessAddress>;
|
||||
size_t found_size = 0;
|
||||
@@ -125,15 +125,15 @@ namespace ams::kern::svc {
|
||||
R_RETURN(QueryPhysicalAddress(out_info, address));
|
||||
}
|
||||
|
||||
Result QueryIoMapping64(ams::svc::Address *out_address, ams::svc::Size *out_size, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
Result QueryMemoryMapping64(ams::svc::Address *out_address, ams::svc::Size *out_size, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
static_assert(sizeof(*out_address) == sizeof(uintptr_t));
|
||||
static_assert(sizeof(*out_size) == sizeof(size_t));
|
||||
R_RETURN(QueryIoMapping(reinterpret_cast<uintptr_t *>(out_address), reinterpret_cast<size_t *>(out_size), physical_address, size));
|
||||
R_RETURN(QueryMemoryMapping(reinterpret_cast<uintptr_t *>(out_address), reinterpret_cast<size_t *>(out_size), physical_address, size));
|
||||
}
|
||||
|
||||
Result LegacyQueryIoMapping64(ams::svc::Address *out_address, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
static_assert(sizeof(*out_address) == sizeof(uintptr_t));
|
||||
R_RETURN(QueryIoMapping(reinterpret_cast<uintptr_t *>(out_address), nullptr, physical_address, size));
|
||||
R_RETURN(QueryMemoryMapping(reinterpret_cast<uintptr_t *>(out_address), nullptr, physical_address, size));
|
||||
}
|
||||
|
||||
/* ============================= 64From32 ABI ============================= */
|
||||
@@ -150,15 +150,15 @@ namespace ams::kern::svc {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result QueryIoMapping64From32(ams::svc::Address *out_address, ams::svc::Size *out_size, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
Result QueryMemoryMapping64From32(ams::svc::Address *out_address, ams::svc::Size *out_size, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
static_assert(sizeof(*out_address) == sizeof(uintptr_t));
|
||||
static_assert(sizeof(*out_size) == sizeof(size_t));
|
||||
R_RETURN(QueryIoMapping(reinterpret_cast<uintptr_t *>(out_address), reinterpret_cast<size_t *>(out_size), physical_address, size));
|
||||
R_RETURN(QueryMemoryMapping(reinterpret_cast<uintptr_t *>(out_address), reinterpret_cast<size_t *>(out_size), physical_address, size));
|
||||
}
|
||||
|
||||
Result LegacyQueryIoMapping64From32(ams::svc::Address *out_address, ams::svc::PhysicalAddress physical_address, ams::svc::Size size) {
|
||||
static_assert(sizeof(*out_address) == sizeof(uintptr_t));
|
||||
R_RETURN(QueryIoMapping(reinterpret_cast<uintptr_t *>(out_address), nullptr, physical_address, size));
|
||||
R_RETURN(QueryMemoryMapping(reinterpret_cast<uintptr_t *>(out_address), nullptr, physical_address, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -106,6 +106,9 @@ namespace ams::kern::svc {
|
||||
*out = 0;
|
||||
}
|
||||
break;
|
||||
case ams::svc::InfoType_AliasRegionExtraSize:
|
||||
*out = process->GetPageTable().GetAliasRegionExtraSize();
|
||||
break;
|
||||
MESOSPHERE_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
|
||||
@@ -134,6 +137,7 @@ namespace ams::kern::svc {
|
||||
case ams::svc::InfoType_UsedNonSystemMemorySize:
|
||||
case ams::svc::InfoType_IsApplication:
|
||||
case ams::svc::InfoType_FreeThreadCount:
|
||||
case ams::svc::InfoType_AliasRegionExtraSize:
|
||||
{
|
||||
/* These info types don't support non-zero subtypes. */
|
||||
R_UNLESS(info_subtype == 0, svc::ResultInvalidCombination());
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace ams::kern::svc {
|
||||
|
||||
namespace {
|
||||
|
||||
Result MapInsecureMemory(uintptr_t address, size_t size) {
|
||||
Result MapInsecurePhysicalMemory(uintptr_t address, size_t size) {
|
||||
/* Validate the address/size. */
|
||||
R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
@@ -33,10 +33,10 @@ namespace ams::kern::svc {
|
||||
R_UNLESS(GetCurrentProcess().GetPageTable().CanContain(address, size, KMemoryState_Insecure), svc::ResultInvalidMemoryRegion());
|
||||
|
||||
/* Map the insecure memory. */
|
||||
R_RETURN(pt.MapInsecureMemory(address, size));
|
||||
R_RETURN(pt.MapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
Result UnmapInsecureMemory(uintptr_t address, size_t size) {
|
||||
Result UnmapInsecurePhysicalMemory(uintptr_t address, size_t size) {
|
||||
/* Validate the address/size. */
|
||||
R_UNLESS(util::IsAligned(size, PageSize), svc::ResultInvalidSize());
|
||||
R_UNLESS(size > 0, svc::ResultInvalidSize());
|
||||
@@ -48,29 +48,29 @@ namespace ams::kern::svc {
|
||||
R_UNLESS(GetCurrentProcess().GetPageTable().CanContain(address, size, KMemoryState_Insecure), svc::ResultInvalidMemoryRegion());
|
||||
|
||||
/* Map the insecure memory. */
|
||||
R_RETURN(pt.UnmapInsecureMemory(address, size));
|
||||
R_RETURN(pt.UnmapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* ============================= 64 ABI ============================= */
|
||||
|
||||
Result MapInsecureMemory64(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(MapInsecureMemory(address, size));
|
||||
Result MapInsecurePhysicalMemory64(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(MapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
Result UnmapInsecureMemory64(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(UnmapInsecureMemory(address, size));
|
||||
Result UnmapInsecurePhysicalMemory64(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(UnmapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
/* ============================= 64From32 ABI ============================= */
|
||||
|
||||
Result MapInsecureMemory64From32(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(MapInsecureMemory(address, size));
|
||||
Result MapInsecurePhysicalMemory64From32(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(MapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
Result UnmapInsecureMemory64From32(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(UnmapInsecureMemory(address, size));
|
||||
Result UnmapInsecurePhysicalMemory64From32(ams::svc::Address address, ams::svc::Size size) {
|
||||
R_RETURN(UnmapInsecurePhysicalMemory(address, size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace ams::kern::svc {
|
||||
/* Get the process page table. */
|
||||
auto &page_table = GetCurrentProcess().GetPageTable();
|
||||
|
||||
/* Lock the mesage buffer. */
|
||||
/* Lock the message buffer. */
|
||||
R_TRY(page_table.LockForIpcUserBuffer(nullptr, message, buffer_size));
|
||||
|
||||
{
|
||||
@@ -186,7 +186,7 @@ namespace ams::kern::svc {
|
||||
/* Commit our reservation. */
|
||||
event_reservation.Commit();
|
||||
|
||||
/* At end of scope, kill the standing references to the sub events. */
|
||||
/* At end of scope, kill the standing event references. */
|
||||
ON_SCOPE_EXIT {
|
||||
event->GetReadableEvent().Close();
|
||||
event->Close();
|
||||
@@ -215,7 +215,7 @@ namespace ams::kern::svc {
|
||||
/* Get the process page table. */
|
||||
auto &page_table = GetCurrentProcess().GetPageTable();
|
||||
|
||||
/* Lock the mesage buffer. */
|
||||
/* Lock the message buffer. */
|
||||
R_TRY(page_table.LockForIpcUserBuffer(nullptr, message, buffer_size));
|
||||
|
||||
/* Ensure that if we fail and aren't terminating that we unlock the user buffer. */
|
||||
@@ -242,7 +242,7 @@ namespace ams::kern::svc {
|
||||
/* Get the process page table. */
|
||||
auto &page_table = GetCurrentProcess().GetPageTable();
|
||||
|
||||
/* Lock the mesage buffer, getting its physical address. */
|
||||
/* Lock the message buffer, getting its physical address. */
|
||||
KPhysicalAddress message_paddr;
|
||||
R_TRY(page_table.LockForIpcUserBuffer(std::addressof(message_paddr), message, buffer_size));
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace ams::kern::svc {
|
||||
/* Add the client to the handle table. */
|
||||
R_TRY(handle_table.Add(out_client, std::addressof(port->GetClientPort())));
|
||||
|
||||
/* Ensure that we maintaing a clean handle state on exit. */
|
||||
/* Ensure that we maintain a clean handle state on exit. */
|
||||
ON_RESULT_FAILURE { handle_table.Remove(*out_client); };
|
||||
|
||||
/* Add the server to the handle table. */
|
||||
|
||||
@@ -162,6 +162,18 @@ namespace ams::kern::svc {
|
||||
/* Check that the number of extra resource pages is >= 0. */
|
||||
R_UNLESS(params.system_resource_num_pages >= 0, svc::ResultInvalidSize());
|
||||
|
||||
/* Validate that the alias region extra size is allowed, if enabled. */
|
||||
if (params.flags & ams::svc::CreateProcessFlag_EnableAliasRegionExtraSize) {
|
||||
/* Check that we have a 64-bit address space. */
|
||||
R_UNLESS((params.flags & ams::svc::CreateProcessFlag_AddressSpaceMask) == ams::svc::CreateProcessFlag_AddressSpace64Bit, svc::ResultInvalidState());
|
||||
|
||||
/* Check that the system resource page count is non-zero. */
|
||||
R_UNLESS(params.system_resource_num_pages > 0, svc::ResultInvalidState());
|
||||
|
||||
/* Check that debug mode is enabled. */
|
||||
R_UNLESS(KTargetSystem::IsDebugMode(), svc::ResultInvalidState());
|
||||
}
|
||||
|
||||
/* Convert to sizes. */
|
||||
const size_t code_num_pages = params.code_num_pages;
|
||||
const size_t system_resource_num_pages = params.system_resource_num_pages;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,6 @@ namespace ams::erpt {
|
||||
|
||||
enum CategoryId {
|
||||
AMS_ERPT_FOREACH_CATEGORY(GENERATE_ENUM)
|
||||
CategoryId_Count,
|
||||
};
|
||||
|
||||
#undef GENERATE_ENUM
|
||||
@@ -43,7 +42,6 @@ namespace ams::erpt {
|
||||
|
||||
enum FieldId {
|
||||
AMS_ERPT_FOREACH_FIELD(GENERATE_ENUM)
|
||||
FieldId_Count,
|
||||
};
|
||||
|
||||
#undef GENERATE_ENUM
|
||||
|
||||
@@ -58,34 +58,88 @@ namespace ams::erpt::srv {
|
||||
};
|
||||
#undef STRINGIZE_HANDLER
|
||||
|
||||
#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId FieldToCategoryMap[] = {
|
||||
#define GET_FIELD_CATEGORY(FIELD, ID, CATEGORY, TYPE, FLAG) CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId FieldIndexToCategoryMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_CATEGORY)
|
||||
};
|
||||
#undef GET_FIELD_CATEGORY
|
||||
|
||||
#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = TYPE,
|
||||
constexpr inline const FieldType FieldToTypeMap[] = {
|
||||
#define GET_FIELD_TYPE(FIELD, ID, CATEGORY, TYPE, FLAG) TYPE,
|
||||
constexpr inline const FieldType FieldIndexToTypeMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_TYPE)
|
||||
};
|
||||
#undef GET_FIELD_TYPE
|
||||
|
||||
#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) [FieldId_##FIELD] = FLAG,
|
||||
constexpr inline const FieldFlag FieldToFlagMap[] = {
|
||||
#define GET_FIELD_FLAG(FIELD, ID, CATEGORY, TYPE, FLAG) FLAG,
|
||||
constexpr inline const FieldFlag FieldIndexToFlagMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_FLAG)
|
||||
};
|
||||
#undef GET_FIELD_FLAG
|
||||
|
||||
inline CategoryId ConvertFieldToCategory(FieldId id) {
|
||||
return FieldToCategoryMap[id];
|
||||
#define GET_FIELD_ID(FIELD, ...) FieldId_##FIELD,
|
||||
constexpr inline const FieldId FieldIndexToFieldIdMap[] = {
|
||||
AMS_ERPT_FOREACH_FIELD(GET_FIELD_ID)
|
||||
};
|
||||
#undef GET_FIELD_ID
|
||||
|
||||
#define GET_CATEGORY_ID(CATEGORY, ...) CategoryId_##CATEGORY,
|
||||
constexpr inline const CategoryId CategoryIndexToCategoryIdMap[] = {
|
||||
AMS_ERPT_FOREACH_CATEGORY(GET_CATEGORY_ID)
|
||||
};
|
||||
#undef GET_CATEGORY_ID
|
||||
|
||||
constexpr util::optional<size_t> FindFieldIndex(FieldId id) {
|
||||
if (std::is_constant_evaluated()) {
|
||||
for (size_t i = 0; i < util::size(FieldIndexToFieldIdMap); ++i) {
|
||||
if (FieldIndexToFieldIdMap[i] == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return util::nullopt;
|
||||
} else {
|
||||
if (const auto it = std::lower_bound(std::begin(FieldIndexToFieldIdMap), std::end(FieldIndexToFieldIdMap), id); it != std::end(FieldIndexToFieldIdMap) && *it == id) {
|
||||
return std::distance(FieldIndexToFieldIdMap, it);
|
||||
} else {
|
||||
return util::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline FieldType ConvertFieldToType(FieldId id) {
|
||||
return FieldToTypeMap[id];
|
||||
constexpr util::optional<size_t> FindCategoryIndex(CategoryId id) {
|
||||
if (std::is_constant_evaluated()) {
|
||||
for (size_t i = 0; i < util::size(CategoryIndexToCategoryIdMap); ++i) {
|
||||
if (CategoryIndexToCategoryIdMap[i] == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return util::nullopt;
|
||||
} else {
|
||||
if (const auto it = std::lower_bound(std::begin(CategoryIndexToCategoryIdMap), std::end(CategoryIndexToCategoryIdMap), id); it != std::end(CategoryIndexToCategoryIdMap) && *it == id) {
|
||||
return std::distance(CategoryIndexToCategoryIdMap, it);
|
||||
} else {
|
||||
return util::nullopt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline FieldFlag ConvertFieldToFlag(FieldId id) {
|
||||
return FieldToFlagMap[id];
|
||||
constexpr inline CategoryId ConvertFieldToCategory(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToCategoryMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline FieldType ConvertFieldToType(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToTypeMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline FieldFlag ConvertFieldToFlag(FieldId id) {
|
||||
const auto index = FindFieldIndex(id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
return FieldIndexToFlagMap[index.value()];
|
||||
}
|
||||
|
||||
constexpr inline ReportFlagSet MakeNoReportFlags() {
|
||||
|
||||
17
libraries/libstratosphere/include/stratosphere/fat.hpp
Normal file
17
libraries/libstratosphere/include/stratosphere/fat.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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 <stratosphere/fat/fat_file_system.hpp>
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
|
||||
namespace ams::fat {
|
||||
|
||||
constexpr inline size_t FatErrorNameMaxLength = 0x10;
|
||||
|
||||
struct FatError {
|
||||
int error;
|
||||
int extra_error;
|
||||
int drive_id;
|
||||
char name[FatErrorNameMaxLength];
|
||||
u8 reserved[4];
|
||||
};
|
||||
static_assert(sizeof(FatError) == 0x20);
|
||||
static_assert(util::is_pod<FatError>::value);
|
||||
|
||||
struct FatReportInfo1 {
|
||||
u16 open_file_peak_count;
|
||||
u16 open_directory_peak_count;
|
||||
};
|
||||
static_assert(sizeof(FatReportInfo1) == 4);
|
||||
static_assert(util::is_pod<FatReportInfo1>::value);
|
||||
|
||||
struct FatReportInfo2 {
|
||||
u16 open_unique_file_entry_peak_count;
|
||||
u16 open_unique_directory_entry_peak_count;
|
||||
};
|
||||
static_assert(sizeof(FatReportInfo2) == 4);
|
||||
static_assert(util::is_pod<FatReportInfo2>::value);
|
||||
|
||||
struct FatSafeInfo {
|
||||
u32 result;
|
||||
u32 error_number;
|
||||
u32 safe_error_number;
|
||||
};
|
||||
static_assert(sizeof(FatSafeInfo) == 12);
|
||||
static_assert(util::is_pod<FatSafeInfo>::value);
|
||||
|
||||
}
|
||||
@@ -51,9 +51,11 @@
|
||||
#include <stratosphere/fs/fs_code.hpp>
|
||||
#include <stratosphere/fs/fs_content.hpp>
|
||||
#include <stratosphere/fs/fs_content_storage.hpp>
|
||||
#include <stratosphere/fs/fs_error_info.hpp>
|
||||
#include <stratosphere/fs/fs_game_card.hpp>
|
||||
#include <stratosphere/fs/fs_host.hpp>
|
||||
#include <stratosphere/fs/fs_image_directory.hpp>
|
||||
#include <stratosphere/fs/fs_mmc.hpp>
|
||||
#include <stratosphere/fs/fs_save_data_types.hpp>
|
||||
#include <stratosphere/fs/fs_save_data_management.hpp>
|
||||
#include <stratosphere/fs/fs_save_data_transaction.hpp>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 <stratosphere/fs/fs_common.hpp>
|
||||
#include <stratosphere/fat/fat_file_system.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
struct StorageErrorInfo {
|
||||
u32 num_activation_failures;
|
||||
u32 num_activation_error_corrections;
|
||||
u32 num_read_write_failures;
|
||||
u32 num_read_write_error_corrections;
|
||||
};
|
||||
static_assert(sizeof(StorageErrorInfo) == 0x10);
|
||||
static_assert(util::is_pod<StorageErrorInfo>::value);
|
||||
|
||||
struct FileSystemProxyErrorInfo {
|
||||
u32 rom_fs_remount_for_data_corruption_count;
|
||||
u32 rom_fs_unrecoverable_data_corruption_by_remount_count;
|
||||
fat::FatError fat_fs_error;
|
||||
u32 rom_fs_recovered_by_invalidate_cache_count;
|
||||
u32 save_data_index_count;
|
||||
fat::FatReportInfo1 bis_system_fat_report_info_1;
|
||||
fat::FatReportInfo1 bis_user_fat_report_info_1;
|
||||
fat::FatReportInfo1 sd_card_fat_report_info_1;
|
||||
fat::FatReportInfo2 bis_system_fat_report_info_2;
|
||||
fat::FatReportInfo2 bis_user_fat_report_info_2;
|
||||
fat::FatReportInfo2 sd_card_fat_report_info_2;
|
||||
u32 rom_fs_deep_retry_start_count;
|
||||
u32 rom_fs_unrecoverable_by_game_card_access_failed_count;
|
||||
fat::FatSafeInfo bis_system_fat_safe_info;
|
||||
fat::FatSafeInfo bis_user_fat_safe_info;
|
||||
|
||||
u8 reserved[0x18];
|
||||
};
|
||||
static_assert(sizeof(FileSystemProxyErrorInfo) == 0x80);
|
||||
static_assert(util::is_pod<FileSystemProxyErrorInfo>::value);
|
||||
|
||||
Result GetAndClearMmcErrorInfo(StorageErrorInfo *out_sei, size_t *out_log_size, char *out_log_buffer, size_t log_buffer_size);
|
||||
Result GetAndClearSdCardErrorInfo(StorageErrorInfo *out_sei, size_t *out_log_size, char *out_log_buffer, size_t log_buffer_size);
|
||||
|
||||
Result GetAndClearFileSystemProxyErrorInfo(FileSystemProxyErrorInfo *out);
|
||||
|
||||
}
|
||||
@@ -19,6 +19,9 @@
|
||||
namespace ams::fs {
|
||||
|
||||
/* ACCURATE_TO_VERSION: Unknown */
|
||||
constexpr inline size_t GameCardCidSize = 0x10;
|
||||
constexpr inline size_t GameCardDeviceIdSize = 0x10;
|
||||
|
||||
enum class GameCardPartition {
|
||||
Update = 0,
|
||||
Normal = 1,
|
||||
@@ -47,9 +50,44 @@ namespace ams::fs {
|
||||
Terra = 1,
|
||||
};
|
||||
|
||||
struct GameCardErrorReportInfo {
|
||||
u16 game_card_crc_error_num;
|
||||
u16 reserved1;
|
||||
u16 asic_crc_error_num;
|
||||
u16 reserved2;
|
||||
u16 refresh_num;
|
||||
u16 reserved3;
|
||||
u16 retry_limit_out_num;
|
||||
u16 timeout_retry_num;
|
||||
u16 asic_reinitialize_failure_detail;
|
||||
u16 insertion_count;
|
||||
u16 removal_count;
|
||||
u16 asic_reinitialize_num;
|
||||
u32 initialize_count;
|
||||
u16 asic_reinitialize_failure_num;
|
||||
u16 awaken_failure_num;
|
||||
u16 reserved4;
|
||||
u16 refresh_succeeded_count;
|
||||
u32 last_read_error_page_address;
|
||||
u32 last_read_error_page_count;
|
||||
u32 awaken_count;
|
||||
u32 read_count_from_insert;
|
||||
u32 read_count_from_awaken;
|
||||
u8 reserved5[8];
|
||||
};
|
||||
static_assert(util::is_pod<GameCardErrorReportInfo>::value);
|
||||
static_assert(sizeof(GameCardErrorReportInfo) == 0x40);
|
||||
|
||||
using GameCardHandle = u32;
|
||||
|
||||
Result GetGameCardHandle(GameCardHandle *out);
|
||||
Result MountGameCardPartition(const char *name, GameCardHandle handle, GameCardPartition partition);
|
||||
|
||||
Result GetGameCardCid(void *dst, size_t size);
|
||||
Result GetGameCardDeviceId(void *dst, size_t size);
|
||||
|
||||
Result GetGameCardErrorReportInfo(GameCardErrorReportInfo *out);
|
||||
|
||||
bool IsGameCardInserted();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 <stratosphere/fs/fs_common.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
struct MemoryReportInfo {
|
||||
u64 pooled_buffer_peak_free_size;
|
||||
u64 pooled_buffer_retried_count;
|
||||
u64 pooled_buffer_reduce_allocation_count;
|
||||
u64 buffer_manager_peak_free_size;
|
||||
u64 buffer_manager_retried_count;
|
||||
u64 exp_heap_peak_free_size;
|
||||
u64 buffer_pool_peak_free_size;
|
||||
u64 patrol_read_allocate_buffer_success_count;
|
||||
u64 patrol_read_allocate_buffer_failure_count;
|
||||
u64 buffer_manager_peak_total_allocatable_size;
|
||||
u64 buffer_pool_max_allocate_size;
|
||||
u64 pooled_buffer_failed_ideal_allocation_count_on_async_access;
|
||||
|
||||
u8 reserved[0x20];
|
||||
};
|
||||
static_assert(sizeof(MemoryReportInfo) == 0x80);
|
||||
static_assert(util::is_pod<MemoryReportInfo>::value);
|
||||
|
||||
Result GetAndClearMemoryReportInfo(MemoryReportInfo *out);
|
||||
|
||||
}
|
||||
57
libraries/libstratosphere/include/stratosphere/fs/fs_mmc.hpp
Normal file
57
libraries/libstratosphere/include/stratosphere/fs/fs_mmc.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 <stratosphere/fs/fs_common.hpp>
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
constexpr inline size_t MmcCidSize = 0x10;
|
||||
|
||||
constexpr inline size_t MmcExtendedCsdSize = 0x200;
|
||||
|
||||
constexpr inline int MmcExtendedCsdOffsetReEolInfo = 267;
|
||||
constexpr inline int MmcExtendedCsdOffsetDeviceLifeTimeEstTypA = 268;
|
||||
constexpr inline int MmcExtendedCsdOffsetDeviceLifeTimeEstTypB = 269;
|
||||
|
||||
enum MmcSpeedMode {
|
||||
MmcSpeedMode_Identification = 0,
|
||||
MmcSpeedMode_LegacySpeed = 1,
|
||||
MmcSpeedMode_HighSpeed = 2,
|
||||
MmcSpeedMode_Hs200 = 3,
|
||||
MmcSpeedMode_Hs400 = 4,
|
||||
MmcSpeedMode_Unknown = 5,
|
||||
};
|
||||
|
||||
enum class MmcPartition {
|
||||
UserData = 0,
|
||||
BootPartition1 = 1,
|
||||
BootPartition2 = 2,
|
||||
};
|
||||
|
||||
Result GetMmcCid(void *dst, size_t size);
|
||||
|
||||
inline void ClearMmcCidSerialNumber(u8 *cid) {
|
||||
/* Clear the serial number from the cid. */
|
||||
std::memset(cid + 1, 0, 4);
|
||||
}
|
||||
|
||||
Result GetMmcSpeedMode(MmcSpeedMode *out);
|
||||
|
||||
Result GetMmcPatrolCount(u32 *out);
|
||||
|
||||
Result GetMmcExtendedCsd(void *dst, size_t size);
|
||||
|
||||
}
|
||||
@@ -21,12 +21,38 @@ namespace ams::fs {
|
||||
/* ACCURATE_TO_VERSION: Unknown */
|
||||
class IEventNotifier;
|
||||
|
||||
constexpr inline size_t SdCardCidSize = 0x10;
|
||||
|
||||
enum SdCardSpeedMode {
|
||||
SdCardSpeedMode_Identification = 0,
|
||||
SdCardSpeedMode_DefaultSpeed = 1,
|
||||
SdCardSpeedMode_HighSpeed = 2,
|
||||
SdCardSpeedMode_Sdr12 = 3,
|
||||
SdCardSpeedMode_Sdr25 = 4,
|
||||
SdCardSpeedMode_Sdr50 = 5,
|
||||
SdCardSpeedMode_Sdr104 = 6,
|
||||
SdCardSpeedMode_Ddr50 = 7,
|
||||
SdCardSpeedMode_Unknown = 8,
|
||||
};
|
||||
|
||||
struct EncryptionSeed {
|
||||
char value[0x10];
|
||||
};
|
||||
static_assert(util::is_pod<EncryptionSeed>::value);
|
||||
static_assert(sizeof(EncryptionSeed) == 0x10);
|
||||
|
||||
Result GetSdCardCid(void *dst, size_t size);
|
||||
|
||||
inline void ClearSdCardCidSerialNumber(u8 *cid) {
|
||||
/* Clear the serial number from the cid. */
|
||||
std::memset(cid + 2, 0, 4);
|
||||
}
|
||||
|
||||
Result GetSdCardUserAreaSize(s64 *out);
|
||||
Result GetSdCardProtectedAreaSize(s64 *out);
|
||||
|
||||
Result GetSdCardSpeedMode(SdCardSpeedMode *out);
|
||||
|
||||
Result MountSdCard(const char *name);
|
||||
|
||||
Result MountSdCardErrorReportDirectoryForAtmosphere(const char *name);
|
||||
|
||||
@@ -121,6 +121,7 @@ namespace ams::fssrv {
|
||||
Result IsSignedSystemPartitionOnSdCardValid(ams::sf::Out<bool> out);
|
||||
Result OpenAccessFailureDetectionEventNotifier();
|
||||
/* ... */
|
||||
Result GetAndClearErrorInfo(ams::sf::Out<fs::FileSystemProxyErrorInfo> out);
|
||||
Result RegisterProgramIndexMapInfo(const ams::sf::InBuffer &buffer, s32 count);
|
||||
Result SetBisRootForHost(u32 id, const fssrv::sf::FspPath &path);
|
||||
Result SetSaveDataSize(s64 size, s64 journal_size);
|
||||
@@ -131,6 +132,7 @@ namespace ams::fssrv {
|
||||
Result OutputAccessLogToSdCard(const ams::sf::InBuffer &buf);
|
||||
Result RegisterUpdatePartition();
|
||||
Result OpenRegisteredUpdatePartition(ams::sf::Out<ams::sf::SharedPointer<fssrv::sf::IFileSystem>> out);
|
||||
Result GetAndClearMemoryReportInfo(ams::sf::Out<fs::MemoryReportInfo> out);
|
||||
/* ... */
|
||||
Result GetProgramIndexForAccessLog(ams::sf::Out<u32> out_idx, ams::sf::Out<u32> out_count);
|
||||
Result GetFsStackUsage(ams::sf::Out<u32> out, u32 type);
|
||||
|
||||
@@ -16,12 +16,27 @@
|
||||
#pragma once
|
||||
#include <vapours.hpp>
|
||||
#include <stratosphere/sf.hpp>
|
||||
#include <stratosphere/fs/fs_error_info.hpp>
|
||||
#include <stratosphere/fs/fs_game_card.hpp>
|
||||
|
||||
/* TODO */
|
||||
/* ACCURATE_TO_VERSION: 13.4.0.0 */
|
||||
#define AMS_FSSRV_I_DEVICE_OPERATOR_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, IsSdCardInserted, (ams::sf::Out<bool> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 200, Result, IsGameCardInserted, (ams::sf::Out<bool> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 202, Result, GetGameCardHandle, (ams::sf::Out<u32> out), (out))
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, IsSdCardInserted, (ams::sf::Out<bool> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetSdCardSpeedMode, (ams::sf::Out<s64> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, GetSdCardCid, (ams::sf::OutBuffer out, s64 size), (out, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 3, Result, GetSdCardUserAreaSize, (ams::sf::Out<s64> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 4, Result, GetSdCardProtectedAreaSize, (ams::sf::Out<s64> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 5, Result, GetAndClearSdCardErrorInfo, (ams::sf::Out<fs::StorageErrorInfo> out_sei, ams::sf::Out<s64> out_size, ams::sf::OutBuffer out_buf, s64 size), (out_sei, out_size, out_buf, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 100, Result, GetMmcCid, (ams::sf::OutBuffer out, s64 size), (out, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 101, Result, GetMmcSpeedMode, (ams::sf::Out<s64> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 112, Result, GetMmcPatrolCount, (ams::sf::Out<u32> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 113, Result, GetAndClearMmcErrorInfo, (ams::sf::Out<fs::StorageErrorInfo> out_sei, ams::sf::Out<s64> out_size, ams::sf::OutBuffer out_buf, s64 size), (out_sei, out_size, out_buf, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 114, Result, GetMmcExtendedCsd, (ams::sf::OutBuffer out, s64 size), (out, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 200, Result, IsGameCardInserted, (ams::sf::Out<bool> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 202, Result, GetGameCardHandle, (ams::sf::Out<u32> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 208, Result, GetGameCardIdSet, (ams::sf::OutBuffer out, s64 size), (out, size)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 217, Result, GetGameCardErrorReportInfo, (ams::sf::Out<fs::GameCardErrorReportInfo> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 218, Result, GetGameCardDeviceId, (ams::sf::OutBuffer out, s64 size), (out, size))
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, IDeviceOperator, AMS_FSSRV_I_DEVICE_OPERATOR_INTERFACE_INFO, 0x1484E21C)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <stratosphere/fssrv/sf/fssrv_sf_istorage.hpp>
|
||||
#include <stratosphere/fssrv/sf/fssrv_sf_i_device_operator.hpp>
|
||||
#include <stratosphere/fssrv/sf/fssrv_sf_i_event_notifier.hpp>
|
||||
#include <stratosphere/fs/fs_error_info.hpp>
|
||||
#include <stratosphere/fs/fs_memory_report_info.hpp>
|
||||
|
||||
/* ACCURATE_TO_VERSION: 13.4.0.0 */
|
||||
#define AMS_FSSRV_I_FILE_SYSTEM_PROXY_INTERFACE_INFO(C, H) \
|
||||
@@ -125,7 +127,7 @@
|
||||
/* AMS_SF_METHOD_INFO(C, H, 702, Result, IsAccessFailureDetected, (), (), hos::Version_5_0_0) */ \
|
||||
/* AMS_SF_METHOD_INFO(C, H, 710, Result, ResolveAccessFailure, (), (), hos::Version_5_0_0) */ \
|
||||
/* AMS_SF_METHOD_INFO(C, H, 720, Result, AbandonAccessFailure, (), (), hos::Version_5_0_0) */ \
|
||||
/* AMS_SF_METHOD_INFO(C, H, 800, Result, GetAndClearErrorInfo, (), (), hos::Version_2_0_0) */ \
|
||||
AMS_SF_METHOD_INFO(C, H, 800, Result, GetAndClearErrorInfo, (ams::sf::Out<fs::FileSystemProxyErrorInfo> out), (out), hos::Version_2_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 810, Result, RegisterProgramIndexMapInfo, (const ams::sf::InBuffer &buffer, s32 count), (buffer, count), hos::Version_7_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1000, Result, SetBisRootForHost, (u32 id, const fssrv::sf::FspPath &path), (id, path), hos::Version_Min, hos::Version_9_2_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1001, Result, SetSaveDataSize, (s64 size, s64 journal_size), (size, journal_size)) \
|
||||
@@ -136,7 +138,7 @@
|
||||
AMS_SF_METHOD_INFO(C, H, 1006, Result, OutputAccessLogToSdCard, (const ams::sf::InBuffer &buf), (buf)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1007, Result, RegisterUpdatePartition, (), (), hos::Version_4_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1008, Result, OpenRegisteredUpdatePartition, (ams::sf::Out<ams::sf::SharedPointer<fssrv::sf::IFileSystem>> out), (out), hos::Version_4_0_0) \
|
||||
/* AMS_SF_METHOD_INFO(C, H, 1009, Result, GetAndClearMemoryReportInfo, (ams::sf::Out<fs::MemoryReportInfo> out), (out), hos::Version_4_0_0) */ \
|
||||
AMS_SF_METHOD_INFO(C, H, 1009, Result, GetAndClearMemoryReportInfo, (ams::sf::Out<fs::MemoryReportInfo> out), (out), hos::Version_4_0_0) \
|
||||
/* AMS_SF_METHOD_INFO(C, H, 1010, Result, SetDataStorageRedirectTarget, (), (), hos::Version_5_1_0, hos::Version_6_2_0) */ \
|
||||
AMS_SF_METHOD_INFO(C, H, 1011, Result, GetProgramIndexForAccessLog, (ams::sf::Out<u32> out_idx, ams::sf::Out<u32> out_count), (out_idx, out_count), hos::Version_7_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1012, Result, GetFsStackUsage, (ams::sf::Out<u32> out, u32 type), (out, type), hos::Version_9_0_0) \
|
||||
|
||||
@@ -18,3 +18,4 @@
|
||||
#include <stratosphere/gc/impl/gc_types.hpp>
|
||||
#include <stratosphere/gc/impl/gc_gc_crypto.hpp>
|
||||
#include <stratosphere/gc/impl/gc_embedded_data_holder.hpp>
|
||||
#include <stratosphere/gc/gc.hpp>
|
||||
|
||||
30
libraries/libstratosphere/include/stratosphere/gc/gc.hpp
Normal file
30
libraries/libstratosphere/include/stratosphere/gc/gc.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 <vapours.hpp>
|
||||
#include <stratosphere/gc/impl/gc_types.hpp>
|
||||
|
||||
namespace ams::gc {
|
||||
|
||||
struct GameCardIdSet {
|
||||
gc::impl::CardId1 id1;
|
||||
gc::impl::CardId2 id2;
|
||||
gc::impl::CardId3 id3;
|
||||
};
|
||||
static_assert(util::is_pod<GameCardIdSet>::value);
|
||||
static_assert(sizeof(GameCardIdSet) == 0xC);
|
||||
|
||||
}
|
||||
@@ -76,6 +76,11 @@ namespace ams::gc::impl {
|
||||
static_assert(util::is_pod<CardHeaderEncryptedData>::value);
|
||||
static_assert(sizeof(CardHeaderEncryptedData) == 0x70);
|
||||
|
||||
enum MakerCodeForCardId1 : u8 {
|
||||
MakerCodeForCardId1_MegaChips = 0xC2,
|
||||
MakerCodeForCardId1_Lapis = 0xAE,
|
||||
};
|
||||
|
||||
enum MemoryCapacity : u8 {
|
||||
MemoryCapacity_1GB = 0xFA,
|
||||
MemoryCapacity_2GB = 0xF8,
|
||||
@@ -85,6 +90,33 @@ namespace ams::gc::impl {
|
||||
MemoryCapacity_32GB = 0xE2,
|
||||
};
|
||||
|
||||
enum MemoryType : u8 {
|
||||
MemoryType_T1RomFast = 0x01,
|
||||
MemoryType_T2RomFast = 0x02,
|
||||
MemoryType_T1NandFast = 0x09,
|
||||
MemoryType_T2NandFast = 0x0A,
|
||||
MemoryType_T1RomLate = 0x21,
|
||||
MemoryType_T2RomLate = 0x22,
|
||||
MemoryType_T1NandLate = 0x29,
|
||||
MemoryType_T2NandLate = 0x2A,
|
||||
};
|
||||
|
||||
enum CardSecurityNumber : u8 {
|
||||
CardSecurityNumber_0 = 0x00,
|
||||
CardSecurityNumber_1 = 0x01,
|
||||
CardSecurityNumber_2 = 0x02,
|
||||
CardSecurityNumber_3 = 0x03,
|
||||
CardSecurityNumber_4 = 0x04,
|
||||
};
|
||||
|
||||
enum CardType : u8 {
|
||||
CardType_Rom = 0x00,
|
||||
CardType_Writable_Dev_T1 = 0x01,
|
||||
CardType_Writable_Prod_T1 = 0x02,
|
||||
CardType_Writable_Dev_T2 = 0x03,
|
||||
CardType_Writable_Prod_T2 = 0x04,
|
||||
};
|
||||
|
||||
enum AccessControl1ClockRate : u32 {
|
||||
AccessControl1ClockRate_25MHz = 0x00A10011,
|
||||
AccessControl1ClockRate_50MHz = 0x00A10010,
|
||||
@@ -95,6 +127,23 @@ namespace ams::gc::impl {
|
||||
SelSec_T2 = 2,
|
||||
};
|
||||
|
||||
struct CardId1 {
|
||||
MakerCodeForCardId1 maker_code;
|
||||
MemoryCapacity memory_capacity;
|
||||
u8 reserved;
|
||||
MemoryType memory_type;
|
||||
};
|
||||
|
||||
struct CardId2 {
|
||||
CardSecurityNumber card_security_number;
|
||||
CardType card_type;
|
||||
u8 reserved[2];
|
||||
};
|
||||
|
||||
struct CardId3 {
|
||||
u8 reserved[4];
|
||||
};
|
||||
|
||||
struct CardHeader {
|
||||
static constexpr u32 Magic = util::FourCC<'H','E','A','D'>::Code;
|
||||
|
||||
|
||||
@@ -81,6 +81,8 @@ namespace ams::hos {
|
||||
Version_16_0_3 = ::ams::TargetFirmware_16_0_3,
|
||||
Version_16_1_0 = ::ams::TargetFirmware_16_1_0,
|
||||
Version_17_0_0 = ::ams::TargetFirmware_17_0_0,
|
||||
Version_17_0_1 = ::ams::TargetFirmware_17_0_1,
|
||||
Version_18_0_0 = ::ams::TargetFirmware_18_0_0,
|
||||
|
||||
Version_Current = ::ams::TargetFirmware_Current,
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
AMS_SF_METHOD_INFO(C, H, 4, Result, GetApplicationProcessId, (sf::Out<os::ProcessId> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 5, Result, HookToCreateApplicationProcess, (sf::OutCopyHandle out_hook), (out_hook)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 6, Result, ClearHook, (u32 which), (which), hos::Version_6_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 7, Result, GetProgramId, (sf::Out<ncm::ProgramId> out, os::ProcessId process_id), (out, process_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 7, Result, GetProgramId, (sf::Out<ncm::ProgramId> out, os::ProcessId process_id), (out, process_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessInfo, (sf::OutCopyHandle out_process_handle, sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status, os::ProcessId process_id), (out_process_handle, out_loc, out_status, process_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereGetCurrentLimitInfo, (sf::Out<s64> out_cur_val, sf::Out<s64> out_lim_val, u32 group, u32 resource), (out_cur_val, out_lim_val, group, resource))
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
#define AMS_PM_I_INFORMATION_INTERFACE_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, GetProgramId, (sf::Out<ncm::ProgramId> out, os::ProcessId process_id), (out, process_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetAppletCurrentResourceLimitValues, (sf::Out<pm::ResourceLimitValues> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, GetAppletPeakResourceLimitValues, (sf::Out<pm::ResourceLimitValues> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetAppletResourceLimitCurrentValue, (sf::Out<pm::ResourceLimitValue> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, GetAppletResourceLimitPeakValue, (sf::Out<pm::ResourceLimitValue> out), (out)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereGetProcessId, (sf::Out<os::ProcessId> out, ncm::ProgramId program_id), (out, program_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65001, Result, AtmosphereHasLaunchedBootProgram, (sf::Out<bool> out, ncm::ProgramId program_id), (out, program_id)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 65002, Result, AtmosphereGetProcessInfo, (sf::Out<ncm::ProgramLocation> out_loc, sf::Out<cfg::OverrideStatus> out_status, os::ProcessId process_id), (out_loc, out_status, process_id))
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace ams::pm::info {
|
||||
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id);
|
||||
Result HasLaunchedBootProgram(bool *out, ncm::ProgramId program_id);
|
||||
|
||||
Result GetAppletCurrentResourceLimitValues(pm::ResourceLimitValues *out);
|
||||
Result GetAppletPeakResourceLimitValues(pm::ResourceLimitValues *out);
|
||||
Result GetAppletResourceLimitCurrentValue(pm::ResourceLimitValue *out);
|
||||
Result GetAppletResourceLimitPeakValue(pm::ResourceLimitValue *out);
|
||||
|
||||
Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace ams::pm {
|
||||
LaunchFlagsDeprecated_SignalOnStart = (1 << 5),
|
||||
};
|
||||
|
||||
struct ResourceLimitValues {
|
||||
struct ResourceLimitValue {
|
||||
u64 physical_memory;
|
||||
u32 thread_count;
|
||||
u32 event_count;
|
||||
|
||||
@@ -53,7 +53,8 @@ namespace ams::settings {
|
||||
/* 4.0.0+ */
|
||||
Language_SimplifiedChinese,
|
||||
Language_TraditionalChinese,
|
||||
|
||||
/* 10.1.0+ */
|
||||
Language_PortugueseBr,
|
||||
Language_Count,
|
||||
};
|
||||
|
||||
@@ -92,6 +93,8 @@ namespace ams::settings {
|
||||
/* 4.0.0+ */
|
||||
AMS_MATCH_LANGUAGE(SimplifiedChinese, "zh-Hans")
|
||||
AMS_MATCH_LANGUAGE(TraditionalChinese, "zh-Hant")
|
||||
/* 10.1.0+ */
|
||||
AMS_MATCH_LANGUAGE(PortugueseBr, "pt-BR")
|
||||
#undef AMS_MATCH_LANGUAGE
|
||||
else { static_assert(Lang != Language_Japanese); }
|
||||
}
|
||||
@@ -116,6 +119,8 @@ namespace ams::settings {
|
||||
/* 4.0.0+ */
|
||||
EncodeLanguage<Language_SimplifiedChinese>(),
|
||||
EncodeLanguage<Language_TraditionalChinese>(),
|
||||
/* 10.1.0+ */
|
||||
EncodeLanguage<Language_PortugueseBr>(),
|
||||
};
|
||||
return EncodedLanguages[language];
|
||||
}
|
||||
@@ -156,7 +161,11 @@ namespace ams::settings {
|
||||
}
|
||||
|
||||
constexpr inline bool IsValidLanguageCodeDeprecated(const LanguageCode &lc) {
|
||||
return impl::IsValidLanguageCode(lc, std::make_index_sequence<Language_Count - 2>{});
|
||||
return impl::IsValidLanguageCode(lc, std::make_index_sequence<Language_Count - 3>{});
|
||||
}
|
||||
|
||||
constexpr inline bool IsValidLanguageCodeDeprecated2(const LanguageCode &lc) {
|
||||
return impl::IsValidLanguageCode(lc, std::make_index_sequence<Language_Count - 1>{});
|
||||
}
|
||||
|
||||
constexpr inline bool IsValidLanguageCode(const LanguageCode &lc) {
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace ams::sf::cmif {
|
||||
}
|
||||
|
||||
constexpr size_t GetImplOutDataTotalSize() const {
|
||||
return m_impl_metadata.GetOutDataSize() + m_impl_metadata.GetOutHeadersSize();
|
||||
return m_impl_metadata.GetUnalignedOutDataSize() + m_impl_metadata.GetOutHeadersSize();
|
||||
}
|
||||
public:
|
||||
/* Used to enabled templated message processors. */
|
||||
@@ -80,12 +80,12 @@ namespace ams::sf::cmif {
|
||||
const auto runtime_metadata = m_impl_processor->GetRuntimeMetadata();
|
||||
|
||||
return ServerMessageRuntimeMetadata {
|
||||
.in_data_size = static_cast<u16>(runtime_metadata.GetInDataSize() + runtime_metadata.GetInObjectCount() * sizeof(DomainObjectId)),
|
||||
.out_data_size = static_cast<u16>(runtime_metadata.GetOutDataSize() + runtime_metadata.GetOutObjectCount() * sizeof(DomainObjectId)),
|
||||
.in_headers_size = static_cast<u8>(runtime_metadata.GetInHeadersSize() + sizeof(CmifDomainInHeader)),
|
||||
.out_headers_size = static_cast<u8>(runtime_metadata.GetOutHeadersSize() + sizeof(CmifDomainOutHeader)),
|
||||
.in_object_count = 0,
|
||||
.out_object_count = 0,
|
||||
.in_data_size = static_cast<u16>(runtime_metadata.GetInDataSize() + runtime_metadata.GetInObjectCount() * sizeof(DomainObjectId)),
|
||||
.unaligned_out_data_size = static_cast<u16>(runtime_metadata.GetOutDataSize() + runtime_metadata.GetOutObjectCount() * sizeof(DomainObjectId)),
|
||||
.in_headers_size = static_cast<u8>(runtime_metadata.GetInHeadersSize() + sizeof(CmifDomainInHeader)),
|
||||
.out_headers_size = static_cast<u8>(runtime_metadata.GetOutHeadersSize() + sizeof(CmifDomainOutHeader)),
|
||||
.in_object_count = 0,
|
||||
.out_object_count = 0,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ams::sf::cmif {
|
||||
/* This is needed for non-templated domain message processing. */
|
||||
struct ServerMessageRuntimeMetadata {
|
||||
u16 in_data_size;
|
||||
u16 out_data_size;
|
||||
u16 unaligned_out_data_size;
|
||||
u8 in_headers_size;
|
||||
u8 out_headers_size;
|
||||
u8 in_object_count;
|
||||
@@ -39,7 +39,11 @@ namespace ams::sf::cmif {
|
||||
}
|
||||
|
||||
constexpr size_t GetOutDataSize() const {
|
||||
return static_cast<size_t>(this->out_data_size);
|
||||
return static_cast<size_t>(util::AlignUp(this->unaligned_out_data_size, sizeof(u32)));
|
||||
}
|
||||
|
||||
constexpr size_t GetUnalignedOutDataSize() const {
|
||||
return static_cast<size_t>(this->unaligned_out_data_size);
|
||||
}
|
||||
|
||||
constexpr size_t GetInHeadersSize() const {
|
||||
|
||||
@@ -472,6 +472,7 @@ namespace ams::sf::impl {
|
||||
static constexpr size_t InDataSize = util::AlignUp(InDataOffsets[NumInDatas], alignof(u16));
|
||||
|
||||
static constexpr std::array<size_t, NumOutDatas+1> OutDataOffsets = RawDataOffsetCalculator<OutDatas>::Offsets;
|
||||
static constexpr size_t UnalignedOutDataSize = OutDataOffsets[NumOutDatas];
|
||||
static constexpr size_t OutDataSize = util::AlignUp(OutDataOffsets[NumOutDatas], alignof(u32));
|
||||
static constexpr size_t OutDataAlign = [] {
|
||||
if constexpr (std::tuple_size<OutDatas>::value) {
|
||||
@@ -492,12 +493,12 @@ namespace ams::sf::impl {
|
||||
|
||||
/* Used by server message processor at runtime. */
|
||||
static constexpr inline const cmif::ServerMessageRuntimeMetadata RuntimeMetadata = cmif::ServerMessageRuntimeMetadata{
|
||||
.in_data_size = InDataSize,
|
||||
.out_data_size = OutDataSize,
|
||||
.in_headers_size = sizeof(CmifInHeader),
|
||||
.out_headers_size = sizeof(CmifOutHeader),
|
||||
.in_object_count = NumInObjects,
|
||||
.out_object_count = NumOutObjects,
|
||||
.in_data_size = InDataSize,
|
||||
.unaligned_out_data_size = UnalignedOutDataSize,
|
||||
.in_headers_size = sizeof(CmifInHeader),
|
||||
.out_headers_size = sizeof(CmifOutHeader),
|
||||
.in_object_count = NumInObjects,
|
||||
.out_object_count = NumOutObjects,
|
||||
};
|
||||
|
||||
/* Construction of argument serialization structs. */
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace ams::spl::impl {
|
||||
Result ModularExponentiateWithDrmDeviceCertKey(void *out, size_t out_size, const void *base, size_t base_size, const void *mod, size_t mod_size);
|
||||
Result PrepareEsArchiveKey(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation);
|
||||
Result LoadPreparedAesKey(s32 keyslot, const AccessKey &access_key);
|
||||
Result PrepareEsUnknown2Key(AccessKey *out_access_key, const void *base, size_t base_size, const void *mod, size_t mod_size, const void *label_digest, size_t label_digest_size, u32 generation);
|
||||
|
||||
/* FS */
|
||||
Result DecryptAndStoreGcKey(const void *src, size_t src_size, const AccessKey &access_key, const KeySource &key_source, u32 option);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
AMS_SF_METHOD_INFO(C, H, 28, Result, DecryptAndStoreDrmDeviceCertKey, (const sf::InPointerBuffer &src, spl::AccessKey access_key, spl::KeySource key_source), (src, access_key, key_source), hos::Version_5_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 29, Result, ModularExponentiateWithDrmDeviceCertKey, (const sf::OutPointerBuffer &out, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod), (out, base, mod), hos::Version_5_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 31, Result, PrepareEsArchiveKey, (sf::Out<spl::AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation), (out_access_key, base, mod, label_digest, generation), hos::Version_6_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 32, Result, LoadPreparedAesKey, (s32 keyslot, spl::AccessKey access_key), (keyslot, access_key), hos::Version_6_0_0)
|
||||
AMS_SF_METHOD_INFO(C, H, 32, Result, LoadPreparedAesKey, (s32 keyslot, spl::AccessKey access_key), (keyslot, access_key), hos::Version_6_0_0) \
|
||||
AMS_SF_METHOD_INFO(C, H, 33, Result, PrepareEsUnknown2Key, (sf::Out<spl::AccessKey> out_access_key, const sf::InPointerBuffer &base, const sf::InPointerBuffer &mod, const sf::InPointerBuffer &label_digest, u32 generation), (out_access_key, base, mod, label_digest, generation), hos::Version_18_0_0)
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE_WITH_BASE(ams::spl::impl, IEsInterface, ::ams::spl::impl::IDeviceUniqueDataInterface, AMS_SPL_I_ES_INTERFACE_INTERFACE_INFO, 0x346D5001)
|
||||
|
||||
@@ -331,8 +331,8 @@
|
||||
R_RETURN(::svcQueryPhysicalAddress(reinterpret_cast<::PhysicalMemoryInfo *>(out_info), address));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Result QueryIoMapping(::ams::svc::Address *out_address, ::ams::svc::Size *out_size, ::ams::svc::PhysicalAddress physical_address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcQueryIoMapping(reinterpret_cast<u64 *>(out_address), reinterpret_cast<u64 *>(out_size), physical_address, size));
|
||||
ALWAYS_INLINE Result QueryMemoryMapping(::ams::svc::Address *out_address, ::ams::svc::Size *out_size, ::ams::svc::PhysicalAddress physical_address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcQueryMemoryMapping(reinterpret_cast<u64 *>(out_address), reinterpret_cast<u64 *>(out_size), physical_address, size));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Result LegacyQueryIoMapping(::ams::svc::Address *out_address, ::ams::svc::PhysicalAddress physical_address, ::ams::svc::Size size) {
|
||||
@@ -503,12 +503,12 @@
|
||||
::svcCallSecureMonitor(reinterpret_cast<::SecmonArgs *>(args));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Result MapInsecureMemory(::ams::svc::Address address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcMapInsecureMemory(reinterpret_cast<void *>(static_cast<uintptr_t>(address)), size));
|
||||
ALWAYS_INLINE Result MapInsecurePhysicalMemory(::ams::svc::Address address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcMapInsecurePhysicalMemory(reinterpret_cast<void *>(static_cast<uintptr_t>(address)), size));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Result UnmapInsecureMemory(::ams::svc::Address address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcUnmapInsecureMemory(reinterpret_cast<void *>(static_cast<uintptr_t>(address)), size));
|
||||
ALWAYS_INLINE Result UnmapInsecurePhysicalMemory(::ams::svc::Address address, ::ams::svc::Size size) {
|
||||
R_RETURN(::svcUnmapInsecurePhysicalMemory(reinterpret_cast<void *>(static_cast<uintptr_t>(address)), size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,11 +16,16 @@
|
||||
#include <stratosphere.hpp>
|
||||
#include "decodersrv_decoder_server_object.hpp"
|
||||
#include "../jpeg/decodersrv_software_jpeg_decoder.hpp"
|
||||
#include "../jpeg/decodersrv_software_jpeg_shrinker.hpp"
|
||||
|
||||
namespace ams::capsrv::server {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const int JpegShrinkQualities[] = {
|
||||
98, 95, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0
|
||||
};
|
||||
|
||||
Result DecodeJpegImpl(void *dst, size_t dst_size, const void *src_jpeg, size_t src_jpeg_size, u32 width, u32 height, const ScreenShotDecodeOption &option, void *work, size_t work_size) {
|
||||
/* Clear the work memory. */
|
||||
std::memset(work, 0, work_size);
|
||||
@@ -67,6 +72,61 @@ namespace ams::capsrv::server {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ShrinkJpegImpl(u64 *out_size, void *dst, size_t dst_size, const void *src_jpeg, size_t src_jpeg_size, u32 width, u32 height, const ScreenShotDecodeOption &option, void *work, size_t work_size) {
|
||||
/* Validate parameters. */
|
||||
R_UNLESS(util::IsAligned(width, 0x10), capsrv::ResultAlbumOutOfRange());
|
||||
R_UNLESS(util::IsAligned(height, 0x4), capsrv::ResultAlbumOutOfRange());
|
||||
|
||||
R_UNLESS(dst != nullptr, capsrv::ResultInternalJpegOutBufferShortage());
|
||||
R_UNLESS(dst_size != 0, capsrv::ResultAlbumReadBufferShortage());
|
||||
|
||||
R_UNLESS(src_jpeg != nullptr, capsrv::ResultAlbumInvalidFileData());
|
||||
R_UNLESS(src_jpeg_size != 0, capsrv::ResultAlbumInvalidFileData());
|
||||
|
||||
/* Create the input. */
|
||||
const jpeg::SoftwareJpegShrinkerInput shrink_input = {
|
||||
.jpeg = src_jpeg,
|
||||
.jpeg_size = src_jpeg_size,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.fancy_upsampling = option.HasJpegDecoderFlag(ScreenShotDecoderFlag_EnableFancyUpsampling),
|
||||
.block_smoothing = option.HasJpegDecoderFlag(ScreenShotDecoderFlag_EnableBlockSmoothing),
|
||||
};
|
||||
|
||||
/* Create the output. */
|
||||
u64 shrunk_size = 0;
|
||||
s32 shrunk_width = 0, shrunk_height = 0;
|
||||
jpeg::SoftwareJpegShrinkerOutput shrink_output = {
|
||||
.out_size = std::addressof(shrunk_size),
|
||||
.out_width = std::addressof(shrunk_width),
|
||||
.out_height = std::addressof(shrunk_height),
|
||||
.dst = dst,
|
||||
.dst_size = dst_size,
|
||||
};
|
||||
|
||||
/* Try to shrink the jpeg at various quality levels. */
|
||||
for (auto quality : JpegShrinkQualities) {
|
||||
/* Shrink at the current quality. */
|
||||
R_TRY_CATCH(jpeg::SoftwareJpegShrinker::ShrinkRgba8(shrink_output, shrink_input, quality, work, work_size)) {
|
||||
/* If the output buffer isn't large enough to fit the output, we should try at a lower quality. */
|
||||
R_CATCH(capsrv::ResultInternalJpegOutBufferShortage) {
|
||||
continue;
|
||||
}
|
||||
/* Nintendo doesn't catch this result, but our lack of work buffer use makes me think this may be necessary. */
|
||||
R_CATCH(capsrv::ResultInternalJpegWorkMemoryShortage) {
|
||||
continue;
|
||||
}
|
||||
} R_END_TRY_CATCH;
|
||||
|
||||
/* Write the output size. */
|
||||
*out_size = shrunk_size;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
/* Nintendo aborts if no quality succeeds. */
|
||||
AMS_ABORT("ShrinkJpeg should succeed before this point\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result DecoderControlService::DecodeJpeg(const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const ScreenShotDecodeOption &option) {
|
||||
@@ -78,4 +138,13 @@ namespace ams::capsrv::server {
|
||||
R_RETURN(DecodeJpegImpl(out.GetPointer(), out.GetSize(), in.GetPointer(), in.GetSize(), width, height, option, work, work_size));
|
||||
}
|
||||
|
||||
Result DecoderControlService::ShrinkJpeg(ams::sf::Out<u64> out_size, const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const capsrv::ScreenShotDecodeOption &option) {
|
||||
/* Get the work buffer. */
|
||||
void *work = g_work_memory.jpeg_decoder_memory;
|
||||
size_t work_size = sizeof(g_work_memory.jpeg_decoder_memory);
|
||||
|
||||
/* Call the shrink implementation. */
|
||||
R_RETURN(ShrinkJpegImpl(out_size.GetPointer(), out.GetPointer(), out.GetSize(), in.GetPointer(), in.GetSize(), width, height, option, work, work_size));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,8 @@
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#define AMS_CAPSRV_DECODER_CONTROL_SERVICE_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 3001, Result, DecodeJpeg, (const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const capsrv::ScreenShotDecodeOption &option), (out, in, width, height, option))
|
||||
AMS_SF_METHOD_INFO(C, H, 3001, Result, DecodeJpeg, (const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const capsrv::ScreenShotDecodeOption &option), (out, in, width, height, option)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 4001, Result, ShrinkJpeg, (ams::sf::Out<u64> out_size, const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const capsrv::ScreenShotDecodeOption &option), (out_size, out, in, width, height, option))
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(ams::capsrv::sf, IDecoderControlService, AMS_CAPSRV_DECODER_CONTROL_SERVICE_INTERFACE_INFO, 0xD168E90B)
|
||||
|
||||
@@ -26,6 +27,7 @@ namespace ams::capsrv::server {
|
||||
class DecoderControlService final {
|
||||
public:
|
||||
Result DecodeJpeg(const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const ScreenShotDecodeOption &option);
|
||||
Result ShrinkJpeg(ams::sf::Out<u64> out_size, const ams::sf::OutNonSecureBuffer &out, const ams::sf::InBuffer &in, u32 width, u32 height, const capsrv::ScreenShotDecodeOption &option);
|
||||
};
|
||||
static_assert(capsrv::sf::IsIDecoderControlService<DecoderControlService>);
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "decodersrv_software_jpeg_shrinker.hpp"
|
||||
#include "capsrv_server_jpeg_library_types.hpp"
|
||||
#include "capsrv_server_jpeg_error_handler.hpp"
|
||||
|
||||
|
||||
namespace ams::capsrv::server::jpeg {
|
||||
|
||||
#define CAPSRV_ABORT_UNLESS(expr) do { \
|
||||
const bool __capsrv_assert_res = (expr); \
|
||||
AMS_ASSERT(__capsrv_assert_res); \
|
||||
AMS_ABORT_UNLESS(__capsrv_assert_res); \
|
||||
} while (0)
|
||||
|
||||
#define CAPSRV_ASSERT(expr) do { \
|
||||
const bool __capsrv_assert_res = (expr); \
|
||||
AMS_ASSERT(__capsrv_assert_res); \
|
||||
R_UNLESS(__capsrv_assert_res, capsrv::ResultAlbumError()); \
|
||||
} while (0)
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr s32 ImageSizeHorizonalUnit = 0x10;
|
||||
constexpr s32 ImageSizeVerticalUnitDecode = 0x4;
|
||||
constexpr s32 ImageSizeVerticalUnitEncode = 0x8;
|
||||
|
||||
constexpr s32 RgbColorComponentCount = 3;
|
||||
constexpr s32 RgbaColorComponentCount = 4;
|
||||
|
||||
Result GetRgbBufferSize(size_t *out_size, size_t *out_stride, s32 width, size_t work_size) {
|
||||
/* Calculate the space we need and verify we have enough. */
|
||||
const size_t rgb_width = util::AlignUp(static_cast<size_t>(width), ImageSizeHorizonalUnit);
|
||||
const size_t rgb_stride = rgb_width * RgbColorComponentCount;
|
||||
const size_t rgb_size = rgb_stride * ImageSizeVerticalUnitEncode;
|
||||
R_UNLESS(work_size >= rgb_size, capsrv::ResultInternalJpegWorkMemoryShortage());
|
||||
|
||||
/* Return the output to the caller. */
|
||||
*out_size = rgb_size;
|
||||
*out_stride = rgb_stride;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
void SetupEncodingParameter(JpegLibraryType::jpeg_compress_struct *cinfo, const SoftwareJpegShrinkerInput &input, int quality) {
|
||||
/* Set parameters. */
|
||||
cinfo->image_width = static_cast<JpegLibraryType::JDIMENSION>(input.width / 2);
|
||||
cinfo->image_height = static_cast<JpegLibraryType::JDIMENSION>(input.height / 2);
|
||||
cinfo->input_components = RgbColorComponentCount;
|
||||
cinfo->in_color_space = JpegLibraryType::J_COLOR_SPACE::JCS_RGB;
|
||||
|
||||
/* Set defaults/color space. */
|
||||
jpeg_set_defaults(cinfo);
|
||||
jpeg_set_colorspace(cinfo, JpegLibraryType::J_COLOR_SPACE::JCS_YCbCr);
|
||||
|
||||
/* Configure sampling. */
|
||||
/* libjpeg-turbo doesn't actually have this field, as of now. */
|
||||
/* cinfo->do_fancy_downsampling = false; */
|
||||
cinfo->comp_info[0].h_samp_factor = 2;
|
||||
cinfo->comp_info[0].v_samp_factor = 1;
|
||||
cinfo->comp_info[1].h_samp_factor = 1;
|
||||
cinfo->comp_info[1].v_samp_factor = 1;
|
||||
cinfo->comp_info[2].h_samp_factor = 1;
|
||||
cinfo->comp_info[2].v_samp_factor = 1;
|
||||
|
||||
/* Set the quality. */
|
||||
jpeg_set_quality(cinfo, quality, true);
|
||||
|
||||
/* Configure remaining parameters. */
|
||||
cinfo->dct_method = JpegLibraryType::J_DCT_METHOD::JDCT_ISLOW;
|
||||
cinfo->optimize_coding = false;
|
||||
cinfo->write_JFIF_header = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result SoftwareJpegShrinker::ShrinkRgba8(SoftwareJpegShrinkerOutput &output, const SoftwareJpegShrinkerInput &input, int quality, void *work, size_t work_size) {
|
||||
CAPSRV_ABORT_UNLESS(util::IsAligned(input.width, ImageSizeHorizonalUnit));
|
||||
CAPSRV_ABORT_UNLESS(util::IsAligned(input.height, ImageSizeVerticalUnitDecode));
|
||||
|
||||
const u32 shrunk_width = input.width / 2;
|
||||
const u32 shrunk_height = input.height / 2;
|
||||
CAPSRV_ABORT_UNLESS(util::IsAligned(shrunk_width, ImageSizeHorizonalUnit));
|
||||
|
||||
CAPSRV_ABORT_UNLESS(output.dst != nullptr);
|
||||
|
||||
CAPSRV_ABORT_UNLESS(output.out_width != nullptr);
|
||||
CAPSRV_ABORT_UNLESS(output.out_height != nullptr);
|
||||
|
||||
/* Determine work buffer extents. */
|
||||
char *work_start = static_cast<char *>(work);
|
||||
char *work_end = work_start + work_size;
|
||||
|
||||
/* Determine the buffer extents for our linebuffers. */
|
||||
u8 *rgb_buffer = static_cast<u8 *>(static_cast<void *>(work_start));
|
||||
size_t rgb_buffer_size;
|
||||
size_t rgb_buffer_stride;
|
||||
R_TRY(GetRgbBufferSize(std::addressof(rgb_buffer_size), std::addressof(rgb_buffer_stride), input.width, work_size));
|
||||
|
||||
/* The start of the workbuffer is reserved for linebuffer space. */
|
||||
work_start += rgb_buffer_size;
|
||||
|
||||
/* Create our compression structures. */
|
||||
JpegLibraryType::jpeg_decompress_struct dcinfo = {};
|
||||
JpegLibraryType::jpeg_compress_struct ecinfo = {};
|
||||
|
||||
/* Here nintendo creates a work buffer structure containing work_start + work_size. */
|
||||
/* This seems to be a custom patch for/to libjpeg-turbo. */
|
||||
/* It would be desirable for us to mimic this, because it gives Nintendo strong */
|
||||
/* fixed memory usage guarantees. */
|
||||
/* TODO: Determine if it is feasible for us to recreate this ourselves, */
|
||||
/* Either by adding support to the devkitPro libjpeg-turbo portlib or otherwise. */
|
||||
AMS_UNUSED(work_end);
|
||||
|
||||
/* Create our error managers. */
|
||||
JpegErrorHandler jerr_dc = { .result = ResultSuccess(), };
|
||||
JpegErrorHandler jerr_ec = { .result = ResultSuccess(), };
|
||||
jerr_dc.error_exit = JpegErrorHandler::HandleError,
|
||||
jerr_ec.error_exit = JpegErrorHandler::HandleError,
|
||||
|
||||
/* Link our error managers to our compression structures. */
|
||||
dcinfo.err = jpeg_std_error(std::addressof(jerr_dc));
|
||||
ecinfo.err = jpeg_std_error(std::addressof(jerr_ec));
|
||||
|
||||
/* Use setjmp, so that on error our handler will longjmp to return an error result. */
|
||||
if (setjmp(jerr_ec.jmp_buf) == 0) {
|
||||
if (setjmp(jerr_dc.jmp_buf) == 0) {
|
||||
/* Create our decompressor. */
|
||||
jpeg_create_decompress(std::addressof(dcinfo));
|
||||
ON_SCOPE_EXIT { jpeg_destroy_decompress(std::addressof(dcinfo)); };
|
||||
|
||||
/* Setup our memory reader, ensure the header is correct. */
|
||||
jpeg_mem_src(std::addressof(dcinfo), const_cast<unsigned char *>(static_cast<const unsigned char *>(input.jpeg)), input.jpeg_size);
|
||||
R_UNLESS(jpeg_read_header(std::addressof(dcinfo), true) == JPEG_HEADER_OK, capsrv::ResultAlbumInvalidFileData());
|
||||
|
||||
/* Ensure width and height are correct. */
|
||||
R_UNLESS(dcinfo.image_width == input.width, capsrv::ResultAlbumInvalidFileData());
|
||||
R_UNLESS(dcinfo.image_height == input.height, capsrv::ResultAlbumInvalidFileData());
|
||||
|
||||
/* Set output parameters. */
|
||||
dcinfo.out_color_space = JpegLibraryType::J_COLOR_SPACE::JCS_RGB;
|
||||
dcinfo.dct_method = JpegLibraryType::J_DCT_METHOD::JDCT_ISLOW;
|
||||
dcinfo.do_fancy_upsampling = input.fancy_upsampling;
|
||||
dcinfo.do_block_smoothing = input.block_smoothing;
|
||||
dcinfo.scale_num = 1;
|
||||
dcinfo.scale_denom = 2;
|
||||
|
||||
/* Start decompression. */
|
||||
R_UNLESS(jpeg_start_decompress(std::addressof(dcinfo)) == TRUE, capsrv::ResultAlbumInvalidFileData());
|
||||
|
||||
/* Check the parameters. */
|
||||
CAPSRV_ASSERT(dcinfo.output_width == shrunk_width);
|
||||
CAPSRV_ASSERT(dcinfo.output_height == shrunk_height);
|
||||
CAPSRV_ASSERT(dcinfo.out_color_components == RgbColorComponentCount);
|
||||
CAPSRV_ASSERT(dcinfo.output_components == RgbColorComponentCount);
|
||||
|
||||
/* Create our compressor. */
|
||||
jpeg_create_compress(std::addressof(ecinfo));
|
||||
ON_SCOPE_EXIT { jpeg_destroy_compress(std::addressof(ecinfo)); };
|
||||
|
||||
/* Setup our memory writer. */
|
||||
unsigned long out_size = static_cast<unsigned long>(output.dst_size);
|
||||
jpeg_mem_dest(std::addressof(ecinfo), reinterpret_cast<unsigned char **>(std::addressof(output.dst)), std::addressof(out_size));
|
||||
|
||||
/* Setup the encoding parameters. */
|
||||
SetupEncodingParameter(std::addressof(ecinfo), input, quality);
|
||||
|
||||
/* Start compression. */
|
||||
jpeg_start_compress(std::addressof(ecinfo), true);
|
||||
|
||||
/* Parse the scanlines. */
|
||||
{
|
||||
/* Create our linebuffer structure. */
|
||||
JpegLibraryType::JSAMPROW linebuffers[ImageSizeVerticalUnitEncode] = {};
|
||||
for (int i = 0; i < ImageSizeVerticalUnitEncode; i++) {
|
||||
linebuffers[i] = rgb_buffer + rgb_buffer_stride * i;
|
||||
}
|
||||
|
||||
/* While we still have scanlines, parse! */
|
||||
while (dcinfo.output_scanline < shrunk_height) {
|
||||
/* Determine remaining scanlines. */
|
||||
const auto remaining_scanlines = shrunk_height - dcinfo.output_scanline;
|
||||
const auto cur_max_scanlines = std::min<s32>(remaining_scanlines, ImageSizeVerticalUnitEncode);
|
||||
|
||||
/* If we have scanlines to decode, try to do so. */
|
||||
auto writable_scanlines = 0;
|
||||
while (writable_scanlines < cur_max_scanlines) {
|
||||
const auto decoded = jpeg_read_scanlines(std::addressof(dcinfo), linebuffers + writable_scanlines, ImageSizeVerticalUnitDecode);
|
||||
CAPSRV_ASSERT(decoded <= ImageSizeVerticalUnitDecode / 2);
|
||||
|
||||
writable_scanlines += decoded;
|
||||
}
|
||||
|
||||
/* If we have scanlines to write, try to do so. */
|
||||
jpeg_write_scanlines(std::addressof(ecinfo), linebuffers, writable_scanlines);
|
||||
}
|
||||
}
|
||||
|
||||
/* Finish the decompression. */
|
||||
R_UNLESS(jpeg_finish_decompress(std::addressof(dcinfo)) == TRUE, capsrv::ResultAlbumInvalidFileData());
|
||||
|
||||
/* Finish the compression. */
|
||||
jpeg_finish_compress(std::addressof(ecinfo));
|
||||
|
||||
/* Set the output size. */
|
||||
*output.out_size = out_size;
|
||||
} else {
|
||||
/* Some unknown error was caught by our handler. */
|
||||
R_THROW(capsrv::ResultAlbumInvalidFileData());
|
||||
}
|
||||
} else {
|
||||
/* Return the encoding result. */
|
||||
R_THROW(jerr_ec.result);
|
||||
}
|
||||
|
||||
/* Write the size we decoded to output. */
|
||||
*output.out_width = static_cast<s32>(dcinfo.output_width);
|
||||
*output.out_width = static_cast<s32>(dcinfo.output_height);
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <stratosphere.hpp>
|
||||
|
||||
namespace ams::capsrv::server::jpeg {
|
||||
|
||||
struct SoftwareJpegShrinkerInput {
|
||||
const void *jpeg;
|
||||
size_t jpeg_size;
|
||||
u32 width;
|
||||
u32 height;
|
||||
bool fancy_upsampling;
|
||||
bool block_smoothing;
|
||||
};
|
||||
|
||||
struct SoftwareJpegShrinkerOutput {
|
||||
u64 *out_size;
|
||||
s32 *out_width;
|
||||
s32 *out_height;
|
||||
void *dst;
|
||||
size_t dst_size;
|
||||
};
|
||||
|
||||
class SoftwareJpegShrinker {
|
||||
public:
|
||||
static Result ShrinkRgba8(SoftwareJpegShrinkerOutput &output, const SoftwareJpegShrinkerInput &input, int quality, void *work, size_t work_size);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -69,13 +69,13 @@ namespace ams::erpt::srv {
|
||||
|
||||
auto guard = SCOPE_GUARD { m_ctx.field_count = 0; };
|
||||
|
||||
R_UNLESS(m_ctx.field_count <= FieldsPerContext, erpt::ResultInvalidArgument());
|
||||
R_UNLESS(0 <= m_ctx.category && m_ctx.category < CategoryId_Count, erpt::ResultInvalidArgument());
|
||||
R_UNLESS(m_ctx.field_count <= FieldsPerContext, erpt::ResultInvalidArgument());
|
||||
R_UNLESS(FindCategoryIndex(m_ctx.category).has_value(), erpt::ResultInvalidArgument());
|
||||
|
||||
for (u32 i = 0; i < m_ctx.field_count; i++) {
|
||||
m_ctx.fields[i] = ctx_ptr->fields[i];
|
||||
|
||||
R_UNLESS(0 <= m_ctx.fields[i].id && m_ctx.fields[i].id < FieldId_Count, erpt::ResultInvalidArgument());
|
||||
R_UNLESS(FindFieldIndex(m_ctx.fields[i].id).has_value(), erpt::ResultInvalidArgument());
|
||||
R_UNLESS(0 <= m_ctx.fields[i].type && m_ctx.fields[i].type < FieldType_Count, erpt::ResultInvalidArgument());
|
||||
|
||||
R_UNLESS(m_ctx.fields[i].type == ConvertFieldToType(m_ctx.fields[i].id), erpt::ResultFieldTypeMismatch());
|
||||
|
||||
@@ -62,7 +62,10 @@ namespace ams::erpt::srv {
|
||||
static Result AddId(Report *report, FieldId field_id) {
|
||||
static_assert(MaxFieldStringSize < ElementSize_256);
|
||||
|
||||
R_TRY(AddStringValue(report, FieldString[field_id], strnlen(FieldString[field_id], MaxFieldStringSize)));
|
||||
const auto index = FindFieldIndex(field_id);
|
||||
AMS_ASSERT(index.has_value());
|
||||
|
||||
R_TRY(AddStringValue(report, FieldString[index.value()], strnlen(FieldString[index.value()], MaxFieldStringSize)));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 <stratosphere.hpp>
|
||||
|
||||
namespace ams::erpt::srv {
|
||||
|
||||
Result SubmitFsInfo();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "erpt_srv_fs_info.hpp"
|
||||
#include "erpt_srv_context_record.hpp"
|
||||
#include "erpt_srv_context.hpp"
|
||||
|
||||
namespace ams::erpt::srv {
|
||||
|
||||
namespace {
|
||||
|
||||
Result SubmitMmcDetailInfo() {
|
||||
/* Submit the mmc cid. */
|
||||
{
|
||||
u8 mmc_cid[fs::MmcCidSize] = {};
|
||||
if (R_SUCCEEDED(fs::GetMmcCid(mmc_cid, sizeof(mmc_cid)))) {
|
||||
/* Clear the serial number from the cid. */
|
||||
fs::ClearMmcCidSerialNumber(mmc_cid);
|
||||
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDTypeInfo, sizeof(mmc_cid));
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add the cid. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDType, mmc_cid, sizeof(mmc_cid)));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Submit the mmc speed mode. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDSpeedModeInfo, 0x20);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Get the speed mode. */
|
||||
fs::MmcSpeedMode speed_mode{};
|
||||
const auto res = fs::GetMmcSpeedMode(std::addressof(speed_mode));
|
||||
if (R_SUCCEEDED(res)) {
|
||||
const char *speed_mode_name = "None";
|
||||
switch (speed_mode) {
|
||||
case fs::MmcSpeedMode_Identification:
|
||||
speed_mode_name = "Identification";
|
||||
break;
|
||||
case fs::MmcSpeedMode_LegacySpeed:
|
||||
speed_mode_name = "LegacySpeed";
|
||||
break;
|
||||
case fs::MmcSpeedMode_HighSpeed:
|
||||
speed_mode_name = "HighSpeed";
|
||||
break;
|
||||
case fs::MmcSpeedMode_Hs200:
|
||||
speed_mode_name = "Hs200";
|
||||
break;
|
||||
case fs::MmcSpeedMode_Hs400:
|
||||
speed_mode_name = "Hs400";
|
||||
break;
|
||||
case fs::MmcSpeedMode_Unknown:
|
||||
speed_mode_name = "Unknown";
|
||||
break;
|
||||
default:
|
||||
speed_mode_name = "UnDefined";
|
||||
break;
|
||||
}
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDSpeedMode, speed_mode_name, std::strlen(speed_mode_name)));
|
||||
} else {
|
||||
/* Getting speed mode failed, so add the result. */
|
||||
char res_str[0x20];
|
||||
util::SNPrintf(res_str, sizeof(res_str), "0x%08X", res.GetValue());
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDSpeedMode, res_str, std::strlen(res_str)));
|
||||
}
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
/* Submit the mmc extended csd. */
|
||||
{
|
||||
u8 mmc_csd[fs::MmcExtendedCsdSize] = {};
|
||||
if (R_SUCCEEDED(fs::GetMmcExtendedCsd(mmc_csd, sizeof(mmc_csd)))) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDExtendedCsd, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields from the csd. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDPreEolInfo, static_cast<u32>(mmc_csd[fs::MmcExtendedCsdOffsetReEolInfo])));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDDeviceLifeTimeEstTypA, static_cast<u32>(mmc_csd[fs::MmcExtendedCsdOffsetDeviceLifeTimeEstTypA])));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDDeviceLifeTimeEstTypB, static_cast<u32>(mmc_csd[fs::MmcExtendedCsdOffsetDeviceLifeTimeEstTypB])));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Submit the mmc patrol count. */
|
||||
{
|
||||
u32 count = 0;
|
||||
if (R_SUCCEEDED(fs::GetMmcPatrolCount(std::addressof(count)))) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDPatrolInfo, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add the count. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDPatrolCount, count));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitMmcErrorInfo() {
|
||||
/* Get the mmc error info. */
|
||||
fs::StorageErrorInfo sei = {};
|
||||
char log_buffer[erpt::ArrayBufferSizeDefault] = {};
|
||||
size_t log_size = 0;
|
||||
if (R_SUCCEEDED(fs::GetAndClearMmcErrorInfo(std::addressof(sei), std::addressof(log_size), log_buffer, sizeof(log_buffer)))) {
|
||||
/* Submit the error info. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDErrorInfo, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDNumActivationFailures, sei.num_activation_failures));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDNumActivationErrorCorrections, sei.num_activation_error_corrections));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDNumReadWriteFailures, sei.num_read_write_failures));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDNumReadWriteErrorCorrections, sei.num_read_write_error_corrections));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
/* If we have a log, submit it. */
|
||||
if (log_size > 0) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_NANDDriverLog, log_size);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_NANDErrorLog, log_buffer, log_size));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitSdCardDetailInfo() {
|
||||
/* Submit the sd card cid. */
|
||||
{
|
||||
u8 sd_cid[fs::SdCardCidSize] = {};
|
||||
if (R_SUCCEEDED(fs::GetSdCardCid(sd_cid, sizeof(sd_cid)))) {
|
||||
/* Clear the serial number from the cid. */
|
||||
fs::ClearSdCardCidSerialNumber(sd_cid);
|
||||
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_MicroSDTypeInfo, sizeof(sd_cid));
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add the cid. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_MicroSDType, sd_cid, sizeof(sd_cid)));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Submit the sd card speed mode. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_MicroSDSpeedModeInfo, 0x20);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Get the speed mode. */
|
||||
fs::SdCardSpeedMode speed_mode{};
|
||||
const auto res = fs::GetSdCardSpeedMode(std::addressof(speed_mode));
|
||||
if (R_SUCCEEDED(res)) {
|
||||
const char *speed_mode_name = "None";
|
||||
switch (speed_mode) {
|
||||
case fs::SdCardSpeedMode_Identification:
|
||||
speed_mode_name = "Identification";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_DefaultSpeed:
|
||||
speed_mode_name = "DefaultSpeed";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_HighSpeed:
|
||||
speed_mode_name = "HighSpeed";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Sdr12:
|
||||
speed_mode_name = "Sdr12";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Sdr25:
|
||||
speed_mode_name = "Sdr25";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Sdr50:
|
||||
speed_mode_name = "Sdr50";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Sdr104:
|
||||
speed_mode_name = "Sdr104";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Ddr50:
|
||||
speed_mode_name = "Ddr50";
|
||||
break;
|
||||
case fs::SdCardSpeedMode_Unknown:
|
||||
speed_mode_name = "Unknown";
|
||||
break;
|
||||
default:
|
||||
speed_mode_name = "UnDefined";
|
||||
break;
|
||||
}
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_MicroSDSpeedMode, speed_mode_name, std::strlen(speed_mode_name)));
|
||||
} else {
|
||||
/* Getting speed mode failed, so add the result. */
|
||||
char res_str[0x20];
|
||||
util::SNPrintf(res_str, sizeof(res_str), "0x%08X", res.GetValue());
|
||||
R_ABORT_UNLESS(record->Add(FieldId_MicroSDSpeedMode, res_str, std::strlen(res_str)));
|
||||
}
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
/* Submit the area sizes. */
|
||||
{
|
||||
s64 user_area_size = 0;
|
||||
s64 prot_area_size = 0;
|
||||
const Result res_user = fs::GetSdCardUserAreaSize(std::addressof(user_area_size));
|
||||
const Result res_prot = fs::GetSdCardProtectedAreaSize(std::addressof(prot_area_size));
|
||||
if (R_SUCCEEDED(res_user) || R_SUCCEEDED(res_prot)) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardSizeSpec, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add sizes. */
|
||||
if (R_SUCCEEDED(res_user)) {
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardUserAreaSize, user_area_size));
|
||||
}
|
||||
if (R_SUCCEEDED(res_prot)) {
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardProtectedAreaSize, prot_area_size));
|
||||
}
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitSdCardErrorInfo() {
|
||||
/* Get the sd card error info. */
|
||||
fs::StorageErrorInfo sei = {};
|
||||
char log_buffer[erpt::ArrayBufferSizeDefault] = {};
|
||||
size_t log_size = 0;
|
||||
if (R_SUCCEEDED(fs::GetAndClearSdCardErrorInfo(std::addressof(sei), std::addressof(log_size), log_buffer, sizeof(log_buffer)))) {
|
||||
/* Submit the error info. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardErrorInfo, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumActivationFailures, sei.num_activation_failures));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumActivationErrorCorrections, sei.num_activation_error_corrections));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumReadWriteFailures, sei.num_read_write_failures));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumReadWriteErrorCorrections, sei.num_read_write_error_corrections));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
/* If we have a log, submit it. */
|
||||
if (log_size > 0) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardDriverLog, log_size);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_SdCardErrorLog, log_buffer, log_size));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitGameCardDetailInfo() {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_GameCardCIDInfo, fs::GameCardCidSize + fs::GameCardDeviceIdSize);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add the game card cid. */
|
||||
{
|
||||
u8 gc_cid[fs::GameCardCidSize] = {};
|
||||
if (fs::IsGameCardInserted() && R_SUCCEEDED(fs::GetGameCardCid(gc_cid, sizeof(gc_cid)))) {
|
||||
/* Add the cid. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardCID, gc_cid, sizeof(gc_cid)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the game card device id. */
|
||||
{
|
||||
u8 gc_device_id[fs::GameCardDeviceIdSize] = {};
|
||||
if (fs::IsGameCardInserted() && R_SUCCEEDED(fs::GetGameCardDeviceId(gc_device_id, sizeof(gc_device_id)))) {
|
||||
/* Add the cid. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardDeviceId, gc_device_id, sizeof(gc_device_id)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitGameCardErrorInfo() {
|
||||
/* Get the game card error info. */
|
||||
fs::GameCardErrorReportInfo ei = {};
|
||||
if (R_SUCCEEDED(fs::GetGameCardErrorReportInfo(std::addressof(ei)))) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_GameCardErrorInfo, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardCrcErrorCount, static_cast<u32>(ei.game_card_crc_error_num)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAsicCrcErrorCount, static_cast<u32>(ei.asic_crc_error_num)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardRefreshCount, static_cast<u32>(ei.refresh_num)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardReadRetryCount, static_cast<u32>(ei.retry_limit_out_num)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardTimeoutRetryErrorCount, static_cast<u32>(ei.timeout_retry_num)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardInsertionCount, static_cast<u32>(ei.insertion_count)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardRemovalCount, static_cast<u32>(ei.removal_count)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAsicInitializeCount, ei.initialize_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAsicReinitializeCount, ei.asic_reinitialize_num));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAsicReinitializeFailureCount, ei.asic_reinitialize_failure_num));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAsicReinitializeFailureDetail, ei.asic_reinitialize_failure_detail));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardRefreshSuccessCount, ei.refresh_succeeded_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAwakenCount, ei.awaken_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardAwakenFailureCount, ei.awaken_failure_num));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardReadCountFromInsert, ei.read_count_from_insert));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardReadCountFromAwaken, ei.read_count_from_awaken));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardLastReadErrorPageAddress, ei.last_read_error_page_address));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_GameCardLastReadErrorPageCount, ei.last_read_error_page_count));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitFileSystemErrorInfo() {
|
||||
/* Get the fsp error info. */
|
||||
fs::FileSystemProxyErrorInfo ei = {};
|
||||
if (R_SUCCEEDED(fs::GetAndClearFileSystemProxyErrorInfo(std::addressof(ei)))) {
|
||||
/* Submit FsProxyErrorInfo. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_FsProxyErrorInfo, fat::FatErrorNameMaxLength);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsRemountForDataCorruptCount, ei.rom_fs_remount_for_data_corruption_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsRemountForDataCorruptRetryOutCount, ei.rom_fs_unrecoverable_data_corruption_by_remount_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsError, ei.fat_fs_error.error));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsExtraError, ei.fat_fs_error.extra_error));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsErrorDrive, ei.fat_fs_error.drive_id));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsErrorName, ei.fat_fs_error.name, fat::FatErrorNameMaxLength));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsRecoveredByInvalidateCacheCount, ei.rom_fs_recovered_by_invalidate_cache_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsSaveDataIndexCount, ei.save_data_index_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFilePeakOpenCount, ei.bis_system_fat_report_info_1.open_file_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemDirectoryPeakOpenCount, ei.bis_system_fat_report_info_1.open_directory_peak_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFilePeakOpenCount, ei.bis_user_fat_report_info_1.open_file_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserDirectoryPeakOpenCount, ei.bis_user_fat_report_info_1.open_directory_peak_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardFilePeakOpenCount, ei.sd_card_fat_report_info_1.open_file_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardDirectoryPeakOpenCount, ei.sd_card_fat_report_info_1.open_directory_peak_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemUniqueFileEntryPeakOpenCount, ei.bis_system_fat_report_info_2.open_unique_file_entry_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemUniqueDirectoryEntryPeakOpenCount, ei.bis_system_fat_report_info_2.open_unique_directory_entry_peak_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserUniqueFileEntryPeakOpenCount, ei.bis_user_fat_report_info_2.open_unique_file_entry_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserUniqueDirectoryEntryPeakOpenCount, ei.bis_user_fat_report_info_2.open_unique_directory_entry_peak_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardUniqueFileEntryPeakOpenCount, ei.sd_card_fat_report_info_2.open_unique_file_entry_peak_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardUniqueDirectoryEntryPeakOpenCount, ei.sd_card_fat_report_info_2.open_unique_directory_entry_peak_count));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
/* Submit FsProxyErrorInfo2. */
|
||||
{
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_FsProxyErrorInfo2, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsDeepRetryStartCount, ei.rom_fs_deep_retry_start_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsUnrecoverableByGameCardAccessFailedCount, ei.rom_fs_unrecoverable_by_game_card_access_failed_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatSafeControlResult, static_cast<u8>(ei.bis_system_fat_safe_info.result)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatErrorNumber, ei.bis_system_fat_safe_info.error_number));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatSafeErrorNumber, ei.bis_system_fat_safe_info.safe_error_number));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatSafeControlResult, static_cast<u8>(ei.bis_user_fat_safe_info.result)));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatErrorNumber, ei.bis_user_fat_safe_info.error_number));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatSafeErrorNumber, ei.bis_user_fat_safe_info.safe_error_number));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result SubmitMemoryReportInfo() {
|
||||
/* Get the memory report info. */
|
||||
fs::MemoryReportInfo mri = {};
|
||||
if (R_SUCCEEDED(fs::GetAndClearMemoryReportInfo(std::addressof(mri)))) {
|
||||
/* Create a record. */
|
||||
auto record = std::make_unique<ContextRecord>(CategoryId_FsMemoryInfo, 0);
|
||||
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
|
||||
|
||||
/* Add fields. */
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPooledBufferPeakFreeSize, mri.pooled_buffer_peak_free_size));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPooledBufferRetriedCount, mri.pooled_buffer_retried_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPooledBufferReduceAllocationCount, mri.pooled_buffer_reduce_allocation_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsBufferManagerPeakFreeSize, mri.buffer_manager_peak_free_size));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsBufferManagerRetriedCount, mri.buffer_manager_retried_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsExpHeapPeakFreeSize, mri.exp_heap_peak_free_size));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsBufferPoolPeakFreeSize, mri.buffer_pool_peak_free_size));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPatrolReadAllocateBufferSuccessCount, mri.patrol_read_allocate_buffer_success_count));
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPatrolReadAllocateBufferFailureCount, mri.patrol_read_allocate_buffer_failure_count));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsBufferManagerPeakTotalAllocatableSize, mri.buffer_manager_peak_total_allocatable_size));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsBufferPoolMaxAllocateSize, mri.buffer_pool_max_allocate_size));
|
||||
|
||||
R_ABORT_UNLESS(record->Add(FieldId_FsPooledBufferFailedIdealAllocationCountOnAsyncAccess, mri.pooled_buffer_failed_ideal_allocation_count_on_async_access));
|
||||
|
||||
/* Submit the record. */
|
||||
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
|
||||
}
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result SubmitFsInfo() {
|
||||
/* Temporarily disable auto-abort. */
|
||||
fs::ScopedAutoAbortDisabler aad;
|
||||
|
||||
/* Submit various FS info. */
|
||||
R_TRY(SubmitMmcDetailInfo());
|
||||
R_TRY(SubmitMmcErrorInfo());
|
||||
R_TRY(SubmitSdCardDetailInfo());
|
||||
R_TRY(SubmitSdCardErrorInfo());
|
||||
R_TRY(SubmitGameCardDetailInfo());
|
||||
R_TRY(SubmitGameCardErrorInfo());
|
||||
R_TRY(SubmitFileSystemErrorInfo());
|
||||
R_TRY(SubmitMemoryReportInfo());
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -105,8 +105,8 @@ namespace ams::erpt::srv {
|
||||
|
||||
g_sf_allocator.Attach(g_heap_handle);
|
||||
|
||||
for (auto i = 0; i < CategoryId_Count; i++) {
|
||||
Context *ctx = new Context(static_cast<CategoryId>(i));
|
||||
for (const auto category_id : CategoryIndexToCategoryIdMap) {
|
||||
Context *ctx = new Context(category_id);
|
||||
AMS_ABORT_UNLESS(ctx != nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "erpt_srv_journal.hpp"
|
||||
#include "erpt_srv_context_record.hpp"
|
||||
#include "erpt_srv_context.hpp"
|
||||
#include "erpt_srv_fs_info.hpp"
|
||||
|
||||
namespace ams::erpt::srv {
|
||||
|
||||
@@ -276,7 +277,7 @@ namespace ams::erpt::srv {
|
||||
void SaveSyslogReportIfRequired(const ContextEntry *ctx, const ReportId &report_id) {
|
||||
bool needs_save_syslog = true;
|
||||
for (u32 i = 0; i < ctx->field_count; i++) {
|
||||
static_assert(FieldToTypeMap[FieldId_HasSyslogFlag] == FieldType_Bool);
|
||||
static_assert(FieldIndexToTypeMap[*FindFieldIndex(FieldId_HasSyslogFlag)] == FieldType_Bool);
|
||||
if (ctx->fields[i].id == FieldId_HasSyslogFlag && !ctx->fields[i].value_bool) {
|
||||
needs_save_syslog = false;
|
||||
break;
|
||||
@@ -530,9 +531,14 @@ namespace ams::erpt::srv {
|
||||
SubmitResourceLimitContexts();
|
||||
#endif
|
||||
|
||||
if (flags.Test<CreateReportOptionFlag::SubmitFsInfo>()) {
|
||||
/* TODO: 17.0.0 SubmitFsInfo() */
|
||||
/* If we should, submit fs info. */
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
if (hos::GetVersion() >= hos::Version_17_0_0 && flags.Test<CreateReportOptionFlag::SubmitFsInfo>()) {
|
||||
/* NOTE: Nintendo ignores the result of this call. */
|
||||
SubmitFsInfo();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
35
libraries/libstratosphere/source/fs/fs_error_info.cpp
Normal file
35
libraries/libstratosphere/source/fs/fs_error_info.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fsa/fs_mount_utils.hpp"
|
||||
#include "impl/fs_file_system_proxy_service_object.hpp"
|
||||
#include "impl/fs_file_system_service_object_adapter.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result GetAndClearFileSystemProxyErrorInfo(FileSystemProxyErrorInfo *out) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Get the error info. */
|
||||
AMS_FS_R_TRY(fsp->GetAndClearErrorInfo(out));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,4 +100,65 @@ namespace ams::fs {
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
bool IsGameCardInserted() {
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_ABORT_UNLESS(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get insertion status. */
|
||||
bool inserted;
|
||||
AMS_FS_R_ABORT_UNLESS(device_operator->IsGameCardInserted(std::addressof(inserted)));
|
||||
|
||||
return inserted;
|
||||
}
|
||||
|
||||
Result GetGameCardCid(void *dst, size_t size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(size >= sizeof(gc::GameCardIdSet), fs::ResultInvalidSize());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the id set. */
|
||||
gc::GameCardIdSet gc_id_set;
|
||||
AMS_FS_R_TRY(device_operator->GetGameCardIdSet(sf::OutBuffer(std::addressof(gc_id_set), sizeof(gc_id_set)), static_cast<s64>(sizeof(gc_id_set))));
|
||||
|
||||
/* Copy the id set to output. */
|
||||
std::memcpy(dst, std::addressof(gc_id_set), sizeof(gc_id_set));
|
||||
|
||||
R_SUCCEED();
|
||||
|
||||
}
|
||||
|
||||
Result GetGameCardDeviceId(void *dst, size_t size) {
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the cid. */
|
||||
AMS_FS_R_TRY(device_operator->GetGameCardDeviceId(sf::OutBuffer(dst, size), static_cast<s64>(size)));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetGameCardErrorReportInfo(GameCardErrorReportInfo *out) {
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the error report info. */
|
||||
AMS_FS_R_TRY(device_operator->GetGameCardErrorReportInfo(out));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fsa/fs_mount_utils.hpp"
|
||||
#include "impl/fs_file_system_proxy_service_object.hpp"
|
||||
#include "impl/fs_file_system_service_object_adapter.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result GetAndClearMemoryReportInfo(MemoryReportInfo *out) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Get the memory report info. */
|
||||
AMS_FS_R_TRY(fsp->GetAndClearMemoryReportInfo(out));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
109
libraries/libstratosphere/source/fs/fs_mmc.cpp
Normal file
109
libraries/libstratosphere/source/fs/fs_mmc.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "fsa/fs_mount_utils.hpp"
|
||||
#include "impl/fs_file_system_proxy_service_object.hpp"
|
||||
#include "impl/fs_file_system_service_object_adapter.hpp"
|
||||
|
||||
namespace ams::fs {
|
||||
|
||||
Result GetMmcCid(void *dst, size_t size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the cid. */
|
||||
AMS_FS_R_TRY(device_operator->GetMmcCid(sf::OutBuffer(dst, size), static_cast<s64>(size)));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetMmcSpeedMode(MmcSpeedMode *out) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the speed mode. */
|
||||
s64 speed_mode = 0;
|
||||
AMS_FS_R_TRY(device_operator->GetMmcSpeedMode(std::addressof(speed_mode)));
|
||||
|
||||
*out = static_cast<MmcSpeedMode>(speed_mode);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetMmcPatrolCount(u32 *out) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the patrol count. */
|
||||
AMS_FS_R_TRY(device_operator->GetMmcPatrolCount(out));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetAndClearMmcErrorInfo(StorageErrorInfo *out_sei, size_t *out_log_size, char *out_log_buffer, size_t log_buffer_size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(out_sei != nullptr, fs::ResultNullptrArgument());
|
||||
AMS_FS_R_UNLESS(out_log_size != nullptr, fs::ResultNullptrArgument());
|
||||
AMS_FS_R_UNLESS(out_log_buffer != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the error info. */
|
||||
s64 log_size = 0;
|
||||
AMS_FS_R_TRY(device_operator->GetAndClearMmcErrorInfo(out_sei, std::addressof(log_size), sf::OutBuffer(out_log_buffer, log_buffer_size), static_cast<s64>(log_buffer_size)));
|
||||
|
||||
*out_log_size = static_cast<size_t>(log_size);
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result GetMmcExtendedCsd(void *dst, size_t size) {
|
||||
/* Check pre-conditions. */
|
||||
AMS_FS_R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
|
||||
|
||||
auto fsp = impl::GetFileSystemProxyServiceObject();
|
||||
|
||||
/* Open a device operator. */
|
||||
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
|
||||
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
|
||||
|
||||
/* Get the csd. */
|
||||
AMS_FS_R_TRY(device_operator->GetMmcExtendedCsd(sf::OutBuffer(dst, size), static_cast<s64>(size)));
|
||||
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -389,6 +389,11 @@ namespace ams::fs {
|
||||
|
||||
/* ... */
|
||||
|
||||
Result GetAndClearErrorInfo(ams::sf::Out<fs::FileSystemProxyErrorInfo> out) {
|
||||
static_assert(sizeof(fs::FileSystemProxyErrorInfo) == sizeof(::FsFileSystemProxyErrorInfo));
|
||||
R_RETURN(::fsGetAndClearErrorInfo(reinterpret_cast<::FsFileSystemProxyErrorInfo *>(out.GetPointer())));
|
||||
}
|
||||
|
||||
Result RegisterProgramIndexMapInfo(const ams::sf::InBuffer &buffer, s32 count) {
|
||||
AMS_ABORT("TODO");
|
||||
}
|
||||
@@ -429,6 +434,11 @@ namespace ams::fs {
|
||||
AMS_ABORT("TODO");
|
||||
}
|
||||
|
||||
Result GetAndClearMemoryReportInfo(ams::sf::Out<fs::MemoryReportInfo> out) {
|
||||
static_assert(sizeof(fs::MemoryReportInfo) == sizeof(::FsMemoryReportInfo));
|
||||
R_RETURN(::fsGetAndClearMemoryReportInfo(reinterpret_cast<::FsMemoryReportInfo *>(out.GetPointer())));
|
||||
}
|
||||
|
||||
/* ... */
|
||||
|
||||
Result GetProgramIndexForAccessLog(ams::sf::Out<u32> out_idx, ams::sf::Out<u32> out_count) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user