Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
Zipr Toolchain
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
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
Open Source Software
Zipr Toolchain
Commits
36c74548
Commit
36c74548
authored
6 years ago
by
Jason Hiser
Browse files
Options
Downloads
Patches
Plain Diff
changes to support scons from peasoup-umbrella dir
parent
1c1e26a1
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
SConscript
+2
-1
2 additions, 1 deletion
SConscript
unpin.cpp
+6
-58
6 additions, 58 deletions
unpin.cpp
unpin_aarch64.cpp
+0
-1
0 additions, 1 deletion
unpin_aarch64.cpp
unpin_x86.cpp
+4
-11
4 additions, 11 deletions
unpin_x86.cpp
with
15 additions
and
71 deletions
.gitignore
+
3
−
0
View file @
36c74548
...
...
@@ -2,3 +2,6 @@
build
*.swp
*.os
*.o
*.zpi
This diff is collapsed.
Click to expand it.
SConscript
+
2
−
1
View file @
36c74548
...
...
@@ -63,4 +63,5 @@ Default( pedi )
ret
=
pedi
+
lib
Return
(
'
ret
'
)
This diff is collapsed.
Click to expand it.
unpin.cpp
+
6
−
58
View file @
36c74548
...
...
@@ -43,57 +43,6 @@ using namespace Zipr_SDK;
#define ALLOF(a) begin(a),end(a)
static
std
::
string
findAndReplace
(
const
std
::
string
&
in_str
,
const
std
::
string
&
oldStr
,
const
std
::
string
&
newStr
)
{
std
::
string
str
=
in_str
;
size_t
pos
=
0
;
while
((
pos
=
str
.
find
(
oldStr
,
pos
))
!=
std
::
string
::
npos
)
{
str
.
replace
(
pos
,
oldStr
.
length
(),
newStr
);
pos
+=
newStr
.
length
();
}
return
str
;
}
static
bool
has_cfi_reloc
(
Instruction_t
*
insn
)
{
for
(
auto
reloc
:
insn
->
getRelocations
())
{
/* check for a nonce relocation */
if
(
reloc
->
getType
().
find
(
"cfi_nonce"
)
!=
string
::
npos
)
{
return
true
;
}
}
return
false
;
}
bool
Unpin_t
::
should_cfi_pin
(
Instruction_t
*
insn
)
{
// add command line option that:
// 1) return false if !has_cfi_reloc(insn)
// 2) return true if option is on.
return
*
m_should_cfi_pin
;
}
#if 0
ZiprOptionsNamespace_t *Unpin_t::registerOptions(ZiprOptionsNamespace_t *global)
{
auto unpin_ns = new ZiprOptionsNamespace_t("unpin");
global->addOption(&m_verbose);
m_should_cfi_pin.setDescription("Pin CFI instructions.");
unpin_ns->addOption(&m_should_cfi_pin);
m_on.setDescription("Turn unpin plugin on/off.");
unpin_ns->addOption(&m_on);
m_max_unpins.setDescription("Set how many unpins are allowed, useful for debugging.");
unpin_ns->addOption(&m_max_unpins);
return unpin_ns;
}
#endif
// CAN BE DELETED, left in just for stats? (Would speed up zipr step to delete)
void
Unpin_t
::
DoUnpin
()
...
...
@@ -106,7 +55,7 @@ void Unpin_t::DoUnpin()
// scan instructions and process instruction relocs that can be unpinned.
void
Unpin_t
::
DoUnpinForFixedCalls
()
{
if
(
*
m_max_unpins
!=
-
1
&&
unpins
>=
*
m_max_unpins
)
if
(
(
int64_t
)
*
m_max_unpins
!=
(
int64_t
)
-
1
&&
(
int64_t
)
unpins
>=
(
int64_t
)
*
m_max_unpins
)
return
;
auto
insn_unpins
=
0
;
auto
missed_unpins
=
0
;
...
...
@@ -130,7 +79,7 @@ void Unpin_t::DoUnpinForFixedCalls()
unpins
++
;
insn_unpins
++
;
if
(
*
m_max_unpins
!=
-
1
&&
unpins
>=
*
m_max_unpins
)
if
(
(
int64_t
)
*
m_max_unpins
!=
(
int64_t
)
-
1
&&
(
int64_t
)
unpins
>=
(
int64_t
)
*
m_max_unpins
)
return
;
}
}
...
...
@@ -143,8 +92,9 @@ void Unpin_t::DoUnpinForFixedCalls()
// CAN BE DELETED, left in just for stats?
void
Unpin_t
::
DoUnpinForScoops
()
{
if
(
*
m_max_unpins
!=
-
1
&&
unpins
>=
*
m_max_unpins
)
if
(
(
int64_t
)
*
m_max_unpins
!=
(
int64_t
)
-
1
&&
(
int64_t
)
unpins
>=
(
int64_t
)
*
m_max_unpins
)
return
;
auto
missed_unpins
=
0
;
auto
scoop_unpins
=
0
;
...
...
@@ -161,7 +111,7 @@ void Unpin_t::DoUnpinForScoops()
unpins
++
;
scoop_unpins
++
;
if
(
*
m_max_unpins
!=
-
1
&&
unpins
>=
*
m_max_unpins
)
if
(
(
int64_t
)
*
m_max_unpins
!=
(
int64_t
)
-
1
&&
(
int64_t
)
unpins
>=
(
int64_t
)
*
m_max_unpins
)
return
;
}
}
...
...
@@ -179,13 +129,11 @@ Zipr_SDK::ZiprPreference Unpin_t::retargetCallback(
if
(
!*
m_on
)
return
Zipr_SDK
::
ZiprPluginInterface_t
::
retargetCallback
(
callback_address
,
callback_entry
,
target_address
);
unpins
++
;
// unpinning a call to a scoop.
if
(
*
m_max_unpins
!=
-
1
&&
unpins
>=
*
m_max_unpins
)
if
(
(
int64_t
)
*
m_max_unpins
!=
(
int64_t
)
-
1
&&
(
int64_t
)
unpins
>=
(
int64_t
)
*
m_max_unpins
)
return
Zipr_SDK
::
ZiprPluginInterface_t
::
retargetCallback
(
callback_address
,
callback_entry
,
target_address
);
auto
&
ms
=*
zo
->
getMemorySpace
();
auto
insn
=
callback_entry
->
getInstruction
();
auto
&
locMap
=*
(
zo
->
getLocationMap
());
for
(
auto
reloc
:
insn
->
getRelocations
())
{
if
(
reloc
->
getType
()
==
string
(
"callback_to_scoop"
))
...
...
This diff is collapsed.
Click to expand it.
unpin_aarch64.cpp
+
0
−
1
View file @
36c74548
...
...
@@ -58,7 +58,6 @@ void UnpinAarch64_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* re
const
auto
insn_wrt
=
dynamic_cast
<
Instruction_t
*>
(
reloc
->
getWRT
());
assert
(
the_arg_it
!=
operands
.
end
());
const
auto
the_arg
=*
the_arg_it
;
const
auto
mt
=
firp
.
getArchitecture
()
->
getMachineType
();
// get the new insn addr
const
auto
from_insn_location
=
(
VirtualOffset_t
)
locMap
[
from_insn
];
...
...
This diff is collapsed.
Click to expand it.
unpin_x86.cpp
+
4
−
11
View file @
36c74548
...
...
@@ -102,7 +102,6 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc)
const
auto
insn_wrt
=
dynamic_cast
<
Instruction_t
*>
(
reloc
->
getWRT
());
assert
(
the_arg_it
!=
operands
.
end
());
const
auto
the_arg
=*
the_arg_it
;
const
auto
mt
=
firp
.
getArchitecture
()
->
getMachineType
();
// get the new insn addr
const
auto
from_insn_location
=
(
VirtualOffset_t
)
locMap
[
from_insn
];
...
...
@@ -133,7 +132,7 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc)
const
auto
disp_offset
=
(
int
)
disasm
->
getMemoryDisplacementOffset
(
the_arg
.
get
(),
from_insn
);
const
auto
disp_size
=
(
int
)
the_arg
->
getMemoryDisplacementEncodingSize
();
assert
(
disp_size
==
4
);
assert
(
0
<
disp_offset
&&
disp_offset
<=
from_insn
->
getDataBits
().
size
()
-
disp_size
);
assert
(
0
<
disp_offset
&&
(
int64_t
)
disp_offset
<=
(
int64_t
)
from_insn
->
getDataBits
().
size
()
-
disp_size
);
const
auto
new_disp
=
(
int
)(
rel_addr1
+
to_addr
-
from_insn
->
getDataBits
().
size
()
-
from_insn_location
);
const
auto
newbits
=
from_insn
->
getDataBits
().
replace
(
disp_offset
,
disp_size
,
(
char
*
)
&
new_disp
,
disp_size
);
...
...
@@ -158,12 +157,11 @@ void UnpinX86_t::HandleAbsptrReloc(Instruction_t* from_insn, Relocation_t* reloc
assert
(
wrt
);
assert
(
the_arg_it
!=
operands
.
end
());
const
auto
&
the_arg
=*
the_arg_it
;
VirtualOffset_t
rel_addr1
=
the_arg
->
getMemoryDisplacement
();
int
disp_offset
=
disasm
->
getMemoryDisplacementOffset
(
the_arg
.
get
(),
from_insn
);
int
disp_size
=
the_arg
->
getMemoryDisplacementEncodingSize
();
assert
(
disp_size
==
4
);
assert
(
0
<
disp_offset
&&
disp_offset
<=
from_insn
->
getDataBits
().
size
()
-
disp_size
);
assert
(
0
<
disp_offset
&&
(
int64_t
)
disp_offset
<=
(
int64_t
)
from_insn
->
getDataBits
().
size
()
-
disp_size
);
assert
(
reloc
->
getWRT
());
unsigned
int
new_disp
=
the_arg
->
getMemoryDisplacement
()
+
wrt
->
getStart
()
->
getVirtualOffset
();
...
...
@@ -210,21 +208,17 @@ void UnpinX86_t::HandleImmedptrReloc(Instruction_t* from_insn, Relocation_t* rel
void
UnpinX86_t
::
HandleCallbackReloc
(
Instruction_t
*
from_insn
,
Relocation_t
*
reloc
)
{
DataScoop_t
*
wrt
=
dynamic_cast
<
DataScoop_t
*>
(
reloc
->
getWRT
());
int
addend
=
reloc
->
getAddend
();
char
bytes
[]
=
{(
char
)
0x48
,
(
char
)
0x8d
,
(
char
)
0x64
,
(
char
)
0x24
,
(
char
)(
64
/
0x08
)};
// lea rsp, [rsp+8]
uintptr_t
call_addr
=
0x0
,
at
=
0x0
;
uint32_t
target_addr
=
0x0
;
if
(
m_verbose
)
cout
<<
"The call insn is "
<<
from_insn
->
getDataBits
().
length
()
<<
" bytes long."
<<
endl
;
call_addr
=
locMap
[
from_insn
];
auto
call_addr
=
locMap
[
from_insn
];
if
(
m_verbose
)
{
cout
<<
"Unpin::callback_to_scoop: call_addr "
...
...
@@ -234,8 +228,7 @@ void UnpinX86_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* rel
/*
* Put down the bogus pop.
*/
at
=
call_addr
+
1
;
at
=
call_addr
+
from_insn
->
getDataBits
().
length
();
auto
at
=
call_addr
+
from_insn
->
getDataBits
().
length
();
ms
.
plopBytes
(
at
,
bytes
,
sizeof
(
bytes
));
/*
...
...
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