Commit Graph

23 Commits

Author SHA1 Message Date
PhilippTakacs
65ed715081 Snapshot use after free (#2125)
* memory snapshots fix use after free on flatview copy

When restoring a snapshot with memory the flatview must be restored
before the memory reagions are filtered. Because the
AddressSpaceDispatcher also has pointer to the MemoryRegions and on copy
they need to be cleared. The memory_filter_subregions function frees
MemoryRegions which are not used at the time of the snapshot.

* fix some memleaks in tests

These tests has forgott to call uc_close(uc), which lead to memory
leaks. Found by the LeakSanitizer.

* memory snapshots correct clean up container memory regions

* Fix further stackoverflow in tests

---------

Co-authored-by: mio <mio@lazym.io>
2025-03-06 23:23:02 +08:00
Martin Atkins
7d8fe2ab11 riscv: Expose privilege level as pseudo-register PRIV (#1989)
Unlike some other architectures, RISC-V does not expose the current
privilege mode in any architecturally-defined register. That is intentional
to make it easier to implement virtualization in software, but a Unicorn
caller operates outside of the emulated hart and so it can and should be
able to observe and change the current privilege mode in order to properly
emulate certain behaviors of a real CPU.

The current privilege level is therefore now exposed as a new
pseudo-register using the name "priv", which matches the name of the
virtual register used by RISC-V's debug extension to allow the debugger
to read and change the privilege mode while the hart is halted. Unicorn's
use of it is conceptually similar to a debugger.

The bit encoding of this register is the same as specified in RISC-V Debug
Specification v1.0-rc3 Section 4.10.1. It's defined as a "virtual"
register exposing a subset of fields from the dcsr register, although here
it's implemented directly inside the Unicorn code because QEMU doesn't
currently have explicit support for the CSRs from the debug specification.
If it supports "dcsr" in a future release then this implementation could
change to wrap reading and writing that CSR and then projecting the "prv"
and "v" bitfields into the correct locations for the virtual register.
2024-11-11 21:09:45 +08: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
d7a806c026 Reformat code with format.sh 2023-06-16 15:23:41 -07:00
Takacs, Philipp
e96ac42b2e Remove MMU hacks
Unicorn has included some ugly hacks to provide a envirement where vaddr == paddr.
These hacks where to use the full 64 bit mappings on x86 without init the mmu
and some memory redirect for MIPS.

The UC_TLB_CPU mode defaults to vaddr == paddr, therfor these hacks aren't
required anymore.
2023-03-28 14:02:17 +02:00
Takacs, Philipp
7f1eb4532d add basic mmu tests
Some simple tests for diffrent mmu.
Basicly add some tlb entries, enable the mmu try to read from virtual address

The aarm64 test was provided by imre-kis-arm in #1718
2023-03-28 13:50:11 +02:00
ba50035830 Format code 2022-05-23 12:30:44 +02:00
dae48aecee Mem hook should return a bool 2022-05-20 13:31:54 +02:00
Quentin DUCASSE
f569417878 Equivalent tests for riscv 2022-05-04 17:18:47 +02:00
shuffle2
2912cd1e29 fix rust bindings build on windows (#1584)
Refine rust bindings.
2022-04-16 13:40:04 +02:00
7bb0abb977 Format 2021-12-22 20:37:15 +01:00
Quentin DUCASSE
033e79abac Added cache flush after code patching in unit tests for arm64 and riscv 2021-12-17 14:55:08 +01:00
Quentin DUCASSE
549274f44c Code patching tests for riscv and arm64 2021-12-10 15:27:54 +01:00
907ec5095d Fix a stackoverflow in tests 2021-11-21 19:28:45 +01:00
fc467edbc6 Fix 32bit target getting wrong offset for mmio 2021-11-16 22:40:57 +01:00
c6fdbb3735 Add RISCV CSR registers 2021-11-07 20:36:04 +01:00
67e2386da6 Add test and close #1477 2021-11-03 21:40:13 +01:00
58edb2abe7 Format 2021-11-03 13:28:12 +01:00
09aa0f944f Merge QDucasse:riscv_extension_d
Fix and close #1469

Fix test for riscv float points

Fix the riscv cpu config we left out
2021-11-03 13:20:46 +01:00
e62b0ef255 Add clang-format and format code to qemu code style 2021-10-29 12:44:49 +02:00
Quentin DUCASSE
5fd90ca1ef Added 3 steps unit test 2021-10-19 17:20:10 +02:00
Quentin DUCASSE
47f986fc93 Unit test POC for RISCV issue 2021-10-19 17:12:52 +02:00
Nguyen Anh Quynh
aaaea14214 import Unicorn2 2021-10-03 22:14:44 +08:00