Commit Graph

3043 Commits

Author SHA1 Message Date
Eli 922c1e6333
Merge branch 'dev' into uc-py-next 2023-07-13 23:00:01 +03:00
lockbox 2f2bf8d96f add cpu model to architectures for rust bindings 2023-07-13 13:58:14 -04:00
lockbox 84fe5d1756 expose ffi in rust bindings 2023-07-13 13:57:04 -04:00
lazymio e88264c658
Merge pull request #1820 from PhilippTakacs/cow
add memory snapshots
2023-07-11 19:24:00 +08:00
Takacs, Philipp ab5938b3f6 Update CREDITS.TXT 2023-07-11 11:51:44 +02:00
Takacs, Philipp df18756234 implement uc_mem_unmap with snapshots
still has todos and need tests
2023-07-11 11:51:44 +02:00
Takacs, Philipp 716c8f1c4c handle snapshots over context_save context_restore 2023-07-11 11:51:44 +02:00
Takacs, Philipp e54cf7ee03 find_ram_offset optimization
The ram_offset allocator searches the smalest gap in the ram_offset address space.
This is slow especialy in combination with many allocation (i.e. snapshots). When
it is known that there is no gap, this is now optimized.
2023-07-11 11:51:44 +02:00
Takacs, Philipp 550265f3c1 snapshot benchmark
simple benchmark for the snapshots
2023-07-11 11:51:44 +02:00
Takacs, Philipp 80bd825420 implement simple memory snapshot mechanismus
Uses Copy on Write to make it posible to restore the memory state after a snapshot
was made. To restore all MemoryRegions created after the snapshot are removed.
2023-07-11 11:51:40 +02:00
Takacs, Philipp 065af19dc5 use address_space_translate to find memory mapping
first version has bugs
2023-07-11 11:47:50 +02:00
Takacs, Philipp cd85f589a2 add memory_region_add_subregion_overlap 2023-07-11 11:47:50 +02:00
mio aee4038526
Fix test_x86_0xff_lcall test 2023-07-07 18:50:55 +08:00
Robert Xiao f55e7834ba Replace javah by javac -h, only write new constant files if something changes.
The const_generator changes help to ensure that e.g. Java rebuilds don't keep
rebuilding everything.
2023-07-06 20:12:36 -07:00
mio 2325f41ead
Add a unit test for a7a5d187e7 2023-06-30 20:28:59 +08:00
mio a7a5d187e7
Backport 10b8eb94c0
target/i386: Verify memory operand for lcall and ljmp

These two opcodes only allow a memory operand.

Lacking the check for a register operand, we used the A0 temp

without initialization, which led to a tcg abort.
2023-06-30 20:21:56 +08:00
Robert Xiao 763d04127c Switch Java bindings to reg2 API.
This is mostly an extra safety measure; the front-end Unicorn.java should always
be sending an appropriately-sized buffer.
2023-06-29 16:37:42 -07:00
Robert Xiao dfdc8e7e8e Switch to Maven to build the Java bits.
Maven is now used to update the constants, build the Java code, call make to
build the native library, and run all the tests. I have removed the "install"
and "uninstall" targets; instead, the expectation will be that the JNI library
will be placed somewhere on java.library.path and the JAR file will be used as
usual (e.g. in a downstream Maven project, or placed on the classpath of your
project).

Since Maven is now running our tests, this eliminates the need to bundle test
dependencies in `testdep`, and makes the project structured more like a typical
Java project.
2023-06-29 16:08:18 -07:00
mio 247d643f2f
Restore Py2 compatibility 2023-06-28 16:40:43 +08:00
mio d6d1af243f
Specify the source directory explicitly 2023-06-28 16:40:17 +08:00
mio 75676eb0cd
Also rebuild flags for aarch32 2023-06-28 10:39:25 +08:00
Nguyen Anh Quynh 3bba11c402 remove all legacy DYNLOAD code 2023-06-22 12:19:06 +08:00
lazymio d4b92485b1
Remove stale bot 2023-06-17 23:51:46 +02:00
Robert Xiao 2198ea4f69 Add comment about unicorn_Unicorn.h to the .c file 2023-06-17 14:34:25 -07:00
Robert Xiao d9407c9041 Add a link to the relevant issue for ARM PAC handling 2023-06-17 14:22:56 -07:00
Robert Xiao 05f6fb9bf3 Properly check return value of makeHookWrapper 2023-06-17 14:19:10 -07:00
Robert Xiao 98f70d3213 Port sample_batch_reg.c to Java, incidentally finding a bug in the generic register implementation. 2023-06-17 14:19:10 -07:00
Robert Xiao edd80ddeda Port sample_x86_32_gdt_and_seg_regs over to Sample_x86_mmr 2023-06-17 14:19:10 -07:00
Robert Xiao 4f563490e2 Update Java samples to match C samples.
Also add all of the samples as Java tests, referencing the output of the C
samples.
2023-06-17 14:19:10 -07:00
Robert Xiao 3739c7e3e0 Write some code to test out ARM64 CP register handling. 2023-06-17 14:19:10 -07:00
Robert Xiao 910bb572d3 Accept unsigned BigIntegers, and produce unsigned BigIntegers by default.
Unsigned BigIntegers are a bit more ergonomic, particularly for bitwise
operations. reg_write still accepts negative BigIntegers (and will automatically
sign extend them), but reg_read will produce unsigned BigIntegers by default.
2023-06-17 14:19:10 -07:00
Robert Xiao d4df61b4c5 Refactor tests and add a few more 2023-06-17 14:19:10 -07:00
Robert Xiao 77d4a1d8b1 Fix definition of uc_version 2023-06-17 14:19:10 -07:00
Robert Xiao 32e638dcf4 Add more deprecated APIs for backwards compat 2023-06-17 14:19:10 -07:00
Robert Xiao 48870c4cc3 Reintroduce hook_del(Hook), since it seems useful.
This also improves backwards compatibility a bit.
2023-06-17 14:19:10 -07:00
Robert Xiao e787f49d21 Use an incrementing handle instead of returning a raw pointer to the user. 2023-06-17 14:19:10 -07:00
Robert Xiao 4764d54250 Javadoc updates 2023-06-17 14:19:10 -07:00
Robert Xiao 3fab8abca7 Restore some of the less problematic old APIs for backwards compatibility. 2023-06-17 14:19:10 -07:00
Robert Xiao b8bd25030e Javadoc updates 2023-06-17 14:19:10 -07:00
Robert Xiao 78de584409 Switch samples to use long instead of Long for registers 2023-06-17 14:19:10 -07:00
Robert Xiao aa430587cc Rewrite the Java bindings.
This brings the Java API up to par with Python feature-wise and substantially
simplifies the hook implementation, enabling proper bounds-checked hooks.

