Repository navigation
i#1726: Port Umbra to ARM - #2044
Conversation
Pulls out shadow_table_insert_app_to_shadow() into 2 arch-specific methods for x86 and for ARM. Also implements this method for ARM. Issue: #1726
| disp_hi >>= 0x10; | ||
|
|
||
| /* %reg_idx = table */ | ||
| PRE(ilist, where, INSTR_CREATE_movw(drcontext, |
There was a problem hiding this comment.
INSTR_CREATE_load_int() does not load 32-bit ints, so I resorted to using movw and movt. Is there a shorthand for this in the repo already? If not, should there be one?
There was a problem hiding this comment.
There is instrlist_insert_mov_immed_ptrsz()
There was a problem hiding this comment.
Whoops, forgot about that method. Done.
|
Some questions:
I think Umbra on x86 and ARM should now be functionally equivalent, but there are no tests in the repo for it; should I add some tests? |
This is a hole is the test suite: see #1468. We would love to have some tests added. |
- Fixes build error/typo in CMakeLists.txt - Replaces movw/movt sequence with instrlist_insert_mov_immed_ptrsz()
|
I'll add some tests in with this CL then. |
derekbruening
left a comment
There was a problem hiding this comment.
Should we split the files up even more? We're basically using all the same code between x86 and ARM, so maybe it's not worth.
If we did split I would suggest renaming umbra_x86.c to umbra_32bit.c (or just umbra_32.c?) and having umbra_x86.c and umbra_arm.c contain the differing code. It does seem weird to have ARM use a file named "umbra_x86.c". We could rename that file and not add any others (keeping the ifdef inside it for that one routine)?
Is the new code sequence alright? It looks non-optimal because it requires a second scratch register, but I haven't been able to get it to use a single scratch register.
I put a suggestion that I think gets rid of the 2nd scratch.
| reg_id_t reg_addr, reg_id_t *regs) | ||
| { | ||
| reg_id_t reg_idx = regs[0]; | ||
| reg_id_t reg_tmp = regs[1]; |
There was a problem hiding this comment.
Hmm, this just looks risky: maybe pass in "int num_scratch_regs" and assert on it or sthg. At least a comment next to the regs (I like scratch_regs better) param.
There was a problem hiding this comment.
Since we can do this with 1 reg, the array is no longer passed in.
| #ifdef X86 | ||
| shadow_table_insert_app_to_shadow_arch(void *drcontext, umbra_map_t *map, | ||
| instrlist_t *ilist, instr_t *where, | ||
| reg_id_t reg_addr, reg_id_t *regs) |
There was a problem hiding this comment.
Since we can do this with 1 reg, the array is no longer passed in.
| /* code sequence: | ||
| * %reg_idx = table | ||
| * %reg_tmp = (%reg_addr >> 0x10) | ||
| * %reg_idx += (%reg_tmp << 0x02) |
There was a problem hiding this comment.
You could get rid of reg_tmp by adding (%reg_addr >> 14) here and then zeroing the bottom 2 bits, right?
There was a problem hiding this comment.
Sorry about the delay. I think this would only work if the static table already has the bottom 2 bits cleared:
reg_idx = 0x41414141
reg_idx += (reg_addr >> 14)
reg_idx &= 0xfffffffc
If we simply clear the last two bits of reg_idx, we might overwrite the bottom 2 bits of the address of the shadow table. I guess it's ok to assume that the static table is 4 byte aligned though, so maybe this is fine.
There was a problem hiding this comment.
Unrelated: there's a confusing variable called static_shadow_table_is_used which is statically set to false, though really the variable should be named static_shadow_table_unused or sthg. Can update this.
There was a problem hiding this comment.
Hmm yeah that seems to never be written to?
There was a problem hiding this comment.
Yup looks like it's only being used once to determine whether to allocate the shadow table using nonheap_alloc() (if static_shadow_table_is_used is true), but uses the static shadow table if static_shadow_table_is_used is false, hence the confusion.
- Reduces number of regs required for Umbra on ARM - Renames umbra_x86 to umbra_32, and umbra_x64 to umbra_64
|
I think most of the failures are the same ones that hit DR when Travis updated their VM image about 2 weeks ago: DynamoRIO/dynamorio#2632, DynamoRIO/dynamorio#2634, DynamoRIO/dynamorio#2641 I fixed the first two but am still working on the last one: if anyone can reproduce it locally that would help a great deal as it is slow going trying to diagnose through just what I can print out on Travis. Xref #2050 where @mxmssh is also hitting failures and about to update DR and I think hitting some further warnings from the clang upgrade. |
| @@ -1,4 +1,4 @@ | |||
| #!/bin/sh | |||
There was a problem hiding this comment.
On my box, /bin/sh -> /bin/dash, and I believe that this script uses a bash-ism. Not sure why I only saw this recently though. Should I change this back?
There was a problem hiding this comment.
Making it bash seems fine: we did the same thing with git_review.sh
| # a function scope, we must set the global vars ahead of time: | ||
| configure_DynamoRIO_global(OFF ON) | ||
|
|
||
| # We save pdb+dll space by not using libc (xref DRi#714). |
There was a problem hiding this comment.
Umbra pulls in libc, so we can't do this anymore.
There was a problem hiding this comment.
That one may have unnecessarily changed Windows too. If I re-instate set(DynamoRIO_USE_LIBC OFF) today and build umbra it builds fine and there are no unusual imports. Missing symbols at runtime are usually a UNIX thing for ELF and !LD_BIND_NOW: on Windows the linker complains at link time.
There was a problem hiding this comment.
Gotcha, should I file an issue and fix in a later CL? Or should I just fix it in this CL (i.e. revert effects of dddcfc6 only for Windows)
|
I only added 2 tests, one of which tests |
| @@ -1,4 +1,4 @@ | |||
| #!/bin/sh | |||
There was a problem hiding this comment.
Making it bash seems fine: we did the same thing with git_review.sh
| # a function scope, we must set the global vars ahead of time: | ||
| configure_DynamoRIO_global(OFF ON) | ||
|
|
||
| # We save pdb+dll space by not using libc (xref DRi#714). |
| PUSH_SEH(REG_XDI) | ||
| sub REG_XSP, FRAME_PADDING /* align */ | ||
| mov REG_XBP, REG_XSP | ||
| sub REG_XSP, 4 |
There was a problem hiding this comment.
The operand alignment looks off here and on the line above. The style guide says "place opcodes on column 8 and start operands on column 17" -- hard to tell from this view which one of lines 78 and 79 is correct.
There was a problem hiding this comment.
Done. Looks like this was a tabs vs spaces confusion issue.
| test1: | ||
| mov REG_XDI, UMBRA_TEST_1_ASM | ||
| mov REG_XDI, UMBRA_TEST_1_ASM | ||
| mov [REG_XBP], REG_XDI |
| test2: | ||
| mov REG_XDI, UMBRA_TEST_2_ASM | ||
| mov REG_XDI, UMBRA_TEST_2_ASM | ||
| mov REG_XDI, [REG_XBP] |
| jmp epilog | ||
|
|
||
| epilog: | ||
| mov REG_XSP, REG_XBP |
For inlined instrumentation, it is a fault handler: e.g., https://github.com/DynamoRIO/drmemory/blob/master/drmemory/fastpath.c#L350. For C code it's sthg like this https://github.com/DynamoRIO/drmemory/blob/master/drmemory/shadow.c#L482 |
Noted. Is there a reason 64-bit Umbra abstracts away the fault handler (i.e. the fault handler appears in umbra_64.c), but 32-bit Umbra does not? Is it due to poor interaction with DrMemory? |
I don't think there's a good reason: it may just be historical, that DrM has a fault handler there for other reasons. Paging @zhaoqin who wrote umbra -- is there a reason? |
- (Hopefully) fixes Windows cmake build error - Fixes whitespace errors in umbra_app.c - Re-adds building without libc on Windows
- tests umbra_insert_app_to_shadow() - tests consistency between umbra_insert_app_to_shadow() and umbra_get_shadow_memory()
|
The travis Mac build seems to be erroring out with the following message: |
DR hit this last week and I was hoping Travis would fix it by now. Searching shows this Travis issue which lists some workarounds (didn't read it all yet): |
Suggested in travis-ci/travis-ci#8552
|
Thanks for trying this here, I'm doing the same thing for DR: DynamoRIO/dynamorio#2672 |
|
Is this ready for merge? Were the last few tests I added reviewed? |
derekbruening
left a comment
There was a problem hiding this comment.
The tests look good to me. Thanks for adding them!
Pulls out shadow_table_insert_app_to_shadow() into 2 arch-specific
methods for x86 and for ARM. Also implements this method for ARM.
Issue: #1726