33 Commits
Author SHA1 Message Date
niklascfw ef369fd9be Merge upstream Atmosphere master into boot-storage 2026-11-12 17:38:05 +01:00
hexkyz 4e3f37038d git subrepo push libraries
subrepo:
  subdir:   "libraries"
  merged:   "75c688910"
upstream:
  origin:   "https://github.com/Atmosphere-NX/Atmosphere-libs"
  branch:   "master"
  commit:   "75c688910"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-11-10 22:56:12 +00:00
hexkyz 6623efc817 git subrepo push emummc
subrepo:
  subdir:   "emummc"
  merged:   "dfac26960"
upstream:
  origin:   "https://github.com/m4xw/emummc"
  branch:   "develop"
  commit:   "dfac26960"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-11-10 22:55:43 +00:00
hexkyz 55319fd40f docs: add changelog for 1.12.2 2026-11-10 22:54:49 +00:00
hexkyz ce8ae4a5b3 emummc: update for 23.5.0 2026-11-10 21:52:52 +00:00
hexkyz c721b0d2f6 web: update browser patches for 23.5.0 2026-11-10 21:30:06 +00:00
hexkyz 1eb3b08c77 loader: update USB 3.0 patches for 23.5.0 2026-11-10 20:55:47 +00:00
hexkyz bab60d8ade ams: add enum recognition for 23.5.0 2026-11-10 20:42:30 +00:00
niklascfw 8adf9022af Merge upstream Atmosphere master into boot-storage 2026-11-09 20:13:15 +01:00
saad-script 6bfe5b8b26 Fix fpu registers not being restored when thread switched out during user exception handler (#2909) 2026-11-07 21:32:25 +00:00
niklascfw b29e92192e Merge upstream Atmosphere master into boot-storage 2026-10-16 20:19:15 +02:00
niklascfw a53e983269 Revert "Replaced 1st stage boot logo with NiklasCFW"
This reverts commit 144570aa48.
2026-10-16 20:17:23 +02:00
hexkyz 6b0c077b4c git subrepo push libraries
subrepo:
  subdir:   "libraries"
  merged:   "cf48d2337"
upstream:
  origin:   "https://github.com/Atmosphere-NX/Atmosphere-libs"
  branch:   "master"
  commit:   "cf48d2337"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-10-16 00:17:09 +01:00
hexkyz ff43bc566a git subrepo push emummc
subrepo:
  subdir:   "emummc"
  merged:   "11a2fd2a2"
upstream:
  origin:   "https://github.com/m4xw/emummc"
  branch:   "develop"
  commit:   "11a2fd2a2"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-10-16 00:16:30 +01:00
hexkyz 6eb8c3e7ce docs: add changelog for 1.12.1 2026-10-16 00:14:22 +01:00
hexkyz a8258fb31f ams: bump version and add enum version support for 23.0.1 2026-10-15 22:35:01 +01:00
hexkyz d9654e3bd0 emummc: update README for 23.0.1 2026-10-15 22:29:04 +01:00
hexkyz 43c6da000c dns.mitm: allow bsdsocket to cleanup 2026-10-15 22:06:50 +01:00
hexkyz 0165f5dcc1 web: better browser memory patching strategy 2026-10-15 20:25:15 +01:00
hexkyz 2fec688983 libstrat: account for sockaddr as well in windows target 2026-10-14 22:23:03 +01:00
hexkyz 90cd78a3a3 dns.mitm: trust bsdsocket to generate query ids
Further testing confirmed that bsdsocket ensures each query is unique and per-process.
Not only this allows us to simplify the mitm logic, but also fix a noticeable slowdown that was being caused by clients not being informed that bsdsocket's queue was full.
2026-10-14 22:08:48 +01:00
Chris Bräucker 4c233196dd Fall back to RSA device certificate for cal0 authenticity check (#2887)
* Fix device ID check in cal0 backup path

Only the ECC device certificate was used, which may be absent on some devices. Adds a fallback to use the RSA device certificate which is present on those.

* Move cert validity check into device ID check

* Fix ecc case condition

in cases where ECC is not blank and not valid, instead of aborting, it falls through to RSA
2026-10-14 19:48:41 +01:00
hexkyz 06870a20e7 libstrat: synchronize zstd.inc with https://github.com/hexkyz/zstd/tree/zbic
Implement a more robust platform check cherry-picked from zstd's dev branch
2026-10-12 20:37:25 +01:00
borntohonk fa19cc38b7 libstrat: fix building for non-windows targets (#2881) 2026-10-12 20:04:08 +01:00
hexkyz c7e6c35e90 libstrat: fix building for windows target 2026-10-11 22:59:40 +01:00
hexkyz eccd393126 fs.mitm: add entries for regional versions of Trails in the Sky 2nd Chapter (closes #2879) 2026-10-11 22:38:45 +01:00
hexkyz 4106801486 dns.mitm: forward queries for hostnames not in the hosts file 2026-10-11 22:21:31 +01:00
niklascfw 8592b1a303 Merge upstream Atmosphere master into boot-storage 2026-10-10 12:45:28 +02:00
hexkyz 0e9cd964c0 fs.mitm: mitm StorageForBatchRead as well as previously missing FileSystem/DataStorage commands 2026-10-09 20:09:52 +01:00
fl0be 36cc9a9f49 set state Initialized/Created for Shared/Transfer mem type (#2873) 2026-10-06 21:02:20 +01:00
hexkyz f5cd912604 dns.mitm: implement mitm for the new c-ares resolver and update serializer code 2026-10-06 02:25:38 +01:00
MasaGratoR c8b7316581 Add Trails in the Sky 2nd Chapter to ApplicationsWithDynamicHeap (#2870) 2026-10-02 19:22:56 +01:00
Niklas080208 144570aa48 Replaced 1st stage boot logo with NiklasCFW 2026-09-29 21:27:26 +02:00
49 changed files with 1823 additions and 224 deletions

No files matched your search

+25
View File
@@ -1,4 +1,29 @@
# Changelog # Changelog
## 1.12.2
+ Basic support was added for 23.5.0.
+ General system stability improvements to enhance the user's experience.
## 1.12.1
+ Support was added for the new c-ares resolver in `dns.mitm`.
+ Firmware 23.0.0 introduced a new set of commands to the `sfdnsres` service. These commands provide c-ares async support for DNS resolution and are now used by most sysmodules.
+ This resulted in host redirection not being applied at all and without warning since we simply were not intercepting the new commands.
+ `dns.mitm` now fully reimplements the c-ares serialization code and intercepts the relevant commands. In tandem with the `bsdsocket` sysmodule, we now keep track of resolution queries and redirect their results.
+ Support was added for the new "BatchRead" storage in `fs.mitm`.
+ Firmware 23.0.0 introduced a new type of filesystem storage object abstracted by the interface "IStorageForBatchRead". This is a derived class from "IStorage" with the purpose of adding the new "BatchRead" command.
+ Anything that uses the filesystem API now attempts to use this type of storage instead of the old one. This is of particular relevance for `qlaunch` and for supporting custom themes which were broken as a consequence of this change.
+ `fs.mitm` was updated and extended to not only support the new storage type but also intercept a few newer commands that were previously missing.
+ The patches for the browser applets were redesigned.
+ The introduction of these patches in the previous release led to several issues and crashes, notably during media playback in the eshop and within games that use LibAppletOff.
+ After extensive analysis and testing it was concluded that the browser applets were running out of memory and still required reducing the memory we reserve for custom sysmodules.
+ New patches have been devised and introduced in this release.
+ Instead of patching size checks, we now trick the browser applets into thinking there is 1GB of free memory available to them.
+ Unused memory is still being reclaimed and discounted from the root heap, but now more realistically.
+ The browser engine's heap is now being shrunk with no noticeable downsides to media playback nor web page rendering.
+ Thanks to these changes we can now provide 40MB for custom system modules once again.
+ A number of minor issues were fixed and improvements were made, such as:
+ Automatic PRODINFO backup was fixed for recent console models that no longer use the ECC device certificate (thanks @chrisbraucker).
+ State initialization for SharedMemory and TransferMemory was fixed (thanks @fl0be).
+ Compatibility was fixed for Trails in the Sky 2nd Chapter (thanks @masagrator).
+ General system stability improvements to enhance the user's experience.
## 1.12.0 ## 1.12.0
+ Support was added for 23.0.0. + Support was added for 23.0.0.
+ Special thanks to @alula for handling the implementation of several kernel changes. + Special thanks to @alula for handling the implementation of several kernel changes.
+2 -2
View File
@@ -6,7 +6,7 @@
[subrepo] [subrepo]
remote = https://github.com/m4xw/emummc remote = https://github.com/m4xw/emummc
branch = develop branch = develop
commit = 5b966b6f3f83349ec65066a1877f7f948b48d08c commit = dfac26960c3460c59c3bbaaa07c822155345b4df
parent = 7442487ace6b79ddddf2cd0007b8dade8150bf5c parent = 55319fd40f4a57e5042288a91542b19924d62e26
method = merge method = merge
cmdver = 0.4.9 cmdver = 0.4.9
+1 -1
View File
@@ -2,7 +2,7 @@
*A SDMMC driver replacement for Nintendo's Filesystem Services, by **m4xw*** *A SDMMC driver replacement for Nintendo's Filesystem Services, by **m4xw***
### Supported Horizon Versions ### Supported Horizon Versions
**1.0.0 - 23.0.0** **1.0.0 - 23.5.0**
## Features ## Features
* Arbitrary SDMMC backend selection * Arbitrary SDMMC backend selection
+8
View File
@@ -89,6 +89,8 @@
#include "offsets/2250_exfat.h" #include "offsets/2250_exfat.h"
#include "offsets/2300.h" #include "offsets/2300.h"
#include "offsets/2300_exfat.h" #include "offsets/2300_exfat.h"
#include "offsets/2350.h"
#include "offsets/2350_exfat.h"
#include "../utils/fatal.h" #include "../utils/fatal.h"
#define GET_OFFSET_STRUCT_NAME(vers) g_offsets##vers #define GET_OFFSET_STRUCT_NAME(vers) g_offsets##vers
@@ -189,6 +191,8 @@ DEFINE_OFFSET_STRUCT(_2250);
DEFINE_OFFSET_STRUCT(_2250_EXFAT); DEFINE_OFFSET_STRUCT(_2250_EXFAT);
DEFINE_OFFSET_STRUCT(_2300); DEFINE_OFFSET_STRUCT(_2300);
DEFINE_OFFSET_STRUCT(_2300_EXFAT); DEFINE_OFFSET_STRUCT(_2300_EXFAT);
DEFINE_OFFSET_STRUCT(_2350);
DEFINE_OFFSET_STRUCT(_2350_EXFAT);
const fs_offsets_t *get_fs_offsets(enum FS_VER version) { const fs_offsets_t *get_fs_offsets(enum FS_VER version) {
switch (version) { switch (version) {
@@ -338,6 +342,10 @@ const fs_offsets_t *get_fs_offsets(enum FS_VER version) {
return &(GET_OFFSET_STRUCT_NAME(_2300)); return &(GET_OFFSET_STRUCT_NAME(_2300));
case FS_VER_23_0_0_EXFAT: case FS_VER_23_0_0_EXFAT:
return &(GET_OFFSET_STRUCT_NAME(_2300_EXFAT)); return &(GET_OFFSET_STRUCT_NAME(_2300_EXFAT));
case FS_VER_23_5_0:
return &(GET_OFFSET_STRUCT_NAME(_2350));
case FS_VER_23_5_0_EXFAT:
return &(GET_OFFSET_STRUCT_NAME(_2350_EXFAT));
default: default:
fatal_abort(Fatal_UnknownVersion); fatal_abort(Fatal_UnknownVersion);
} }
+3
View File
@@ -131,6 +131,9 @@ enum FS_VER
FS_VER_23_0_0, FS_VER_23_0_0,
FS_VER_23_0_0_EXFAT, FS_VER_23_0_0_EXFAT,
FS_VER_23_5_0,
FS_VER_23_5_0_EXFAT,
FS_VER_MAX, FS_VER_MAX,
}; };
+59
View 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_2350_H__
#define __FS_2350_H__
// Accessor vtable getters
#define FS_OFFSET_2350_SDMMC_ACCESSOR_GC 0x1B3650
#define FS_OFFSET_2350_SDMMC_ACCESSOR_SD 0x1B5650
#define FS_OFFSET_2350_SDMMC_ACCESSOR_NAND 0x1B3C80
// Hooks
#define FS_OFFSET_2350_SDMMC_WRAPPER_READ 0x1AF580
#define FS_OFFSET_2350_SDMMC_WRAPPER_WRITE 0x1AF5E0
#define FS_OFFSET_2350_RTLD 0x2F520
#define FS_OFFSET_2350_RTLD_DESTINATION ((uintptr_t)(INT64_C(-0x4C)))
#define FS_OFFSET_2350_CLKRST_SET_MIN_V_CLK_RATE 0x1D27F0
// Misc funcs
#define FS_OFFSET_2350_LOCK_MUTEX 0x1A80A0
#define FS_OFFSET_2350_UNLOCK_MUTEX 0x1A80F0
#define FS_OFFSET_2350_SDMMC_WRAPPER_CONTROLLER_OPEN 0x1AF540
#define FS_OFFSET_2350_SDMMC_WRAPPER_CONTROLLER_CLOSE 0x1AF560
// Misc Data
#define FS_OFFSET_2350_SD_MUTEX 0xFF5408
#define FS_OFFSET_2350_NAND_MUTEX 0xFF0D70
#define FS_OFFSET_2350_ACTIVE_PARTITION 0xFF0DB0
#define FS_OFFSET_2350_SDMMC_DAS_HANDLE 0xFD2BE8
// NOPs
#define FS_OFFSET_2350_SD_DAS_INIT 0x2CA98
// Nintendo Paths
#define FS_OFFSET_2350_NINTENDO_PATHS \
{ \
{.opcode_reg = 3, .adrp_offset = 0x00072D8C, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 3, .adrp_offset = 0x00081BB4, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 4, .adrp_offset = 0x0008A678, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 4, .adrp_offset = 0x0009F98C, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 0, .adrp_offset = 0, .add_rel_offset = 0}, \
}
#endif // __FS_2350_H__
+59
View 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_2350_EXFAT_H__
#define __FS_2350_EXFAT_H__
// Accessor vtable getters
#define FS_OFFSET_2350_EXFAT_SDMMC_ACCESSOR_GC 0x1BE850
#define FS_OFFSET_2350_EXFAT_SDMMC_ACCESSOR_SD 0x1C0850
#define FS_OFFSET_2350_EXFAT_SDMMC_ACCESSOR_NAND 0x1BEE80
// Hooks
#define FS_OFFSET_2350_EXFAT_SDMMC_WRAPPER_READ 0x1BA780
#define FS_OFFSET_2350_EXFAT_SDMMC_WRAPPER_WRITE 0x1BA7E0
#define FS_OFFSET_2350_EXFAT_RTLD 0x2F530
#define FS_OFFSET_2350_EXFAT_RTLD_DESTINATION ((uintptr_t)(INT64_C(-0x4C)))
#define FS_OFFSET_2350_EXFAT_CLKRST_SET_MIN_V_CLK_RATE 0x1DD9F0
// Misc funcs
#define FS_OFFSET_2350_EXFAT_LOCK_MUTEX 0x1B32A0
#define FS_OFFSET_2350_EXFAT_UNLOCK_MUTEX 0x1B32F0
#define FS_OFFSET_2350_EXFAT_SDMMC_WRAPPER_CONTROLLER_OPEN 0x1BA740
#define FS_OFFSET_2350_EXFAT_SDMMC_WRAPPER_CONTROLLER_CLOSE 0x1BA760
// Misc Data
#define FS_OFFSET_2350_EXFAT_SD_MUTEX 0x1006408
#define FS_OFFSET_2350_EXFAT_NAND_MUTEX 0x1001D70
#define FS_OFFSET_2350_EXFAT_ACTIVE_PARTITION 0x1001DB0
#define FS_OFFSET_2350_EXFAT_SDMMC_DAS_HANDLE 0xFDFBE8
// NOPs
#define FS_OFFSET_2350_EXFAT_SD_DAS_INIT 0x2CAA8
// Nintendo Paths
#define FS_OFFSET_2350_EXFAT_NINTENDO_PATHS \
{ \
{.opcode_reg = 3, .adrp_offset = 0x00072D9C, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 3, .adrp_offset = 0x00081BC4, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 4, .adrp_offset = 0x0008A688, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 4, .adrp_offset = 0x0009F99C, .add_rel_offset = 0x00000004}, \
{.opcode_reg = 0, .adrp_offset = 0, .add_rel_offset = 0}, \
}
#endif // __FS_2350_EXFAT_H__
@@ -160,6 +160,8 @@ namespace ams::nxboot {
return ams::TargetFirmware_22_0_0; return ams::TargetFirmware_22_0_0;
} else if (std::memcmp(package1 + 0x10, "20260730", 8) == 0) { } else if (std::memcmp(package1 + 0x10, "20260730", 8) == 0) {
return ams::TargetFirmware_23_0_0; return ams::TargetFirmware_23_0_0;
} else if (std::memcmp(package1 + 0x10, "20260930", 8) == 0) {
return ams::TargetFirmware_23_5_0;
} }
break; break;
default: default:
@@ -201,6 +201,9 @@ namespace ams::nxboot {
FsVersion_23_0_0, FsVersion_23_0_0,
FsVersion_23_0_0_Exfat, FsVersion_23_0_0_Exfat,
FsVersion_23_5_0,
FsVersion_23_5_0_Exfat,
FsVersion_Count, FsVersion_Count,
}; };
@@ -314,6 +317,9 @@ namespace ams::nxboot {
{ 0x34, 0x38, 0x3E, 0xE7, 0x99, 0x92, 0x63, 0x40 }, /* FsVersion_23_0_0 */ { 0x34, 0x38, 0x3E, 0xE7, 0x99, 0x92, 0x63, 0x40 }, /* FsVersion_23_0_0 */
{ 0xFD, 0xAF, 0x16, 0x32, 0x88, 0xE1, 0x08, 0x05 }, /* FsVersion_23_0_0_Exfat */ { 0xFD, 0xAF, 0x16, 0x32, 0x88, 0xE1, 0x08, 0x05 }, /* FsVersion_23_0_0_Exfat */
{ 0x01, 0xED, 0x6B, 0x87, 0x4C, 0x1F, 0xEF, 0x41 }, /* FsVersion_23_5_0 */
{ 0x7B, 0x90, 0x28, 0x37, 0xF2, 0x00, 0x27, 0x49 }, /* FsVersion_23_5_0_Exfat */
}; };
const InitialProcessBinaryHeader *FindInitialProcessBinary(const pkg2::Package2Header *header, const u8 *data, ams::TargetFirmware target_firmware) { const InitialProcessBinaryHeader *FindInitialProcessBinary(const pkg2::Package2Header *header, const u8 *data, ams::TargetFirmware target_firmware) {
@@ -749,6 +755,16 @@ namespace ams::nxboot {
AddPatch(fs_meta, 0x1BE8D5, NogcPatch0, sizeof(NogcPatch0)); AddPatch(fs_meta, 0x1BE8D5, NogcPatch0, sizeof(NogcPatch0));
AddPatch(fs_meta, 0x191540, NogcPatch1, sizeof(NogcPatch1)); AddPatch(fs_meta, 0x191540, NogcPatch1, sizeof(NogcPatch1));
break; break;
case FsVersion_23_5_0:
AddPatch(fs_meta, 0x1BE8CD, NogcPatch0, sizeof(NogcPatch0));
AddPatch(fs_meta, 0x1B36E5, NogcPatch0, sizeof(NogcPatch0));
AddPatch(fs_meta, 0x186350, NogcPatch1, sizeof(NogcPatch1));
break;
case FsVersion_23_5_0_Exfat:
AddPatch(fs_meta, 0x1BE8CD, NogcPatch0, sizeof(NogcPatch0));
AddPatch(fs_meta, 0x1BE8E5, NogcPatch0, sizeof(NogcPatch0));
AddPatch(fs_meta, 0x191550, NogcPatch1, sizeof(NogcPatch1));
break;
default: default:
break; break;
} }
+2 -2
View File
@@ -6,7 +6,7 @@
[subrepo] [subrepo]
remote = https://github.com/Atmosphere-NX/Atmosphere-libs remote = https://github.com/Atmosphere-NX/Atmosphere-libs
branch = master branch = master
commit = aae2da0155a490abd3bfd17a70ccd16bb73c916a commit = 75c688910baf76c0f5e62a3a7fe90bc0dc7f70a1
parent = c68e08a101353a89777eb118d6bd21d1dba98ce5 parent = 6623efc81715a6196ebd6d49354ebd77aadb10cc
method = merge method = merge
cmdver = 0.4.9 cmdver = 0.4.9
@@ -24,7 +24,7 @@ namespace ams::pkg2 {
constexpr inline int PayloadCount = 3; constexpr inline int PayloadCount = 3;
constexpr inline int MinimumValidDataVersion = 0; /* We allow older package2 to load; this value is currently 0x18 in Nintendo's code. */ constexpr inline int MinimumValidDataVersion = 0; /* We allow older package2 to load; this value is currently 0x18 in Nintendo's code. */
constexpr inline int CurrentBootloaderVersion = 0x18; constexpr inline int CurrentBootloaderVersion = 0x19;
struct Package2Meta { struct Package2Meta {
using Magic = util::FourCC<'P','K','2','1'>; using Magic = util::FourCC<'P','K','2','1'>;
@@ -177,6 +177,7 @@ namespace ams::fuse {
} }
constexpr const TargetFirmware FuseVersionIncrementFirmwares[] = { constexpr const TargetFirmware FuseVersionIncrementFirmwares[] = {
TargetFirmware_23_5_0,
TargetFirmware_23_0_0, TargetFirmware_23_0_0,
TargetFirmware_22_0_0, TargetFirmware_22_0_0,
TargetFirmware_21_0_0, TargetFirmware_21_0_0,
@@ -358,9 +358,10 @@ namespace ams::kern::board::nintendo::nx {
/* NOTE: On 20.0.0+ (and even more-so 21.0.0+) the browser requires much more memory in the applet pool in order to function. */ /* NOTE: On 20.0.0+ (and even more-so 21.0.0+) the browser requires much more memory in the applet pool in order to function. */
/* Thus, we have to reduce our extra system memory size by 26 MB to compensate. */ /* Thus, we have to reduce our extra system memory size by 26 MB to compensate. */
/* NOTE: On 23.0.0+ we are patching memory allocation for each browser applet since there are only 3 of them now. */ /* NOTE: On 23.0.0+ we are patching memory allocation for each browser applet since there are only 3 of them now. */
/* Given that the root "Reserved" region is 0x43E000 bytes and the "ReservedTbd" subregion is 0x540000 bytes, we can safely reclaim 9MB.*/ /* Reclaiming unused memory and lying to the browser about memory limits allows us to go back to 40 MB of extra system memory. */
/* TODO: Deduplicate post 23.0.0 and pre 20.0.0. For now, this structure helps with readability and is still subject to change. */
if (kern::GetTargetFirmware() >= ams::TargetFirmware_23_0_0) { if (kern::GetTargetFirmware() >= ams::TargetFirmware_23_0_0) {
constexpr size_t ExtraSystemMemoryForAtmosphere_23_0_0 = 16_MB; constexpr size_t ExtraSystemMemoryForAtmosphere_23_0_0 = 40_MB;
return base_pool_size - ExtraSystemMemoryForAtmosphere_23_0_0 - KTraceBufferSize; return base_pool_size - ExtraSystemMemoryForAtmosphere_23_0_0 - KTraceBufferSize;
} else if (kern::GetTargetFirmware() >= ams::TargetFirmware_21_0_0) { } else if (kern::GetTargetFirmware() >= ams::TargetFirmware_21_0_0) {
constexpr size_t ExtraSystemMemoryForAtmosphere_21_0_0 = 7_MB; constexpr size_t ExtraSystemMemoryForAtmosphere_21_0_0 = 7_MB;
@@ -70,8 +70,8 @@ namespace ams::fs {
virtual Result Read(s64 offset, void *buffer, size_t size) override; virtual Result Read(s64 offset, void *buffer, size_t size) override;
virtual Result Write(s64 offset, const void *buffer, size_t size) override; virtual Result Write(s64 offset, const void *buffer, size_t size) override;
virtual Result Flush() override; virtual Result Flush() override;
virtual Result GetSize(s64 *out_size) override;
virtual Result SetSize(s64 size) override; virtual Result SetSize(s64 size) override;
virtual Result GetSize(s64 *out_size) override;
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override; virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override;
}; };
@@ -0,0 +1,96 @@
/*
* 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/fs/fs_file.hpp>
#include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_operate_range.hpp>
namespace ams::fs {
class IStorageForBatchRead : public IStorage {
public:
virtual ~IStorageForBatchRead() { /* ... */ }
virtual Result BatchRead(void *out0, void *out1, void *out2, void *out3, void *out4, void *out5, void *out6, const void *in) = 0;
};
class ReadOnlyStorageAdapterForBatchRead : public IStorageForBatchRead {
private:
std::shared_ptr<IStorageForBatchRead> m_shared_storage;
std::unique_ptr<IStorageForBatchRead> m_unique_storage;
IStorageForBatchRead *m_storage;
public:
explicit ReadOnlyStorageAdapterForBatchRead(IStorageForBatchRead *s) : m_unique_storage(s) {
m_storage = m_unique_storage.get();
}
explicit ReadOnlyStorageAdapterForBatchRead(std::shared_ptr<IStorageForBatchRead> s) : m_shared_storage(s) {
m_storage = m_shared_storage.get();
}
explicit ReadOnlyStorageAdapterForBatchRead(std::unique_ptr<IStorageForBatchRead> s) : m_unique_storage(std::move(s)) {
m_storage = m_unique_storage.get();
}
explicit ReadOnlyStorageAdapterForBatchRead(IStorage *s) : m_unique_storage(static_cast<IStorageForBatchRead *>(s)) {
m_storage = m_unique_storage.get();
}
explicit ReadOnlyStorageAdapterForBatchRead(std::shared_ptr<IStorage> s) : m_shared_storage(std::static_pointer_cast<IStorageForBatchRead>(s)) {
m_storage = m_shared_storage.get();
}
explicit ReadOnlyStorageAdapterForBatchRead(std::unique_ptr<IStorage> s) : m_unique_storage(std::unique_ptr<IStorageForBatchRead>(static_cast<IStorageForBatchRead *>(s.release()))) {
m_storage = m_unique_storage.get();
}
virtual ~ReadOnlyStorageAdapterForBatchRead() { /* ... */ }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override {
R_RETURN(m_storage->Read(offset, buffer, size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
/* TODO: Better result? Is it possible to get a more specific one? */
AMS_UNUSED(offset, buffer, size);
R_THROW(fs::ResultUnsupportedOperation());
}
virtual Result Flush() override {
R_RETURN(m_storage->Flush());
}
virtual Result SetSize(s64 size) override {
/* TODO: Better result? Is it possible to get a more specific one? */
AMS_UNUSED(size);
R_THROW(fs::ResultUnsupportedOperation());
}
virtual Result GetSize(s64 *out) override {
R_RETURN(m_storage->GetSize(out));
}
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
R_RETURN(m_storage->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
}
virtual Result BatchRead(void *out0, void *out1, void *out2, void *out3, void *out4, void *out5, void *out6, const void *in) override {
/* TODO */
AMS_UNUSED(out0, out1, out2, out3, out4, out5, out6, in);
R_THROW(fs::ResultUnsupportedOperation());
}
};
template<typename T>
concept PointerToStorageForBatchRead = ::ams::util::RawOrSmartPointerTo<T, ::ams::fs::IStorageForBatchRead>;
}
@@ -16,6 +16,7 @@
#pragma once #pragma once
#include <stratosphere/fs/fs_common.hpp> #include <stratosphere/fs/fs_common.hpp>
#include <stratosphere/fs/fs_istorage.hpp> #include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_istorage_for_batch_read.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp> #include <stratosphere/fs/impl/fs_newable.hpp>
namespace ams::fs { namespace ams::fs {
@@ -33,29 +34,72 @@ namespace ams::fs {
public: public:
virtual Result Read(s64 offset, void *buffer, size_t size) override { virtual Result Read(s64 offset, void *buffer, size_t size) override {
R_RETURN(fsStorageRead(std::addressof(m_base_storage), offset, buffer, size)); R_RETURN(fsStorageRead(std::addressof(m_base_storage), offset, buffer, size));
}; }
virtual Result Write(s64 offset, const void *buffer, size_t size) override { virtual Result Write(s64 offset, const void *buffer, size_t size) override {
R_RETURN(fsStorageWrite(std::addressof(m_base_storage), offset, buffer, size)); R_RETURN(fsStorageWrite(std::addressof(m_base_storage), offset, buffer, size));
}; }
virtual Result Flush() override { virtual Result Flush() override {
R_RETURN(fsStorageFlush(std::addressof(m_base_storage))); R_RETURN(fsStorageFlush(std::addressof(m_base_storage)));
}; }
virtual Result GetSize(s64 *out_size) override {
R_RETURN(fsStorageGetSize(std::addressof(m_base_storage), out_size));
};
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
R_RETURN(fsStorageSetSize(std::addressof(m_base_storage), size)); R_RETURN(fsStorageSetSize(std::addressof(m_base_storage), size));
}; }
virtual Result GetSize(s64 *out_size) override {
R_RETURN(fsStorageGetSize(std::addressof(m_base_storage), out_size));
}
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override { virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
/* TODO: How to deal with this? */ /* TODO: How to deal with this? */
AMS_UNUSED(dst, dst_size, op_id, offset, size, src, src_size); AMS_UNUSED(dst, dst_size, op_id, offset, size, src, src_size);
R_THROW(fs::ResultUnsupportedOperation()); R_THROW(fs::ResultUnsupportedOperation());
}; }
};
class RemoteStorageForBatchRead : public IStorageForBatchRead, public impl::Newable {
NON_COPYABLE(RemoteStorageForBatchRead);
NON_MOVEABLE(RemoteStorageForBatchRead);
private:
::FsStorageForBatchRead m_base_storage;
public:
RemoteStorageForBatchRead(::FsStorageForBatchRead &s) : m_base_storage(s) { /* ... */}
virtual ~RemoteStorageForBatchRead() { fsStorageForBatchReadClose(std::addressof(m_base_storage)); }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override {
R_RETURN(fsStorageForBatchReadRead(std::addressof(m_base_storage), offset, buffer, size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
R_RETURN(fsStorageForBatchReadWrite(std::addressof(m_base_storage), offset, buffer, size));
}
virtual Result Flush() override {
R_RETURN(fsStorageForBatchReadFlush(std::addressof(m_base_storage)));
}
virtual Result SetSize(s64 size) override {
R_RETURN(fsStorageForBatchReadSetSize(std::addressof(m_base_storage), size));
}
virtual Result GetSize(s64 *out_size) override {
R_RETURN(fsStorageForBatchReadGetSize(std::addressof(m_base_storage), out_size));
}
virtual Result OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
/* TODO: How to deal with this? */
AMS_UNUSED(dst, dst_size, op_id, offset, size, src, src_size);
R_THROW(fs::ResultUnsupportedOperation());
}
virtual Result BatchRead(void *out0, void *out1, void *out2, void *out3, void *out4, void *out5, void *out6, const void *in) override {
/* TODO */
AMS_UNUSED(out0, out1, out2, out3, out4, out5, out6, in);
R_THROW(fs::ResultUnsupportedOperation());
}
}; };
#endif #endif
@@ -16,6 +16,7 @@
#pragma once #pragma once
#include <stratosphere/fs/fs_common.hpp> #include <stratosphere/fs/fs_common.hpp>
#include <stratosphere/fs/fs_istorage.hpp> #include <stratosphere/fs/fs_istorage.hpp>
#include <stratosphere/fs/fs_istorage_for_batch_read.hpp>
#include <stratosphere/fs/impl/fs_newable.hpp> #include <stratosphere/fs/impl/fs_newable.hpp>
namespace ams::fs::impl { namespace ams::fs::impl {
@@ -34,22 +35,22 @@ namespace ams::fs::impl {
R_RETURN(m_x->Read(offset, sf::OutNonSecureBuffer(buffer, size), static_cast<s64>(size))); R_RETURN(m_x->Read(offset, sf::OutNonSecureBuffer(buffer, size), static_cast<s64>(size)));
} }
virtual Result GetSize(s64 *out) override final { virtual Result Write(s64 offset, const void *buffer, size_t size) override final {
R_RETURN(m_x->GetSize(out)); R_RETURN(m_x->Write(offset, sf::InNonSecureBuffer(buffer, size), static_cast<s64>(size)));
} }
virtual Result Flush() override final { virtual Result Flush() override final {
R_RETURN(m_x->Flush()); R_RETURN(m_x->Flush());
} }
virtual Result Write(s64 offset, const void *buffer, size_t size) override final {
R_RETURN(m_x->Write(offset, sf::InNonSecureBuffer(buffer, size), static_cast<s64>(size)));
}
virtual Result SetSize(s64 size) override final { virtual Result SetSize(s64 size) override final {
R_RETURN(m_x->SetSize(size)); R_RETURN(m_x->SetSize(size));
} }
virtual Result GetSize(s64 *out) override final {
R_RETURN(m_x->GetSize(out));
}
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final { virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final {
AMS_UNUSED(src, src_size); AMS_UNUSED(src, src_size);
switch (op_id) { switch (op_id) {
@@ -73,4 +74,63 @@ namespace ams::fs::impl {
} }
}; };
template<typename StorageInterfaceForBatchRead>
class StorageServiceObjectAdapterForBatchRead : public ::ams::fs::impl::Newable, public ::ams::fs::IStorageForBatchRead {
NON_COPYABLE(StorageServiceObjectAdapterForBatchRead);
NON_MOVEABLE(StorageServiceObjectAdapterForBatchRead);
private:
sf::SharedPointer<StorageInterfaceForBatchRead> m_x;
public:
explicit StorageServiceObjectAdapterForBatchRead(sf::SharedPointer<StorageInterfaceForBatchRead> &&o) : m_x(o) { /* ... */}
virtual ~StorageServiceObjectAdapterForBatchRead() { /* ... */ }
public:
virtual Result Read(s64 offset, void *buffer, size_t size) override final {
R_RETURN(m_x->Read(offset, sf::OutNonSecureBuffer(buffer, size), static_cast<s64>(size)));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override final {
R_RETURN(m_x->Write(offset, sf::InNonSecureBuffer(buffer, size), static_cast<s64>(size)));
}
virtual Result Flush() override final {
R_RETURN(m_x->Flush());
}
virtual Result SetSize(s64 size) override final {
R_RETURN(m_x->SetSize(size));
}
virtual Result GetSize(s64 *out) override final {
R_RETURN(m_x->GetSize(out));
}
virtual Result OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override final {
AMS_UNUSED(src, src_size);
switch (op_id) {
case OperationId::Invalidate:
{
fs::QueryRangeInfo dummy_range_info;
R_RETURN(m_x->OperateRange(std::addressof(dummy_range_info), static_cast<s32>(op_id), offset, size));
}
case OperationId::QueryRange:
{
R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
R_UNLESS(dst_size == sizeof(fs::QueryRangeInfo), fs::ResultInvalidSize());
R_RETURN(m_x->OperateRange(reinterpret_cast<fs::QueryRangeInfo *>(dst), static_cast<s32>(op_id), offset, size));
}
default:
{
R_THROW(fs::ResultUnsupportedOperateRangeForStorageServiceObjectAdapter());
}
}
}
virtual Result BatchRead(void *out0, void *out1, void *out2, void *out3, void *out4, void *out5, void *out6, const void *in) override final {
/* TODO */
AMS_UNUSED(out0, out1, out2, out3, out4, out5, out6, in);
R_THROW(fs::ResultUnsupportedOperation());
}
};
} }
@@ -18,10 +18,12 @@
#include <stratosphere/fs/fs_query_range.hpp> #include <stratosphere/fs/fs_query_range.hpp>
#include <stratosphere/fssystem/fssystem_utility.hpp> #include <stratosphere/fssystem/fssystem_utility.hpp>
#include <stratosphere/fssrv/sf/fssrv_sf_istorage.hpp> #include <stratosphere/fssrv/sf/fssrv_sf_istorage.hpp>
#include <stratosphere/fssrv/sf/fssrv_sf_istorage_for_batch_read.hpp>
namespace ams::fs { namespace ams::fs {
class IStorage; class IStorage;
class IStorageForBatchRead;
} }
@@ -45,6 +47,16 @@ namespace ams::fssrv::impl {
}; };
static_assert(fssrv::sf::IsIStorage<StorageInterfaceAdapter>); static_assert(fssrv::sf::IsIStorage<StorageInterfaceAdapter>);
class StorageInterfaceAdapterForBatchRead : public StorageInterfaceAdapter {
NON_COPYABLE(StorageInterfaceAdapterForBatchRead);
public:
explicit StorageInterfaceAdapterForBatchRead(std::shared_ptr<fs::IStorageForBatchRead> &&storage) : StorageInterfaceAdapter(storage) { /* ... */ }
public:
/* Command API. */
Result BatchRead(const ams::sf::OutNonSecureBuffer &out0, const ams::sf::OutNonSecureBuffer &out1, const ams::sf::OutNonSecureBuffer &out2, const ams::sf::OutNonSecureBuffer &out3, const ams::sf::OutNonSecureBuffer &out4, const ams::sf::OutNonSecureBuffer &out5, const ams::sf::OutNonSecureBuffer &out6, const ams::sf::InBuffer &in);
};
static_assert(fssrv::sf::IsIStorageForBatchRead<StorageInterfaceAdapterForBatchRead>);
#if defined(ATMOSPHERE_OS_HORIZON) #if defined(ATMOSPHERE_OS_HORIZON)
class RemoteStorage { class RemoteStorage {
NON_COPYABLE(RemoteStorage); NON_COPYABLE(RemoteStorage);
@@ -82,6 +94,47 @@ namespace ams::fssrv::impl {
} }
}; };
static_assert(fssrv::sf::IsIStorage<RemoteStorage>); static_assert(fssrv::sf::IsIStorage<RemoteStorage>);
class RemoteStorageForBatchRead {
NON_COPYABLE(RemoteStorageForBatchRead);
NON_MOVEABLE(RemoteStorageForBatchRead);
private:
::FsStorageForBatchRead m_base_storage;
public:
RemoteStorageForBatchRead(::FsStorageForBatchRead &s) : m_base_storage(s) { /* ... */}
virtual ~RemoteStorageForBatchRead() { fsStorageForBatchReadClose(std::addressof(m_base_storage)); }
public:
Result Read(s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size) {
R_RETURN(fsStorageForBatchReadRead(std::addressof(m_base_storage), offset, buffer.GetPointer(), size));
}
Result Write(s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size) {
R_RETURN(fsStorageForBatchReadWrite(std::addressof(m_base_storage), offset, buffer.GetPointer(), size));
}
Result Flush(){
R_RETURN(fsStorageForBatchReadFlush(std::addressof(m_base_storage)));
}
Result SetSize(s64 size) {
R_RETURN(fsStorageForBatchReadSetSize(std::addressof(m_base_storage), size));
}
Result GetSize(ams::sf::Out<s64> out) {
R_RETURN(fsStorageForBatchReadGetSize(std::addressof(m_base_storage), out.GetPointer()));
}
Result OperateRange(ams::sf::Out<fs::StorageQueryRangeInfo> out, s32 op_id, s64 offset, s64 size) {
static_assert(sizeof(::FsRangeInfo) == sizeof(fs::StorageQueryRangeInfo));
R_RETURN(fsStorageForBatchReadOperateRange(std::addressof(m_base_storage), static_cast<::FsOperationId>(op_id), offset, size, reinterpret_cast<::FsRangeInfo *>(out.GetPointer())));
}
Result BatchRead(const ams::sf::OutNonSecureBuffer &out0, const ams::sf::OutNonSecureBuffer &out1, const ams::sf::OutNonSecureBuffer &out2, const ams::sf::OutNonSecureBuffer &out3, const ams::sf::OutNonSecureBuffer &out4, const ams::sf::OutNonSecureBuffer &out5, const ams::sf::OutNonSecureBuffer &out6, const ams::sf::InBuffer &in) {
R_RETURN(fsStorageForBatchReadBatchRead(std::addressof(m_base_storage), out0.GetPointer(), out1.GetPointer(), out2.GetPointer(), out3.GetPointer(), out4.GetPointer(), out5.GetPointer(), out6.GetPointer(), in.GetPointer()));
}
};
static_assert(fssrv::sf::IsIStorageForBatchRead<RemoteStorageForBatchRead>);
#endif #endif
} }
@@ -0,0 +1,31 @@
/*
* 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/sf.hpp>
#include <stratosphere/fs/fs_file.hpp>
#include <stratosphere/fs/fs_query_range.hpp>
#define AMS_FSSRV_I_STORAGE_FOR_BATCH_READ_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, Read, (s64 offset, const ams::sf::OutNonSecureBuffer &buffer, s64 size), (offset, buffer, size)) \
AMS_SF_METHOD_INFO(C, H, 1, Result, Write, (s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size), (offset, buffer, size)) \
AMS_SF_METHOD_INFO(C, H, 2, Result, Flush, (), ()) \
AMS_SF_METHOD_INFO(C, H, 3, Result, SetSize, (s64 size), (size)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, GetSize, (ams::sf::Out<s64> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 5, Result, OperateRange, (ams::sf::Out<ams::fs::StorageQueryRangeInfo> out, s32 op_id, s64 offset, s64 size), (out, op_id, offset, size)) \
AMS_SF_METHOD_INFO(C, H, 10, Result, BatchRead, (const ams::sf::OutNonSecureBuffer &out0, const ams::sf::OutNonSecureBuffer &out1, const ams::sf::OutNonSecureBuffer &out2, const ams::sf::OutNonSecureBuffer &out3, const ams::sf::OutNonSecureBuffer &out4, const ams::sf::OutNonSecureBuffer &out5, const ams::sf::OutNonSecureBuffer &out6, const ams::sf::InBuffer &in), (out0, out1, out2, out3, out4, out5, out6, in))
AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, IStorageForBatchRead, AMS_FSSRV_I_STORAGE_FOR_BATCH_READ_INTERFACE_INFO, 0xCD2D5606)
@@ -104,6 +104,8 @@ namespace ams::hos {
Version_22_1_0 = ::ams::TargetFirmware_22_1_0, Version_22_1_0 = ::ams::TargetFirmware_22_1_0,
Version_22_5_0 = ::ams::TargetFirmware_22_5_0, Version_22_5_0 = ::ams::TargetFirmware_22_5_0,
Version_23_0_0 = ::ams::TargetFirmware_23_0_0, Version_23_0_0 = ::ams::TargetFirmware_23_0_0,
Version_23_0_1 = ::ams::TargetFirmware_23_0_1,
Version_23_5_0 = ::ams::TargetFirmware_23_5_0,
Version_Current = ::ams::TargetFirmware_Current, Version_Current = ::ams::TargetFirmware_Current,
@@ -159,6 +159,44 @@ namespace ams::socket {
AddrInfo *ai_next; AddrInfo *ai_next;
}; };
/* NOTE: We are using the c-ares structs under ams::socket. */
/* Should we include c-ares instead somewhere? */
struct ares_addrinfo_node {
int ai_ttl;
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
#if defined(ATMOSPHERE_OS_WINDOWS)
int ai_addrlen;
void *ai_addr;
#else
socklen_t ai_addrlen;
struct sockaddr *ai_addr;
#endif
struct ares_addrinfo_node *ai_next;
};
struct ares_addrinfo_cname {
int ttl;
char *alias;
char *name;
struct ares_addrinfo_cname *next;
};
struct ares_addrinfo {
struct ares_addrinfo_cname *cnames;
struct ares_addrinfo_node *nodes;
char *name;
};
struct ares_addrinfo_hints {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
};
struct TimeVal { struct TimeVal {
long tv_sec; long tv_sec;
long tv_usec; long tv_usec;
@@ -59,17 +59,17 @@ namespace ams::fs {
R_RETURN(m_base_file->Flush()); R_RETURN(m_base_file->Flush());
} }
Result FileStorage::SetSize(s64 size) {
m_size = InvalidSize;
R_RETURN(m_base_file->SetSize(size));
}
Result FileStorage::GetSize(s64 *out_size) { Result FileStorage::GetSize(s64 *out_size) {
R_TRY(this->UpdateSize()); R_TRY(this->UpdateSize());
*out_size = m_size; *out_size = m_size;
R_SUCCEED(); R_SUCCEED();
} }
Result FileStorage::SetSize(s64 size) {
m_size = InvalidSize;
R_RETURN(m_base_file->SetSize(size));
}
Result FileStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) { Result FileStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
switch (op_id) { switch (op_id) {
case OperationId::Invalidate: case OperationId::Invalidate:
@@ -150,17 +150,17 @@ namespace ams::fs {
R_RETURN(FlushFile(m_handle)); R_RETURN(FlushFile(m_handle));
} }
Result FileHandleStorage::SetSize(s64 size) {
m_size = InvalidSize;
R_RETURN(SetFileSize(m_handle, size));
}
Result FileHandleStorage::GetSize(s64 *out_size) { Result FileHandleStorage::GetSize(s64 *out_size) {
R_TRY(this->UpdateSize()); R_TRY(this->UpdateSize());
*out_size = m_size; *out_size = m_size;
R_SUCCEED(); R_SUCCEED();
} }
Result FileHandleStorage::SetSize(s64 size) {
m_size = InvalidSize;
R_RETURN(SetFileSize(m_handle, size));
}
Result FileHandleStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) { Result FileHandleStorage::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
AMS_UNUSED(src, src_size); AMS_UNUSED(src, src_size);
@@ -30,7 +30,7 @@ namespace ams::fssrv::impl {
})); }));
} }
Result StorageInterfaceAdapter::Write(s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size) { Result StorageInterfaceAdapter::Write(s64 offset, const ams::sf::InNonSecureBuffer &buffer, s64 size) {
/* Check pre-conditions. */ /* Check pre-conditions. */
R_UNLESS(0 <= offset, fs::ResultInvalidOffset()); R_UNLESS(0 <= offset, fs::ResultInvalidOffset());
R_UNLESS(0 <= size, fs::ResultInvalidSize()); R_UNLESS(0 <= size, fs::ResultInvalidSize());
@@ -42,16 +42,16 @@ namespace ams::fssrv::impl {
R_RETURN(m_base_storage->Write(offset, buffer.GetPointer(), size)); R_RETURN(m_base_storage->Write(offset, buffer.GetPointer(), size));
} }
Result StorageInterfaceAdapter::Flush() { Result StorageInterfaceAdapter::Flush() {
R_RETURN(m_base_storage->Flush()); R_RETURN(m_base_storage->Flush());
} }
Result StorageInterfaceAdapter::SetSize(s64 size) { Result StorageInterfaceAdapter::SetSize(s64 size) {
R_UNLESS(size >= 0, fs::ResultInvalidSize()); R_UNLESS(size >= 0, fs::ResultInvalidSize());
R_RETURN(m_base_storage->SetSize(size)); R_RETURN(m_base_storage->SetSize(size));
} }
Result StorageInterfaceAdapter::GetSize(ams::sf::Out<s64> out) { Result StorageInterfaceAdapter::GetSize(ams::sf::Out<s64> out) {
R_RETURN(m_base_storage->GetSize(out.GetPointer())); R_RETURN(m_base_storage->GetSize(out.GetPointer()));
} }
@@ -73,4 +73,10 @@ namespace ams::fssrv::impl {
R_SUCCEED(); R_SUCCEED();
} }
Result StorageInterfaceAdapterForBatchRead::BatchRead(const ams::sf::OutNonSecureBuffer &out0, const ams::sf::OutNonSecureBuffer &out1, const ams::sf::OutNonSecureBuffer &out2, const ams::sf::OutNonSecureBuffer &out3, const ams::sf::OutNonSecureBuffer &out4, const ams::sf::OutNonSecureBuffer &out5, const ams::sf::OutNonSecureBuffer &out6, const ams::sf::InBuffer &in) {
/* TODO */
AMS_UNUSED(out0, out1, out2, out3, out4, out5, out6, in);
R_THROW(fs::ResultUnsupportedOperation());
}
} }
@@ -33,6 +33,9 @@ namespace ams::os {
/* Create the critical section. */ /* Create the critical section. */
util::ConstructAt(shared_memory->cs_shared_memory); util::ConstructAt(shared_memory->cs_shared_memory);
/* Set state to initialized. */
shared_memory->state = SharedMemoryType::State_Initialized;
} }
} }
@@ -33,6 +33,9 @@ namespace ams::os {
/* Create the critical section. */ /* Create the critical section. */
util::ConstructAt(tmem->cs_transfer_memory); util::ConstructAt(tmem->cs_transfer_memory);
/* Set state to created. */
tmem->state = TransferMemoryType::State_Created;
} }
} }
+53 -21
View File
@@ -46857,14 +46857,18 @@ size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx,
/*-************************************* /*-*************************************
* Dependencies * Dependencies
***************************************/ ***************************************/
/* qsort_r is an extension. */ /* qsort_r is an extension.
#if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \ *
defined(__CYGWIN__) || defined(__MSYS__) * Android NDK does not ship qsort_r().
#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */ */
#define _GNU_SOURCE #if (defined(__linux__) && !defined(__ANDROID__)) || defined(__CYGWIN__) || defined(__MSYS__)
#endif # ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
#endif #endif
#define __STDC_WANT_LIB_EXT1__ 1 /* request C11 Annex K, which includes qsort_s() */
#include <stdio.h> /* fprintf */ #include <stdio.h> /* fprintf */
#include <stdlib.h> /* malloc, free, qsort_r */ #include <stdlib.h> /* malloc, free, qsort_r */
@@ -46875,6 +46879,7 @@ size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx,
# define ZDICT_STATIC_LINKING_ONLY # define ZDICT_STATIC_LINKING_ONLY
#endif #endif
/**** skipping file: ../common/debug.h ****/
/**** skipping file: ../common/mem.h ****/ /**** skipping file: ../common/mem.h ****/
/**** skipping file: ../common/pool.h ****/ /**** skipping file: ../common/pool.h ****/
/**** skipping file: ../common/threading.h ****/ /**** skipping file: ../common/threading.h ****/
@@ -47531,6 +47536,31 @@ void COVER_dictSelectionFree(COVER_dictSelection_t selection);
#define COVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB)) #define COVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB))
#define COVER_DEFAULT_SPLITPOINT 1.0 #define COVER_DEFAULT_SPLITPOINT 1.0
/**
* Select the qsort() variant used by cover
*/
#define ZDICT_QSORT_MIN 0
#define ZDICT_QSORT_C90 ZDICT_QSORT_MIN
#define ZDICT_QSORT_GNU 1
#define ZDICT_QSORT_APPLE 2
#define ZDICT_QSORT_MSVC 3
#define ZDICT_QSORT_C11 ZDICT_QSORT_MAX
#define ZDICT_QSORT_MAX 4
#ifndef ZDICT_QSORT
# if defined(__APPLE__)
# define ZDICT_QSORT ZDICT_QSORT_APPLE /* uses qsort_r() with a different order for parameters */
# elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__CYGWIN__) || defined(__MSYS__)
# define ZDICT_QSORT ZDICT_QSORT_GNU /* uses qsort_r() */
# elif defined(_WIN32) && defined(_MSC_VER)
# define ZDICT_QSORT ZDICT_QSORT_MSVC /* uses qsort_s() with a different order for parameters */
# elif defined(STDC_LIB_EXT1) && (STDC_LIB_EXT1 > 0) /* C11 Annex K */
# define ZDICT_QSORT ZDICT_QSORT_C11 /* uses qsort_s() */
# else
# define ZDICT_QSORT ZDICT_QSORT_C90 /* uses standard qsort() which is not re-entrant (requires global variable) */
# endif
#endif
/*-************************************* /*-*************************************
* Console display * Console display
***************************************/ ***************************************/
@@ -47712,8 +47742,8 @@ typedef struct {
unsigned d; unsigned d;
} COVER_ctx_t; } COVER_ctx_t;
#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER) #if ZDICT_QSORT == ZDICT_QSORT_C90
/* C90 only offers qsort() that needs a global context. */ /* Use global context for non-reentrant sort functions */
static COVER_ctx_t *g_coverCtx = NULL; static COVER_ctx_t *g_coverCtx = NULL;
#endif #endif
@@ -47759,9 +47789,9 @@ static int COVER_cmp8(COVER_ctx_t *ctx, const void *lp, const void *rp) {
/** /**
* Same as COVER_cmp() except ties are broken by pointer value * Same as COVER_cmp() except ties are broken by pointer value
*/ */
#if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__) #if (ZDICT_QSORT == ZDICT_QSORT_MSVC) || (ZDICT_QSORT == ZDICT_QSORT_APPLE)
static int WIN_CDECL COVER_strict_cmp(void* g_coverCtx, const void* lp, const void* rp) { static int WIN_CDECL COVER_strict_cmp(void* g_coverCtx, const void* lp, const void* rp) {
#elif defined(_GNU_SOURCE) #elif (ZDICT_QSORT == ZDICT_QSORT_GNU) || (ZDICT_QSORT == ZDICT_QSORT_C11)
static int COVER_strict_cmp(const void *lp, const void *rp, void *g_coverCtx) { static int COVER_strict_cmp(const void *lp, const void *rp, void *g_coverCtx) {
#else /* C90 fallback.*/ #else /* C90 fallback.*/
static int COVER_strict_cmp(const void *lp, const void *rp) { static int COVER_strict_cmp(const void *lp, const void *rp) {
@@ -47775,9 +47805,9 @@ static int COVER_strict_cmp(const void *lp, const void *rp) {
/** /**
* Faster version for d <= 8. * Faster version for d <= 8.
*/ */
#if (defined(_WIN32) && defined(_MSC_VER)) || defined(__APPLE__) #if (ZDICT_QSORT == ZDICT_QSORT_MSVC) || (ZDICT_QSORT == ZDICT_QSORT_APPLE)
static int WIN_CDECL COVER_strict_cmp8(void* g_coverCtx, const void* lp, const void* rp) { static int WIN_CDECL COVER_strict_cmp8(void* g_coverCtx, const void* lp, const void* rp) {
#elif defined(_GNU_SOURCE) #elif (ZDICT_QSORT == ZDICT_QSORT_GNU) || (ZDICT_QSORT == ZDICT_QSORT_C11)
static int COVER_strict_cmp8(const void *lp, const void *rp, void *g_coverCtx) { static int COVER_strict_cmp8(const void *lp, const void *rp, void *g_coverCtx) {
#else /* C90 fallback.*/ #else /* C90 fallback.*/
static int COVER_strict_cmp8(const void *lp, const void *rp) { static int COVER_strict_cmp8(const void *lp, const void *rp) {
@@ -47794,26 +47824,28 @@ static int COVER_strict_cmp8(const void *lp, const void *rp) {
* Hopefully when C11 become the norm, we will be able * Hopefully when C11 become the norm, we will be able
* to clean it up. * to clean it up.
*/ */
static void stableSort(COVER_ctx_t *ctx) { static void stableSort(COVER_ctx_t *ctx)
#if defined(__APPLE__) {
DEBUG_STATIC_ASSERT(ZDICT_QSORT_MIN <= ZDICT_QSORT && ZDICT_QSORT <= ZDICT_QSORT_MAX);
#if (ZDICT_QSORT == ZDICT_QSORT_APPLE)
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
ctx, ctx,
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#elif defined(_GNU_SOURCE) #elif (ZDICT_QSORT == ZDICT_QSORT_GNU)
qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp), (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx); ctx);
#elif defined(_WIN32) && defined(_MSC_VER) #elif (ZDICT_QSORT == ZDICT_QSORT_MSVC)
qsort_s(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx);
#elif (ZDICT_QSORT == ZDICT_QSORT_C11)
qsort_s(ctx->suffix, ctx->suffixSize, sizeof(U32), qsort_s(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp), (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp),
ctx); ctx);
#elif defined(__OpenBSD__)
g_coverCtx = ctx;
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#else /* C90 fallback.*/ #else /* C90 fallback.*/
g_coverCtx = ctx; g_coverCtx = ctx;
/* TODO(cavalcanti): implement a reentrant qsort() when is not available. */ /* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
qsort(ctx->suffix, ctx->suffixSize, sizeof(U32), qsort(ctx->suffix, ctx->suffixSize, sizeof(U32),
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
#endif #endif
@@ -17,10 +17,10 @@
#define ATMOSPHERE_RELEASE_VERSION_MAJOR 1 #define ATMOSPHERE_RELEASE_VERSION_MAJOR 1
#define ATMOSPHERE_RELEASE_VERSION_MINOR 12 #define ATMOSPHERE_RELEASE_VERSION_MINOR 12
#define ATMOSPHERE_RELEASE_VERSION_MICRO 0 #define ATMOSPHERE_RELEASE_VERSION_MICRO 2
#define ATMOSPHERE_RELEASE_VERSION ATMOSPHERE_RELEASE_VERSION_MAJOR, ATMOSPHERE_RELEASE_VERSION_MINOR, ATMOSPHERE_RELEASE_VERSION_MICRO #define ATMOSPHERE_RELEASE_VERSION ATMOSPHERE_RELEASE_VERSION_MAJOR, ATMOSPHERE_RELEASE_VERSION_MINOR, ATMOSPHERE_RELEASE_VERSION_MICRO
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR 23 #define ATMOSPHERE_SUPPORTED_HOS_VERSION_MAJOR 23
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR 0 #define ATMOSPHERE_SUPPORTED_HOS_VERSION_MINOR 5
#define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO 0 #define ATMOSPHERE_SUPPORTED_HOS_VERSION_MICRO 0
@@ -102,8 +102,10 @@
#define ATMOSPHERE_TARGET_FIRMWARE_22_1_0 ATMOSPHERE_TARGET_FIRMWARE(22, 1, 0) #define ATMOSPHERE_TARGET_FIRMWARE_22_1_0 ATMOSPHERE_TARGET_FIRMWARE(22, 1, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_22_5_0 ATMOSPHERE_TARGET_FIRMWARE(22, 5, 0) #define ATMOSPHERE_TARGET_FIRMWARE_22_5_0 ATMOSPHERE_TARGET_FIRMWARE(22, 5, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_23_0_0 ATMOSPHERE_TARGET_FIRMWARE(23, 0, 0) #define ATMOSPHERE_TARGET_FIRMWARE_23_0_0 ATMOSPHERE_TARGET_FIRMWARE(23, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_23_0_1 ATMOSPHERE_TARGET_FIRMWARE(23, 0, 1)
#define ATMOSPHERE_TARGET_FIRMWARE_23_5_0 ATMOSPHERE_TARGET_FIRMWARE(23, 5, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_23_0_0 #define ATMOSPHERE_TARGET_FIRMWARE_CURRENT ATMOSPHERE_TARGET_FIRMWARE_23_5_0
#define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE(0, 0, 0) #define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE(0, 0, 0)
#define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_CURRENT #define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_CURRENT
@@ -198,6 +200,8 @@ namespace ams {
TargetFirmware_22_1_0 = ATMOSPHERE_TARGET_FIRMWARE_22_1_0, TargetFirmware_22_1_0 = ATMOSPHERE_TARGET_FIRMWARE_22_1_0,
TargetFirmware_22_5_0 = ATMOSPHERE_TARGET_FIRMWARE_22_5_0, TargetFirmware_22_5_0 = ATMOSPHERE_TARGET_FIRMWARE_22_5_0,
TargetFirmware_23_0_0 = ATMOSPHERE_TARGET_FIRMWARE_23_0_0, TargetFirmware_23_0_0 = ATMOSPHERE_TARGET_FIRMWARE_23_0_0,
TargetFirmware_23_0_1 = ATMOSPHERE_TARGET_FIRMWARE_23_0_1,
TargetFirmware_23_5_0 = ATMOSPHERE_TARGET_FIRMWARE_23_5_0,
TargetFirmware_Current = ATMOSPHERE_TARGET_FIRMWARE_CURRENT, TargetFirmware_Current = ATMOSPHERE_TARGET_FIRMWARE_CURRENT,
@@ -90,10 +90,10 @@ _ZN3ams4kern10KScheduler12ScheduleImplEv:
/* We have a 64-bit fpu. */ /* We have a 64-bit fpu. */
/* If we're in a usermode exception, we need to save the caller-save fpu registers. */ /* If we're in a usermode exception, we need to save the caller-save fpu registers. */
tbz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_IN_USERMODE_EXCEPTION_HANDLER), 2f tbnz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_IN_USERMODE_EXCEPTION_HANDLER), 2f
/* If we're in an SVC (and not a usermode exception), we only need to save the callee-save fpu registers. */ /* If we're in an SVC (and not a usermode exception), we only need to save the callee-save fpu registers. */
tbz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_CALLING_SVC), 3f tbnz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_CALLING_SVC), 3f
2: /* Save the 64-bit caller-save fpu registers. */ 2: /* Save the 64-bit caller-save fpu registers. */
ldr x6, [x2, #(THREAD_STACK_PARAMETERS_CALLER_SAVE_FPU_REGISTERS)] ldr x6, [x2, #(THREAD_STACK_PARAMETERS_CALLER_SAVE_FPU_REGISTERS)]
@@ -120,10 +120,10 @@ _ZN3ams4kern10KScheduler12ScheduleImplEv:
4: /* We have a 32-bit fpu. */ 4: /* We have a 32-bit fpu. */
/* If we're in a usermode exception, we need to save the caller-save fpu registers. */ /* If we're in a usermode exception, we need to save the caller-save fpu registers. */
tbz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_IN_USERMODE_EXCEPTION_HANDLER), 5f tbnz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_IN_USERMODE_EXCEPTION_HANDLER), 5f
/* If we're in an SVC (and not a usermode exception), we only need to save the callee-save fpu registers. */ /* If we're in an SVC (and not a usermode exception), we only need to save the callee-save fpu registers. */
tbz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_CALLING_SVC), 6f tbnz w4, #(THREAD_EXCEPTION_FLAG_BIT_INDEX_IS_CALLING_SVC), 6f
5: /* Save the 32-bit caller-save fpu registers. */ 5: /* Save the 32-bit caller-save fpu registers. */
ldr x6, [x2, #(THREAD_STACK_PARAMETERS_CALLER_SAVE_FPU_REGISTERS)] ldr x6, [x2, #(THREAD_STACK_PARAMETERS_CALLER_SAVE_FPU_REGISTERS)]
@@ -256,7 +256,6 @@ namespace ams::mitm {
bool IsValid(const CalibrationInfo &cal) { bool IsValid(const CalibrationInfo &cal) {
return IsValidHeader(cal) && return IsValidHeader(cal) &&
IsValid(cal.GetBlock<SerialNumberBlock>()) && IsValid(cal.GetBlock<SerialNumberBlock>()) &&
IsValid(cal.GetBlock<EccB233DeviceCertificateBlock>()) &&
IsValid(cal.GetBlock<SslKeyBlock>()) && IsValid(cal.GetBlock<SslKeyBlock>()) &&
IsValid(cal.GetBlock<SslCertificateSizeBlock>()) && IsValid(cal.GetBlock<SslCertificateSizeBlock>()) &&
cal.GetBlock<SslCertificateSizeBlock>().ssl_certificate_size <= sizeof(cal.GetBlock<SslCertificateBlock>().ssl_certificate) && cal.GetBlock<SslCertificateSizeBlock>().ssl_certificate_size <= sizeof(cal.GetBlock<SslCertificateBlock>().ssl_certificate) &&
@@ -267,7 +266,8 @@ namespace ams::mitm {
IsValidSerialNumber(cal); IsValidSerialNumber(cal);
} }
bool ContainsCorrectDeviceId(const EccB233DeviceCertificateBlock &block, u64 device_id) { template<typename Block>
bool ContainsCorrectDeviceId(const Block &block, u64 device_id) {
static constexpr size_t DeviceIdOffset = 0xC6; static constexpr size_t DeviceIdOffset = 0xC6;
char found_device_id_str[sizeof("0011223344556677")] = {}; char found_device_id_str[sizeof("0011223344556677")] = {};
ON_SCOPE_EXIT { std::memset(found_device_id_str, 0, sizeof(found_device_id_str)); }; ON_SCOPE_EXIT { std::memset(found_device_id_str, 0, sizeof(found_device_id_str)); };
@@ -279,7 +279,14 @@ namespace ams::mitm {
} }
bool ContainsCorrectDeviceId(const CalibrationInfo &cal) { bool ContainsCorrectDeviceId(const CalibrationInfo &cal) {
return ContainsCorrectDeviceId(cal.GetBlock<EccB233DeviceCertificateBlock>(), exosphere::GetDeviceId()); const auto &ecc = cal.GetBlock<EccB233DeviceCertificateBlock>();
if (!IsBlank(ecc)) {
return IsValid(ecc) && ContainsCorrectDeviceId(ecc, exosphere::GetDeviceId());
}
/* Newer consoles may leave the ECC certificate unprogrammed. */
const auto &rsa = cal.GetBlock<Rsa2048DeviceCertificateBlock>();
return !IsBlank(rsa) && IsValid(rsa) && ContainsCorrectDeviceId(rsa, exosphere::GetDeviceId());
} }
bool IsValidForSecureBackup(const CalibrationInfo &cal) { bool IsValidForSecureBackup(const CalibrationInfo &cal) {
@@ -22,6 +22,20 @@
namespace ams::mitm::socket::resolver { namespace ams::mitm::socket::resolver {
namespace {
struct AresAddrInfoQuery {
std::string hostname;
ams::socket::InAddrT redirect_addr;
u16 redirect_port;
bool use_hint;
struct ams::socket::ares_addrinfo_hints hint;
};
std::map<ssize_t, std::unique_ptr<AresAddrInfoQuery>> g_ares_addr_info_queries;
}
ssize_t SerializeRedirectedHostEnt(u8 * const dst, size_t dst_size, const char *hostname, ams::socket::InAddrT redirect_addr) { ssize_t SerializeRedirectedHostEnt(u8 * const dst, size_t dst_size, const char *hostname, ams::socket::InAddrT redirect_addr) {
struct in_addr addr = { .s_addr = redirect_addr }; struct in_addr addr = { .s_addr = redirect_addr };
struct in_addr *addr_list[2] = { std::addressof(addr), nullptr }; struct in_addr *addr_list[2] = { std::addressof(addr), nullptr };
@@ -86,6 +100,95 @@ namespace ams::mitm::socket::resolver {
return result; return result;
} }
void QueueAresAddrInfoQuery(ssize_t query_id, const char *hostname, ams::socket::InAddrT redirect_addr, u16 redirect_port, const struct ams::socket::ares_addrinfo_hints *hint) {
AresAddrInfoQuery query;
query.hostname = hostname;
query.redirect_addr = redirect_addr;
query.redirect_port = redirect_port;
query.use_hint = hint != nullptr;
if (query.use_hint) {
query.hint = *hint;
}
g_ares_addr_info_queries.emplace(query_id, std::make_unique<AresAddrInfoQuery>(query));
}
ssize_t DequeueAresAddrInfoQuery(u8 * const dst, size_t dst_size, u32 query_id) {
AresAddrInfoQuery *query = nullptr;
for (auto it = g_ares_addr_info_queries.begin(); it != g_ares_addr_info_queries.end(); ++it) {
if (it->first == static_cast<ssize_t>(query_id)) {
query = it->second.get();
break;
}
}
if (query == nullptr) {
return -1;
}
struct ams::socket::ares_addrinfo_node node = {
.ai_ttl = 0,
.ai_flags = AF_UNSPEC,
.ai_family = 0,
.ai_socktype = 0,
.ai_protocol = 0,
.ai_addrlen = 0,
.ai_next = nullptr,
};
if (query->use_hint) {
std::memcpy(std::addressof(node.ai_flags), std::addressof(query->hint), sizeof(query->hint));
}
switch (node.ai_family) {
case AF_UNSPEC: node.ai_family = AF_INET; break;
case AF_INET: node.ai_family = AF_INET; break;
case AF_INET6: AMS_ABORT("Redirected INET6 not supported"); break;
AMS_UNREACHABLE_DEFAULT_CASE();
}
if (node.ai_socktype == 0) {
node.ai_socktype = SOCK_STREAM;
}
if (node.ai_protocol == 0) {
node.ai_protocol = IPPROTO_TCP;
}
const struct sockaddr_in sin = {
.sin_family = AF_INET,
.sin_port = ams::socket::InetHtons(query->redirect_port),
.sin_addr = { .s_addr = query->redirect_addr },
.sin_zero = {},
};
node.ai_addrlen = sizeof(sin);
node.ai_addr = (struct sockaddr *)(std::addressof(sin));
struct ams::socket::ares_addrinfo ai {
.cnames = nullptr,
.nodes = std::addressof(node),
.name = const_cast<char *>(query->hostname.c_str()),
};
const auto result = serializer::DNSSerializer::ToBuffer(dst, dst_size, ai);
AMS_ABORT_UNLESS(result >= 0);
g_ares_addr_info_queries.erase(static_cast<ssize_t>(query_id));
return result;
}
bool CancelAresAddrInfoQuery(u32 query_id) {
for (auto it = g_ares_addr_info_queries.begin(); it != g_ares_addr_info_queries.end(); ++it) {
if (it->first == static_cast<ssize_t>(query_id)) {
g_ares_addr_info_queries.erase(it);
return true;
}
}
return false;
}
Result ResolverImpl::GetHostByNameRequest(u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &name, sf::Out<u32> out_host_error, sf::Out<u32> out_errno, const sf::OutBuffer &out_hostent, sf::Out<u32> out_size) { Result ResolverImpl::GetHostByNameRequest(u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &name, sf::Out<u32> out_host_error, sf::Out<u32> out_errno, const sf::OutBuffer &out_hostent, sf::Out<u32> out_size) {
AMS_UNUSED(cancel_handle, client_pid, use_nsd_resolve); AMS_UNUSED(cancel_handle, client_pid, use_nsd_resolve);
@@ -209,6 +312,97 @@ namespace ams::mitm::socket::resolver {
R_SUCCEED(); R_SUCCEED();
} }
Result ResolverImpl::ReportTelemetry(const sf::ClientProcessId &client_pid, const sf::InBuffer &telemetry, u32 version) {
/* NOTE: As of 23.0.0 this command does nothing. We mitm it anyway for future proofing. */
AMS_UNUSED(client_pid, telemetry, version);
R_SUCCEED();
}
Result ResolverImpl::QueryAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &node, const sf::InAutoSelectBuffer &srv, const sf::InAutoSelectBuffer &serialized_hint, sf::Out<u32> out_query_id, u32 fd, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_retval, sf::Out<s32> out_errno) {
const char *hostname = reinterpret_cast<const char *>(node.GetPointer());
LogDebug("[%016lx]: QueryAddrInfoRequestWithOptions(%s, %s)\n", m_client_info.program_id.value, hostname, reinterpret_cast<const char *>(srv.GetPointer()));
R_UNLESS(hostname != nullptr, sm::mitm::ResultShouldForwardToSession());
ams::socket::InAddrT redirect_addr = {};
R_UNLESS(GetRedirectedHostByName(std::addressof(redirect_addr), hostname), sm::mitm::ResultShouldForwardToSession());
u16 port = 0;
if (srv.GetPointer() != nullptr) {
for (const char *cur = reinterpret_cast<const char *>(srv.GetPointer()); *cur != 0; ++cur) {
AMS_ABORT_UNLESS(std::isdigit(static_cast<unsigned char>(*cur)));
port *= 10;
port += *cur - '0';
}
}
LogDebug("[%016lx]: Queueing query for redirecting %s:%u to %u.%u.%u.%u\n", m_client_info.program_id.value, hostname, port, (redirect_addr >> 0) & 0xFF, (redirect_addr >> 8) & 0xFF, (redirect_addr >> 16) & 0xFF, (redirect_addr >> 24) & 0xFF);
const bool use_hint = serialized_hint.GetPointer() != nullptr;
struct ams::socket::ares_addrinfo_hints hint = {};
if (use_hint) {
AMS_ABORT_UNLESS(serializer::DNSSerializer::FromBuffer(hint, serialized_hint.GetPointer(), serialized_hint.GetSize()) >= 0);
}
/* Forward to session. The provided socket EventFd must be signalled by having bsdsocket write 1 to the associated socket. */
/* This is fine though, we only care about replacing with our redirection during fetch. */
/* Additionally, a failure at this point can be safely handled by bsdsocket, it simply won't create a new query. */
R_TRY(sfdnsresQueryAddrInfoRequestWithOptionsFwd(m_forward_service.get(), static_cast<u64>(client_pid.GetValue().value), node.GetPointer(), node.GetSize(), srv.GetPointer(), srv.GetSize(), serialized_hint.GetPointer(), serialized_hint.GetSize(), reinterpret_cast<u32 *>(out_query_id.GetPointer()), fd, options_version, options.GetPointer(), options.GetSize(), num_options, reinterpret_cast<s32 *>(out_retval.GetPointer()), reinterpret_cast<s32 *>(out_errno.GetPointer())));
/* If no errors were returned, trust the id bsdsocket generated and queue the query. */
/* When bsdsocket's queue is full, retval and errno will reflect that and the returned query id will be -1. */
/* This is expected by the client. We must drop this query and let the client see the errors for it to schedule a new query. */
if ((*out_retval == 0) && (*out_errno == 0)) {
ssize_t query_id = static_cast<ssize_t>(*out_query_id);
QueueAresAddrInfoQuery(query_id, hostname, redirect_addr, port, use_hint ? std::addressof(hint) : nullptr);
LogDebug("[%016lx]: Queued query with id 0x%lx\n", m_client_info.program_id.value, query_id);
} else {
LogDebug("[%016lx]: Dropping last query, queue is full\n", m_client_info.program_id.value);
}
R_SUCCEED();
}
Result ResolverImpl::FetchAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, u32 query_id, u32 version, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, sf::Out<s32> out_errno) {
LogDebug("[%016lx]: FetchAddrInfoRequestWithOptions(0x%x)\n", m_client_info.program_id.value, query_id);
const auto size = DequeueAresAddrInfoQuery(out_addrinfo.GetPointer(), out_addrinfo.GetSize(), query_id);
/* If we don't have this query queued, then the hostname is not in the hosts file. Forward to session. */
R_UNLESS(size >= 0, sm::mitm::ResultShouldForwardToSession());
LogDebug("[%016lx]: Dequeued query 0x%x with size 0x%lx\n", m_client_info.program_id.value, query_id, size);
/* Forward to session. The socket EventFd associated with this query must be cleared by having bsdsocket write 0 to the socket. */
/* However, we want to keep our redirection, so we pass nullptr to bsdsocket forcing the command to end early with an error. */
/* We discard the error and replace the output, pretending the command was successful while returning our redirected addrinfo to the client instead. */
R_DISCARD(sfdnsresFetchAddrInfoRequestWithOptionsFwd(m_forward_service.get(), static_cast<u64>(client_pid.GetValue().value), query_id, version, nullptr, 0, reinterpret_cast<u32 *>(out_size.GetPointer()), reinterpret_cast<s32 *>(out_retval.GetPointer()), reinterpret_cast<s32 *>(out_errno.GetPointer())));
*out_size = size;
*out_retval = 0;
*out_errno = 0;
R_SUCCEED();
}
Result ResolverImpl::CancelQuery(const sf::ClientProcessId &client_pid, u32 query_id) {
LogDebug("[%016lx]: CancelQuery(0x%x)\n", m_client_info.program_id.value, query_id);
const auto found = CancelAresAddrInfoQuery(query_id);
/* If we don't have this query queued, then we never intercepted it. Forward to session. */
R_UNLESS(found, sm::mitm::ResultShouldForwardToSession());
LogDebug("[%016lx]: Cancelled query 0x%x\n", m_client_info.program_id.value, query_id);
/* Forward to session. Ensures that bsdsocket cleans up. */
/* We still want to discard any errors and return success in case this was a query we had queued. */
R_DISCARD(sfdnsresCancelQueryFwd(m_forward_service.get(), static_cast<u64>(client_pid.GetValue().value), query_id));
R_SUCCEED();
}
Result ResolverImpl::AtmosphereReloadHostsFile() { Result ResolverImpl::AtmosphereReloadHostsFile() {
/* Perform a hosts file reload. */ /* Perform a hosts file reload. */
InitializeResolverRedirections(); InitializeResolverRedirections();
@@ -16,11 +16,15 @@
#pragma once #pragma once
#include <stratosphere.hpp> #include <stratosphere.hpp>
#define AMS_DNS_MITM_INTERFACE_INFO(C, H) \ #define AMS_DNS_MITM_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 2, Result, GetHostByNameRequest, (u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &name, sf::Out<u32> out_host_error, sf::Out<u32> out_errno, const sf::OutBuffer &out_hostent, sf::Out<u32> out_size), (cancel_handle, client_pid, use_nsd_resolve, name, out_host_error, out_errno, out_hostent, out_size)) \ AMS_SF_METHOD_INFO(C, H, 2, Result, GetHostByNameRequest, (u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &name, sf::Out<u32> out_host_error, sf::Out<u32> out_errno, const sf::OutBuffer &out_hostent, sf::Out<u32> out_size), (cancel_handle, client_pid, use_nsd_resolve, name, out_host_error, out_errno, out_hostent, out_size)) \
AMS_SF_METHOD_INFO(C, H, 6, Result, GetAddrInfoRequest, (u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutBuffer &out_addrinfo, sf::Out<u32> out_errno, sf::Out<s32> out_retval, sf::Out<u32> out_size), (cancel_handle, client_pid, use_nsd_resolve, node, srv, serialized_hint, out_addrinfo, out_errno, out_retval, out_size)) \ AMS_SF_METHOD_INFO(C, H, 6, Result, GetAddrInfoRequest, (u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutBuffer &out_addrinfo, sf::Out<u32> out_errno, sf::Out<s32> out_retval, sf::Out<u32> out_size), (cancel_handle, client_pid, use_nsd_resolve, node, srv, serialized_hint, out_addrinfo, out_errno, out_retval, out_size)) \
AMS_SF_METHOD_INFO(C, H, 10, Result, GetHostByNameRequestWithOptions, (const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &name, const sf::OutAutoSelectBuffer &out_hostent, sf::Out<u32> out_size, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno), (client_pid, name, out_hostent, out_size, options_version, options, num_options, out_host_error, out_errno), hos::Version_5_0_0) \ AMS_SF_METHOD_INFO(C, H, 10, Result, GetHostByNameRequestWithOptions, (const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &name, const sf::OutAutoSelectBuffer &out_hostent, sf::Out<u32> out_size, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno), (client_pid, name, out_hostent, out_size, options_version, options, num_options, out_host_error, out_errno), hos::Version_5_0_0) \
AMS_SF_METHOD_INFO(C, H, 12, Result, GetAddrInfoRequestWithOptions, (const sf::ClientProcessId &client_pid, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno), (client_pid, node, srv, serialized_hint, out_addrinfo, out_size, out_retval, options_version, options, num_options, out_host_error, out_errno), hos::Version_5_0_0) \ AMS_SF_METHOD_INFO(C, H, 12, Result, GetAddrInfoRequestWithOptions, (const sf::ClientProcessId &client_pid, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno), (client_pid, node, srv, serialized_hint, out_addrinfo, out_size, out_retval, options_version, options, num_options, out_host_error, out_errno), hos::Version_5_0_0) \
AMS_SF_METHOD_INFO(C, H, 16, Result, ReportTelemetry, (const sf::ClientProcessId &client_pid, const sf::InBuffer &telemetry, u32 version), (client_pid, telemetry, version), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 100, Result, QueryAddrInfoRequestWithOptions, (const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &node, const sf::InAutoSelectBuffer &srv, const sf::InAutoSelectBuffer &serialized_hint, sf::Out<u32> out_query_id, u32 fd, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_retval, sf::Out<s32> out_errno), (client_pid, node, srv, serialized_hint, out_query_id, fd, options_version, options, num_options, out_retval, out_errno), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 102, Result, FetchAddrInfoRequestWithOptions, (const sf::ClientProcessId &client_pid, u32 query_id, u32 version, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, sf::Out<s32> out_errno), (client_pid, query_id, version, out_addrinfo, out_size, out_retval, out_errno), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 104, Result, CancelQuery, (const sf::ClientProcessId &client_pid, u32 query_id), (client_pid, query_id), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereReloadHostsFile, (), ()) AMS_SF_METHOD_INFO(C, H, 65000, Result, AtmosphereReloadHostsFile, (), ())
AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::socket::resolver, IResolver, AMS_DNS_MITM_INTERFACE_INFO, 0x5935F91A) AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::socket::resolver, IResolver, AMS_DNS_MITM_INTERFACE_INFO, 0x5935F91A)
@@ -44,6 +48,10 @@ namespace ams::mitm::socket::resolver {
Result GetAddrInfoRequest(u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutBuffer &out_addrinfo, sf::Out<u32> out_errno, sf::Out<s32> out_retval, sf::Out<u32> out_size); Result GetAddrInfoRequest(u32 cancel_handle, const sf::ClientProcessId &client_pid, bool use_nsd_resolve, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutBuffer &out_addrinfo, sf::Out<u32> out_errno, sf::Out<s32> out_retval, sf::Out<u32> out_size);
Result GetHostByNameRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &name, const sf::OutAutoSelectBuffer &out_hostent, sf::Out<u32> out_size, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno); Result GetHostByNameRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &name, const sf::OutAutoSelectBuffer &out_hostent, sf::Out<u32> out_size, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno);
Result GetAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno); Result GetAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InBuffer &node, const sf::InBuffer &srv, const sf::InBuffer &serialized_hint, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_host_error, sf::Out<s32> out_errno);
Result ReportTelemetry(const sf::ClientProcessId &client_pid, const sf::InBuffer &telemetry, u32 version);
Result QueryAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, const sf::InAutoSelectBuffer &node, const sf::InAutoSelectBuffer &srv, const sf::InAutoSelectBuffer &serialized_hint, sf::Out<u32> out_query_id, u32 fd, u32 options_version, const sf::InAutoSelectBuffer &options, u32 num_options, sf::Out<s32> out_retval, sf::Out<s32> out_errno);
Result FetchAddrInfoRequestWithOptions(const sf::ClientProcessId &client_pid, u32 query_id, u32 version, const sf::OutAutoSelectBuffer &out_addrinfo, sf::Out<u32> out_size, sf::Out<s32> out_retval, sf::Out<s32> out_errno);
Result CancelQuery(const sf::ClientProcessId &client_pid, u32 query_id);
/* Extension commands. */ /* Extension commands. */
Result AtmosphereReloadHostsFile(); Result AtmosphereReloadHostsFile();
@@ -190,14 +190,20 @@ namespace ams::mitm::socket::resolver::serializer {
return rc; return rc;
} }
} else { } else {
if (dst_size - (cur - dst) < addr_info.ai_addrlen) { if (hos::GetVersion() >= hos::Version_23_0_0) {
/* 23.0.0 fixed this by returning an error instead. */
rc = -1; rc = -1;
return rc; return rc;
} } else {
if (dst_size - (cur - dst) < addr_info.ai_addrlen) {
rc = -1;
return rc;
}
/* NOTE: This is clearly a nintendo bug, see the accompanying note in FromBufferInternalImpl */ /* NOTE: This is clearly a nintendo bug, see the accompanying note in FromBufferInternalImpl */
std::memmove(cur, std::addressof(addr_info.ai_addr), addr_info.ai_addrlen); std::memmove(cur, std::addressof(addr_info.ai_addr), addr_info.ai_addrlen);
rc = addr_info.ai_addrlen; rc = addr_info.ai_addrlen;
}
} }
cur += rc; cur += rc;
} }
@@ -317,6 +323,7 @@ namespace ams::mitm::socket::resolver::serializer {
} else if (IsAfInet<T>(out.ai_family)) { } else if (IsAfInet<T>(out.ai_family)) {
out.ai_addr = static_cast<SockAddrType<T> *>(ams::socket::impl::Alloc(sizeof(SockAddrInType<T>))); out.ai_addr = static_cast<SockAddrType<T> *>(ams::socket::impl::Alloc(sizeof(SockAddrInType<T>)));
if (out.ai_addr == nullptr) { if (out.ai_addr == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -328,6 +335,7 @@ namespace ams::mitm::socket::resolver::serializer {
} else if (IsAfInet6<T>(out.ai_family)) { } else if (IsAfInet6<T>(out.ai_family)) {
out.ai_addr = static_cast<SockAddrType<T> *>(ams::socket::impl::Alloc(sizeof(SockAddrIn6Type<T>))); out.ai_addr = static_cast<SockAddrType<T> *>(ams::socket::impl::Alloc(sizeof(SockAddrIn6Type<T>)));
if (out.ai_addr == nullptr) { if (out.ai_addr == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -337,17 +345,24 @@ namespace ams::mitm::socket::resolver::serializer {
return rc; return rc;
} }
} else { } else {
out.ai_addr = static_cast<decltype(out.ai_addr)>(ams::socket::impl::Alloc(out.ai_addrlen)); if (hos::GetVersion() >= hos::Version_23_0_0) {
if (out.ai_addr == nullptr) { /* 23.0.0 fixed this by returning an error instead. */
ams::socket::SetLastError(ams::socket::Errno::EInval);
rc = -1; rc = -1;
return rc; return rc;
} } else {
out.ai_addr = static_cast<decltype(out.ai_addr)>(ams::socket::impl::Alloc(out.ai_addrlen));
if (out.ai_addr == nullptr) {
rc = -1;
return rc;
}
/* NOTE: This is *clearly* a nintendo bug. */ /* NOTE: This is *clearly* a nintendo bug. */
/* They obviously intend to copy to the buffer they just allocated, but instead they copy to the addrinfo structure itself. */ /* They obviously intend to copy to the buffer they just allocated, but instead they copy to the addrinfo structure itself. */
/* Probably &out.ai_addr instead of &out.ai_addr[0]? Either way, we'll implement what they do, but... */ /* Probably &out.ai_addr instead of &out.ai_addr[0]? Either way, we'll implement what they do, but... */
std::memcpy(std::addressof(out.ai_addr), cur, out.ai_addrlen); std::memcpy(std::addressof(out.ai_addr), cur, out.ai_addrlen);
rc = out.ai_addrlen; rc = out.ai_addrlen;
}
} }
cur += rc; cur += rc;
} }
@@ -368,6 +383,7 @@ namespace ams::mitm::socket::resolver::serializer {
} else if (tmp_value == AddrInfoMagic) { } else if (tmp_value == AddrInfoMagic) {
out.ai_next = static_cast<T *>(ams::socket::impl::Alloc(sizeof(T))); out.ai_next = static_cast<T *>(ams::socket::impl::Alloc(sizeof(T)));
if (out.ai_next == nullptr) { if (out.ai_next == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -0,0 +1,380 @@
/*
* 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 "../dnsmitm_debug.hpp"
#include "../socket_allocator.hpp"
#include "serializer.hpp"
namespace ams::mitm::socket::resolver::serializer {
namespace {
/* NOTE: This is local to the nn::socket::resolver::serializer namespace. */
struct AddrInfoNodeCname {
struct ams::socket::ares_addrinfo_node *node;
char *ai_canonname;
};
constexpr inline u32 AresMagic = 0xBEEFCAFE;
template<typename T>
concept IsAresAddrInfo = std::same_as<T, struct ams::socket::ares_addrinfo>;
template<typename T>
concept IsAresAddrInfoHints = std::same_as<T, struct ams::socket::ares_addrinfo_hints>;
template<typename T>
concept IsAresAddrInfoNode = std::same_as<T, struct ams::socket::ares_addrinfo_node>;
template<typename T>
concept IsAddrInfoNodeCname = std::same_as<T, AddrInfoNodeCname>;
template<typename T> requires IsAresAddrInfoNode<T> || IsAddrInfoNodeCname<T>
using SockAddrInType = typename std::conditional<std::same_as<T, struct ams::socket::ares_addrinfo> || std::same_as<T, AddrInfoNodeCname>, struct sockaddr_in, struct sockaddr_in>::type;
template<typename T> requires IsAresAddrInfoNode<T> || IsAddrInfoNodeCname<T>
using SockAddrIn6Type = typename std::conditional<std::same_as<T, struct ams::socket::ares_addrinfo> || std::same_as<T, AddrInfoNodeCname>, struct sockaddr_in6, struct sockaddr_in6>::type;
template<typename T> requires IsAresAddrInfoNode<T> || IsAddrInfoNodeCname<T>
constexpr bool IsAfInet(const auto ai_family) {
if constexpr (std::same_as<T, struct ams::socket::ares_addrinfo_node> || std::same_as<T, AddrInfoNodeCname>) {
/* NOTE: Keep this in case a nn::socket::AddrInfo equivalent is ever implemented for c-ares. */
/* As of 23.0.0 only the ares_addrinfo struct is supported in the serializer. */
return ai_family == AF_INET;
} else {
return ai_family == AF_INET;
}
}
template<typename T> requires IsAresAddrInfoNode<T> || IsAddrInfoNodeCname<T>
constexpr bool IsAfInet6(const auto ai_family) {
if constexpr (std::same_as<T, struct ams::socket::ares_addrinfo_node> || std::same_as<T, AddrInfoNodeCname>) {
/* NOTE: Keep this in case a nn::socket::AddrInfo equivalent is ever implemented for c-ares. */
/* As of 23.0.0 only the ares_addrinfo struct is supported in the serializer. */
return ai_family == AF_INET6;
} else {
return ai_family == AF_INET6;
}
}
template<typename T> requires IsAresAddrInfoNode<T>
size_t AddrInfoNodeSizeOf(const T *ares_addr_info_node) {
size_t rc = 6 * sizeof(u32);
if (ares_addr_info_node->ai_addr == nullptr) {
rc += sizeof(u32);
} else if (IsAfInet<T>(ares_addr_info_node->ai_family)) {
rc += DNSSerializer::SizeOf(*reinterpret_cast<SockAddrInType<T> *>(ares_addr_info_node->ai_addr));
} else if (IsAfInet6<T>(ares_addr_info_node->ai_family)) {
rc += DNSSerializer::SizeOf(*reinterpret_cast<SockAddrIn6Type<T> *>(ares_addr_info_node->ai_addr));
} else if (ares_addr_info_node->ai_addrlen == 0) {
rc += sizeof(u32);
} else {
rc += ares_addr_info_node->ai_addrlen;
}
if (ares_addr_info_node->ai_next == nullptr) {
rc += sizeof(u32);
}
return rc;
}
template<typename T> requires IsAresAddrInfo<T>
size_t SizeOfImpl(const T &in) {
size_t rc = 0;
const T *ares_addr_info = std::addressof(in);
for (const struct ams::socket::ares_addrinfo_node *ares_addr_info_node = ares_addr_info->nodes; ares_addr_info_node != nullptr; ares_addr_info_node = ares_addr_info_node->ai_next) {
rc += AddrInfoNodeSizeOf(ares_addr_info_node);
}
return rc;
}
template<typename T> requires IsAresAddrInfoHints<T>
size_t SizeOfImpl(const T &) {
return 5 * sizeof(u32);
}
template<typename T> requires IsAddrInfoNodeCname<T>
ssize_t ToBufferInternalImpl(u8 * const dst, size_t dst_size, const T &addr_info_node_cname) {
ssize_t rc = -1;
u8 *cur = dst;
{
const u32 value = AresMagic;
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(addr_info_node_cname.node->ai_flags);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(addr_info_node_cname.node->ai_family);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(addr_info_node_cname.node->ai_socktype);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(addr_info_node_cname.node->ai_protocol);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(addr_info_node_cname.node->ai_addrlen);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
if (addr_info_node_cname.node->ai_addr == nullptr || addr_info_node_cname.node->ai_addrlen == 0) {
const u32 value = 0;
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
} else if (IsAfInet<T>(addr_info_node_cname.node->ai_family)) {
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), *reinterpret_cast<SockAddrInType<T> *>(addr_info_node_cname.node->ai_addr))) == -1) {
return rc;
}
} else if (IsAfInet6<T>(addr_info_node_cname.node->ai_family)) {
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), *reinterpret_cast<SockAddrIn6Type<T> *>(addr_info_node_cname.node->ai_addr))) == -1) {
return rc;
}
} else {
rc = -1;
return rc;
}
cur += rc;
}
{
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), addr_info_node_cname.ai_canonname)) == -1) {
return rc;
}
cur += rc;
}
if (addr_info_node_cname.node->ai_next == nullptr) {
const u32 value = 0;
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
rc = cur - dst;
return rc;
}
template<typename T> requires IsAresAddrInfo<T>
ssize_t ToBufferImpl(u8 * const dst, size_t dst_size, const T &in) {
ssize_t rc = -1;
u8 *cur = dst;
std::memset(dst, 0, dst_size);
const size_t required = DNSSerializer::SizeOf(in);
if ((rc = DNSSerializer::CheckToBufferArguments(cur, dst_size, required, __LINE__)) == -1) {
return rc;
}
AddrInfoNodeCname addr_info_node_cname;
const T *ares_addr_info = std::addressof(in);
if (ares_addr_info->cnames != nullptr) {
const struct ams::socket::ares_addrinfo_cname *ares_addr_info_cname;
for (ares_addr_info_cname = ares_addr_info->cnames; ares_addr_info_cname->next != nullptr; ares_addr_info_cname = ares_addr_info_cname->next) {
/* Do nothing. */
}
addr_info_node_cname.ai_canonname = ares_addr_info_cname->name;
} else {
addr_info_node_cname.ai_canonname = ares_addr_info->name;
}
for (struct ams::socket::ares_addrinfo_node *ares_addr_info_node = ares_addr_info->nodes; ares_addr_info_node != nullptr; ares_addr_info_node = ares_addr_info_node->ai_next) {
addr_info_node_cname.node = ares_addr_info_node;
if ((rc = ToBufferInternalImpl(cur, dst_size, addr_info_node_cname)) == -1) {
return rc;
}
addr_info_node_cname.ai_canonname = nullptr;
cur += rc;
}
rc = cur - dst;
return rc;
}
template<typename T> requires IsAresAddrInfoHints<T>
ssize_t ToBufferImpl(u8 * const dst, size_t dst_size, const T &in) {
ssize_t rc = -1;
u8 *cur = dst;
const size_t required = DNSSerializer::SizeOf(in);
if (dst_size < required) {
return rc;
}
{
const u32 value = AresMagic;
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(in.ai_flags);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(in.ai_family);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(in.ai_socktype);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
{
const u32 value = static_cast<u32>(in.ai_protocol);
if ((rc = DNSSerializer::ToBuffer(cur, dst_size - (cur - dst), value)) == -1) {
return rc;
}
cur += rc;
}
return rc;
}
template<typename T> requires IsAresAddrInfoHints<T>
ssize_t FromBufferImpl(T &out, const u8 *src, size_t src_size) {
ssize_t rc = 0;
const u8 *cur = src;
const size_t required = DNSSerializer::SizeOf(out);
if (src_size < required) {
ams::socket::SetLastError(ams::socket::Errno::ENoSpc);
rc = -1;
return rc;
}
std::memset(std::addressof(out), 0, sizeof(out));
u32 tmp_value;
{
if ((rc = DNSSerializer::FromBuffer(tmp_value, cur, src_size - (cur - src))) == -1) {
return rc;
} else if (tmp_value != AresMagic) {
return rc;
}
cur += rc;
}
{
if ((rc = DNSSerializer::FromBuffer(tmp_value, cur, src_size - (cur - src))) == -1) {
return rc;
}
out.ai_flags = static_cast<decltype(out.ai_flags)>(tmp_value);
cur += rc;
}
{
if ((rc = DNSSerializer::FromBuffer(tmp_value, cur, src_size - (cur - src))) == -1) {
return rc;
}
out.ai_family = static_cast<decltype(out.ai_family)>(tmp_value);
cur += rc;
}
{
if ((rc = DNSSerializer::FromBuffer(tmp_value, cur, src_size - (cur - src))) == -1) {
return rc;
}
out.ai_socktype = static_cast<decltype(out.ai_socktype)>(tmp_value);
cur += rc;
}
{
if ((rc = DNSSerializer::FromBuffer(tmp_value, cur, src_size - (cur - src))) == -1) {
return rc;
}
out.ai_protocol = static_cast<decltype(out.ai_protocol)>(tmp_value);
cur += rc;
}
rc = cur - src;
return rc;
}
}
template<> size_t DNSSerializer::SizeOf(const struct ams::socket::ares_addrinfo &in) {
return SizeOfImpl(in);
}
template<> size_t DNSSerializer::SizeOf(const struct ams::socket::ares_addrinfo_hints &in) {
return SizeOfImpl(in);
}
/* NOTE: DNSSerializer::FromBuffer doesn't exist for ares_addrinfo, only DNSSerializer::ToBuffer does. */
/* Official software pairs it with the old addrinfo DNSSerializer::FromBuffer instead. */
template<> ssize_t DNSSerializer::ToBuffer(u8 * const dst, size_t dst_size, const struct ams::socket::ares_addrinfo &in) {
return ToBufferImpl(dst, dst_size, in);
}
template<> ssize_t DNSSerializer::ToBuffer(u8 * const dst, size_t dst_size, const struct ams::socket::ares_addrinfo_hints &in) {
return ToBufferImpl(dst, dst_size, in);
}
template<> ssize_t DNSSerializer::FromBuffer(struct ams::socket::ares_addrinfo_hints &out, const u8 *src, size_t src_size) {
return FromBufferImpl(out, src, src_size);
}
}
@@ -55,8 +55,9 @@ namespace ams::mitm::socket::resolver::serializer {
rc += DNSSerializer::SizeOf((const char **)(in.h_aliases), dummy); rc += DNSSerializer::SizeOf((const char **)(in.h_aliases), dummy);
rc += sizeof(u32); rc += sizeof(u32);
rc += sizeof(u32); rc += sizeof(u32);
rc += DNSSerializer::SizeOf((const InAddrType<T> **)(in.h_addr_list), dummy); if (IsAfInet<T>(in.h_addrtype)) {
rc += DNSSerializer::SizeOf((const InAddrType<T> **)(in.h_addr_list), dummy);
}
return rc; return rc;
} }
@@ -150,7 +151,16 @@ namespace ams::mitm::socket::resolver::serializer {
cur += rc; cur += rc;
InAddrType<T> **addrs = nullptr; InAddrType<T> **addrs = nullptr;
if ((rc = DNSSerializer::FromBuffer(addrs, cur, src_size - (cur - src))) == -1) { if (IsAfInet<T>(out.h_addrtype)) {
if ((rc = DNSSerializer::FromBuffer(addrs, cur, src_size - (cur - src))) == -1) {
return rc;
}
} else if (IsAfInet6<T>(out.h_addrtype)) {
if ((rc = DNSSerializer::FromBuffer(addrs, cur, src_size - (cur - src))) == -1) {
return rc;
}
} else {
rc = -1;
return rc; return rc;
} }
out.h_addr_list = (char **)addrs; out.h_addr_list = (char **)addrs;
@@ -159,6 +159,7 @@ namespace ams::mitm::socket::resolver::serializer {
out = static_cast<T **>(ams::socket::impl::Alloc((count + 1) * sizeof(T *))); out = static_cast<T **>(ams::socket::impl::Alloc((count + 1) * sizeof(T *)));
if (out == nullptr) { if (out == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -167,6 +168,7 @@ namespace ams::mitm::socket::resolver::serializer {
for (u32 i = 0; i < count; ++i) { for (u32 i = 0; i < count; ++i) {
out[i] = static_cast<T *>(ams::socket::impl::Alloc(sizeof(T))); out[i] = static_cast<T *>(ams::socket::impl::Alloc(sizeof(T)));
if (out[i] == nullptr) { if (out[i] == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -31,7 +31,7 @@ namespace ams::mitm::socket::resolver::serializer {
rc += sizeof(u16); rc += sizeof(u16);
rc += sizeof(u16); rc += sizeof(u16);
rc += sizeof(u32); rc += sizeof(u32);
rc += DNSSerializer::SizeOf(in.sin6_addr); rc += sizeof(in.sin6_addr); /* NOTE: There is no DNSSerializer::SizeOf for in6_addr. */
rc += sizeof(u32); rc += sizeof(u32);
return rc; return rc;
} }
@@ -76,6 +76,7 @@ namespace ams::mitm::socket::resolver::serializer {
out = static_cast<char *>(ams::socket::impl::Alloc(len)); out = static_cast<char *>(ams::socket::impl::Alloc(len));
if (out == nullptr) { if (out == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
return -1; return -1;
} }
@@ -152,6 +153,7 @@ namespace ams::mitm::socket::resolver::serializer {
out = static_cast<char **>(ams::socket::impl::Alloc((count + 1) * sizeof(char *))); out = static_cast<char **>(ams::socket::impl::Alloc((count + 1) * sizeof(char *)));
if (out == nullptr) { if (out == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -162,6 +164,7 @@ namespace ams::mitm::socket::resolver::serializer {
const size_t len = std::strlen(reinterpret_cast<const char *>(cur)); const size_t len = std::strlen(reinterpret_cast<const char *>(cur));
out[i] = static_cast<char *>(ams::socket::impl::Alloc(len + 1)); out[i] = static_cast<char *>(ams::socket::impl::Alloc(len + 1));
if (out[i] == nullptr) { if (out[i] == nullptr) {
ams::socket::SetLastError(ams::socket::Errno::ENoMem);
rc = -1; rc = -1;
return rc; return rc;
} }
@@ -95,3 +95,106 @@ Result sfdnsresGetAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, cons
return rc; return rc;
} }
Result sfdnsresReportTelemetryFwd(Service *s, u64 process_id, const void *telemetry, size_t telemetry_size, u32 version) {
const struct {
u32 version;
u32 padding;
u64 process_id;
} in = { version, 0, process_id };
return serviceMitmDispatchIn(s, 16, in,
.buffer_attrs = {
SfBufferAttr_HipcAutoSelect | SfBufferAttr_In
},
.buffers = {
{ telemetry, telemetry_size }
},
.in_send_pid = true,
.override_pid = process_id,
);
}
Result sfdnsresQueryAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, const void *node, size_t node_size, const void *srv, size_t srv_size, const void *hint, size_t hint_size, u32 *out_query_id, u32 fd, u32 options_version, const void *option, size_t option_size, u32 num_options, s32 *out_rv, s32 *out_errno) {
const struct {
u32 fd;
u32 options_version;
u32 num_options;
u32 padding;
u64 process_id;
} in = { fd, options_version, num_options, 0, process_id };
struct {
u32 query_id;
s32 rv;
s32 errno;
} out;
Result rc = serviceMitmDispatchInOut(s, 100, in, out,
.buffer_attrs = {
SfBufferAttr_HipcAutoSelect | SfBufferAttr_In,
SfBufferAttr_HipcAutoSelect | SfBufferAttr_In,
SfBufferAttr_HipcAutoSelect | SfBufferAttr_In,
SfBufferAttr_HipcAutoSelect | SfBufferAttr_In
},
.buffers = {
{ node, node_size },
{ srv, srv_size },
{ hint, hint_size },
{ option, option_size }
},
.in_send_pid = true,
.override_pid = process_id,
);
if (R_SUCCEEDED(rc)) {
if (out_query_id) *out_query_id = out.query_id;
if (out_rv) *out_rv = out.rv;
if (out_errno) *out_errno = out.errno;
}
return rc;
}
Result sfdnsresFetchAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, u32 query_id, u32 version, void *out_ai, size_t out_ai_size, u32 *out_size, s32 *out_rv, s32 *out_errno) {
const struct {
u32 query_id;
u32 version;
u64 process_id;
} in = { query_id, version, process_id };
struct {
u32 size;
s32 rv;
s32 errno;
} out;
Result rc = serviceMitmDispatchInOut(s, 102, in, out,
.buffer_attrs = {
SfBufferAttr_HipcAutoSelect | SfBufferAttr_Out
},
.buffers = {
{ out_ai, out_ai_size }
},
.in_send_pid = true,
.override_pid = process_id,
);
if (R_SUCCEEDED(rc)) {
if (out_size) *out_size = out.size;
if (out_rv) *out_rv = out.rv;
if (out_errno) *out_errno = out.errno;
}
return rc;
}
Result sfdnsresCancelQueryFwd(Service *s, u64 process_id, u32 query_id) {
const struct {
u32 query_id;
u32 padding;
u64 process_id;
} in = { query_id, 0, process_id };
return serviceMitmDispatchIn(s, 104, in,
.in_send_pid = true,
.override_pid = process_id,
);
}
@@ -16,6 +16,14 @@ Result sfdnsresGetHostByNameRequestWithOptionsFwd(Service *s, u64 process_id, co
Result sfdnsresGetAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, const void *node, size_t node_size, const void *srv, size_t srv_size, const void *hint, size_t hint_size, void *out_ai, size_t out_ai_size, u32 *out_size, s32 *out_rv, u32 options_version, const void *option, size_t option_size, u32 num_options, s32 *out_host_error, s32 *out_errno); Result sfdnsresGetAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, const void *node, size_t node_size, const void *srv, size_t srv_size, const void *hint, size_t hint_size, void *out_ai, size_t out_ai_size, u32 *out_size, s32 *out_rv, u32 options_version, const void *option, size_t option_size, u32 num_options, s32 *out_host_error, s32 *out_errno);
Result sfdnsresReportTelemetryFwd(Service *s, u64 process_id, const void *telemetry, size_t telemetry_size, u32 version);
Result sfdnsresQueryAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, const void *node, size_t node_size, const void *srv, size_t srv_size, const void *hint, size_t hint_size, u32 *out_query_id, u32 fd, u32 options_version, const void *option, size_t option_size, u32 num_options, s32 *out_rv, s32 *out_errno);
Result sfdnsresFetchAddrInfoRequestWithOptionsFwd(Service *s, u64 process_id, u32 query_id, u32 version, void *out_ai, size_t out_ai_size, u32 *out_size, s32 *out_rv, s32 *out_errno);
Result sfdnsresCancelQueryFwd(Service *s, u64 process_id, u32 query_id);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@@ -68,6 +68,11 @@ namespace ams::mitm::fs {
return sf::CreateSharedObjectEmplaced<ams::fssrv::sf::IStorage, ams::fssrv::impl::StorageInterfaceAdapter>(std::forward<Arguments>(args)...); return sf::CreateSharedObjectEmplaced<ams::fssrv::sf::IStorage, ams::fssrv::impl::StorageInterfaceAdapter>(std::forward<Arguments>(args)...);
} }
template<typename... Arguments>
constexpr ALWAYS_INLINE auto MakeSharedStorageForBatchRead(Arguments &&... args) {
return sf::CreateSharedObjectEmplaced<ams::fssrv::sf::IStorageForBatchRead, ams::fssrv::impl::StorageInterfaceAdapterForBatchRead>(std::forward<Arguments>(args)...);
}
Result OpenHblWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId program_id) { Result OpenHblWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId program_id) {
/* Verify eligibility. */ /* Verify eligibility. */
bool is_hbl; bool is_hbl;
@@ -94,7 +99,7 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result OpenProgramSpecificWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id) { Result OpenProgramSpecificWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool with_attributes) {
/* Directory must exist. */ /* Directory must exist. */
R_UNLESS(HasSdManualHtmlContent(program_id), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(HasSdManualHtmlContent(program_id), sm::mitm::ResultShouldForwardToSession());
@@ -121,8 +126,10 @@ namespace ams::mitm::fs {
/* Try to open the existing fs. */ /* Try to open the existing fs. */
FsFileSystem base_fs; FsFileSystem base_fs;
bool opened_base_fs = false; bool opened_base_fs = false;
if (with_id) { if (with_attributes) {
opened_base_fs = R_SUCCEEDED(fsOpenFileSystemWithIdFwd(fwd, std::addressof(base_fs), static_cast<u64>(program_id), filesystem_type, path->str)); opened_base_fs = R_SUCCEEDED(fsOpenFileSystemWithIdFwd(fwd, std::addressof(base_fs), path->str, FsContentAttributes_None, static_cast<u64>(program_id), filesystem_type));
} else if (with_id) {
opened_base_fs = R_SUCCEEDED(fsOpenFileSystemWithIdObsoleteFwd(fwd, std::addressof(base_fs), path->str, static_cast<u64>(program_id), filesystem_type));
} else { } else {
opened_base_fs = R_SUCCEEDED(fsOpenFileSystemWithPatchFwd(fwd, std::addressof(base_fs), static_cast<u64>(program_id), filesystem_type)); opened_base_fs = R_SUCCEEDED(fsOpenFileSystemWithPatchFwd(fwd, std::addressof(base_fs), static_cast<u64>(program_id), filesystem_type));
} }
@@ -141,7 +148,7 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result OpenWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool try_program_specific) { Result OpenWebContentFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> &out, ncm::ProgramId client_program_id, ncm::ProgramId program_id, FsFileSystemType filesystem_type, Service *fwd, const fssrv::sf::Path *path, bool with_id, bool with_attributes, bool try_program_specific) {
/* Check first that we're a web applet opening web content. */ /* Check first that we're a web applet opening web content. */
R_UNLESS(ncm::IsWebAppletId(client_program_id), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(ncm::IsWebAppletId(client_program_id), sm::mitm::ResultShouldForwardToSession());
R_UNLESS(filesystem_type == FsFileSystemType_ContentManual, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(filesystem_type == FsFileSystemType_ContentManual, sm::mitm::ResultShouldForwardToSession());
@@ -153,7 +160,7 @@ namespace ams::mitm::fs {
R_UNLESS(try_program_specific, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(try_program_specific, sm::mitm::ResultShouldForwardToSession());
/* If we're not opening a HBL filesystem, just try to open a generic one. */ /* If we're not opening a HBL filesystem, just try to open a generic one. */
R_RETURN(OpenProgramSpecificWebContentFileSystem(out, program_id, filesystem_type, fwd, path, with_id)); R_RETURN(OpenProgramSpecificWebContentFileSystem(out, program_id, filesystem_type, fwd, path, with_id, with_attributes));
} }
} }
@@ -169,12 +176,17 @@ namespace ams::mitm::fs {
} }
} }
Result FsMitmService::OpenFileSystemWithPatch(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 _filesystem_type) { Result FsMitmService::OpenFileSystemWithPatch(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 file_system_proxy_type) {
R_RETURN(OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), m_forward_service.get(), nullptr, false, m_client_info.override_status.IsProgramSpecific())); R_RETURN(OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(file_system_proxy_type), m_forward_service.get(), nullptr, false, false, m_client_info.override_status.IsProgramSpecific()));
} }
Result FsMitmService::OpenFileSystemWithId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type) { Result FsMitmService::OpenFileSystemWithIdObsolete(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 file_system_proxy_type) {
R_RETURN(OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(_filesystem_type), m_forward_service.get(), std::addressof(path), true, m_client_info.override_status.IsProgramSpecific())); R_RETURN(OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(file_system_proxy_type), m_forward_service.get(), std::addressof(path), true, false, m_client_info.override_status.IsProgramSpecific()));
}
Result FsMitmService::OpenFileSystemWithId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, u8 content_attributes, ncm::ProgramId program_id, u32 file_system_proxy_type) {
AMS_UNUSED(content_attributes);
R_RETURN(OpenWebContentFileSystem(out, m_client_info.program_id, program_id, static_cast<FsFileSystemType>(file_system_proxy_type), m_forward_service.get(), std::addressof(path), true, true, m_client_info.override_status.IsProgramSpecific()));
} }
Result FsMitmService::OpenSdCardFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out) { Result FsMitmService::OpenSdCardFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out) {
@@ -195,7 +207,7 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { Result FsMitmService::OpenSaveDataFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 space_id, const fs::SaveDataAttribute &attribute) {
/* We only want to intercept saves for games, right now. */ /* We only want to intercept saves for games, right now. */
const bool is_game_or_hbl = m_client_info.override_status.IsHbl() || ncm::IsApplicationId(m_client_info.program_id); const bool is_game_or_hbl = m_client_info.override_status.IsHbl() || ncm::IsApplicationId(m_client_info.program_id);
R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession());
@@ -210,12 +222,12 @@ namespace ams::mitm::fs {
R_UNLESS(attribute.type == fs::SaveDataType::Account, sm::mitm::ResultShouldForwardToSession()); R_UNLESS(attribute.type == fs::SaveDataType::Account, sm::mitm::ResultShouldForwardToSession());
/* Get enum type for space id. */ /* Get enum type for space id. */
auto space_id = static_cast<FsSaveDataSpaceId>(_space_id); auto _space_id = static_cast<FsSaveDataSpaceId>(space_id);
/* Verify we can open the save. */ /* Verify we can open the save. */
static_assert(sizeof(fs::SaveDataAttribute) == sizeof(::FsSaveDataAttribute)); static_assert(sizeof(fs::SaveDataAttribute) == sizeof(::FsSaveDataAttribute));
FsFileSystem save_fs; FsFileSystem save_fs;
R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(m_forward_service.get(), std::addressof(save_fs), space_id, reinterpret_cast<const FsSaveDataAttribute *>(std::addressof(attribute)))), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(m_forward_service.get(), std::addressof(save_fs), _space_id, reinterpret_cast<const FsSaveDataAttribute *>(std::addressof(attribute)))), sm::mitm::ResultShouldForwardToSession());
std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs); std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs);
/* Mount the SD card using fs.mitm's session. */ /* Mount the SD card using fs.mitm's session. */
@@ -228,7 +240,7 @@ namespace ams::mitm::fs {
const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? m_client_info.program_id : attribute.program_id; const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? m_client_info.program_id : attribute.program_id;
char save_dir_raw_path[0x100]; char save_dir_raw_path[0x100];
R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_raw_path, sizeof(save_dir_raw_path), application_id, space_id, attribute)); R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_raw_path, sizeof(save_dir_raw_path), application_id, _space_id, attribute));
ams::fs::Path save_dir_path; ams::fs::Path save_dir_path;
R_TRY(save_dir_path.SetShallowBuffer(save_dir_raw_path)); R_TRY(save_dir_path.SetShallowBuffer(save_dir_raw_path));
@@ -270,12 +282,12 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result FsMitmService::OpenBisStorage(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 _bis_partition_id) { Result FsMitmService::OpenBisStorage(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 bis_partition_id) {
const ::FsBisPartitionId bis_partition_id = static_cast<::FsBisPartitionId>(_bis_partition_id); const ::FsBisPartitionId _bis_partition_id = static_cast<::FsBisPartitionId>(bis_partition_id);
/* Try to open a storage for the partition. */ /* Try to open a storage for the partition. */
FsStorage bis_storage; FsStorage bis_storage;
R_TRY(fsOpenBisStorageFwd(m_forward_service.get(), std::addressof(bis_storage), bis_partition_id)); R_TRY(fsOpenBisStorageFwd(m_forward_service.get(), std::addressof(bis_storage), _bis_partition_id));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(bis_storage.s))}; const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(bis_storage.s))};
const bool is_sysmodule = ncm::IsSystemProgramId(m_client_info.program_id); const bool is_sysmodule = ncm::IsSystemProgramId(m_client_info.program_id);
@@ -285,18 +297,18 @@ namespace ams::mitm::fs {
/* Allow HBL to write to boot1 (safe firm) + package2. */ /* Allow HBL to write to boot1 (safe firm) + package2. */
/* This is needed to not break compatibility with ChoiDujourNX, which does not check for write access before beginning an update. */ /* This is needed to not break compatibility with ChoiDujourNX, which does not check for write access before beginning an update. */
/* TODO: get fixed so that this can be turned off without causing bricks :/ */ /* TODO: get fixed so that this can be turned off without causing bricks :/ */
const bool is_package2 = (FsBisPartitionId_BootConfigAndPackage2Part1 <= bis_partition_id && bis_partition_id <= FsBisPartitionId_BootConfigAndPackage2Part6); const bool is_package2 = (FsBisPartitionId_BootConfigAndPackage2Part1 <= _bis_partition_id && _bis_partition_id <= FsBisPartitionId_BootConfigAndPackage2Part6);
const bool is_boot1 = bis_partition_id == FsBisPartitionId_BootPartition2Root; const bool is_boot1 = _bis_partition_id == FsBisPartitionId_BootPartition2Root;
const bool can_write_bis_for_choi_support = is_hbl && (is_package2 || is_boot1); const bool can_write_bis_for_choi_support = is_hbl && (is_package2 || is_boot1);
/* Set output storage. */ /* Set output storage. */
if (bis_partition_id == FsBisPartitionId_BootPartition1Root) { if (_bis_partition_id == FsBisPartitionId_BootPartition1Root) {
if (IsBoot0CustomPublicKey(bis_storage)) { if (IsBoot0CustomPublicKey(bis_storage)) {
out.SetValue(MakeSharedStorage(std::make_shared<CustomPublicKeyBoot0Storage>(bis_storage, m_client_info, spl::GetSocType())), target_object_id); out.SetValue(MakeSharedStorage(std::make_shared<CustomPublicKeyBoot0Storage>(bis_storage, m_client_info, spl::GetSocType())), target_object_id);
} else { } else {
out.SetValue(MakeSharedStorage(std::make_shared<Boot0Storage>(bis_storage, m_client_info)), target_object_id); out.SetValue(MakeSharedStorage(std::make_shared<Boot0Storage>(bis_storage, m_client_info)), target_object_id);
} }
} else if (bis_partition_id == FsBisPartitionId_CalibrationBinary) { } else if (_bis_partition_id == FsBisPartitionId_CalibrationBinary) {
out.SetValue(MakeSharedStorage(std::make_shared<CalibrationBinaryStorage>(bis_storage, m_client_info)), target_object_id); out.SetValue(MakeSharedStorage(std::make_shared<CalibrationBinaryStorage>(bis_storage, m_client_info)), target_object_id);
} else { } else {
if (can_write_bis || can_write_bis_for_choi_support) { if (can_write_bis || can_write_bis_for_choi_support) {
@@ -329,23 +341,40 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result FsMitmService::OpenDataStorageByDataId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId _data_id, u8 storage_id) { Result FsMitmService::OpenDataStorageByProgramId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::ProgramId program_id) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* Only mitm if there is actually an override romfs for the target program. */
R_UNLESS(mitm::fs::HasSdRomfsContent(program_id), sm::mitm::ResultShouldForwardToSession());
/* Try to open the program romfs. */
FsStorage data_storage;
R_TRY(fsOpenDataStorageByProgramIdFwd(m_forward_service.get(), std::addressof(data_storage), static_cast<u64>(program_id)));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
/* Get a layered storage for the program romfs. */
out.SetValue(MakeSharedStorage(GetLayeredRomfsStorage(program_id, data_storage, true)), target_object_id);
R_SUCCEED();
}
Result FsMitmService::OpenDataStorageByDataId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId data_id, u8 storage_id) {
/* Only mitm if we should override contents for the current process. */ /* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* TODO: Decide how to handle DataId vs ProgramId for this API. */ /* TODO: Decide how to handle DataId vs ProgramId for this API. */
const ncm::ProgramId data_id = {_data_id.value}; const ncm::ProgramId program_or_data_id = {data_id.value};
/* Only mitm if there is actually an override romfs. */ /* Only mitm if there is actually an override romfs. */
R_UNLESS(mitm::fs::HasSdRomfsContent(data_id), sm::mitm::ResultShouldForwardToSession()); R_UNLESS(mitm::fs::HasSdRomfsContent(program_or_data_id), sm::mitm::ResultShouldForwardToSession());
/* Try to open the data id. */ /* Try to open the data id. */
FsStorage data_storage; FsStorage data_storage;
R_TRY(fsOpenDataStorageByDataIdFwd(m_forward_service.get(), std::addressof(data_storage), static_cast<u64>(data_id), static_cast<NcmStorageId>(storage_id))); R_TRY(fsOpenDataStorageByDataIdFwd(m_forward_service.get(), std::addressof(data_storage), static_cast<u64>(program_or_data_id), static_cast<NcmStorageId>(storage_id)));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))}; const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
/* Get a layered storage for the data id. */ /* Get a layered storage for the data id. */
out.SetValue(MakeSharedStorage(GetLayeredRomfsStorage(data_id, data_storage, false)), target_object_id); out.SetValue(MakeSharedStorage(GetLayeredRomfsStorage(program_or_data_id, data_storage, false)), target_object_id);
R_SUCCEED(); R_SUCCEED();
} }
@@ -370,6 +399,79 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result FsMitmService::OpenDataStorageByPath(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* TODO */
AMS_UNUSED(out, path, content_attributes, file_system_proxy_type);
R_SUCCEED();
}
Result FsMitmService::OpenDataStorageByCurrentProcessForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* Only mitm if there is actually an override romfs. */
R_UNLESS(mitm::fs::HasSdRomfsContent(m_client_info.program_id), sm::mitm::ResultShouldForwardToSession());
/* Try to open the process romfs. */
FsStorageForBatchRead data_storage;
R_TRY(fsOpenDataStorageByCurrentProcessForBatchReadFwd(m_forward_service.get(), std::addressof(data_storage)));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
/* Get a layered storage for the program romfs (batch read variant). */
out.SetValue(MakeSharedStorageForBatchRead(GetLayeredRomfsStorageForBatchRead(m_client_info.program_id, data_storage, true)), target_object_id);
R_SUCCEED();
}
Result FsMitmService::OpenDataStorageByProgramIdForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, ncm::ProgramId program_id) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* Only mitm if there is actually an override romfs for the target program. */
R_UNLESS(mitm::fs::HasSdRomfsContent(program_id), sm::mitm::ResultShouldForwardToSession());
/* Try to open the program romfs. */
FsStorageForBatchRead data_storage;
R_TRY(fsOpenDataStorageByProgramIdForBatchReadFwd(m_forward_service.get(), std::addressof(data_storage), static_cast<u64>(program_id)));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
/* Get a layered storage for the program romfs (batch read variant). */
out.SetValue(MakeSharedStorageForBatchRead(GetLayeredRomfsStorageForBatchRead(program_id, data_storage, true)), target_object_id);
R_SUCCEED();
}
Result FsMitmService::OpenDataStorageWithProgramIndexForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, u8 program_index) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* Get the relevant program id. */
const ncm::ProgramId program_id = g_program_index_map_info_manager.GetProgramId(m_client_info.program_id, program_index);
/* If we don't know about the program or don't have content, forward. */
R_UNLESS(program_id != ncm::InvalidProgramId, sm::mitm::ResultShouldForwardToSession());
R_UNLESS(mitm::fs::HasSdRomfsContent(program_id), sm::mitm::ResultShouldForwardToSession());
/* Try to open the process romfs. */
FsStorageForBatchRead data_storage;
R_TRY(fsOpenDataStorageWithProgramIndexForBatchReadFwd(m_forward_service.get(), std::addressof(data_storage), program_index));
const sf::cmif::DomainObjectId target_object_id{serviceGetObjectId(std::addressof(data_storage.s))};
/* Get a layered storage for the program romfs (batch read variant). */
out.SetValue(MakeSharedStorageForBatchRead(GetLayeredRomfsStorageForBatchRead(program_id, data_storage, true)), target_object_id);
R_SUCCEED();
}
Result FsMitmService::OpenDataStorageByPathForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type) {
/* Only mitm if we should override contents for the current process. */
R_UNLESS(m_client_info.override_status.IsProgramSpecific(), sm::mitm::ResultShouldForwardToSession());
/* TODO */
AMS_UNUSED(out, path, content_attributes, file_system_proxy_type);
R_SUCCEED();
}
Result FsMitmService::RegisterProgramIndexMapInfo(const sf::InBuffer &info_buffer, s32 info_count) { Result FsMitmService::RegisterProgramIndexMapInfo(const sf::InBuffer &info_buffer, s32 info_count) {
/* Try to register with FS. */ /* Try to register with FS. */
R_TRY(fsRegisterProgramIndexMapInfoFwd(m_forward_service.get(), info_buffer.GetPointer(), info_buffer.GetSize(), info_count)); R_TRY(fsRegisterProgramIndexMapInfoFwd(m_forward_service.get(), info_buffer.GetPointer(), info_buffer.GetSize(), info_count));
@@ -17,16 +17,23 @@
#include <stratosphere.hpp> #include <stratosphere.hpp>
#include <stratosphere/fssrv/fssrv_interface_adapters.hpp> #include <stratosphere/fssrv/fssrv_interface_adapters.hpp>
#define AMS_FS_MITM_INTERFACE_INFO(C, H) \ #define AMS_FS_MITM_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 7, Result, OpenFileSystemWithPatch, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 _filesystem_type), (out, program_id, _filesystem_type), hos::Version_2_0_0) \ AMS_SF_METHOD_INFO(C, H, 7, Result, OpenFileSystemWithPatch, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 file_system_proxy_type), (out, program_id, file_system_proxy_type), hos::Version_2_0_0) \
AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFileSystemWithId, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type), (out, path, program_id, _filesystem_type), hos::Version_2_0_0) \ AMS_SF_METHOD_INFO(C, H, 8, Result, OpenFileSystemWithIdObsolete, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 file_system_proxy_type), (out, path, program_id, file_system_proxy_type), hos::Version_2_0_0) \
AMS_SF_METHOD_INFO(C, H, 18, Result, OpenSdCardFileSystem, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out), (out)) \ AMS_SF_METHOD_INFO(C, H, 10, Result, OpenFileSystemWithId, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, u8 content_attributes, ncm::ProgramId program_id, u32 file_system_proxy_type), (out, path, content_attributes, program_id, file_system_proxy_type), hos::Version_16_0_0) \
AMS_SF_METHOD_INFO(C, H, 51, Result, OpenSaveDataFileSystem, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute), (out, space_id, attribute)) \ AMS_SF_METHOD_INFO(C, H, 18, Result, OpenSdCardFileSystem, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 12, Result, OpenBisStorage, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 bis_partition_id), (out, bis_partition_id)) \ AMS_SF_METHOD_INFO(C, H, 51, Result, OpenSaveDataFileSystem, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute), (out, space_id, attribute)) \
AMS_SF_METHOD_INFO(C, H, 200, Result, OpenDataStorageByCurrentProcess, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out), (out)) \ AMS_SF_METHOD_INFO(C, H, 12, Result, OpenBisStorage, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 bis_partition_id), (out, bis_partition_id)) \
AMS_SF_METHOD_INFO(C, H, 202, Result, OpenDataStorageByDataId, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId data_id, u8 storage_id), (out, data_id, storage_id)) \ AMS_SF_METHOD_INFO(C, H, 200, Result, OpenDataStorageByCurrentProcess, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out), (out)) \
AMS_SF_METHOD_INFO(C, H, 205, Result, OpenDataStorageWithProgramIndex, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u8 program_index), (out, program_index), hos::Version_7_0_0) \ AMS_SF_METHOD_INFO(C, H, 201, Result, OpenDataStorageByProgramId, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::ProgramId program_id), (out, program_id), hos::Version_3_0_0) \
AMS_SF_METHOD_INFO(C, H, 810, Result, RegisterProgramIndexMapInfo, (const sf::InBuffer &info_buffer, s32 info_count), (info_buffer, info_count), hos::Version_7_0_0) AMS_SF_METHOD_INFO(C, H, 202, Result, OpenDataStorageByDataId, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId data_id, u8 storage_id), (out, data_id, storage_id)) \
AMS_SF_METHOD_INFO(C, H, 205, Result, OpenDataStorageWithProgramIndex, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u8 program_index), (out, program_index), hos::Version_7_0_0) \
AMS_SF_METHOD_INFO(C, H, 206, Result, OpenDataStorageByPath, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type), (out, path, content_attributes, file_system_proxy_type), hos::Version_13_0_0) \
AMS_SF_METHOD_INFO(C, H, 210, Result, OpenDataStorageByCurrentProcessForBatchRead, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out), (out), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 211, Result, OpenDataStorageByProgramIdForBatchRead, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, ncm::ProgramId program_id), (out, program_id), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 212, Result, OpenDataStorageWithProgramIndexForBatchRead, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, u8 program_index), (out, program_index), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 213, Result, OpenDataStorageByPathForBatchRead, (sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type), (out, path, content_attributes, file_system_proxy_type), hos::Version_23_0_0) \
AMS_SF_METHOD_INFO(C, H, 810, Result, RegisterProgramIndexMapInfo, (const sf::InBuffer &info_buffer, s32 info_count), (info_buffer, info_count), hos::Version_7_0_0)
AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::fs, IFsMitmInterface, AMS_FS_MITM_INTERFACE_INFO, 0x7DF34ED2) AMS_SF_DEFINE_MITM_INTERFACE(ams::mitm::fs, IFsMitmInterface, AMS_FS_MITM_INTERFACE_INFO, 0x7DF34ED2)
@@ -77,14 +84,21 @@ namespace ams::mitm::fs {
} }
public: public:
/* Overridden commands. */ /* Overridden commands. */
Result OpenFileSystemWithPatch(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 _filesystem_type); Result OpenFileSystemWithPatch(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, ncm::ProgramId program_id, u32 file_system_proxy_type);
Result OpenFileSystemWithId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); Result OpenFileSystemWithIdObsolete(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 file_system_proxy_type);
Result OpenFileSystemWithId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, const fssrv::sf::Path &path, u8 content_attributes, ncm::ProgramId program_id, u32 file_system_proxy_type);
Result OpenSdCardFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out); Result OpenSdCardFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out);
Result OpenSaveDataFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); Result OpenSaveDataFileSystem(sf::Out<sf::SharedPointer<ams::fssrv::sf::IFileSystem>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute);
Result OpenBisStorage(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 bis_partition_id); Result OpenBisStorage(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u32 bis_partition_id);
Result OpenDataStorageByCurrentProcess(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out); Result OpenDataStorageByCurrentProcess(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out);
Result OpenDataStorageByProgramId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::ProgramId program_id);
Result OpenDataStorageByDataId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId data_id, u8 storage_id); Result OpenDataStorageByDataId(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, ncm::DataId data_id, u8 storage_id);
Result OpenDataStorageWithProgramIndex(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u8 program_index); Result OpenDataStorageWithProgramIndex(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, u8 program_index);
Result OpenDataStorageByPath(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorage>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type);
Result OpenDataStorageByCurrentProcessForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out);
Result OpenDataStorageByProgramIdForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, ncm::ProgramId program_id);
Result OpenDataStorageWithProgramIndexForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, u8 program_index);
Result OpenDataStorageByPathForBatchRead(sf::Out<sf::SharedPointer<ams::fssrv::sf::IStorageForBatchRead>> out, const fssrv::sf::Path &path, u8 content_attributes, u32 file_system_proxy_type);
Result RegisterProgramIndexMapInfo(const sf::InBuffer &info_buffer, s32 info_count); Result RegisterProgramIndexMapInfo(const sf::InBuffer &info_buffer, s32 info_count);
}; };
static_assert(IsIFsMitmInterface<FsMitmService>); static_assert(IsIFsMitmInterface<FsMitmService>);
+110 -39
View File
@@ -23,8 +23,46 @@ static Result _fsOpenSession(Service *s, Service* out, u32 cmd_id) {
); );
} }
Result fsOpenSdCardFileSystemFwd(Service* s, FsFileSystem* out) { Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType) {
return _fsOpenSession(s, &out->s, 18); const struct {
u32 fsType;
u64 id;
} in = { fsType, id };
return serviceDispatchIn(s, 7, in,
.out_num_objects = 1,
.out_objects = &out->s
);
}
Result fsOpenFileSystemWithIdObsoleteFwd(Service* s, FsFileSystem* out, const char* contentPath, u64 id, FsFileSystemType fsType) {
const struct {
u32 fsType;
u64 id;
} in = { fsType, id };
return serviceDispatchIn(s, 8, in,
.buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize },
.buffers = { { contentPath, FS_MAX_PATH } },
.out_num_objects = 1,
.out_objects = &out->s
);
}
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, const char* contentPath, FsContentAttributes attributes, u64 id, FsFileSystemType fsType) {
const struct {
u8 attributes;
u8 pad[3];
u32 fsType;
u64 id;
} in = { attributes, {0}, fsType, id };
return serviceDispatchIn(s, 10, in,
.buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize },
.buffers = { { contentPath, FS_MAX_PATH } },
.out_num_objects = 1,
.out_objects = &out->s
);
} }
Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisPartitionId partition_id) { Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisPartitionId partition_id) {
@@ -35,10 +73,34 @@ Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisPartitionId partitio
); );
} }
Result fsOpenSdCardFileSystemFwd(Service* s, FsFileSystem* out) {
return _fsOpenSession(s, &out->s, 18);
}
Result fsOpenSaveDataFileSystemFwd(Service* s, FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr) {
const struct {
u8 save_data_space_id;
u8 pad[7];
FsSaveDataAttribute attr;
} in = { (u8)save_data_space_id, {0}, *attr };
return serviceDispatchIn(s, 51, in,
.out_num_objects = 1,
.out_objects = &out->s,
);
}
Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out) { Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out) {
return _fsOpenSession(s, &out->s, 200); return _fsOpenSession(s, &out->s, 200);
} }
Result fsOpenDataStorageByProgramIdFwd(Service* s, FsStorage* out, u64 id) {
return serviceDispatchIn(s, 201, id,
.out_num_objects = 1,
.out_objects = &out->s,
);
}
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorage* out, u64 data_id, NcmStorageId storage_id) { Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorage* out, u64 data_id, NcmStorageId storage_id) {
const struct { const struct {
u8 storage_id; u8 storage_id;
@@ -58,48 +120,57 @@ Result fsOpenDataStorageWithProgramIndexFwd(Service* s, FsStorage* out, u8 progr
); );
} }
Result fsRegisterProgramIndexMapInfoFwd(Service* s, const void *buf, size_t buf_size, s32 count) { Result fsOpenDataStorageByPathFwd(Service* s, FsStorage* out, const char* contentPath, FsContentAttributes attributes, FsFileSystemType fsType) {
return serviceDispatchIn(s, 810, count,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In },
.buffers = { { buf, buf_size } },
);
}
Result fsOpenSaveDataFileSystemFwd(Service* s, FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr) {
const struct {
u8 save_data_space_id;
u8 pad[7];
FsSaveDataAttribute attr;
} in = { (u8)save_data_space_id, {0}, *attr };
return serviceDispatchIn(s, 51, in,
.out_num_objects = 1,
.out_objects = &out->s,
);
}
Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType) {
const struct { const struct {
u8 attributes;
u8 pad[3];
u32 fsType; u32 fsType;
u64 id; } in = { attributes, {0}, fsType };
} in = { fsType, id };
return serviceDispatchIn(s, 7, in, return serviceDispatchIn(s, 206, in,
.out_num_objects = 1, .buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize },
.out_objects = &out->s
);
}
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath) {
const struct {
u32 fsType;
u64 id;
} in = { fsType, id };
return serviceDispatchIn(s, 8, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
.buffers = { { contentPath, FS_MAX_PATH } }, .buffers = { { contentPath, FS_MAX_PATH } },
.out_num_objects = 1, .out_num_objects = 1,
.out_objects = &out->s .out_objects = &out->s
); );
} }
Result fsOpenDataStorageByCurrentProcessForBatchReadFwd(Service* s, FsStorageForBatchRead* out) {
return _fsOpenSession(s, &out->s, 210);
}
Result fsOpenDataStorageByProgramIdForBatchReadFwd(Service* s, FsStorageForBatchRead* out, u64 id) {
return serviceDispatchIn(s, 211, id,
.out_num_objects = 1,
.out_objects = &out->s,
);
}
Result fsOpenDataStorageWithProgramIndexForBatchReadFwd(Service* s, FsStorageForBatchRead* out, u8 program_index) {
return serviceDispatchIn(s, 212, program_index,
.out_num_objects = 1,
.out_objects = &out->s,
);
}
Result fsOpenDataStorageByPathForBatchReadFwd(Service* s, FsStorageForBatchRead* out, const char* contentPath, FsContentAttributes attributes, FsFileSystemType fsType) {
const struct {
u8 attributes;
u8 pad[3];
u32 fsType;
} in = { attributes, {0}, fsType };
return serviceDispatchIn(s, 213, in,
.buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcPointer | SfBufferAttr_FixedSize },
.buffers = { { contentPath, FS_MAX_PATH } },
.out_num_objects = 1,
.out_objects = &out->s
);
}
Result fsRegisterProgramIndexMapInfoFwd(Service* s, const void *buf, size_t buf_size, s32 count) {
return serviceDispatchIn(s, 810, count,
.buffer_attrs = { SfBufferAttr_In | SfBufferAttr_HipcMapAlias },
.buffers = { { buf, buf_size } },
);
}
+17 -9
View File
@@ -12,18 +12,26 @@ extern "C" {
#endif #endif
/* Missing fsp-srv commands. */ /* Missing fsp-srv commands. */
Result fsOpenSdCardFileSystemFwd(Service* s, FsFileSystem* out); Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType);
Result fsOpenFileSystemWithIdObsoleteFwd(Service* s, FsFileSystem* out, const char* contentPath, u64 id, FsFileSystemType fsType);
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, const char* contentPath, FsContentAttributes attributes, u64 id, FsFileSystemType fsType);
Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisPartitionId partition_id); Result fsOpenBisStorageFwd(Service* s, FsStorage* out, FsBisPartitionId partition_id);
Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out); Result fsOpenSdCardFileSystemFwd(Service* s, FsFileSystem* out);
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorage* out, u64 data_id, NcmStorageId storage_id);
Result fsOpenDataStorageWithProgramIndexFwd(Service* s, FsStorage* out, u8 program_index);
Result fsRegisterProgramIndexMapInfoFwd(Service* s, const void *buf, size_t buf_size, s32 count);
Result fsOpenSaveDataFileSystemFwd(Service* s, FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr); Result fsOpenSaveDataFileSystemFwd(Service* s, FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr);
Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType); Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out);
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath); Result fsOpenDataStorageByProgramIdFwd(Service* s, FsStorage* out, u64 id);
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorage* out, u64 data_id, NcmStorageId storage_id);
Result fsOpenDataStorageWithProgramIndexFwd(Service* s, FsStorage* out, u8 program_index);
Result fsOpenDataStorageByPathFwd(Service* s, FsStorage* out, const char* contentPath, FsContentAttributes attributes, FsFileSystemType fsType);
Result fsOpenDataStorageByCurrentProcessForBatchReadFwd(Service* s, FsStorageForBatchRead* out);
Result fsOpenDataStorageByProgramIdForBatchReadFwd(Service* s, FsStorageForBatchRead* out, u64 id);
Result fsOpenDataStorageWithProgramIndexForBatchReadFwd(Service* s, FsStorageForBatchRead* out, u8 program_index);
Result fsOpenDataStorageByPathForBatchReadFwd(Service* s, FsStorageForBatchRead* out, const char* contentPath, FsContentAttributes attributes, FsFileSystemType fsType);
Result fsRegisterProgramIndexMapInfoFwd(Service* s, const void *buf, size_t buf_size, s32 count);
#ifdef __cplusplus #ifdef __cplusplus
@@ -180,34 +180,80 @@ namespace ams::mitm::fs {
CloseReference(m_impl); CloseReference(m_impl);
} }
virtual Result Read(s64 offset, void *buffer, size_t size) override { virtual Result Read(s64 offset, void *buffer, size_t size) override {
R_RETURN(m_impl->Read(offset, buffer, size)); R_RETURN(m_impl->Read(offset, buffer, size));
} }
virtual Result GetSize(s64 *out_size) override {
R_RETURN(m_impl->GetSize(out_size));
}
virtual Result Flush() override {
R_RETURN(m_impl->Flush());
}
virtual Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
R_RETURN(m_impl->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override { virtual Result Write(s64 offset, const void *buffer, size_t size) override {
/* TODO: Better result code? */ /* TODO: Better result code? */
AMS_UNUSED(offset, buffer, size); AMS_UNUSED(offset, buffer, size);
R_THROW(ams::fs::ResultUnsupportedOperation()) R_THROW(ams::fs::ResultUnsupportedOperation())
} }
virtual Result Flush() override {
R_RETURN(m_impl->Flush());
}
virtual Result SetSize(s64 size) override { virtual Result SetSize(s64 size) override {
/* TODO: Better result code? */ /* TODO: Better result code? */
AMS_UNUSED(size); AMS_UNUSED(size);
R_THROW(ams::fs::ResultUnsupportedOperation()) R_THROW(ams::fs::ResultUnsupportedOperation())
} }
virtual Result GetSize(s64 *out_size) override {
R_RETURN(m_impl->GetSize(out_size));
}
virtual Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
R_RETURN(m_impl->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
}
};
class LayeredRomfsStorageForBatchRead : public ams::fs::IStorageForBatchRead {
private:
LayeredRomfsStorageImpl *m_impl;
public:
LayeredRomfsStorageForBatchRead(LayeredRomfsStorageImpl *impl) : m_impl(impl) {
OpenReference(m_impl);
}
virtual ~LayeredRomfsStorageForBatchRead() {
CloseReference(m_impl);
}
virtual Result Read(s64 offset, void *buffer, size_t size) override {
R_RETURN(m_impl->Read(offset, buffer, size));
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
/* TODO: Better result code? */
AMS_UNUSED(offset, buffer, size);
R_THROW(ams::fs::ResultUnsupportedOperation())
}
virtual Result Flush() override {
R_RETURN(m_impl->Flush());
}
virtual Result SetSize(s64 size) override {
/* TODO: Better result code? */
AMS_UNUSED(size);
R_THROW(ams::fs::ResultUnsupportedOperation())
}
virtual Result GetSize(s64 *out_size) override {
R_RETURN(m_impl->GetSize(out_size));
}
virtual Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) override {
R_RETURN(m_impl->OperateRange(dst, dst_size, op_id, offset, size, src, src_size));
}
virtual Result BatchRead(void *out0, void *out1, void *out2, void *out3, void *out4, void *out5, void *out6, const void *in) override {
/* TODO */
AMS_UNUSED(out0, out1, out2, out3, out4, out5, out6, in);
R_THROW(ams::fs::ResultUnsupportedOperation());
}
}; };
} }
@@ -262,6 +308,54 @@ namespace ams::mitm::fs {
return std::make_shared<LayeredRomfsStorage>(impl); return std::make_shared<LayeredRomfsStorage>(impl);
} }
std::shared_ptr<ams::fs::IStorageForBatchRead> GetLayeredRomfsStorageForBatchRead(ncm::ProgramId program_id, ::FsStorageForBatchRead &data_storage, bool is_process_romfs) {
/*Prepare to find or create a new storage. */
LayeredRomfsStorageImpl *impl = nullptr;
{
std::scoped_lock lk(g_storage_set_mutex);
/* Find an existing storage. */
if (auto it = g_storage_set.find_key(program_id.value); it != g_storage_set.end()) {
return std::make_shared<LayeredRomfsStorageForBatchRead>(it->GetImpl());
}
/* We don't have an existing storage. If we're creating process romfs, free any unreferenced process romfs. */
/* This should help prevent too much memory in use at any time. */
if (is_process_romfs) {
auto it = g_storage_set.begin();
while (it != g_storage_set.end()) {
if (it->GetReferenceCount() > 0 || !it->IsProcessRomfs()) {
++it;
} else {
auto *holder = std::addressof(*it);
it = g_storage_set.erase(it);
delete holder;
}
}
}
/* Create a new storage. */
{
::FsFile data_file;
if (R_SUCCEEDED(OpenAtmosphereSdFile(std::addressof(data_file), program_id, "romfs.bin", OpenMode_Read))) {
impl = new LayeredRomfsStorageImpl(std::make_unique<ReadOnlyStorageAdapterForBatchRead>(new RemoteStorageForBatchRead(data_storage)), std::make_unique<ReadOnlyStorageAdapterForBatchRead>(new FileStorage(new RemoteFile(data_file))), program_id);
} else {
impl = new LayeredRomfsStorageImpl(std::make_unique<ReadOnlyStorageAdapterForBatchRead>(new RemoteStorageForBatchRead(data_storage)), nullptr, program_id);
}
}
/* Insert holder. Reference count will now be one. */
g_storage_set.insert(*(new LayeredRomfsStorageHolder(impl, is_process_romfs)));
}
/* Begin initialization. When this finishes, a decref will occur. */
AMS_ABORT_UNLESS(impl != nullptr);
impl->BeginInitialize();
/* Return a new shared storage for the impl. */
return std::make_shared<LayeredRomfsStorageForBatchRead>(impl);
}
void FinalizeLayeredRomfsStorage(ncm::ProgramId program_id) { void FinalizeLayeredRomfsStorage(ncm::ProgramId program_id) {
std::scoped_lock lk(g_initialization_mutex); std::scoped_lock lk(g_initialization_mutex);
std::scoped_lock lk2(g_storage_set_mutex); std::scoped_lock lk2(g_storage_set_mutex);
@@ -393,6 +487,10 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result LayeredRomfsStorageImpl::Flush() {
R_SUCCEED();
}
Result LayeredRomfsStorageImpl::GetSize(s64 *out_size) { Result LayeredRomfsStorageImpl::GetSize(s64 *out_size) {
/* Ensure we're initialized. */ /* Ensure we're initialized. */
if (!m_is_initialized) { if (!m_is_initialized) {
@@ -403,10 +501,6 @@ namespace ams::mitm::fs {
R_SUCCEED(); R_SUCCEED();
} }
Result LayeredRomfsStorageImpl::Flush() {
R_SUCCEED();
}
Result LayeredRomfsStorageImpl::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) { Result LayeredRomfsStorageImpl::OperateRange(void *dst, size_t dst_size, OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
AMS_UNUSED(offset, src, src_size); AMS_UNUSED(offset, src, src_size);
@@ -44,13 +44,13 @@ namespace ams::mitm::fs {
constexpr ncm::ProgramId GetProgramId() const { return m_program_id; } constexpr ncm::ProgramId GetProgramId() const { return m_program_id; }
Result Read(s64 offset, void *buffer, size_t size); Result Read(s64 offset, void *buffer, size_t size);
Result GetSize(s64 *out_size);
Result Flush(); Result Flush();
Result GetSize(s64 *out_size);
Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size); Result OperateRange(void *dst, size_t dst_size, ams::fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size);
}; };
std::shared_ptr<ams::fs::IStorage> GetLayeredRomfsStorage(ncm::ProgramId program_id, ::FsStorage &data_storage, bool is_process_romfs); std::shared_ptr<ams::fs::IStorage> GetLayeredRomfsStorage(ncm::ProgramId program_id, ::FsStorage &data_storage, bool is_process_romfs);
std::shared_ptr<ams::fs::IStorageForBatchRead> GetLayeredRomfsStorageForBatchRead(ncm::ProgramId program_id, ::FsStorageForBatchRead &data_storage, bool is_process_romfs);
void FinalizeLayeredRomfsStorage(ncm::ProgramId program_id); void FinalizeLayeredRomfsStorage(ncm::ProgramId program_id);
} }
@@ -51,6 +51,13 @@ namespace ams::mitm::fs {
/* Unknown heap sensitivity. */ /* Unknown heap sensitivity. */
{ 0x01002C9022770000, 16_MB, 0_MB }, { 0x01002C9022770000, 16_MB, 0_MB },
/* Trails in the Sky 2nd Chapter (Global, Asia and Japan versions). */
/* Requirement ~16 MB.*/
/* No particular heap sensitivity. */
{ 0x01007A2027548000, 8_MB, 0_MB },
{ 0x0100E8B028B54000, 8_MB, 0_MB },
{ 0x01002270268E0000, 8_MB, 0_MB },
/* STAR WARS: Knights of the Old Republic II: The Sith Lords. */ /* STAR WARS: Knights of the Old Republic II: The Sith Lords. */
/* Requirement ? MB. 16 MB stolen heap fixes a crash, though. */ /* Requirement ? MB. 16 MB stolen heap fixes a crash, though. */
/* Unknown heap sensitivity. */ /* Unknown heap sensitivity. */
@@ -769,7 +776,6 @@ namespace ams::mitm::fs {
} }
} }
void Builder::AddSdFiles() { void Builder::AddSdFiles() {
/* Open Sd Card filesystem. */ /* Open Sd Card filesystem. */
FsFileSystem sd_filesystem; FsFileSystem sd_filesystem;
@@ -102,5 +102,6 @@ constexpr inline const EmbeddedPatch Usb30ForceEnablePatches[] = {
{ ParseModuleId("766D0C2277207B40AD9B8DE309396D50CCE94885"), util::size(Usb30ForceEnablePatches_21_0_0), Usb30ForceEnablePatches_21_0_0 }, /* 21.0.0 */ { ParseModuleId("766D0C2277207B40AD9B8DE309396D50CCE94885"), util::size(Usb30ForceEnablePatches_21_0_0), Usb30ForceEnablePatches_21_0_0 }, /* 21.0.0 */
{ ParseModuleId("B734339F2280170AF0200573F9B943242CEF8C15"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 22.0.0 - 22.1.0 */ { ParseModuleId("B734339F2280170AF0200573F9B943242CEF8C15"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 22.0.0 - 22.1.0 */
{ ParseModuleId("AD8D36F2029822A4C498F055ADBDAA789EB913C6"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 22.5.0 */ { ParseModuleId("AD8D36F2029822A4C498F055ADBDAA789EB913C6"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 22.5.0 */
{ ParseModuleId("760E48C572F8192C9BC6DC8FEB3D6213F0551505"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 23.0.0 */ { ParseModuleId("760E48C572F8192C9BC6DC8FEB3D6213F0551505"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 23.0.0 - 23.0.1 */
{ ParseModuleId("1DBD36057473928B76875E8B209A17FDB3E4C231"), util::size(Usb30ForceEnablePatches_22_0_0), Usb30ForceEnablePatches_22_0_0 }, /* 23.5.0 */
}; };
@@ -15,47 +15,73 @@
*/ */
/* Breakdown of each patch in order: */ /* Breakdown of each patch in order: */
/* #1 - Patch the 0xDEEF000 size check branch to NOP. */ /* #1 - Set TotalAvailableMemorySize to 1GB. */
/* #2 - Change the root heap "Reserved" region allocation size from 0x43E000 to 0. */ /* #2 - Change the root heap "Reserved" region allocation size from 0x43E000 to 0. */
/* #3 - Change the root heap "Scene" size from 0x4580000 to 0x4040000. */ /* #3 - Patch the initial memory block allocation size from 0xB400000 to 0xB000000. */
/* #4 - Change the scene heap "ReservedTbd" region allocation size from 0x540000 to 0. */ /* #4 - Patch the initial memory block heap size from 0xB400000 to 0xB000000. */
/* #5 - Patch the linking of "ReservedTbd" to the parent heap with a NOP. */ /* #5 - Patch the browser engine memory capacity from 0xAA00000 to 0x9000000. */
/* #6 - Patch the initial memory block allocation size from 0xB400000 to 0xAC00000. */ /* #6 - Patch the browser engine memory allocation size from 0xAA00000 to 0x9000000. */
/* #7 - Patch the initial memory block initialization size from 0xB400000 to 0xAC00000. */
constexpr inline const EmbeddedPatchEntry SystemWebMemoryPatches_23_0_0[] = { constexpr inline const EmbeddedPatchEntry SystemWebMemoryPatches_23_0_0[] = {
{ 0x861DD4, "\x1F\x20\x03\xD5", 4 }, { 0x6113A8, "\x09\x00\xA8\xD2", 4 },
{ 0x861E80, "\x02\x00\x80\x52", 4 }, { 0x861E80, "\x02\x00\x80\x52", 4 },
{ 0x861E6C, "\x82\x80\xA0\x52", 4 }, { 0x861D44, "\x01\x60\xA1\x52", 4 },
{ 0x8C1718, "\x02\x00\x80\x52", 4 }, { 0x861D5C, "\x03\x60\xA1\x52", 4 },
{ 0x8C172C, "\x1F\x20\x03\xD5", 4 }, { 0x8623D0, "\x01\x20\xA1\x52", 4 },
{ 0x861D44, "\x01\x58\xA1\x52", 4 }, { 0x862498, "\x01\x20\xA1\x52", 4 },
{ 0x861D5C, "\x03\x58\xA1\x52", 4 }, };
constexpr inline const EmbeddedPatchEntry SystemWebMemoryPatches_23_5_0[] = {
{ 0x611468, "\x09\x00\xA8\xD2", 4 },
{ 0x729FE8, "\x02\x00\x80\x52", 4 },
{ 0x729EA8, "\x01\x60\xA1\x52", 4 },
{ 0x729EC0, "\x03\x60\xA1\x52", 4 },
{ 0x72A53C, "\x01\x20\xA1\x52", 4 },
{ 0x72A604, "\x01\x20\xA1\x52", 4 },
}; };
constexpr inline const EmbeddedPatchEntry OpenWebMemoryPatches_23_0_0[] = { constexpr inline const EmbeddedPatchEntry OpenWebMemoryPatches_23_0_0[] = {
{ 0x828DBC, "\x1F\x20\x03\xD5", 4 }, { 0x611428, "\x09\x00\xA8\xD2", 4 },
{ 0x828E68, "\x02\x00\x80\x52", 4 }, { 0x828E68, "\x02\x00\x80\x52", 4 },
{ 0x828E54, "\x82\x80\xA0\x52", 4 }, { 0x828D2C, "\x01\x60\xA1\x52", 4 },
{ 0x74C564, "\x02\x00\x80\x52", 4 }, { 0x828D44, "\x03\x60\xA1\x52", 4 },
{ 0x74C578, "\x1F\x20\x03\xD5", 4 }, { 0x8293B8, "\x01\x20\xA1\x52", 4 },
{ 0x828D2C, "\x01\x58\xA1\x52", 4 }, { 0x829480, "\x01\x20\xA1\x52", 4 },
{ 0x828D44, "\x03\x58\xA1\x52", 4 }, };
constexpr inline const EmbeddedPatchEntry OpenWebMemoryPatches_23_5_0[] = {
{ 0x6114E8, "\x09\x00\xA8\xD2", 4 },
{ 0x8E4C70, "\x02\x00\x80\x52", 4 },
{ 0x8E4B30, "\x01\x60\xA1\x52", 4 },
{ 0x8E4B48, "\x03\x60\xA1\x52", 4 },
{ 0x8E51C4, "\x01\x20\xA1\x52", 4 },
{ 0x8E528C, "\x01\x20\xA1\x52", 4 },
}; };
constexpr inline const EmbeddedPatchEntry OfflineWebMemoryPatches_23_0_0[] = { constexpr inline const EmbeddedPatchEntry OfflineWebMemoryPatches_23_0_0[] = {
{ 0x130698, "\x1F\x20\x03\xD5", 4 }, { 0x6DE0DC, "\x09\x00\xA8\xD2", 4 },
{ 0x130744, "\x02\x00\x80\x52", 4 }, { 0x130744, "\x02\x00\x80\x52", 4 },
{ 0x130730, "\x82\x80\xA0\x52", 4 }, { 0x130614, "\x01\x60\xA1\x52", 4 },
{ 0x4D728, "\x02\x00\x80\x52", 4 }, { 0x130624, "\x02\x60\xA1\x52", 4 },
{ 0x4D738, "\x1F\x20\x03\xD5", 4 }, { 0x130C30, "\x01\x20\xA1\x52", 4 },
{ 0x130614, "\x01\x58\xA1\x52", 4 }, { 0x130CD0, "\x01\x20\xA1\x52", 4 },
{ 0x130624, "\x02\x58\xA1\x52", 4 }, };
constexpr inline const EmbeddedPatchEntry OfflineWebMemoryPatches_23_5_0[] = {
{ 0x6E28FC, "\x09\x00\xA8\xD2", 4 },
{ 0x168144, "\x02\x00\x80\x52", 4 },
{ 0x168014, "\x01\x60\xA1\x52", 4 },
{ 0x168024, "\x02\x60\xA1\x52", 4 },
{ 0x168630, "\x01\x20\xA1\x52", 4 },
{ 0x1686D0, "\x01\x20\xA1\x52", 4 },
}; };
constexpr inline const EmbeddedPatch WebMemoryPatches[] = { constexpr inline const EmbeddedPatch WebMemoryPatches[] = {
{ ParseModuleId("97BF9C2D43EB002FB5B3578E7714F428104ED596"), util::size(SystemWebMemoryPatches_23_0_0), SystemWebMemoryPatches_23_0_0 }, /* 23.0.0 */ { ParseModuleId("97BF9C2D43EB002FB5B3578E7714F428104ED596"), util::size(SystemWebMemoryPatches_23_0_0), SystemWebMemoryPatches_23_0_0 }, /* 23.0.0 - 23.0.1 */
{ ParseModuleId("BFC1836C97C456CA4E56DEABF7FBF275E5522363"), util::size(SystemWebMemoryPatches_23_5_0), SystemWebMemoryPatches_23_5_0 }, /* 23.5.0 */
{ ParseModuleId("1470453424A9CDE689BE6DA86457ED1C79F5F403"), util::size(OpenWebMemoryPatches_23_0_0), OpenWebMemoryPatches_23_0_0 }, /* 23.0.0 */ { ParseModuleId("1470453424A9CDE689BE6DA86457ED1C79F5F403"), util::size(OpenWebMemoryPatches_23_0_0), OpenWebMemoryPatches_23_0_0 }, /* 23.0.0 - 23.0.1 */
{ ParseModuleId("C01A479EB77D4118D092EEF9F7E6AA0F8D1B0FE1"), util::size(OpenWebMemoryPatches_23_5_0), OpenWebMemoryPatches_23_5_0 }, /* 23.5.0 */
{ ParseModuleId("86DAFFA68DA38660317018ADC7AD415BCCDDC583"), util::size(OfflineWebMemoryPatches_23_0_0), OfflineWebMemoryPatches_23_0_0 }, /* 23.0.0 */ { ParseModuleId("86DAFFA68DA38660317018ADC7AD415BCCDDC583"), util::size(OfflineWebMemoryPatches_23_0_0), OfflineWebMemoryPatches_23_0_0 }, /* 23.0.0 - 23.0.1 */
{ ParseModuleId("0F20276C46BAEFF61762EBB4765DFA08EB56385B"), util::size(OfflineWebMemoryPatches_23_5_0), OfflineWebMemoryPatches_23_5_0 }, /* 23.5.0 */
}; };