google / google/mpact-cheriot

cgettop sometimes returning wrong value?

Open
#2 2 comments 0 reactions 1 assignee Claimed by @torj9n View on GitHub
Dominant language
C++
Stars
8
Forks
2
PR merge metrics
No merged PRs in 30d

Description

We observed the following when stepping through the attached elf with mpact:

```
ct2 = 0x8000aed0 (v: 1 0x8000aed0-0x08000b290 l: 0x0000003c0 o: 0x0 p: - RWcmgl -- ---)
cgettop s0, ct2
cs0 = 0x8000b480 (v: 0 0x8000b400-0x08000b400 l: 0x000000000 o: 0x0 p: - ------ -- ---)
```

Note that the top returned is not the top of `ct2`. This happens in the [CHERIoT RTOS switcher when truncating the stack](https://github.com/CHERIoT-Platform/cheriot-rtos/blob/a6d409e2ab2b9f4ccef79f912a3bf830809c1508/sdk/core/switcher/entry.S#L455) causing a crash. The same file runs successfully with the Sail simulator.

It might be relevant that the immediately preceding instruction is a `CSetBoundsRoundDown`?

We also notice that there is a commented out line in the [implementation of cgettop](https://github.com/google/mpact-cheriot/blame/7fb7c59cd46a248f47dc245e91ad9324ce13c984/cheriot/riscv_cheriot_instructions.cc#L149) that is a bit puzzling.

[cgettop_test.elf.zip](https://github.com/user-attachments/files/27532398/cgettop_test.elf.zip)

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.