switchbrew / nx-hbloader

Host process for loading Switch homebrew NROs
ISC License
339 stars 72 forks source link

Add some non-zero SystemResourceSize to NPDM #35

Open DCNick3 opened 3 years ago

DCNick3 commented 3 years ago

As for now, all homebrew apps are ran with SystemResourceSize = 0. This prevents from doing anything useful with svcMapPhysicalMemory, as it uses this limit. I propose increasing it to maximum value - 0x1FE00000 to suit all (possible) homebrew.

This should be as simple as:

--- a/hbl.json
+++ b/hbl.json
@@ -11,6 +11,7 @@
     "is_64_bit": true,
     "address_space_type": 1,
     "is_retail": true,
+    "system_resource_size": "0x1FE00000",
     "filesystem_access": {
         "permissions": "0xFFFFFFFFFFFFFFFF"
     },
fincs commented 3 years ago

Support for new-style heap allocation is under consideration, however there are still problems we need to solve, such as the fact that it is not available on kernels older than 3.0.

DCNick3 commented 3 years ago

it is not available on kernels older than 3.0.

Wouldn't stable release of mesosphere lift this problem? I heard SciresM talk about it providing newer SVCs on low firmware versions

fincs commented 3 years ago

Yes it does. However we cannot have hbloader unconditionally use it regardless of system version, because it would break compatibility with the official kernel on old system versions. We've also not taken a decision yet on whether we'd require mesosphère to run on older system versions.

DCNick3 commented 3 years ago

Makes sense.

But, as far as I can understand SystemResourceSize NPDM field was simply reserved before 3.0.0. I guess whether adding it would be a breaking change depends on the way it was "reserved": either ignored (just fine) or forced to be zero (would be problematic).

fincs commented 3 years ago

I mean the fact that we'd have to remove usage of svcSetHeapSize in favor of dynamically resizing heap using PhysicalMemory SVCs. Currently it is using the old approach of reserving all the memory (leaving nothing left for potential PhysicalMemory users!).

DCNick3 commented 3 years ago

Oh, yeah, now I see the problem. Maybe something hybrid would work: use the novel API when available and svcSetHeapSize as a fallback. But this would probably be a maintenance pain..

SciresM commented 3 years ago

The actual field isn't an issue, as the field in CreateProcessParameter is only set on 3.0.0+ (https://github.com/Atmosphere-NX/Atmosphere/blob/master/stratosphere/loader/source/ldr_process_creation.cpp#L340), and even then 1.0.0/2.0.0 kernels simply do not access the field inside svc::CreateProcessParameter (it was reserved/padding previously).

But yeah, it requires actual hbl design logic thought/changes, as finc has described.

SciresM commented 3 years ago

(But also, yeah, if you want to use physical memory on < 3.0.0 this will require ams.loader changes. I guess I should think about that once mesosphere is stable).