Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Timo Koch
dune-common
Commits
bf329242
Commit
bf329242
authored
12 years ago
by
Christian Engwer
Browse files
Options
Downloads
Patches
Plain Diff
[DebugAllocator]
- check result of mprotect - unprotect memory upon free [[Imported from SVN: r7007]]
parent
015c3798
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/debug_allocator.hh
+35
-8
35 additions, 8 deletions
dune/common/debug_allocator.hh
dune/common/test/test-debug-alloc.cc
+1
-1
1 addition, 1 deletion
dune/common/test/test-debug-alloc.cc
with
36 additions
and
9 deletions
dune/common/debug_allocator.hh
+
35
−
8
View file @
bf329242
...
...
@@ -9,6 +9,7 @@
#include
<sys/mman.h>
#include
<vector>
#include
<iostream>
#include
<cstring>
namespace
Dune
{
...
...
@@ -49,6 +50,28 @@ namespace Dune
typedef
std
::
vector
<
AllocationInfo
>
AllocationList
;
AllocationList
allocation_list
;
private
:
void
memprotect
(
void
*
from
,
difference_type
len
,
int
prot
)
{
int
result
=
mprotect
(
from
,
len
,
prot
);
if
(
result
==
-
1
)
{
std
::
cerr
<<
"ERROR: ("
<<
result
<<
": "
<<
strerror
(
result
)
<<
")"
<<
std
::
endl
;
std
::
cerr
<<
" Failed to "
;
if
(
prot
==
PROT_NONE
)
std
::
cerr
<<
"protect "
;
else
std
::
cerr
<<
"unprotect "
;
std
::
cerr
<<
"memory range: "
<<
from
<<
", "
<<
static_cast
<
void
*>
(
static_cast
<
char
*>
(
from
)
+
len
)
<<
std
::
endl
;
abort
();
}
}
public
:
~
AllocationManager
()
...
...
@@ -78,17 +101,17 @@ namespace Dune
ai
.
capacity
=
n
*
sizeof
(
T
);
ai
.
pages
=
(
ai
.
capacity
)
/
page_size
+
2
;
ai
.
not_free
=
true
;
size_type
ski
p
=
ai
.
capacity
%
page_size
;
size_type
overla
p
=
ai
.
capacity
%
page_size
;
ai
.
page_ptr
=
memalign
(
page_size
,
ai
.
pages
*
page_size
);
if
(
0
==
ai
.
page_ptr
)
{
throw
std
::
bad_alloc
();
}
ai
.
ptr
=
static_cast
<
char
*>
(
ai
.
page_ptr
)
+
page_size
-
ski
p
;
ai
.
ptr
=
static_cast
<
char
*>
(
ai
.
page_ptr
)
+
page_size
-
overla
p
;
// write protect memory behind the actual data
mprotect
(
static_cast
<
char
*>
(
ai
.
page_ptr
)
+
(
ai
.
pages
-
1
)
*
page_size
,
page_size
,
PROT_NONE
);
me
mprotect
(
static_cast
<
char
*>
(
ai
.
page_ptr
)
+
(
ai
.
pages
-
1
)
*
page_size
,
page_size
,
PROT_NONE
);
// remember the chunk
allocation_list
.
push_back
(
ai
);
// return the ptr
...
...
@@ -120,10 +143,14 @@ namespace Dune
it
->
not_free
=
false
;
#if DEBUG_ALLOCATOR_KEEP
// write protect old memory
mprotect
(
it
->
page_ptr
,
it
->
pages
*
page_size
,
PROT_NONE
);
me
mprotect
(
it
->
page_ptr
,
(
it
->
pages
)
*
page_size
,
PROT_NONE
);
#else
// unprotect old memory
memprotect
(
it
->
page_ptr
,
(
it
->
pages
)
*
page_size
,
PROT_READ
|
PROT_WRITE
);
free
(
it
->
page_ptr
);
// remove chunk info
allocation_list
.
erase
(
it
);
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/test-debug-alloc.cc
+
1
−
1
View file @
bf329242
...
...
@@ -4,7 +4,7 @@
#include
"config.h"
#endif
#define DEBUG_ALLOCATOR_KEEP 1
//
#define DEBUG_ALLOCATOR_KEEP 1
// #define DEBUG_NEW_DELETE 3
#include
<dune/common/debug_allocator.hh>
...
...
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