Compiling kernel code on Linux

Well, I'm reading about Linux kernel development, and there are some code snippets using kernel data structures and stuff. Say I would like to experiment with them, for example. there is a very simple fragment:

#include <../../linux-2.6.37.1/include/linux/sched.h>
struct task_struct *task;
for_each_process(task) {
    printk("%s[%d]\n", task->comm, task->pid);
}

Seems pretty simple, huh? Now I can’t build a thing. I am using NetBeans. The sched.h file is the correct file, as if it had pressed CTRL +, it was added to the desired file.

Do I have any way to add a sample file and build a core piece of the Makefile? I just wanted to see what he was building and might work. If I need to build an entire core, how would I really test my stuff?

I have to do something really stupid as I am very new to kernel development. I lost a little bit.

Thanks guys!

+5
source share
5 answers

You do not need to compile the entire kernel, but you should at least create a kernel module that is much easier to compile. You should take a look at a textbook, such as this one , or even a full blown book, such as this .

Keep in mind that not all kernel codes can be moved to a module β€” only those that use the public (exported) kernel interfaces. Code that is an integral part of core kernels (such as a VM or scheduler) is probably not available to the rest of the kernel.

, - . , . VirtualBox.

, : , . , -, , ​​, . , , -, .

C, , , Linux-. , . , X- .

BTW Netbeans . , , , . , IDE . ( ), edit- > compile- > run- > debug, IDE.

C, Vim Emacs. Emacs IDE ( ), , , IDE .

+6

, , , ... , , . . . . C ( C).

task_struct, . - .

+1

. "" ( , , ) . "" , . :

    if (unlikely(inode_init_always(sb, inode))) {
            if (inode->i_sb->s_op->destroy_inode)
                    inode->i_sb->s_op->destroy_inode(inode);
            else
                    kmem_cache_free(inode_cachep, inode);
            return NULL;
    }

, inodes . , . ( , , .)

, qemu + kvm virtualbox uml, . "" , , .

.:)

+1

systemtap :

# stap -g -e 'probe begin { your_function() exit() }
%{
#include <linux/whatever.h>
%}
function your_function() %{
   ... insert safe c code here ...
%}'

( stap --remote=VIRTMACHINE ...).

0

All Articles