Friday, September 20, 2019

Wednesday, September 18, 2019



userspace::insmod.c

int
main(int argc, char *argv[])
{
ret = init_module(file, len, options);


SYSCALL_DEFINE3(init_module, void __user *, umod,
unsigned long, len, const char __user *, uargs)
{

return load_module(&info, uargs, 0);



SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
{

return load_module(&info, uargs, flags);


static int load_module(struct load_info *info, const char __user *uargs,
       int flags)
{

/* Module is ready to execute: parsing args may do that. */
after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
  -32768, 32767, mod,
  unknown_module_param_cb);

return do_init_module(mod);



static int unknown_module_param_cb(char *param, char *val, const char *modname,
   void *arg)
{
struct module *mod = arg;
int ret;

if (strcmp(param, "async_probe") == 0) {
mod->async_probe_requested = true;
return 0;
}

/* Check for magic 'dyndbg' arg */
ret = ddebug_dyndbg_module_param_cb(param, val, modname);
if (ret != 0)
pr_warn("%s: unknown parameter '%s' ignored\n", modname, param);
return 0;
}


/*
 * This is where the real work happens.
 *
 * Keep it uninlined to provide a reliable breakpoint target, e.g. for the gdb
 * helper command 'lx-symbols'.
 */
static noinline int do_init_module(struct module *mod)
{
int ret = 0;
struct mod_initfree *freeinit;

freeinit = kmalloc(sizeof(*freeinit), GFP_KERNEL);
if (!freeinit) {
ret = -ENOMEM;
goto fail;
}
freeinit->module_init = mod->init_layout.base;

/*
* We want to find out whether @mod uses async during init.  Clear