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
742339ca
Commit
742339ca
authored
6 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Hacky version of memalign
parent
dabd8dc6
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/stdlib/src/lib.rs
+18
-0
18 additions, 0 deletions
src/stdlib/src/lib.rs
tests/alloc.c
+9
-1
9 additions, 1 deletion
tests/alloc.c
with
27 additions
and
1 deletion
src/stdlib/src/lib.rs
+
18
−
0
View file @
742339ca
...
@@ -323,6 +323,24 @@ pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
...
@@ -323,6 +323,24 @@ pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
}
}
}
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
memalign
(
alignment
:
size_t
,
size
:
size_t
)
->
*
mut
c_void
{
let
mut
align
=
16
;
while
align
<=
alignment
{
align
*=
2
;
}
let
offset
=
align
/
2
;
let
ptr
=
ralloc
::
alloc
(
size
+
offset
,
align
);
if
!
ptr
.is_null
()
{
*
(
ptr
as
*
mut
u64
)
=
(
size
+
offset
)
as
u64
;
*
(
ptr
as
*
mut
u64
)
.offset
(
1
)
=
align
as
u64
;
ptr
.offset
(
offset
as
isize
)
as
*
mut
c_void
}
else
{
ptr
as
*
mut
c_void
}
}
#[no_mangle]
#[no_mangle]
pub
extern
"C"
fn
mblen
(
s
:
*
const
c_char
,
n
:
size_t
)
->
c_int
{
pub
extern
"C"
fn
mblen
(
s
:
*
const
c_char
,
n
:
size_t
)
->
c_int
{
unimplemented!
();
unimplemented!
();
...
...
This diff is collapsed.
Click to expand it.
tests/alloc.c
+
9
−
1
View file @
742339ca
...
@@ -10,11 +10,19 @@ int main(int argc, char ** argv) {
...
@@ -10,11 +10,19 @@ int main(int argc, char ** argv) {
}
}
free
(
ptr
);
free
(
ptr
);
char
*
ptrc
=
(
char
*
)
calloc
(
256
,
1
);
char
*
ptrc
=
(
char
*
)
calloc
(
256
,
1
);
printf
(
"calloc %p
\n
"
,
ptrc
);
printf
(
"calloc %p
\n
"
,
ptrc
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
for
(
i
=
0
;
i
<
256
;
i
++
)
{
ptrc
[
i
]
=
(
char
)
i
;
ptrc
[
i
]
=
(
char
)
i
;
}
}
free
(
ptrc
);
free
(
ptrc
);
char
*
ptra
=
(
char
*
)
memalign
(
256
,
256
);
printf
(
"memalign %p
\n
"
,
ptra
);
for
(
i
=
0
;
i
<
256
;
i
++
)
{
ptra
[
i
]
=
(
char
)
i
;
}
free
(
ptra
);
return
0
;
return
0
;
}
}
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