Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Limkilde Svendsen
relibc
Commits
f4f68a34
Commit
f4f68a34
authored
4 years ago
by
Ahmed Abd El Mawgood
Browse files
Options
Downloads
Patches
Plain Diff
Make use of mspaces
parent
3a881707
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/platform/allocator/dlmalloc.rs
+13
-8
13 additions, 8 deletions
src/platform/allocator/dlmalloc.rs
src/start.rs
+20
-5
20 additions, 5 deletions
src/start.rs
with
33 additions
and
13 deletions
src/platform/allocator/dlmalloc.rs
+
13
−
8
View file @
f4f68a34
...
...
@@ -2,15 +2,20 @@ use core::{
alloc
::{
GlobalAlloc
,
Layout
},
sync
::
atomic
::{
AtomicUsize
,
Ordering
},
};
use
crate
::
ALLOCATOR
;
use
super
::
types
::
*
;
extern
"C"
{
fn
create_mspace
(
capacity
:
size_t
,
locked
:
c_int
)
->
usize
;
fn
dlmalloc
(
bytes
:
size_t
)
->
*
mut
c_void
;
fn
dlmemalign
(
alignment
:
size_t
,
bytes
:
size_t
)
->
*
mut
c_void
;
fn
dlrealloc
(
oldmem
:
*
mut
c_void
,
bytes
:
size_t
)
->
*
mut
c_void
;
fn
dlfree
(
mem
:
*
mut
c_void
);
fn
mspace_malloc
(
msp
:
usize
,
bytes
:
size_t
)
->
*
mut
c_void
;
fn
mspace_memalign
(
msp
:
usize
,
alignment
:
size_t
,
bytes
:
size_t
)
->
*
mut
c_void
;
fn
mspace_realloc
(
msp
:
usize
,
oldmem
:
*
mut
c_void
,
bytes
:
size_t
)
->
*
mut
c_void
;
fn
mspace_free
(
msp
:
usize
,
mem
:
*
mut
c_void
);
//fn dlmalloc(bytes: size_t) -> *mut c_void;
//fn dlmemalign(alignment: size_t, bytes: size_t) -> *mut c_void;
//fn dlrealloc(oldmem: *mut c_void, bytes: size_t) -> *mut c_void;
//fn dlfree(mem: *mut c_void);
}
pub
struct
Allocator
{
...
...
@@ -40,19 +45,19 @@ unsafe impl<'a> GlobalAlloc for Allocator {
}
pub
unsafe
fn
alloc
(
size
:
usize
)
->
*
mut
c_void
{
dlmalloc
(
size
)
mspace_malloc
(
ALLOCATOR
.get_book_keeper
(),
size
)
}
pub
unsafe
fn
alloc_align
(
size
:
usize
,
alignment
:
usize
)
->
*
mut
c_void
{
dl
memalign
(
alignment
,
size
)
mspace_
memalign
(
ALLOCATOR
.get_book_keeper
(),
alignment
,
size
)
}
pub
unsafe
fn
realloc
(
ptr
:
*
mut
c_void
,
size
:
size_t
)
->
*
mut
c_void
{
dl
realloc
(
ptr
,
size
)
mspace_
realloc
(
ALLOCATOR
.get_book_keeper
(),
ptr
,
size
)
}
pub
unsafe
fn
free
(
ptr
:
*
mut
c_void
)
{
dlfree
(
ptr
)
mspace_free
(
ALLOCATOR
.get_book_keeper
(),
ptr
)
}
pub
fn
new_mspace
()
->
usize
{
...
...
This diff is collapsed.
Click to expand it.
src/start.rs
+
20
−
5
View file @
f4f68a34
...
...
@@ -67,7 +67,26 @@ static INIT_ARRAY: [extern "C" fn(); 1] = [init_array];
static
mut
init_complete
:
bool
=
false
;
fn
alloc_init
()
{
unsafe
{
if
let
Some
(
tcb
)
=
ld_so
::
tcb
::
Tcb
::
current
()
{
if
tcb
.mspace
!=
0
{
ALLOCATOR
.set_book_keeper
(
tcb
.mspace
);
}
else
if
ALLOCATOR
.get_book_keeper
()
==
0
{
ALLOCATOR
.set_book_keeper
(
new_mspace
());
}
}
else
if
ALLOCATOR
.get_book_keeper
()
==
0
{
ALLOCATOR
.set_book_keeper
(
new_mspace
());
}
}
}
extern
"C"
fn
init_array
()
{
// The thing is that we cannot guarantee if
// init_array runs first or if relibc_start runs first
// Still whoever gets to run first must initialize rust
// memory allocator before doing anything else.
alloc_init
();
io_init
();
unsafe
{
init_complete
=
true
};
}
...
...
@@ -95,11 +114,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
}
// Step 1 setup the right allocator...
// if any memory rust based memory allocation happen before this step .. we are doomed.
if
let
Some
(
tcb
)
=
ld_so
::
tcb
::
Tcb
::
current
()
{
ALLOCATOR
.set_book_keeper
(
tcb
.mspace
);
}
else
{
ALLOCATOR
.set_book_keeper
(
new_mspace
());
}
alloc_init
();
// Ensure correct host system before executing more system calls
relibc_verify_host
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment