-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial version of init. Currently it only does exec() on a dummy file. This is addressed in the future commits. Introduced "make user" to compile the init process. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
- Loading branch information
1 parent
25f859b
commit 3b272b7
Showing
9 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "init" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "init" | ||
path = "src/main.rs" | ||
test = false | ||
|
||
[dependencies] | ||
syscall = { path = "../syscall" } | ||
buddy_system_allocator = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
fn main() { | ||
println!("cargo:rustc-link-arg-bin=init=-nostdlib"); | ||
println!("cargo:rustc-link-arg-bin=init=-no-pie"); | ||
println!("cargo:rustc-link-arg-bin=init=-Tinit/init.lds"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Temporary WA until p_vaddr alignment issue is fixed in our ELF parser */ | ||
|
||
OUTPUT_ARCH(i386:x86-64) | ||
|
||
PHDRS | ||
{ | ||
text PT_LOAD FLAGS(5); /* Read + Execute */ | ||
rodata PT_LOAD FLAGS(4); /* Read-only */ | ||
data PT_LOAD FLAGS(6); /* Read + Write */ | ||
bss PT_LOAD FLAGS(6); /* Read + Write */ | ||
} | ||
|
||
SECTIONS | ||
{ | ||
.text : { | ||
*(.text) | ||
*(.text.*) | ||
} :text | ||
. = ALIGN(4096); | ||
.rodata : { | ||
*(.rodata) | ||
*(.rodata.*) | ||
} : rodata | ||
. = ALIGN(4096); | ||
.data : { | ||
*(.data) | ||
*(.data.*) | ||
} :data | ||
. = ALIGN(4096); | ||
.bss : { | ||
*(.bss) *(.bss.*) | ||
. = ALIGN(4096); | ||
} :bss | ||
. = ALIGN(4096); | ||
} | ||
|
||
ENTRY(init_start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// | ||
// Copyright (c) 2024 Intel Corporation. | ||
// | ||
// Author: Peter Fang <[email protected]> | ||
|
||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate alloc; | ||
use alloc::ffi::CString; | ||
use buddy_system_allocator::*; | ||
use core::panic::PanicInfo; | ||
use syscall::{exec, exit, SysCallError}; | ||
|
||
const HEAP_SIZE: usize = 64 * 1024; | ||
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE]; | ||
|
||
#[global_allocator] | ||
static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::<32>::empty(); | ||
|
||
#[no_mangle] | ||
pub extern "C" fn init_start() -> ! { | ||
unsafe { | ||
HEAP_ALLOCATOR | ||
.lock() | ||
.init(core::ptr::addr_of!(HEAP) as usize, HEAP_SIZE); | ||
} | ||
|
||
let file = CString::new("/dummy").expect("Failed to create new string"); | ||
let root = CString::new("/").expect("Failed to create new string"); | ||
|
||
match exec(&file, &root, 0) { | ||
Ok(_) => exit(0), | ||
Err(SysCallError::ENOTFOUND) => exit(1), | ||
_ => panic!("exec launch failed"), | ||
}; | ||
} | ||
|
||
#[panic_handler] | ||
fn panic(_info: &PanicInfo<'_>) -> ! { | ||
exit(u32::MAX); | ||
} |