dynamorio icon indicating copy to clipboard operation
dynamorio copied to clipboard

i#3544 RV64: Implement return address handling for post wrappers

Open apach301 opened this issue 1 year ago • 6 comments

Substitute value of return address register to enable post wrappers.

Partially enables drwrap-test for RISC-V:

  1. Add drwrap-test-callconv test to pipeline
  2. Partially supported drwrap-drreg-test: check for pre/post wrappers passes, but checks for clean_call and restore registers functionality are failing.

Issue: https://github.com/DynamoRIO/dynamorio/issues/3544

apach301 avatar Mar 27 '24 12:03 apach301

I suppose this is covered by some tests, do these tests work now? If yes, maybe state that in the PR description and enable it in the RUN_ON_QEMU label for RISC-V so it can be checked by the CI.

I tested it only on my DR client. I don't familiar with DynamoRIO test system, and all I found is https://github.com/DynamoRIO/dynamorio/blob/8e23247a8610e954584c9b8ad0481b058118e16e/suite/tests/CMakeLists.txt#L3032 and https://github.com/DynamoRIO/dynamorio/blob/8e23247a8610e954584c9b8ad0481b058118e16e/suite/tests/CMakeLists.txt#L3061 that are disabling drwrap tests on RISC-V. Is it sufficient to just remove the guards to enable these tests?

Also, as much as I understand, the one failing test (ci-aarchxx) isn't related to these changes, and is failing on current master.

apach301 avatar Mar 28 '24 10:03 apach301

Yes, remove the guards should be enough for CMake to build the test, then add the test name into suite/tests/CMakeLists.txt#L6152 and run ctest -L RUNS_ON_QEMU see if the test passes.

ksco avatar Mar 28 '24 10:03 ksco

Yes, remove the guards should be enough for CMake to build the test, then add the test name into suite/tests/CMakeLists.txt#L6152 and run ctest -L RUNS_ON_QEMU see if the test passes.

The tests couldn't be compiled currently for RISCV64: it needs a platform-depend fixes in suite/tests/client-interface/drwrap-drreg-test.dll.c, which requires implementing some functions in core/ir/riscv64/instr_create_api.h.in.

apach301 avatar Mar 29 '24 15:03 apach301

I suppose you’re referring to XINST_CREATE_cmp() and XINST_CREATE_jmp_cond? There won’t be such thing on RISC-V since we don’t have eflags. You can use INSTR_CREATE_beq() to rewrite this part for RISC-V.

ksco avatar Mar 29 '24 15:03 ksco

I suppose you’re referring to XINST_CREATE_cmp() and XINST_CREATE_jmp_cond? There won’t be such thing on RISC-V since we don’t have eflags. You can use INSTR_CREATE_beq() to rewrite this part for RISC-V.

Finally being able to compile and run tests. Test drwrap-callconv seems to work, but with drwrap-drreg things more complicated. The part with pre/post wrappers passes, the part with drreg save/restore registers fails.

Moreover, for riscv default callconv is not working, it requires explicitly setup DRWRAP_CALLCONV_RISCV_LP64 | DRWRAP_REPLACE_RETADDR flags

apach301 avatar Apr 02 '24 16:04 apach301

Please don't do force push, see: https://dynamorio.org/page_code_reviews.html.

ksco avatar Apr 03 '24 10:04 ksco

@derekbruening @ksco Disabled unimplemented drwrap-drreg-test, now CI for riscv passes.

apach301 avatar Aug 06 '24 15:08 apach301

Please see https://dynamorio.org/page_code_reviews.html#autotoc_md118 "request a re-review...clicking the re-review button..."

derekbruening avatar Aug 06 '24 15:08 derekbruening

Sorry still on vacation this week.

ksco avatar Aug 06 '24 16:08 ksco