You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

内核PCI设备枚举时getDriver函数莫名阻塞问题求助

PCI控制器设备识别时getDriver函数阻塞问题

问题背景

我在编写小型系统内核时,PCI控制器识别设备的代码会卡在getDriver函数处——哪怕这个函数仅返回0,依然会出现阻塞。下载教程配套源码在本地编译运行,同样触发该问题,因此确定是本地计算机环境导致的异常。

相关代码

PCI控制器设备扫描函数

//PCI controller function
void PeripheralComponentInterconnectController::selectDrivers(DriverManager* driver_manager,InterruptManager* interrupt_manager){
    // printf("{ void PeripheralComponentInterconnectController::selectDrivers\n");
    int function_num=0;
    for(int bus=0;bus<8;++bus){
        for(int device=0;device<32;++device){
            function_num=deviceHasFunction(bus,device) ? 8:1;
            for(int function=0;function<function_num;++function){
                PeripheralComponentInterconnectDeviceDescriptor dev= getDeviceDescriptor(bus,device,function);
                if(dev.vendor_id == 0 || dev.vendor_id == 0xFFFF){
                    continue;
                }
                for(int bar_num=0;bar_num<6;++bar_num){
                    BaseAddreeRegister bar = getBaseAddressRegister(bus,device,function,bar_num);
                    if(bar.addr && (bar.type == InputOutput))
                        dev.port_base = (uint32_t)bar.addr;
                }
// blocked in this getDriver
                Driver* driver = getDriver(dev, interrupt_manager);
                if(driver != 0){
                    driver_manager->AddDriver(driver);
                }
//end 
                printf("FOUND DEVICE:");
                printf("PCI BUS:");
                printfHex(bus & 0xFF);
                printf(",DEVICE:");
                printfHex(device & 0xFF );
                printf(", FUNCTION:");
                printfHex(function & 0xFF);
                printf(" = VENDOR_ID:");
                printfHex((dev.vendor_id & 0xFF00) >> 8);
                printfHex(dev.vendor_id & 0xFF);
                printf(",DEVICE_ID:");
                printfHex((dev.device_id & 0xFF00) >> 8);
                printfHex(dev.device_id & 0xFF);
                printf("\n");

            }
        }
    }

}

阻塞点getDriver函数

//getDriver function:
Driver*
PeripheralComponentInterconnectController::getDriver(PeripheralComponentInterconnectDeviceDescriptor dev,
InterruptManager* interrupt_manager){
   
    return 0; 
}

排查过程

  1. 最初怀疑是栈溢出:将getDriver的参数PeripheralComponentInterconnectDeviceDescriptor dev改为指针传递PeripheralComponentInterconnectDeviceDescriptor* dev后,阻塞问题消失。
  2. 尝试增大栈空间验证:在编译参数中添加-Wl,-z,stack-size=4194304(设置栈大小为4MB),改回值传递参数后,依然出现阻塞。

当前使用的Makefile编译参数:

//makefile compile parameter
GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -fpermissive -fno-stack-protector -Iinclude 

疑问

为什么改用指针参数能解决阻塞,但增大栈空间却不行?教程中的相同代码在其环境下正常运行,本地环境的差异点在哪里?


内容的提问来源于stack exchange,提问作者Rain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:36:31