内核驱动常用头文件之--linux/module.h

本文介绍在编写Linux内核驱动时不可或缺的`linux/module.h`头文件,该头文件用于动态加载模块到内核,并包含了如MODULE_LICENSE()、MODULE_AUTHOR()等宏定义。同时,kobject和kset结构体及相关操作也在该头文件中定义,学习头文件对于驱动开发至关重要。
摘要由CSDN通过智能技术生成

/*

*写内核驱动的时候 必须加载这个头文件,作用是动态的将模块加载到内核中去

*常用的宏定义如 MODULE_LICESENCE(),MODULE_AUTHOR(),等在此文件中

*而且 kobject,kset结构体题及其操作函数也在这个结构体中,,,其实学习头文件最好的方法就是仔细的看头文件--看看有哪些功能就好用的时候再查阅

*

*

*/

#ifndef _LINUX_MODULE_H

#define _LINUX_MODULE_H
/*
 * Dynamic loading of modules into the kernel.
 *
 * Rewritten by Richard Henderson <rth@tamu.edu> Dec 1996
 * Rewritten again by Rusty Russell, 2002
 */
#include <linux/list.h>
#include <linux/stat.h>
#include <linux/compiler.h>
#include <linux/cache.h>
#include <linux/kmod.h>
#include <linux/elf.h>
#include <linux/stringify.h>
#include <linux/kobject.h>
#include <linux/moduleparam.h>
#include <linux/tracepoint.h>


#include <linux/percpu.h>
#include <asm/module.h>


#include <trace/events/module.h>


/* Not Yet Implemented */
#define MODULE_SUPPORTED_DEVICE(name)


/* Some toolchains use a `_' prefix for all user symbols. */
#ifdef CONFIG_SYMBOL_PREFIX
#define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX
#else
#define MODULE_SYMBOL_PREFIX ""
#endif


#define MODULE_NAME_LEN MAX_PARAM_PREFIX_LEN


struct kernel_symbol
{
unsigned long value;
const char *name;
};


struct modversion_info
{
unsigned long crc;
char name[MODULE_NAME_LEN];
};


struct module;


struct module_attribute {
        struct attribute attr;
        ssize_t (*show)(struct module_attribute *, struct module *, char *);
        ssize_t (*store)(struct module_attribute *, struct module *,
const char *, size_t count);
void (*setup)(struct module *, const char *);
int (*test)(struct module *);
void (*free)(struct module *);
};


struct module_version_attribute {
struct module_attribute mattr;
const char *module_name;
const char *version;
} __attribute__ ((__aligned__(sizeof(void *))));


struct module_kobject
{
struct kobject kobj;
struct module *mod;
struct kobject *drivers_dir;
struct module_param_attrs *mp;
};


/* These are either module local, or the kernel's dummy ones. */
extern int init_module(void);
extern void cleanup_module(void);


/* Archs provide a method of finding the correct exception table. */
struct exception_table_entry;


const struct exception_table_entry *
search_extable(const struct exception_table_entry *first,
      const struct exception_table_entry *last,
      unsigned long value);
void sort_extable(struct exception_table_entry *start,
 struct exception_table_entry *finish);
void sort_main_extable(void);
void trim_init_extable(struct module *m);


#ifdef MODULE
#define MODULE_GENERIC_TABLE(gtype,name) \
extern const struct gtype##_id __mod_##gtype##_table \
  __attribute__ ((unused, alias(__stringify(name))))


extern struct module __this_module;
#define THIS_MODULE (&__this_module)
#else  /* !MODULE */
#define MODULE_GENERIC_TABLE(gtype,name)
#define THIS_MODULE ((struct module *)0)
#endif


/* Generic info of form tag = "info" */
#define MODULE_INFO(tag, info) __MODULE_INFO(tag, tag, info)


/* For userspace: you can also call me... */
#define MODULE_ALIAS(_alias) MODULE_INFO(alias, _alias)


/*
 * The following license idents are currently accepted as indicating free
 * software modules
 *
 * "GPL" [GNU Public License v2 or later]
 * "GPL v2" [GNU Public License v2]
 * "GPL and additional rights" [GNU Public License v2 rights and more]
 * "Dual BSD/GPL" [GNU Public License v2
 * or BSD license choice]
 * "Dual MIT/GPL" [GNU Public License v2
 * or MIT license choice]
 * "Dual MPL/GPL" [GNU Public License v2
 * or Mozilla license choice]
 *
 * The following other idents are available
 *
 * "Proprietary" [Non free products]
 *
 * There are dual licensed components, but when running with Linux it is the
 * GPL that is relevant so this is a non issue. Similarly LGPL linked with GPL
 * is a GPL combined work.
 *
 * This exists for several reasons
 * 1. So modinfo can show license info for users wanting to vet their setup 
 * is free
 * 2. So the community can ignore bug reports including proprietary modules
 * 3. So vendors can do likewise based on their own policies
 */
#define MODULE_LICENSE(_license) MODULE_INFO(license, _license)


/*
 * Author(s), use "Name <email>" or just "Name", for multiple
 * authors use multiple MODULE_AUTHOR() statements/lines.
 */
#define MODULE_AUTHOR(_author) MODULE_IN
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值