DynamoRIO / DynamoRIO/dynamorio

Move dr_simd_t to separate allocation to support dynamic vector sizing and reduce stack usage

Open
#7,212 0 comments 0 reactions 0 assignees View on GitHub
Type-Feature
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 15h
Merged PRs (30d)
31

Description

Xref discussion at https://github.com/DynamoRIO/dynamorio/issues/3544#issuecomment-2605265904 on splitting out dr_simd_t from the mcontext to help reduce offset sizes for RISC-V.

The primary cross-arch benefit of separating out dr_simd_t and making it dynamically allocated would be to support any vector size. Today both RISC-V and AArch64 support large SIMD vectors, but DR has a hardcoded cap (256-bit for RISC-V and 512-bit for AArch64) in order to keep the mcontext small and stack-allocatable.

The size of the mcontext is a problem on all platforms since DR uses small thread stacks. Allocating several mcontexts across a call chain can overflow the stack and with today's large SIMD fields inside mcontext we have to be careful declaring them on the stack. See comments in signal.c like these:
```C
/* It's safe to allocate since we do not send signals that interrupt DR.
* With priv_mcontext_t x2 that's a little big for stack alloc.
*/
si.mcontext = heap_alloc(dcontext, sizeof(*si.mcontext) HEAPACCT(ACCT_OTHER));
si.raw_mcontext = heap_alloc(dcontext, sizeof(*si.raw_mcontext) HEAPACCT(ACCT_OTHER));
```
```
/* Helper that takes over the current thread signaled via SUSPEND_SIGNAL. Kept
* separate mostly to keep the priv_mcontext_t allocation out of
* main_signal_handler_C.
```

However, there are signal handler paths where we need to declare and use new mcontexts and allocating heap is problematic. An indirected dr_simd_t could still be placed on the stack right after the mcontext: but only if there's stack space. We would have to create a new signal-safe heap pool for dr_simd_t, which has to be provisioned ahead of time and so has per-thread overhead to be considered (we run applications with thousands of threads).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.