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
ab82c389
Commit
ab82c389
authored
Jul 06, 2017
by
Jeremy Soller
Browse files
Initial commit
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitignore
0 → 100644
View file @
ab82c389
Cargo.lock
target
Cargo.toml
0 → 100644
View file @
ab82c389
[package]
name
=
"alloc_uefi"
version
=
"0.1.0"
[dependencies]
uefi
=
{
git
=
"https://github.com/redox-os/uefi.git"
}
src/lib.rs
0 → 100644
View file @
ab82c389
#![feature(allocator)]
#![feature(const_fn)]
#![allocator]
#![no_std]
extern
crate
uefi
;
use
uefi
::
boot
::
MemoryType
;
use
uefi
::
system
::
SystemTable
;
static
mut
UEFI
:
*
mut
SystemTable
=
0
as
*
mut
SystemTable
;
pub
unsafe
fn
init
(
table
:
&
'static
mut
SystemTable
)
{
UEFI
=
table
;
}
fn
get_uefi
()
->
Option
<&
'static
mut
SystemTable
>
{
unsafe
{
if
UEFI
as
usize
==
0
{
None
}
else
{
Some
(
&
mut
*
UEFI
)
}
}
}
#[no_mangle]
pub
extern
fn
__rust_allocate
(
size
:
usize
,
_align
:
usize
)
->
*
mut
u8
{
if
let
Some
(
ref
mut
uefi
)
=
get_uefi
()
{
let
mut
ptr
=
0
;
let
ret
=
(
uefi
.BootServices.AllocatePool
)(
MemoryType
::
EfiLoaderData
,
size
,
&
mut
ptr
);
if
ret
!=
0
{
panic!
(
"__rust_allocate: uefi returned {:X}"
,
ret
);
}
ptr
as
*
mut
u8
}
else
{
panic!
(
"__rust_allocate: uefi not initialized"
);
}
}
#[no_mangle]
pub
extern
fn
__rust_deallocate
(
ptr
:
*
mut
u8
,
_size
:
usize
,
_align
:
usize
)
{
if
let
Some
(
ref
mut
uefi
)
=
get_uefi
()
{
(
uefi
.BootServices.FreePool
)(
ptr
as
usize
);
}
else
{
panic!
(
"__rust_deallocate: uefi not initialized"
);
}
}
#[no_mangle]
pub
extern
fn
__rust_usable_size
(
size
:
usize
,
_align
:
usize
)
->
usize
{
size
}
#[no_mangle]
pub
extern
fn
__rust_reallocate_inplace
(
_ptr
:
*
mut
u8
,
size
:
usize
,
_new_size
:
usize
,
_align
:
usize
)
->
usize
{
size
}
#[no_mangle]
pub
extern
fn
__rust_reallocate
(
ptr
:
*
mut
u8
,
size
:
usize
,
new_size
:
usize
,
align
:
usize
)
->
*
mut
u8
{
use
core
::{
ptr
,
cmp
};
// from: https://github.com/rust-lang/rust/blob/
// c66d2380a810c9a2b3dbb4f93a830b101ee49cc2/
// src/liballoc_system/lib.rs#L98-L101
let
new_ptr
=
__rust_allocate
(
new_size
,
align
);
unsafe
{
ptr
::
copy
(
ptr
,
new_ptr
,
cmp
::
min
(
size
,
new_size
))
};
__rust_deallocate
(
ptr
,
size
,
align
);
new_ptr
}
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