The rewrite strives for compatibility with the previous API, but there are some
breaking changes. It is possible to push closer to full backwards compatibility
if required, at the cost of reintroducing some of the suboptimal designs. Here
are the main points of breakage:

- ReadHook and WriteHook are gone, replaced simply by MemHook. Hooking valid
  memory accesses now requires a type parameter. This enables fetch and
  read-after hooks with a unified API and a single callback object.
- mem_read now takes an int, not a long. We are unable to allocate more than 2GB
  in a single request anyway (Java limitation).
- Instruction hooks now require specifying the instruction explicitly, instead
  of guessing based on the hook type. This is necessary to distinguish
  sysenter/syscall and ARM64 mrs/msr/sys/sysl, without excessively bloating the
  library with redundant hook types. Bounds must also be specified, to support
  bounds-checked instruction hooks.
- Reading object-type registers (any register larger than 64 bits, or registers
  with special formats) requires a second argument to reg_read. This allows us
  to provide a fast reg_read that returns a long for the common cases, while
  still supporting a more general reg_read for other registers.
- mem_map_ptr is rewritten to take a *direct* java.nio.Buffer, which enables
  many more use cases than a simple byte array, and improves performance (a
  byte array cannot really be used as a mapped buffer without GC-pinning it,
  which hurts the GC performance).
- Context handling API is redesigned to be safer and more object-oriented.

A lot of bugs are fixed with this implementation:
- Unicorn instances can be properly garbage-collected, instead of hanging around
  forever in the Unicorn.unicorns table.
- Hooks no longer fire outside of their bounds (#1164), and in fact, hook bounds
  are properly respected (previously, all hooks were just registered globally to
  all addresses).
- Hooks are substantially faster, as they are now dispatched directly via a
  single method call rather than being indirected through invokeCallbacks.
- Loading vector registers works now, rather than crashing the VM (#1539).

Several features are now enabled in the Java implementation:

- All of the current ctl_* calls are implemented.
- mmio_map is implemented.
- New virtual TLB mode is implemented.
- reading/writing Context registers is implemented.
- New hook types are added: TcgOpcodeHook, EdgeGeneratedHook,
  InvalidInstructionHook, TlbFillHook, and the instruction hooks Arm64SysHook,
  CpuidHook.
- All known special registers are supported.
2023-06-17 14:19:10 -07:00
Robert Xiao 8777bb6ae6 Make close() idempotent and fix Unicorn memory leak. 2023-06-17 14:19:10 -07:00
Robert Xiao 66c8965f96 Set up testing infrastructure ("make test") 2023-06-17 14:19:10 -07:00
Robert Xiao 4b471e16e9 Remove redundant Makefile 2023-06-17 14:19:10 -07:00
Robert Xiao 9cdb5cb745 Reformat Java bindings. 2023-06-17 14:17:57 -07:00
lazymio c5ae96536b
Merge pull request #1835 from nneonneo/reg_ops2
Implement reg_{read,write}2 API
2023-06-17 21:47:26 +02:00
Robert Xiao 2b80ab425b Return new UC_ERR_OVERFLOW instead of UC_ERR_NOMEM when reg buffer is too small 2023-06-16 15:30:59 -07:00
Robert Xiao b041345a73 Fix RISCV test_riscv32_fp_move test
RISCV FP registers are 64-bit in size, even in 32-bit mode, because they can
hold doubles. The test even uses the double-precision instruction fmv.d. Thus,
the reads should be reading 64-bit registers.
2023-06-16 15:23:43 -07:00
Robert Xiao 30d202b89e Simplify reg_read/reg_write, obtaining a perf boost.
Single reg_read/reg_write is now about 25% faster.
2023-06-16 15:23:42 -07:00
Robert Xiao 074566cf69 Slight refactoring to reduce code duplication.
This also comes with a performance bump due to inlining of reg_read/reg_write
(as they're only called once now) and the unlikely() on CHECK_REG_TYPE.
2023-06-16 15:23:42 -07:00