-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fuse aarch64 register moves #2723
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
Open
siraben
wants to merge
1
commit into
ish-app:master
Choose a base branch
from
siraben:bench/hot-system-paths
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ void gen_exit(struct gen_state *state) { | |
| // This should stay in sync with the definition of .gadget_array in gadgets.h | ||
| enum arg { | ||
| arg_reg_a, arg_reg_c, arg_reg_d, arg_reg_b, arg_reg_sp, arg_reg_bp, arg_reg_si, arg_reg_di, | ||
| arg_reg_ah = arg_reg_sp, arg_reg_ch = arg_reg_bp, arg_reg_dh = arg_reg_si, arg_reg_bh = arg_reg_di, | ||
| arg_imm, arg_mem, arg_addr, arg_gs, | ||
| arg_count, arg_invalid, | ||
| // the following should not be synced with the list mentioned above (no gadgets implement them) | ||
|
|
@@ -212,6 +213,45 @@ static inline bool gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a | |
| GEN(state->orig_ip | state->orig_ip_extra); | ||
| return true; | ||
| } | ||
|
|
||
| static inline enum arg gen_resolve_arg(enum arg arg, struct modrm *modrm, uint64_t *imm, dword_t addr_offset) { | ||
|
Member
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. This is basically the same code as what is right above it, can we avoid duplicating it? We aren't even using its full functionality; I think we should probably just fastpath the things we care about |
||
| switch (arg) { | ||
| case arg_modrm_reg: | ||
| return modrm->reg + arg_reg_a; | ||
| case arg_modrm_val: | ||
| return modrm->type == modrm_reg ? modrm->base + arg_reg_a : arg_mem; | ||
| case arg_mem_addr: | ||
| modrm->type = modrm_mem; | ||
| modrm->base = reg_none; | ||
| modrm->offset = addr_offset; | ||
| return arg_mem; | ||
| case arg_1: | ||
| *imm = 1; | ||
| return arg_imm; | ||
| default: | ||
| return arg; | ||
| } | ||
| } | ||
|
|
||
| static inline bool gen_mov(struct gen_state *state, enum arg src, enum arg dst, struct modrm *modrm, uint64_t *imm, int size, bool seg_gs, dword_t addr_offset) { | ||
| src = gen_resolve_arg(src, modrm, imm, addr_offset); | ||
| dst = gen_resolve_arg(dst, modrm, imm, addr_offset); | ||
|
|
||
| #if defined(__aarch64__) | ||
| if (size == 32 && src >= arg_reg_a && src <= arg_reg_di && dst >= arg_reg_a && dst <= arg_reg_di) { | ||
| if (src != dst) { | ||
| extern gadget_t mov32_reg_reg_gadgets[]; | ||
| GEN(mov32_reg_reg_gadgets[(dst - arg_reg_a) * 8 + (src - arg_reg_a)]); | ||
| } | ||
| return true; | ||
| } | ||
| #endif | ||
|
|
||
| extern gadget_t load_gadgets[]; | ||
| extern gadget_t store_gadgets[]; | ||
| return gen_op(state, load_gadgets, src, modrm, imm, size, seg_gs, addr_offset) && | ||
| gen_op(state, store_gadgets, dst, modrm, imm, size, seg_gs, addr_offset); | ||
| } | ||
| #define op(type, thing, z) do { \ | ||
| extern gadget_t type##_gadgets[]; \ | ||
| if (!gen_op(state, type##_gadgets, arg_##thing, &modrm, &imm, z, seg_gs, addr_offset)) return false; \ | ||
|
|
@@ -223,7 +263,7 @@ static inline bool gen_op(struct gen_state *state, gadget_t *gadgets, enum arg a | |
| #define los(o, src, dst, z) load(dst, z); op(o, src, z); store(dst, z) | ||
| #define lo(o, src, dst, z) load(dst, z); op(o, src, z) | ||
|
|
||
| #define MOV(src, dst,z) load(src, z); store(dst, z) | ||
| #define MOV(src, dst,z) do { if (!gen_mov(state, arg_##src, arg_##dst, &modrm, &imm, z, seg_gs, addr_offset)) return false; } while (0) | ||
| #define MOVZX(src, dst,zs,zd) load(src, zs); gz(zero_extend, zs); store(dst, zd) | ||
| #define MOVSX(src, dst,zs,zd) load(src, zs); gz(sign_extend, zs); store(dst, zd) | ||
| // xchg must generate in this order to be atomic | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we have an each_reg macro for this or something like that