首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问不正确地址的指针OS161

访问不正确地址的指针OS161
EN

Stack Overflow用户
提问于 2020-03-13 02:03:04
回答 1查看 98关注 0票数 2

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

代码语言:javascript
复制
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();


}

process结构的定义:

代码语言:javascript
复制
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消息:

代码语言:javascript
复制
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->p_process->exited_flag = 1;

EN

回答 1

Stack Overflow用户

发布于 2020-03-13 02:38:51

根据@ctx的分析,尝试以下代码来证明我们是否在正确的轨道上:

代码语言:javascript
复制
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 ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60659625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档