samedi 27 juin 2015

locking inside system calls using kernel modules

I have replaced the sys_open system call in the system call table to implement a tallying system. What lock must I use? The spin_lock_irqsave() function freezes the system. I am using an Intel Core i3-4330 on Linux 3.16.0-4-686-pae.

Partial but revelant code:

static DEFINE_SPINLOCK(spin);
static int tally = 0;

static asmlinkage long my_sys_open(const char __user *filename, int flags, int mode)
{
    unsigned long fl;
    spin_lock_irqsave(&spin, fl); // system freeze

    tally++;

    spin_unlock_irqrestore(&spin, fl);

    printk("sys_open used %i times\n", tally);

    return old_sys_open(filename, flags, mode);
}

Aucun commentaire:

Enregistrer un commentaire