Semaphore_create causes kernel panic

2019-07-20 14:07发布

问题:

I am developing a kernel extension. I require to use wait and signal mechanism to wait for particular events (programming logics). I am trying to use semaphores as part of the kernel extension to implement the wait and signal methodology.

The creation of semaphore is causing a kernel panic. Need help in figuring out the right implementation. Let me know if I am using it wrong or if there is any other simpler mechanism to wait and signal for kernel development.

The current code which I am using.

semaphore_t CreateWaitEvent() {

    semaphore_t sema;
    //The below semaphore_create line is causing the kernel panic
    if (semaphore_create(current_task(), &sema, SYNC_POLICY_FIFO, 0) != KERN_SUCCESS){
       return NULL;
    }
    return sema;
}

void Wait(semaphore_t event) {
    semaphore_wait(event);
}

void Signal(semaphore_t event) {
    semaphore_signal(event);
}

I am running this kernel extension on VM using parallels software on a MacBookPro. I have enabled kernel debugging.

don't know what I am doing wrong to cause a kernel panic.