When you create a module in linux and call do_fork, to insert the module, the display fails.

the code is as follows:

-sharpinclude <linux/init.h>
-sharpinclude <linux/module.h>
-sharpinclude <asm/pgalloc.h>
-sharpinclude <asm/pgtable.h>
-sharpinclude <linux/thread_info.h>
-sharpinclude <linux/slab.h>
-sharpinclude <linux/sched.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sun");

static int __init myModule_init(void)
{

    struct pt_regs *regs;
    
    long id=do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->sp, regs, NULL, NULL);
    
    printk(KERN_ALERT"myModule init----fork_id:%d.\r\n",id);

        return 0;
}

static void __exit myModule_exit(void)
{
    printk(KERN_ALERT"myModule exit.\r\n");
}

module_init(myModule_init);
module_exit(myModule_exit);

then after compiling successfully, insmod page.ko, has the following error:

insmod: ERROR: could not insert module page.ko: Unknown symbol in module

View dmesg | tail:

[108843.437019] page: Unknown symbol do_fork (err 0)

View dependencies:

    modinfo page.ko 
filename:       /home/sun/kernel_code/page.ko
author:         colorfulshark@hotmail.com
license:        GPL
rhelversion:    7.4
srcversion:     3913DBD14892947BDDCE568
depends:        
vermagic:       3.10.0-693.el7.x86_64 SMP mod_unload modversions

after reading the relevant information, do you want to modify it in kernelfork.c? add:

EXPORT_SYMOBL(do_fork)

then recompile the linux kernel, but mine is an x86 platform, and the virtual machine recompiles slowly. I don"t know how the linux kernel code calls the do_fork function?

-sharpinclude < linux/sched.h > already contains the do_fork function, why can"t it be called?


When

insmod, the symbolic address is resolved dynamically. The symbol do_fork is not exported by the kernel, so it will not be resolved successfully.
the symbols exported by the kernel through EXPORT_SYMOBL can only be used by the module, which can be understood as the "legal" API that the kernel provides to the module.

fork is a system call for user-mode applications. Kernel module development does not need it.
if you need a kernel creation thread (process) to execute a task, call the standard kernel API--kthread_run.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be466f-316fa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be466f-316fa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?