Try/catch for modules?

Rik van Riel riel at surriel.com
Fri Oct 18 17:24:57 EDT 2019


On Fri, 2019-10-18 at 12:43 -0300, Martin Galvan wrote:
> El jue., 17 oct. 2019 a las 19:13, Valdis Klētnieks
> (<valdis.kletnieks at vt.edu>) escribió:
> > For starters, the *correct* in-kernel way to deal with this is:
> >         if (!ptr) {
> >                 printk("You blew it!\n");
> >                 goto you_blew_it;
> >         }
> 
> goto statements are harmful. In any case, what I meant was to have
> some sort of safety net to prevent exceptions (i.e. if I screw up and
> forget a NULL check) from panicking the system.

https://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/

> > Also, "current PID" and "my module" aren't two things that can
> > correspond....
> 
> I don't understand what you mean by that. Module code (e.g. an ioctl)
> runs as some process. In the case of an ioctl, I'd assume it's the
> same PID of the user process.

Every time you test whether the PID is the PID of the
currently running process, it will be true. Think of
the kernel as a privileged shared library, not as a
program that userspace happens to communicate with.

-- 
All Rights Reversed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20191018/a9c8f141/attachment.sig>


More information about the Kernelnewbies mailing list