Skip to content
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

[FREELDR] Split freeldr into 1st and 2nd stage #7488

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

tkreuzer
Copy link
Contributor

@tkreuzer tkreuzer commented Nov 3, 2024

Purpose

This PR splits freeldr into 2 modules: freeldr.sys, which acts as the 1st stage loader and rosload.exe, which contains the NT loader code and a few other things and is loaded by freeldr.sys. This allows to add more code, especially on x64, where the code size was already at an absolute maximum to fit into the free low memory range and registry healing had to be disabled.

I understand that some people might find that from a philosophical viewpoint, some things are not in the right module, but the split was done on a pragmatical basis, i.e. "make it work", rather than wasting time with hypothetical/philospohical ideas, that provide no practical benefit.

Size changes for freeldr.sys (DEBUG):

GCC x86: 411.136  -> 236.032
MSVC x86: 448.000 -> 275.456
MSVC x64: 484.352 -> 351.744

JIRA issue: CORE-XXXX

Proposed changes

  • Replace some inline functions and global variables with global functions
  • Export functions from freeldr.sys that are needed by 2nd stage loader
  • Move MachInitializeBootDevices to BootMain
  • Remove ShowBootOptions from Menu code (handled in Remove ShowBootOptions from Menu code now)
  • Add rosload.exe as 2nd stage loader
  • Install rosload.exe in usetup
  • Bonus: Enable registry healing code for x64

Tests

  • KVM x86:
  • KVM x64:

…ith functions

This allows to easily import them from a 2nd stage loader without having to bother about _declspec(dllimport)
This removes a dependency of UI code to boot options code by getting rid of a call to DisplayBootTimeOptions() from within the menu code.
Instead this is now handled by MainBootMenuKeyPressFilter.
@tkreuzer tkreuzer added enhancement For PRs with an enhancement/new feature. refactoring For refactoring changes. freeldr Freeloader changes labels Nov 3, 2024
@tkreuzer tkreuzer self-assigned this Nov 3, 2024
This is required, so that the definition is available when preprocessing asm files on MSVC builds. Otherwise systimer.s will contain KeStallExecutionProcessor, which must not be used in freeldr.
…essor

The latter will only be available in rosload.exe.
@github-actions github-actions bot added the kernel&hal Code changes to the ntoskrnl and HAL label Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For PRs with an enhancement/new feature. freeldr Freeloader changes kernel&hal Code changes to the ntoskrnl and HAL refactoring For refactoring changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant