简体   繁体   中英

Pointers Accessing Incorrect Addresses OS161

I'm using OS161, and I have a piece of code that looks like this in 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();


}

The definition of process struct:

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;
};

I'm getting an END OF FILE error, and GDB told me it was where process_exit was defined. I'm not super familiar with OS programming, does anyone know why this could be happening?

Edit: This was the GDB message:

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...

I did gdb list *0x8001a008 and it pointed to the curthread->p_process->exited_flag = 1; .

Given @ctx's analysis, try this code to prove whether we're on the right track:

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 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM