Skip to content

[Bug] rt-smart(risc-v64)信号处理函数出现load page fault以及pthread_cancel无法取消线程问题 #10501

Description

@eatvector

RT-Thread Version

rt-smart master

Hardware Type/Architectures

qemu-virt64-riscv

Develop Toolchain

GCC

Describe the bug

  1. 问题复现

运行下面测试代码,linux可以正确取消终止线程而rt-smart下无法取消终止线程,还可能出现load page fault,由于rt-smart 的risc-v64工具链不支持取消点检测(见#10492),手动插入 __testcancel():

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>

pthread_t tid;

static void *subthread(void *arg)
{
    while (1) {
        // 取消点检测
        __testcancel();
        printf("%s: %d\n", __func__, __LINE__);
        usleep(1000000);
    }

    return 0;
}

int main(int argc, char **argv)
{
    pthread_create(&tid, NULL, subthread, 0);

    usleep(100);

    printf("%s: %d\n", __func__, __LINE__);
    pthread_cancel(tid);
    printf("%s: %d\n", __func__, __LINE__);
    pthread_join(tid, NULL);
    printf("%s: %d\n", __func__, __LINE__);

    return 0;
}

  1. 问题定位

出现load page fault:定位到是由于用户态信号处理函数会访问线程TLS数据,risc-v架构下通过tp寄存器寻址,而内核将控制流转交到到用户态信号处理函数时没有恢复线程tp指针,已提交解决pr:#10499

pthread_cancel无法取消线程:定位到是子线程线程一直反复执行cancel_handler信号处理函数,从而无法继续执行第一次被信号中断处的后续代码,导致其无法运行到延迟取消点,从而无法终止,已提交解决pr:#10500

Other additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions