⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.html

📁 linux操作系统内核编程-----LINUX系统开发非常好的资料
💻 HTML
字号:
<html><head><title>黄金书屋</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="/goldnets.css"></head><body bgcolor="#E4EBF1"><center><a href="http://ad.myrice.com/RealMedia/ads/click_nx.ads/goldnets.myrice.com/banner1@Top" target=_blanck ><script language=JavaScript><!---todayd = new Date();var seconds = todayd.getTime();document.write("<img src=\"http://ad.myrice.com/RealMedia/ads/adstream_nx.ads/goldnets.myrice.com/banner1@Top?dd=seconds\" border=0 width=468 height=60>");//--></script></a></center><br><table width="756" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#E4EBF1">  <tr>    <td colspan="2" valign="top" align="center">      <div align="center">        <table width="100%" border="0" cellspacing="0" cellpadding="0" height="52">          <tr>            <td valign="top"><br>              <div align="center">                <table width="100%" border="0" cellspacing="0" cellpadding="0">                  <tr>                    <td valign="bottom">                      <table width="100%" border="0" cellspacing="0" cellpadding="0">                        <tr>                          <td><a href="/index.html">首页</a>&gt;&gt; <font color="#CC0000"><a href="/book/152/1015178.html">Linux内核编程</a></font></td>                          <td width="22%"> <a href="/index.html">[ 点此回首页 ]</a></td>                        </tr>                        <tr>                          <td colspan="2"><img src="/image/1x1.gif" width="1" height="2"></td>                        </tr>                        <tr bgcolor="#FFCC00">                          <td colspan="2"><img src="/image/1x1.gif" width="1" height="1"></td>                        </tr>                        <tr>                          <td colspan="2"><img src="/image/1x1.gif" width="1" height="6"></td>                        </tr>                      </table>                    </td>                  </tr>                </table>                <br>                <table width="590" border="0" cellspacing="0" cellpadding="0">                  <tr>                    <td><center><a href='3.html'>上一页 </a>||<a href='5.html'>下一页</a></center><br><hr><div style=font-size:12pt><pre>                           1.2 多文件内核模块
有些时候在几个源文件之间分出一个内核模块是很有意义的。在这种情况下,你需要
做下面的事情:
1.	在除了一个以外的所有源文件中,增加一行#define __NO_VERSION__。这是很重
要的,因为module.h一般包括kernel_version的定义,这是一个全局变量,包含模
块编译的内核版本。如果你需要version.h,你需要把自己把它包含进去,因为如果
有__NO_VERSION__的话module.h不会自动包含。
2.	象通常一样编译源文件。
3.	把所有目标文件联编成一个。在X86下,用ld –m elf_i386 –r –o <name of module>.o 
<1st source file>
这里给出一个这样的内核模块的例子。
ex start.c    
 
/* start.c 
 * Copyright (C) 1999 by Ori Pomerantz
 * 
 * \"Hello, world\" - the kernel module version. 
 * This file includes just the start routine
 */

/* The necessary header files */

/* Standard in kernel modules */
#include <linux/kernel.h>   /* We\'re doing kernel work */
#include <linux/module.h>   /* Specifically, a module */



/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif        



/* Initialize the module */
int init_module()
{
  printk(\"Hello, world - this is the kernel speaking\\n\");

  /* If we return a non zero value, it means that 
   * init_module failed and the kernel module 
   * can\'t be loaded */
  return 0;
}
ex stop.c    
 
/* stop.c 
 * Copyright (C) 1999 by Ori Pomerantz
 * 
 * \"Hello, world\" - the kernel module version. This 
 * file includes just the stop routine.
 */

/* The necessary header files */

/* Standard in kernel modules */
#include <linux/kernel.h>   /* We\'re doing kernel work */

#define __NO_VERSION__      /* This isn\'t \"the\" file 
                             * of the kernel module */
#include <linux/module.h>   /* Specifically, a module */

#include <linux/version.h>   /* Not included by 
                              * module.h because 
                              * of the __NO_VERSION__ */



/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif        




/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
  printk(\"Short is the life of a kernel module\\n\");
}
ex Makefile    
 
# Makefile for a multifile kernel module

CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX

hello.o:	start.o stop.o
		ld -m elf_i386 -r -o hello.o start.o stop.o

start.o:	start.c /usr/include/linux/version.h
		$(CC) $(MODCFLAGS) -c start.c

stop.o:		stop.c /usr/include/linux/version.h
		$(CC) $(MODCFLAGS) -c stop.c
</pre><hr><br><center><a href='3.html'>上一页 </a>||<a href='5.html'>下一页</a></center></div> </td>                  </tr>                </table>                <p>&nbsp; </p>                </div>            </td>          </tr>        </table>          <br>          <table border="0" width="75%"><tr><td align="right"><a href="/"><img src="/image2/logo_bottom.gif" border="0"></a></td></tr></table>          <hr size="1" align="center" color="#eecccc">          <br>        </div>      </div>      </td>  </tr></table>  <center><a href="http://ad.myrice.com/RealMedia/ads/click_nx.ads/goldnets.myrice.com/banner1@Bottom" target=_blanck ><script language=JavaScript><!---todayd = new Date();var seconds = todayd.getTime();document.write("<img src=\"http://ad.myrice.com/RealMedia/ads/adstream_nx.ads/goldnets.myrice.com/banner1@Bottom?dd=seconds\" border=0 width=468 height=60>");//--></script></a></center></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -