当前位置:  开发笔记 > 编程语言 > 正文

学习内核编程

如何解决《学习内核编程》经验,为你挑选了5个好方法。

我想学习lLinux内核编程.

那个起点是什么?什么可能是一些更简单的问题?



1> manav m-n..:
**TODO** +editPic: Linux Kernel Developer -> (Ring Layer 0)
         +addSection: Kernel Virtualization Engine

KERN_WARN_CODING_STYLE: Do not Loop unless you absolutely have to.

未初始化的推荐书籍void *i

"在他们有一定数量的生命,或者无论如何没有人理解一本深刻的书,直到他看到并生活至少部分内容之前,男人才会理解书籍".-Ezra Pound

一千英里的行程必须从一步开始.如果您对以下哪本书开头感到困惑,请不要担心,选择任何一种选择.并非所有徘徊的人都迷失了.由于所有道路最终连接到高速公路,您将在内核旅程中探索新事物,因为页面在不遇到任何死角的情况下进展,并最终连接到code-set.以谨慎的心态阅读并记住:代码不是文学.

剩下的不是事物,情感,图像,心理图像,记忆,甚至是想法.这是一个功能.某种过程.生命的一个方面,可以被描述为"更大"的东西的功能.因此,似乎它与其他东西并没有真正"分开".就像刀切割的东西一样 - 实际上并不是与刀本身分开.该功能目前可能正在使用,也可能没有使用,但它可能永远不会分开.

Solovay Strassen原始性测试的随机化算法:

Solovay Strassen Derandomized Algorithm for Primality Test

Read not to contradict and confute; nor to believe and take for granted; nor to find talk and discourse; but to weigh and consider. Some books are to be tasted, others to be swallowed, and some few to be chewed and digested: that is, some books are to be read only in parts, others to be read, but not curiously, and some few to be read wholly, and with diligence and attention.

static void tasklet_hi_action(struct softirq_action *a)
{
        struct tasklet_struct *list;

        local_irq_disable();
        list = __this_cpu_read(tasklet_hi_vec.head);
        __this_cpu_write(tasklet_hi_vec.head, NULL);
        __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
        local_irq_enable();

        while (list) {
                struct tasklet_struct *t = list;

                list = list->next;

                if (tasklet_trylock(t)) {
                        if (!atomic_read(&t->count)) {
                                if (!test_and_clear_bit(TASKLET_STATE_SCHED,
                                                        &t->state))
                                        BUG();
                                t->func(t->data);
                                tasklet_unlock(t);
                                continue;
                        }
                        tasklet_unlock(t);
                }

                local_irq_disable();
                t->next = NULL;
                *__this_cpu_read(tasklet_hi_vec.tail) = t;
                __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
                __raise_softirq_irqoff(HI_SOFTIRQ);
                local_irq_enable();
        }
}

Core Linux ( 5 -> 1 -> 3 -> 2 -> 7 -> 4 -> 6 )

"Nature has neither kernel nor shell; she is everything at once" -- Johann Wolfgang von Goethe

读者应该精通操作系统概念 ; 公平地理解长时间运行的流程及其与短流程执行的流程的差异; 在满足软实时和硬实时约束的同时容错.阅读时,了解n/ack核心子系统中Linux内核源代码的设计选择非常重要.

线程[和]信号[是]平台依赖的苦难,绝望,恐怖和疯狂的痕迹(~Anthony Baxte).这就是说,在进入内核之前,你应该是一个自我评估的C专家.您还应该具有链接列表,堆栈,队列,红黑树,哈希函数等的良好经验.

volatile int i;
int main(void)
{
    int c;
    for (i=0; i<3; i++) {
        c = i&&&i;
        printf("%d\n", c);    /* find c */
    }
    return 0;
}

Linux内核源代码的美妙和艺术在于故意使用的代码混淆.这通常需要以干净和优雅的方式传达涉及两个或更多个操作的计算含义.在为多核架构编写代码时尤其如此.

关于实时系统,任务调度,内存压缩,内存障碍, SMP的视频讲座

#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

    Linux内核开发 - 罗伯特爱

    理解Linux内核 - Daniel P. Bovet,Marco Cesati

    Linux内核设计的艺术 - 杨丽香

    专业的Linux内核架构 - Wolfgang Mauerer

    UNIX操作系统的设计 - Maurice J. Bach

    了解Linux虚拟内存管理器 - Mel Gorman

    Linux Kernel Internals - Tigran Aivazian

    嵌入式Linux入门 - Christopher Hallinan


Linux设备驱动程序(1 - > 2 - > 4 - > 3 - > 8 - > ...)

"音乐并没有带你到来.你必须严格按照你的能力去实现,只关注那些小小的情感或故事." - 黛比哈利

您的任务基本上是在硬件设备和软件内核之间建立高速通信接口.您应阅读硬件参考数据表/手册,以了解设备的行为及其控制和数据状态以及提供的物理通道.了解您的特定架构的汇编以及对VLSI的公平了解硬件描述VHDL或Verilog等语言将长期为您提供帮助.

英特尔®64和IA-32架构软件开发人员手册

ARM体系结构参考手册

ARM系统开发人员指南

:但是,为什么我必须阅读硬件规格?

:因为,"软件无法弥合碳和硅的鸿沟" - Rahul Sonnad

However, the above doesn't poses a problem for Computational Algorithms (Driver code - bottom-half processing), as it can be fully simulated on a Universal Turing Machine. If the computed result holds true in the mathematical domain, it's a certainty that it is also true in the physical domain.

Video Lectures on Linux Device Drivers (Lec. 17 & 18), Anatomy of an Embedded KMS Driver, Pin Control and GPIO Update, Common Clock Framework, Write a Real Linux Driver - Greg KH

static irqreturn_t phy_interrupt(int irq, void *phy_dat)
{
         struct phy_device *phydev = phy_dat;

         if (PHY_HALTED == phydev->state)
                 return IRQ_NONE;                /* It can't be ours.  */

         /* The MDIO bus is not allowed to be written in interrupt
          * context, so we need to disable the irq here.  A work
          * queue will write the PHY to disable and clear the
          * interrupt, and then reenable the irq line.
          */
         disable_irq_nosync(irq);
         atomic_inc(&phydev->irq_disable);

         queue_work(system_power_efficient_wq, &phydev->phy_queue);

         return IRQ_HANDLED;
}

    Linux Device Drivers - Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman

    Essential Linux Device Drivers - Sreekrishnan Venkateswaran

    Writing Linux Device Drivers - Jerry Cooperstein

    The Linux Kernel Module Programming Guide - Peter Jay Salzman, Michael Burian, Ori Pomerantz

    Linux PCMCIA Programmer's Guide - David Hinds

    Linux SCSI Programming Howto - Heiko Eibfeldt

    Serial Programming Guide for POSIX Operating Systems - Michael R. Sweet

    Linux Graphics Drivers: an Introduction - Stéphane Marchesin

    Programming Guide for Linux USB Device Drivers - Detlef Fliegl

    The Linux Kernel Device Model - Patrick Mochel


Kernel Networking ( 1 -> 2 -> 3 -> ... )

"Call it a clan, call it a network, call it a tribe, call it a family: Whatever you call it, whoever you are, you need one." - Jane Howard

Understanding a packet walk-through in the kernel is a key to understanding kernel networking. Understanding it is a must if we want to understand Netfilter or IPSec internals, and more. The two most important structures of linux kernel network layer are: struct sk_buff and struct net_device

static inline int sk_hashed(const struct sock *sk)
{
        return !sk_unhashed(sk);
} 

    Understanding Linux Network Internals - Christian Benvenuti

    Linux Kernel Networking: Implementation and Theory - Rami Rosen

    UNIX Network Programming - W. Richard Stevens

    The Definitive Guide to Linux Network Programming - Keir Davis, John W. Turner, Nathan Yocom

    The Linux TCP/IP Stack: Networking for Embedded Systems - Thomas F. Herbert

    Linux Socket Programming by Example - Warren W. Gay

    Linux Advanced Routing & Traffic Control HOWTO - Bert Hubert


Kernel Debugging ( 1 -> 4 -> 9 -> ... )

Unless in communicating with it one says exactly what one means, trouble is bound to result. ~Alan Turing, about computers

Brian W. Kernighan, in the paper Unix for Beginners (1979) said, "The most effective debugging tool is still careful thought, coupled with judiciously placed print statements". Knowing what to collect will help you to get the right data quickly for a fast diagnosis. The great computer scientist Edsger Dijkstra once said that testing can demonstrate the presence of bugs but not their absence. Good investigation practices should balance the need to solve problems quickly, the need to build your skills, and the effective use of subject matter experts.

There are times when you hit rock-bottom, nothing seems to work and you run out of all your options. Its then that the real debugging begins. A bug may provide the break you need to disengage from a fixation on the ineffective solution.

Video Lectures on Kernel Debug and Profiling, Core Dump Analysis, Multicore Debugging with GDB, Controlling Multi-Core Race Conditions, Debugging Electronics

/* Buggy Code -- Stack frame problem
 * If you require information, do not free memory containing the information
 */
char *initialize() {
  char string[80];
  char* ptr = string;
  return ptr;
}

int main() {
  char *myval = initialize();
  do_something_with(myval);
}
/*  “When debugging, novices insert corrective code; experts remove defective code.”
 *     – Richard Pattis
#if DEBUG
 printk("The above can be considered as Development and Review in Industrial Practises");
#endif
 */

    Linux Debugging and Performance Tuning - Steve Best

    Linux Applications Debugging Techniques - Aurelian Melinte

    Debugging with GDB: The GNU Source-Level Debugger - Roland H. Pesch

    Debugging Embedded Linux - Christopher Hallinan

    The Art of Debugging with GDB, DDD, and Eclipse - Norman S. Matloff

    Why Programs Fail: A Guide to Systematic Debugging - Andreas Zeller

    Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code - Bill Blunden

    Debugging: Finding most Elusive Software and Hardware Problems - David J. Agans

    Debugging by Thinking: A Multidisciplinary Approach - Robert Charles Metzger

    Find the Bug: A Book of Incorrect Programs - Adam Barr


File Systems ( 1 -> 2 -> 6 -> ... )

"I wanted to have virtual memory, at least as it's coupled with file systems". -- Ken Thompson

On a UNIX system, everything is a file; if something is not a file, it is a process, except for named pipes and sockets. In a file system, a file is represented by an inode, a kind of serial number containing information about the actual data that makes up the file. The Linux Virtual File System VFS caches information in memory from each file system as it is mounted and used. A lot of care must be taken to update the file system correctly as data within these caches is modified as files and directories are created, written to and deleted. The most important of these caches is the Buffer Cache, which is integrated into the way that the individual file systems access their underlying block storage devices.

Video Lectures on Storage Systems, Flash Friendly File System

long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
{
        struct open_flags op;
        int fd = build_open_flags(flags, mode, &op);
        struct filename *tmp;

        if (fd)
                return fd;

        tmp = getname(filename);
        if (IS_ERR(tmp))
                return PTR_ERR(tmp);

        fd = get_unused_fd_flags(flags);
        if (fd >= 0) {
                struct file *f = do_filp_open(dfd, tmp, &op);
                if (IS_ERR(f)) {
                        put_unused_fd(fd);
                        fd = PTR_ERR(f);
                } else {
                        fsnotify_open(f);
                        fd_install(fd, f);
                }
        }
        putname(tmp);
        return fd;
}

SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
{
        if (force_o_largefile())
                flags |= O_LARGEFILE;

        return do_sys_open(AT_FDCWD, filename, flags, mode);
}

    Linux File Systems - Moshe Bar

    Linux Filesystems - William Von Hagen

    UNIX Filesystems: Evolution, Design, and Implementation - Steve D. Pate

    Practical File System Design - Dominic Giampaolo

    File System Forensic Analysis - Brian Carrier

    Linux Filesystem Hierarchy - Binh Nguyen

    BTRFS: The Linux B-tree Filesystem - Ohad Rodeh

    StegFS: A Steganographic File System for Linux - Andrew D. McDonald, Markus G. Kuhn


Security ( 1 -> 2 -> 8 -> 4 -> 3 -> ... )

"UNIX was not designed to stop its users from doing stupid things, as that would also stop them from doing clever things". — Doug Gwyn

No technique works if it isn't used. Ethics change with technology.

"F × S = k" the product of freedom and security is a constant. - Niven's Laws

Cryptography forms the basis of trust online. Hacking is exploiting security controls either in a technical, physical or a human-based element. Protecting the kernel from other running programs is a first step toward a secure and stable system, but this is obviously not enough: some degree of protection must exist between different user-land applications as well. Exploits can target local or remote services.

"You can't hack your destiny, brute force...you need a back door, a side channel into Life." ? Clyde Dsouza

Computers do not solve problems, they execute solutions. Behind every non-deterministic algorithmic code, there is a determined mind. -- /var/log/dmesg

Video Lectures on Cryptography and Network Security, Namespaces for Security, Protection Against Remote Attacks, Secure Embedded Linux

env x='() { :;}; echo vulnerable' bash -c "echo this is a test for Shellsock"

    Hacking: The Art of Exploitation - Jon Erickson

    The Rootkit Arsenal: Escape and Evasion in the Dark Corners of the System - Bill Blunden

    Hacking Exposed: Network Security Secrets - Stuart McClure, Joel Scambray, George Kurtz

    A Guide to Kernel Exploitation: Attacking the Core - Enrico Perla, Massimiliano Oldani

    The Art of Memory Forensics - Michael Hale Ligh, Andrew Case, Jamie Levy, AAron Walters

    Practical Reverse Engineering - Bruce Dang, Alexandre Gazet, Elias Bachaalany

    Practical Malware Analysis - Michael Sikorski, Andrew Honig

    Maximum Linux Security: A Hacker's Guide to Protecting Your Linux Server - Anonymous

    Linux Security - Craig Hunt

    Real World Linux Security - Bob Toxen


Kernel Source ( 0.11 -> 2.4 -> 2.6 -> 3.18 )

"Like wine, the mastery of kernel programming matures with time. But, unlike wine, it gets sweeter in the process". --Lawrence Mucheka

You might not think that programmers are artists, but programming is an extremely creative profession. It's logic-based creat


很高兴看到这样一个问题的持久,全面和非链接依赖的答案.+1

2> 小智..:

试着掌握Robert Love关于Linux内核编程的书.它非常简洁易懂.

在那之后或者与之一起,你可能想看看"理解Linux内核".但我不建议在早期阶段.

另外,请查看Linux内核编程指南.由于可以从编程内核模块中学到很多东西,因此该指南可以帮助您.是的,有关大量信息,请参阅内核源代码tarball的'documentation'子目录.



3> John Smith..:

查看Linux Kernel Janitor项目

"我们通过Linux内核源代码,进行代码审查,修复未维护的代码以及进行其他清理和API转换.这是内核黑客入侵的良好开端.''



4> Antonio Lour..:

我不得不说:"学习C".:)

试试这个免费的在线书籍.

Linux内核模块编程指南 http://www.linuxhq.com/guides/LKMPG/mpg.html



5> Raulp..:

我读过以下几本书,发现非常有用:

    Linux内核开发

    了解Linux内核,第三版

    专业的Linux内核架构

    基本的Linux设备驱动程序

    Linux设备驱动程序

    Linux内核编程(第3版)

    LF320 Linux内核内部和调试

    Linux系统编程:直接与内核和C库对话

    编写Linux设备驱动程序:练习指南

推荐阅读
yzh148448
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有