Skip to content

[components][lwp] fix signal ordering and ELF segment protection - #11895

Open
BernardXiong wants to merge 3 commits into
RT-Thread:masterfrom
BernardXiong:pr/lwp-signal-elf
Open

BernardXiong wants to merge 3 commits into
RT-Thread:masterfrom
BernardXiong:pr/lwp-signal-elf

Conversation

@BernardXiong

@BernardXiong BernardXiong commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

拉取/合并请求描述:(PR description)

为什么提交这份PR (why to submit this PR)

Signals with the same number were inserted in reverse order, ELF segments were always mapped read-write regardless of p_flags, and RISC-V signal handling ran with interrupts disabled while taking sleeping locks.

你的解决方案是什么 (what is your solution)

  • keep FIFO order for signals carrying the same signal number
  • map ELF segments with permissions derived from p_flags
  • keep the scheduler usable while handling signals on RISC-V

请提供验证的bsp和config (provide the config and bsp)

  • BSP: bsp/qemu-virt64-riscv (RT-Thread Smart)
  • .config: CONFIG_RT_USING_SMART=y
  • action: local build not run; the RISC-V musleabi toolchain is not available in this environment, CI will verify the build

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

- keep FIFO order for signals carrying the same signal number
- map ELF segments with permissions derived from p_flags
- keep the scheduler usable while handling signals on RISC-V
@BernardXiong
BernardXiong marked this pull request as ready for review October 18, 2026 12:07
@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 pr/lwp-signal-elf
    Enter PR branch pr/lwp-signal-elf in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 pr/lwp-signal-elf 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the pr/lwp-signal-elf branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/lwp/arch/risc-v/rv64/lwp_gcc.S
  • components/lwp/lwp_elf.c
  • components/lwp/lwp_signal.c

🏷️ Tag: components_lwp

Reviewers: @xu18838022837

Changed Files (Click to expand)
  • components/lwp/arch/risc-v/rv64/lwp_gcc.S
  • components/lwp/lwp_elf.c
  • components/lwp/lwp_signal.c

📊 Current Review Status (Last Updated: 2026-11-01 00:52 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions github-actions Bot added RT-Smart RT-Thread Smart related PR or issues component: lwp Component labels Oct 18, 2026
- expand the protection flag checks to braced statements
- no functional change
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

esp32-c3

  • dram0_0_seg: .dram0.bss +9,208 B, .dram0.data +168 B, .dram0.dummy -22,016 B (-5.7%, 208,608 B / 325,120 B, total: 64% used)
  • drom0_0_seg: .eh_frame +78,544 B, .eh_frame_hdr +12,376 B, .flash.rodata +27,368 B, .flash_rodata_dummy +196,608 B (+76.6%, 725,908 B / 8,388,576 B, total: 9% used)
  • iram0_0_seg: .iram0.text -21,766 B, .iram0.text_end -250 B (-29.3%, 53,248 B / 325,120 B, total: 16% used)
  • iram0_2_seg: .flash.text +199,784 B, .text +474 B (+87.2%, 429,852 B / 8,388,576 B, total: 5% used)
  • rtc_iram_seg: .rtc.text +8 B (+60.0%, 64 B / 8,192 B, total: 1% used)

k230

  • SRAM: .bss +4,096 B, .data +8 B, .eh_frame +13,752 B, .sbss +120 B, .srodata.cst8 +16 B, .stack -8 B, .text +62,648 B (+7.1%, 1,209,180 B / 268,300,288 B, total: 0% used)

nordic-nrf51822

  • FLASH: .text -8 B (-0.0%, 52,028 B / 262,144 B, total: 20% used)

nuvoton-m487

  • CODE: .text +24 B (+0.0%, 356,200 B / 524,288 B, total: 68% used)

qemu-virt64-aarch64

  • Code: .eh_frame -15,064 B, .text -52,624 B (-6.3%, 1,010,124 B)
  • Data: .bss +597,200 B, .data -47,560 B (+106.2%, 1,067,160 B)

raspberry-pico-rp2040

  • FLASH: .text -8 B (-0.0%, 114,160 B / 2,097,152 B, total: 5% used)

simulator

  • Code: .eh_frame +4 B, .rela.dyn -216 B, .rodata -23 B, .text +5 B (-0.0%, 2,672,790 B)
  • Data: .data -256 B (-0.0%, 1,609,028 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Comment thread components/lwp/lwp_elf.c
Comment on lines +619 to +636
static size_t elf_prot_from_pflags(uint32_t p_flags)
{
size_t prot = PROT_NONE;
if (p_flags & PF_R)
{
prot |= PROT_READ;
}
if (p_flags & PF_W)
{
prot |= PROT_WRITE;
}
if (p_flags & PF_X)
{
prot |= PROT_EXEC;
}
return prot;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个在后续的:

rt_inline rt_size_t lwp_user_mm_attr_to_kernel(int prot)
{
RT_UNUSED(prot);
rt_size_t k_attr = 0;
#ifdef LWP_USING_MPROTECT
if ((prot & PROT_EXEC) || (prot & PROT_WRITE) ||
((prot & PROT_READ) && (prot & PROT_WRITE)))
k_attr = MMU_MAP_U_RWCB;
else if (prot == PROT_NONE)
k_attr = MMU_MAP_K_RWCB;
else
k_attr = MMU_MAP_U_ROCB;
#else /* !LWP_USING_MPROTECT */
k_attr = MMU_MAP_U_RWCB;
#endif /* LWP_USING_MPROTECT */
return k_attr;
}

不开启 LWP_USING_MPROTECT 会默认设置为 MMU_MAP_U_RWCB,此处是否需要添加 LWP_USING_MPROTECT 控制比较好一些

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

并且原本 elf_file_mmap 的注释放到了elf_prot_from_pflags 前面了

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 prot 只有在开启 LWP_USING_MPROTECT 时才真正生效:lwp_user_mm_attr_to_kernel() 在未开启 MPROTECT 时(lwp_user_mm.h 的 #else 分支)会忽略入参并统一返回 MMU_MAP_U_RWCB,所以映射行为和修改前完全一致,这里不需要再额外加 #ifdef 控制。

已在 commit 7fae086 的调用点补充注释说明这一点,避免后续读者误以为未开启 MPROTECT 时会被映射成只读/可执行。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修正(commit 7fae086):把 elf_prot_from_pflags() 移到 elf_file_mmap() 的 kernel-doc 注释之前,并给这个 helper 单独补了简短注释,elf_file_mmap() 的文档重新紧挨着函数。

Move the new elf_prot_from_pflags() helper above the kernel-doc block of
elf_file_mmap() so the documentation stays attached to the function it
describes. Also document that deriving the protection from p_flags is a
no-op while LWP_USING_MPROTECT is disabled, because
lwp_user_mm_attr_to_kernel() maps every attribute as MMU_MAP_U_RWCB.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: lwp Component RT-Smart RT-Thread Smart related PR or issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants