Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
28963ea6
Commit
28963ea6
authored
Jun 08, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #583 from toshok/mmap-runtime-ics
allocate runtime ics using mmap (with PROT_EXEC)
parents
367d2733
aa69f64b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
src/runtime/ics.cpp
src/runtime/ics.cpp
+30
-0
src/runtime/ics.h
src/runtime/ics.h
+3
-0
No files found.
src/runtime/ics.cpp
View file @
28963ea6
...
@@ -14,6 +14,10 @@
...
@@ -14,6 +14,10 @@
#include "runtime/ics.h"
#include "runtime/ics.h"
#ifndef NVALGRIND
#include <sys/mman.h>
#endif
#include "asm_writing/icinfo.h"
#include "asm_writing/icinfo.h"
#include "asm_writing/rewriter.h"
#include "asm_writing/rewriter.h"
#include "codegen/compvars.h"
#include "codegen/compvars.h"
...
@@ -26,6 +30,10 @@
...
@@ -26,6 +30,10 @@
#include "core/stats.h"
#include "core/stats.h"
#include "core/types.h"
#include "core/types.h"
#ifndef NVALGRIND
#define PAGE_SIZE 4096
#endif
namespace
pyston
{
namespace
pyston
{
// I am not sure if we should use the equivalent of -fomit-frame-pointer for these trampolines.
// I am not sure if we should use the equivalent of -fomit-frame-pointer for these trampolines.
...
@@ -163,7 +171,13 @@ static void writeTrivialEhFrame(void* eh_frame_addr, void* func_addr, uint64_t f
...
@@ -163,7 +171,13 @@ static void writeTrivialEhFrame(void* eh_frame_addr, void* func_addr, uint64_t f
void
EHFrameManager
::
writeAndRegister
(
void
*
func_addr
,
uint64_t
func_size
)
{
void
EHFrameManager
::
writeAndRegister
(
void
*
func_addr
,
uint64_t
func_size
)
{
assert
(
eh_frame_addr
==
NULL
);
assert
(
eh_frame_addr
==
NULL
);
#ifdef NVALGRIND
eh_frame_addr
=
malloc
(
EH_FRAME_SIZE
);
eh_frame_addr
=
malloc
(
EH_FRAME_SIZE
);
#else
eh_frame_addr
=
mmap
(
NULL
,
(
EH_FRAME_SIZE
+
(
PAGE_SIZE
-
1
))
&
~
(
PAGE_SIZE
-
1
),
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
RELEASE_ASSERT
(
eh_frame_addr
!=
MAP_FAILED
,
""
);
#endif
writeTrivialEhFrame
(
eh_frame_addr
,
func_addr
,
func_size
);
writeTrivialEhFrame
(
eh_frame_addr
,
func_addr
,
func_size
);
// (EH_FRAME_SIZE - 4) to omit the 4-byte null terminator, otherwise we trip an assert in parseEhFrame.
// (EH_FRAME_SIZE - 4) to omit the 4-byte null terminator, otherwise we trip an assert in parseEhFrame.
// TODO: can we omit the terminator in general?
// TODO: can we omit the terminator in general?
...
@@ -174,7 +188,11 @@ void EHFrameManager::writeAndRegister(void* func_addr, uint64_t func_size) {
...
@@ -174,7 +188,11 @@ void EHFrameManager::writeAndRegister(void* func_addr, uint64_t func_size) {
EHFrameManager
::~
EHFrameManager
()
{
EHFrameManager
::~
EHFrameManager
()
{
if
(
eh_frame_addr
)
{
if
(
eh_frame_addr
)
{
deregisterEHFrames
((
uint8_t
*
)
eh_frame_addr
,
(
uint64_t
)
eh_frame_addr
,
EH_FRAME_SIZE
);
deregisterEHFrames
((
uint8_t
*
)
eh_frame_addr
,
(
uint64_t
)
eh_frame_addr
,
EH_FRAME_SIZE
);
#ifdef NVALGRIND
free
(
eh_frame_addr
);
free
(
eh_frame_addr
);
#else
munmap
(
eh_frame_addr
,
(
EH_FRAME_SIZE
+
(
PAGE_SIZE
-
1
))
&
~
(
PAGE_SIZE
-
1
));
#endif
}
}
}
}
...
@@ -227,8 +245,16 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
...
@@ -227,8 +245,16 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
static
const
int
CALL_SIZE
=
13
;
static
const
int
CALL_SIZE
=
13
;
int
patchable_size
=
num_slots
*
slot_size
;
int
patchable_size
=
num_slots
*
slot_size
;
#ifdef NVALGRIND
int
total_size
=
PROLOGUE_SIZE
+
patchable_size
+
CALL_SIZE
+
EPILOGUE_SIZE
;
int
total_size
=
PROLOGUE_SIZE
+
patchable_size
+
CALL_SIZE
+
EPILOGUE_SIZE
;
addr
=
malloc
(
total_size
);
addr
=
malloc
(
total_size
);
#else
total_size
=
PROLOGUE_SIZE
+
patchable_size
+
CALL_SIZE
+
EPILOGUE_SIZE
;
addr
=
mmap
(
NULL
,
(
total_size
+
(
PAGE_SIZE
-
1
))
&
~
(
PAGE_SIZE
-
1
),
PROT_READ
|
PROT_WRITE
|
PROT_EXEC
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
RELEASE_ASSERT
(
addr
!=
MAP_FAILED
,
""
);
#endif
// printf("Allocated runtime IC at %p\n", addr);
// printf("Allocated runtime IC at %p\n", addr);
...
@@ -285,7 +311,11 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
...
@@ -285,7 +311,11 @@ RuntimeIC::RuntimeIC(void* func_addr, int num_slots, int slot_size) {
RuntimeIC
::~
RuntimeIC
()
{
RuntimeIC
::~
RuntimeIC
()
{
if
(
ENABLE_RUNTIME_ICS
)
{
if
(
ENABLE_RUNTIME_ICS
)
{
deregisterCompiledPatchpoint
(
icinfo
.
get
());
deregisterCompiledPatchpoint
(
icinfo
.
get
());
#ifdef NVALGRIND
free
(
addr
);
free
(
addr
);
#else
munmap
(
addr
,
total_size
);
#endif
}
else
{
}
else
{
}
}
}
}
...
...
src/runtime/ics.h
View file @
28963ea6
...
@@ -35,6 +35,9 @@ public:
...
@@ -35,6 +35,9 @@ public:
class
RuntimeIC
{
class
RuntimeIC
{
private:
private:
void
*
addr
;
void
*
addr
;
#ifndef NVALGRIND
size_t
total_size
;
#endif
EHFrameManager
eh_frame
;
EHFrameManager
eh_frame
;
std
::
unique_ptr
<
ICInfo
>
icinfo
;
std
::
unique_ptr
<
ICInfo
>
icinfo
;
...
...
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