-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nick Spinale <[email protected]>
- Loading branch information
Showing
5 changed files
with
46 additions
and
0 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
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,39 @@ | ||
// | ||
// Copyright 2024, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
use core::mem; | ||
use core::ptr; | ||
use core::slice; | ||
|
||
use sel4_panicking_env::abort; | ||
|
||
type Ctor = unsafe extern "C" fn(); | ||
|
||
extern "C" { | ||
static __init_array_start: Ctor; | ||
static __init_array_end: Ctor; | ||
} | ||
|
||
pub unsafe fn run_ctors() { | ||
let start = ptr::addr_of!(__init_array_start); | ||
let end = ptr::addr_of!(__init_array_end); | ||
|
||
// Cast to usize for comparison, otherwise rustc seems to apply an erroneous optimization | ||
// assuming __init_array_start != __init_array_end. | ||
if start as usize != end as usize { | ||
if start.align_offset(mem::size_of::<Ctor>()) != 0 | ||
|| end.align_offset(mem::size_of::<Ctor>()) != 0 | ||
{ | ||
abort!("'.init_array' section is not properly aligned"); | ||
} | ||
|
||
let len = (end as usize - start as usize) / mem::size_of::<Ctor>(); | ||
let ctors = slice::from_raw_parts(start, len); | ||
for ctor in ctors { | ||
(ctor)(); | ||
} | ||
} | ||
} |
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