Skip to content

Load m1n1 at top of kernel data #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged

Load m1n1 at top of kernel data #195

merged 1 commit into from
Feb 25, 2025

Conversation

asdfugil
Copy link

@asdfugil asdfugil commented Feb 24, 2025

m1n1 expects itself to be loaded below top of kernel data, so load it right at top of kernel data and then update top of kernel so that it is below top of kernel data.

In particular, its memory allocator start at topOfKernelData and assumes all memory between that and physBase + memSize is free. More severely, the chainloading scripts will derive new topOfKernelData from the current m1n1, so the current approach of loading would actually cause chainloading to set topOfKernelData to near the end of memory, causing problems.

@Siguza
Copy link
Member

Siguza commented Feb 25, 2025

Would it not make more sense to load m1n1 over XNU itself? I'm assuming in 99.9% of cases it will be a smaller image, right? And if it isn't... well, there's alloc_static().

Also, gBootArgs->topOfKernelData is the value originally set by iBoot, while gTopOfKernelData takes into account all alloc_static() allocations done by Pongo - did you actually mean to use the former rather than the latter as source?
And we currently update it back in xnu_boot(), but this makes me wonder whether we should just do that for all types of boots, if we're going to pass them gBootArgs either way...

@asdfugil
Copy link
Author

m1n1 can have kernel or ramdisk appended so it can be arbitrarily large. gTopOfKernelData is updated in this case so the boot trampoline goes elsewhere. It may be worthwhile to keep (patched) XNU around for potential dynamic tracing. Unless the plan is to have Linux boot in pongoOS again, gTopOfKernelData doesn’t need to exist. I think the solution here is to nuke gTopOfKernelData altogether?

@Siguza
Copy link
Member

Siguza commented Feb 25, 2025

gTopOfKernelData is already exported to modules, so I'd rather not remove it now. And I do think there could be some value in preserving the original boot_args struct during Pongo runtime.

m1n1 expects itself to be loaded below top of kernel data, so load it
right at top of kernel data and then update top of kernel so that it is
below top of kernel data.

In particular, its memory allocator start at topOfKernelData and assumes
all memory between that and physBase + memSize is free. More severely,
the chainloading scripts will derive new topOfKernelData from the
current m1n1, so the current approach of loading would actually cause
chainloading to set topOfKernelData to near the end of memory, causing
problems.m1n1 expects itself to be loaded below top of kernel data, so
do it.

Co-authored-by: Siguza <[email protected]>
Signed-off-by: Nick Chan <[email protected]>
@Siguza Siguza merged commit bb492b0 into checkra1n:iOS15 Feb 25, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants