Skip to contentSkip to conversation

Can mm_struct of a process be null?

DISCUSSION Paul Davies C 3 participants 3 messages Nov 15, 2013 – Nov 18, 2013

lore
Share & tools
lore
#0 lore raw

Hi,
I happen to find this code snippet in the kernel source :

**/*struct mm_struct *mm=current->mm**;**
**

     /* some other code */

** if(mm){ /*<==Why is **this here? */**
** /*read the contents by locking*/**
** }

*/The/if /checks whether the mm_struct of the current process is NULL or
not. That means the mm_struct of a process can become NULL. How can that
happen?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131115/90060719/attachment.html

#1 lore raw
Quoted 11 lines · Paul Davies C

Hi,

    I happen to find this code snippet in the kernel source :

    struct mm_struct *mm=current->mm;

    /* some other code */

    if(mm){ /*<==Why is this here? */
        /*read the contents by locking*/
    }
Quoted 2 lines

The if checks whether the mm_struct of the current process is NULL or not. That means the mm_struct of a process can become NULL. How can that happen?

mm_struct points to a process address space. It is NULL for kernel threads.

Daniel.

#2 lore raw
In reply to Paul Davies C

Yes, current->mm points to user space context for the current process. Now for a kernel threads there is no user space context and for them current->mm would be NULL.

Thanks,
Chetan Nanda

Quoted 17 lines · Paul Davies C

Hi,
I happen to find this code snippet in the kernel source :

*struct mm_struct *mm=current->mm; /* some other code */ if(mm){
/*<==Why is this here? */ /*read the contents by locking*/ } *
The* if *checks whether the mm_struct of the current process is NULL or not. That means the mm_struct of a process can become NULL. How can that happen?

Quoted 6 lines

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131118/18eb181f/attachment.html