-
-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aarch64 be patches #985
base: main
Are you sure you want to change the base?
Aarch64 be patches #985
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -220,6 +220,7 @@ gum_arm64_writer_init (GumArm64Writer * writer, | |||||
writer->label_defs = NULL; | ||||||
writer->label_refs.data = NULL; | ||||||
writer->literal_refs.data = NULL; | ||||||
writer->data_endian = GUM_ENDIAN_NATIVE; | ||||||
|
||||||
gum_arm64_writer_reset (writer, code_address); | ||||||
} | ||||||
|
@@ -1992,15 +1993,37 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self) | |||||
if (r->width != GUM_LITERAL_64BIT) | ||||||
continue; | ||||||
|
||||||
/* | ||||||
* Whilst instructions in aarch64 are always in little endian (even on | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(Here and elsewhere.) For consistency with our existing comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
* big-endian systems), the data is in native endian. Thus since we wish to | ||||||
* support writing code for big-endian systems on little-endian targets and | ||||||
* vice versa, we need to check the writer configuration. | ||||||
*/ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this comment to where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
for (slot = first_slot; slot != last_slot; slot++) | ||||||
{ | ||||||
if (GINT64_FROM_LE (*slot) == r->val) | ||||||
WorksButNotTested marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
break; | ||||||
if (self->data_endian == GUM_ENDIAN_LITTLE) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the optimizer able to avoid repeatedly reading and checking this field's value, or should we introduce a local variable used throughout the function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be very surprised if the optimizer didn't take care of it anyway, but the actual code generation part isn't hugely performance critical (to the point where a few cycles matter), its the performance of the generated code which is most important (for applications such as fuzzing). |
||||||
{ | ||||||
if (GINT64_FROM_LE (*slot) == r->val) | ||||||
break; | ||||||
} | ||||||
else | ||||||
{ | ||||||
if (GINT64_FROM_BE (*slot) == r->val) | ||||||
break; | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
if (slot == last_slot) | ||||||
{ | ||||||
*slot = GINT64_TO_LE (r->val); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Like above.) |
||||||
if (self->data_endian == GUM_ENDIAN_LITTLE) | ||||||
{ | ||||||
*slot = GINT64_TO_LE (r->val); | ||||||
} | ||||||
else | ||||||
{ | ||||||
*slot = GINT64_TO_BE (r->val); | ||||||
} | ||||||
last_slot = slot + 1; | ||||||
} | ||||||
|
||||||
|
@@ -2024,15 +2047,36 @@ gum_arm64_writer_commit_literals (GumArm64Writer * self) | |||||
if (r->width != GUM_LITERAL_32BIT) | ||||||
continue; | ||||||
|
||||||
/* | ||||||
* Whilst instructions in aarch64 are always in little endian (even on | ||||||
* big-endian systems), the data is in native endian. Thus since we wish to | ||||||
* support writing code for big-endian systems on little-endian targets and | ||||||
* vice versa, we need to check the writer configuration. | ||||||
*/ | ||||||
for (slot = first_slot; slot != last_slot; slot++) | ||||||
{ | ||||||
if (GINT32_FROM_LE (*slot) == r->val) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Like above.) |
||||||
break; | ||||||
if (self->data_endian == GUM_ENDIAN_LITTLE) | ||||||
{ | ||||||
if (GINT32_FROM_LE (*slot) == r->val) | ||||||
break; | ||||||
} | ||||||
else | ||||||
{ | ||||||
if (GINT32_FROM_BE (*slot) == r->val) | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
if (slot == last_slot) | ||||||
{ | ||||||
*slot = GINT32_TO_LE (r->val); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Like above.) |
||||||
if (self->data_endian == GUM_ENDIAN_LITTLE) | ||||||
{ | ||||||
*slot = GINT32_TO_LE (r->val); | ||||||
} | ||||||
else | ||||||
{ | ||||||
*slot = GINT32_TO_BE (r->val); | ||||||
} | ||||||
last_slot = slot + 1; | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,6 +33,7 @@ G_BEGIN_DECLS | |||||
|
||||||
typedef struct _GumArm64Writer GumArm64Writer; | ||||||
typedef guint GumArm64IndexMode; | ||||||
typedef guint GumArm64DataEndian; | ||||||
|
||||||
struct _GumArm64Writer | ||||||
{ | ||||||
|
@@ -51,6 +52,15 @@ struct _GumArm64Writer | |||||
GumMetalArray label_refs; | ||||||
GumMetalArray literal_refs; | ||||||
const guint32 * earliest_literal_insn; | ||||||
|
||||||
GumArm64DataEndian data_endian; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I kept the |
||||||
}; | ||||||
|
||||||
enum _GumArm64DataEndian | ||||||
{ | ||||||
GUM_ENDIAN_LITTLE = __ORDER_LITTLE_ENDIAN__, | ||||||
GUM_ENDIAN_BIG = __ORDER_BIG_ENDIAN__, | ||||||
GUM_ENDIAN_NATIVE = __BYTE_ORDER__, | ||||||
}; | ||||||
|
||||||
enum _GumArm64IndexMode | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment should go just before
target_os
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.