Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RTEMS-build-workflows
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thanassis Tsiodras
RTEMS-build-workflows
Commits
65afc33a
Commit
65afc33a
authored
Jun 16, 2016
by
Thanassis Tsiodras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for potential address space overlaps (prime windows)
parent
fccd9669
Pipeline
#333
skipped
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
OAR/src/memcheck.c
OAR/src/memcheck.c
+35
-0
No files found.
OAR/src/memcheck.c
View file @
65afc33a
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
void
memcheck
()
void
memcheck
()
{
{
//#define MEMCHECK
#ifdef MEMCHECK
uint32_t
patterns
[]
=
{
uint32_t
patterns
[]
=
{
0x0
,
0x0
,
0xFFFFFFFF
,
0xFFFFFFFF
,
...
@@ -14,6 +16,7 @@ void memcheck()
...
@@ -14,6 +16,7 @@ void memcheck()
0xAA55AA55
,
0xAA55AA55
,
0x55AA55AA
,
0x55AA55AA
,
};
};
unsigned
primes
[]
=
{
3
,
7
,
31
,
127
};
size_t
space
=
512
*
1024
;
size_t
space
=
512
*
1024
;
void
*
p
=
malloc
(
space
);
void
*
p
=
malloc
(
space
);
int
i
;
int
i
;
...
@@ -36,6 +39,34 @@ void memcheck()
...
@@ -36,6 +39,34 @@ void memcheck()
exit
(
1
);
exit
(
1
);
}
}
// Check potential address space overlaps
printf
(
"[MEMCHECK] Checking for potential address space overlap. Window: "
);
for
(
i
=
0
;
i
<
sizeof
(
primes
)
/
sizeof
(
primes
[
0
]);
i
++
)
{
uint8_t
*
pc
=
p
;
unsigned
prime
=
primes
[
i
];
unsigned
bytes
=
space
;
unsigned
idx
=
0
;
printf
(
"%s%d"
,
i
?
", "
:
""
,
prime
);
fflush
(
stdout
);
while
(
bytes
--
)
{
*
pc
++
=
(
idx
%
prime
);
idx
++
;
}
pc
=
p
;
bytes
=
space
;
idx
=
0
;
while
(
bytes
--
)
{
if
(
*
pc
!=
(
idx
%
prime
))
{
printf
(
"[MEMCHECK] Address space wrapped around at 0x%x!
\n
"
,
(
unsigned
)
pc
);
fflush
(
stdout
);
exit
(
1
);
}
pc
++
;
idx
++
;
}
}
puts
(
""
);
for
(
i
=
0
;
i
<
sizeof
(
patterns
)
/
sizeof
(
patterns
[
0
]);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
patterns
)
/
sizeof
(
patterns
[
0
]);
i
++
)
{
printf
(
"[MEMCHECK] Checking memory with pattern: 0x%x...
\n
"
,
(
unsigned
)
patterns
[
i
]);
printf
(
"[MEMCHECK] Checking memory with pattern: 0x%x...
\n
"
,
(
unsigned
)
patterns
[
i
]);
uint32_t
*
pw
=
p
;
uint32_t
*
pw
=
p
;
...
@@ -59,4 +90,8 @@ void memcheck()
...
@@ -59,4 +90,8 @@ void memcheck()
}
}
}
}
free
(
p
);
free
(
p
);
#else
puts
(
"[MEMCHECK] Memory checks disabled in release mode."
);
fflush
(
stdout
);
#endif
}
}
Write
Preview
Markdown
is supported
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