Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Verlässliche Systemsoftware
projects
osv
Commits
7a5d8fe2
Commit
7a5d8fe2
authored
12 years ago
by
Christoph Hellwig
Browse files
Options
Downloads
Patches
Plain Diff
implement a naive realloc() to make the malloc testcase happy
parent
7eb45bd6
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
mempool.cc
+41
-0
41 additions, 0 deletions
mempool.cc
mempool.hh
+1
-0
1 addition, 0 deletions
mempool.hh
with
42 additions
and
0 deletions
mempool.cc
+
41
−
0
View file @
7a5d8fe2
...
...
@@ -68,6 +68,11 @@ void* pool::alloc()
return
obj
;
}
unsigned
pool
::
get_size
()
{
return
_size
;
}
void
pool
::
add_page
()
{
void
*
page
=
alloc_page
();
...
...
@@ -197,6 +202,13 @@ void free_large(void* obj)
}
}
unsigned
large_object_size
(
void
*
obj
)
{
obj
-=
page_size
;
auto
header
=
static_cast
<
page_range
*>
(
obj
);
return
header
->
size
;
}
void
*
alloc_page
()
{
assert
(
!
free_page_ranges
.
empty
());
...
...
@@ -293,6 +305,35 @@ void* calloc(size_t nmemb, size_t size)
return
p
;
}
static
size_t
object_size
(
void
*
object
)
{
if
(
reinterpret_cast
<
uintptr_t
>
(
object
)
&
(
memory
::
page_size
-
1
))
{
return
memory
::
pool
::
from_object
(
object
)
->
get_size
();
}
else
{
return
memory
::
large_object_size
(
object
);
}
}
void
*
realloc
(
void
*
object
,
size_t
size
)
{
if
(
!
object
)
return
malloc
(
size
);
if
(
!
size
)
{
free
(
object
);
return
NULL
;
}
size_t
old_size
=
object_size
(
object
);
size_t
copy_size
=
size
>
old_size
?
old_size
:
size
;
void
*
ptr
=
malloc
(
size
);
if
(
ptr
)
{
memcpy
(
ptr
,
object
,
copy_size
);
free
(
object
);
}
return
NULL
;
}
void
free
(
void
*
object
)
{
if
(
!
object
)
{
...
...
This diff is collapsed.
Click to expand it.
mempool.hh
+
1
−
0
View file @
7a5d8fe2
...
...
@@ -27,6 +27,7 @@ public:
~
pool
();
void
*
alloc
();
void
free
(
void
*
object
);
unsigned
get_size
();
static
pool
*
from_object
(
void
*
object
);
private:
struct
page_header
;
...
...
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