【问题标题】:Pointers Accessing Incorrect Addresses OS161指针访问不正确的地址 OS161
【发布时间】:2020-06-24 19:54:55
【问题描述】:

我使用的是 OS161,我在process.c 中有一段代码如下所示:

void
process_exit(int exit_code)
{
   splhigh(); 
    curthread->p_process->exited_flag = 1; // Process exited
    curthread->p_process->exit_code = exit_code;
    struct process * process;

    // Now all the child process will be orphant, we need to adopt them
    // Search through the process table, change all children's ppid

    for (int i = 0; i < array_getnum(process_table); i++) {
        *process = array_getguy(process_table, i);
        if (process != NULL && process->ppid == curthread->p_process->pid) { // We found a child here, it should be a orphant now
            process->ppid = 1; // Now the init(boot/menu) process should adopt the child process
            process->adopted_flag = 1;
        }
    }

    V(curthread->p_process->sem_exit); // Now signal processes which are waiting

    // Now exit the thread
    thread_exit();


}

流程结构定义:

struct process{

char* process_name;

struct addrspace *process_vmspace;


struct vnode *process_cwd;

pid_t pid;
pid_t ppid;
int adopted_flag;
int exited_flag;
int exit_code;
struct thread *p_thread;
struct semaphore *sem_exit;
};

我收到一个END OF FILE 错误,GDB 告诉我这是定义process_exit 的地方。我对操作系统编程不是很熟悉,有人知道为什么会这样吗?

编辑:这是 GDB 消息:

panic: Fatal exception 3 (TLB miss on store) in kernel mode
panic: EPC 0x8001a008, exception vaddr 0x18
sleep: Dropping thread <boot/menu>
panic: I can't handle this... I think I'll just die now...

我做了gdb list *0x8001a008,它指向curthread-&gt;p_process-&gt;exited_flag = 1;

【问题讨论】:

  • gdb 是否在 process_exit() 中指明了精确的行号?也许它只是表示“process_exit 中的某个地方”(这看起来根本不像 gdb)。也许您在解释 gdb 消息时遇到了麻烦?如果是这样,请修改您的问题以发布所显示的确切消息。
  • curthreadcurthread-&gt;p_process 为 NULL。大概吧。
  • 我对 OS161 不熟悉,很惊讶一个简单的教学操作系统会打扰 TLB;我想知道 TLB 缓存未命中 是否是更直接的病理。
  • @wallyk 好吧,如果底层硬件只支持软件管理的 TLB,那么操作系统就没有太多选择了

标签: c operating-system os161


【解决方案1】:

鉴于@ctx 的分析,试试这段代码来证明我们是否走在正确的轨道上:

void
process_exit(int exit_code)
{
    splhigh();
    if (curthread  &&  curthread->p_process)
    {
        curthread->p_process->exited_flag = 1; // Process exited
        curthread->p_process->exit_code = exit_code;
    }
    // same code as before below here ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    相关资源
    最近更新 更多