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
eaee4e63
Verified
Commit
eaee4e63
authored
4 years ago
by
jD91mZM2
Browse files
Options
Downloads
Patches
Plain Diff
Emulate brk
parent
7b6ba2c7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/platform/redox/mod.rs
+41
-4
41 additions, 4 deletions
src/platform/redox/mod.rs
with
41 additions
and
4 deletions
src/platform/redox/mod.rs
+
41
−
4
View file @
eaee4e63
...
...
@@ -10,9 +10,9 @@ use crate::{
fs
::
File
,
header
::{
dirent
::
dirent
,
errno
::{
EINVAL
,
EIO
,
EPERM
,
ERANGE
},
errno
::{
EINVAL
,
EIO
,
ENOMEM
,
EPERM
,
ERANGE
},
fcntl
,
sys_mman
::
MAP_ANON
,
sys_mman
::
{
PROT_READ
,
PROT_WRITE
,
MAP_ANON
YMOUS
}
,
sys_random
,
sys_resource
::{
rlimit
,
RLIM_INFINITY
},
sys_stat
::
stat
,
...
...
@@ -28,6 +28,9 @@ use crate::{
use
super
::{
errno
,
types
::
*
,
Pal
,
Read
};
static
mut
BRK_CUR
:
*
mut
c_void
=
ptr
::
null_mut
();
static
mut
BRK_END
:
*
mut
c_void
=
ptr
::
null_mut
();
mod
epoll
;
mod
extra
;
mod
ptrace
;
...
...
@@ -95,7 +98,41 @@ impl Pal for Sys {
}
fn
brk
(
addr
:
*
mut
c_void
)
->
*
mut
c_void
{
unsafe
{
syscall
::
brk
(
addr
as
usize
)
.unwrap_or
(
0
)
as
*
mut
c_void
}
unsafe
{
// On first invocation, allocate a buffer for brk
if
BRK_CUR
.is_null
()
{
// 4 megabytes of RAM ought to be enough for anybody
const
BRK_MAX_SIZE
:
usize
=
4
*
1024
*
1024
;
let
allocated
=
Self
::
mmap
(
ptr
::
null_mut
(),
BRK_MAX_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_ANONYMOUS
,
0
,
0
,
);
if
allocated
==
!
0
as
*
mut
c_void
/* MAP_FAILED */
{
return
!
0
as
*
mut
c_void
;
}
BRK_CUR
=
allocated
;
BRK_END
=
(
allocated
as
*
mut
u8
)
.add
(
BRK_MAX_SIZE
)
as
*
mut
c_void
;
}
if
addr
.is_null
()
{
// Lookup what previous brk() invocations have set the address to
BRK_CUR
}
else
if
BRK_CUR
<=
addr
&&
addr
<
BRK_END
{
// It's inside buffer, return
BRK_CUR
=
addr
;
addr
}
else
{
// It was outside of valid range
errno
=
ENOMEM
;
ptr
::
null_mut
()
}
}
}
fn
chdir
(
path
:
&
CStr
)
->
c_int
{
...
...
@@ -674,7 +711,7 @@ impl Pal for Sys {
address
:
addr
as
usize
,
};
if
flags
&
MAP_ANON
==
MAP_ANON
{
if
flags
&
MAP_ANON
YMOUS
==
MAP_ANON
YMOUS
{
let
fd
=
e
(
syscall
::
open
(
"memory:"
,
syscall
::
O_STAT
|
syscall
::
O_CLOEXEC
,
...
...
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