Skip to content

Commit

Permalink
kernel32: split peb init from teb init
Browse files Browse the repository at this point in the history
  • Loading branch information
evmar committed Oct 15, 2024
1 parent 4f9116d commit 085f66f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions win32/src/winapi/kernel32/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ struct _EXCEPTION_REGISTRATION_RECORD {
}
unsafe impl ::memory::Pod for _EXCEPTION_REGISTRATION_RECORD {}

/// Set up TEB, PEB, and other process info.
/// The FS register points at the TEB (thread info), which points at the PEB (process info).
fn init_teb(cmdline: &mut CommandLine, arena: &mut Arena, mem: Mem) -> u32 {
fn init_peb(cmdline: &mut CommandLine, arena: &mut Arena, mem: Mem) -> u32 {
// RTL_USER_PROCESS_PARAMETERS
let params_addr = arena.alloc(
std::cmp::max(
Expand All @@ -88,6 +86,12 @@ fn init_teb(cmdline: &mut CommandLine, arena: &mut Arena, mem: Mem) -> u32 {
peb.ProcessHeap = 0; // TODO: we use state.process_heap instead
peb.TlsCount = 0;

peb_addr
}

/// Set up TEB, PEB, and other process info.
/// The FS register points at the TEB (thread info), which points at the PEB (process info).
fn init_teb(peb_addr: u32, arena: &mut Arena, mem: Mem) -> u32 {
// SEH chain
let seh_addr = arena.alloc(
std::mem::size_of::<_EXCEPTION_REGISTRATION_RECORD>() as u32,
Expand Down Expand Up @@ -199,8 +203,8 @@ impl State {
.copy_from_slice(env);

let mut cmdline = CommandLine::new(cmdline);

let teb = init_teb(&mut cmdline, &mut arena, mem.mem());
let peb = init_peb(&mut cmdline, &mut arena, mem.mem());
let teb = init_teb(peb, &mut arena, mem.mem());

State {
arena,
Expand Down

0 comments on commit 085f66f

Please sign in to comment.