Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
uefi_alloc
Commits
3d865b8d
Verified
Commit
3d865b8d
authored
Nov 13, 2018
by
Jeremy Soller
Browse files
Update to latest allocator API
parent
4f15cb1b
Pipeline
#1723
failed with stages
in 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/lib.rs
View file @
3d865b8d
#![feature(alloc)]
#![feature(allocator_api)]
#![feature(const_fn)]
#![feature(try_trait)]
#![no_std]
extern
crate
alloc
;
extern
crate
uefi
;
use
alloc
::
heap
::{
Alloc
,
Alloc
Err
,
Layout
};
use
core
::
alloc
::{
Global
Alloc
,
Layout
};
use
core
::
ops
::
Try
;
use
core
::
ptr
;
use
uefi
::
memory
::
MemoryType
;
use
uefi
::
system
::
SystemTable
;
...
...
@@ -30,23 +29,21 @@ fn get_uefi() -> Option<&'static mut SystemTable> {
pub
struct
Allocator
;
unsafe
impl
<
'a
>
Alloc
for
&
'a
Allocator
{
unsafe
fn
alloc
(
&
mut
self
,
layout
:
Layout
)
->
Result
<*
mut
u8
,
AllocErr
>
{
unsafe
impl
<
'a
>
Global
Alloc
for
&
'a
Allocator
{
unsafe
fn
alloc
(
&
self
,
layout
:
Layout
)
->
*
mut
u8
{
if
let
Some
(
ref
mut
uefi
)
=
get_uefi
()
{
let
mut
ptr
=
0
;
if
let
Err
(
_
)
=
(
uefi
.BootServices.AllocatePool
)(
MemoryType
::
EfiLoaderData
,
layout
.size
(),
&
mut
ptr
)
.into_result
()
{
Err
(
AllocErr
::
Exhausted
{
request
:
layout
})
ptr
::
null_mut
()
}
else
{
Ok
(
ptr
as
*
mut
u8
)
ptr
as
*
mut
u8
}
}
else
{
panic!
(
"__rust_allocate: uefi not initialized"
);
}
}
unsafe
fn
dealloc
(
&
mut
self
,
ptr
:
*
mut
u8
,
_layout
:
Layout
)
{
unsafe
fn
dealloc
(
&
self
,
ptr
:
*
mut
u8
,
_layout
:
Layout
)
{
if
let
Some
(
ref
mut
uefi
)
=
get_uefi
()
{
let
_
=
(
uefi
.BootServices.FreePool
)(
ptr
as
usize
);
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment