基本上,对于我的OS类,我正在编写一个内核模块,它模拟具有5个终端的机场班车。到目前为止,我已经能够实现系统调用并验证它们是否正常工作。但是,我正在尝试将这些系统调用链接到一个模块中。对于每个内核存根和函数,当我尝试创建要插入的模块时,它会告诉我它是未定义的。此外,作为副产品,当我运行命令:make; sudo insmod terminal.ko时,模块不会插入,因为模块中有一个未知的符号,我很少或根本没有找到关于这个错误的文档。
下面是我尝试生成并插入它时的输出:
make -C /lib/modules/`uname -r`/build/ M=`pwd` modules
make[1]: Entering directory `/home/taylor/OPSYS_P2/linux-3.16.4'
Building modules, stage 2.
MODPOST 1 modules
WARNING: "STUB_issue_request" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
WARNING: "issue_request" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
WARNING: "STUB_stop_shuttle" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
WARNING: "stop_shuttle" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
WARNING: "STUB_start_shuttle" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
WARNING: "start_shuttle" [/home/taylor/OPSYS_P2/linux-3.16.4/opsyscall/module/terminal.ko] undefined!
make[1]: Leaving directory `/home/taylor/OPSYS_P2/linux-3.16.4'
insmod: ERROR: could not insert module terminal.ko: Unknown symbol in module主模块代码:
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/time.h> // Time Lib
#include "./syscall.h"
MODULE_LICENSE("GPL");
// Stubs for kernel module implementation of shuttle services
extern int ( * STUB_start_shuttle )( void );
extern int ( * STUB_stop_shuttle )( void );
extern int ( * STUB_issue_request )( char passenger_type, int initial_terminal, int destination_terminal );
static int terminal_show(struct seq_file *m, void *v) {
seq_printf(m,"%s\n", "The Shuttle is out of service");
return 0;
}
static int terminal_open(struct inode *inode, struct file *file) {
return single_open(file, terminal_show, NULL);
}
static const struct file_operations terminal_fops = {
.owner = THIS_MODULE,
.open = terminal_open,
.read = seq_read,
.release = single_release,
};
/**
* Terminal Init
* Sets up a proc file, sets syscall stubs correctly
*/
static int __init terminal_init(void) {
proc_create("terminal", 0, NULL, &terminal_fops);
// Redirect stub syscalls to our implementation
STUB_start_shuttle = &start_shuttle;
STUB_stop_shuttle = &stop_shuttle;
STUB_issue_request = &issue_request;
return 0;
}
/**
* Terminal Exit
* Removes the proc file, tears down stubs
*/
static void __exit terminal_exit(void) {
STUB_start_shuttle = NULL;
STUB_stop_shuttle = NULL;
STUB_issue_request = NULL;
remove_proc_entry("terminal", NULL);
}
module_init(terminal_init);
module_exit(terminal_exit);下面是syscall.h文件:
#pragma once
#include <linux/err.h>
#include <linux/kthread.h>
#include <linux/list.h>
#include <linux/sched.h>
#include <linux/time.h>
// Prototype Declarations
int start_shuttle( void );
int stop_shuttle( void );
int issue_request( char passenger_type, int initial_terminal, int destination_terminal );下面是相应的c文件syscall.c:
#include "syscalls.h"
/**
* Start Shuttle - Syscall
* Description: Starts the shuttle up in its own thread unless it is already running
*/
int start_shuttle( void ) {
int result = 0;
return result;
}
/**
* Stop Shuttle - Syscall
* Description: Tells the shuttle to stop unless it is already stopping
*/
int stop_shuttle( void ) {
int result = 0;
return result;
}
/**
* Issue Request - Syscall
* Description: Adds a passenger, if valid, into a chosen terminal with a desired
* destination
*/
int issue_request( char passenger_type, int initial_terminal, int destination_terminal ) {
printk( KERN_DEBUG "Shuttle Service: Invalid issue_request - passenger_type %c initial_terminal %d destination_terminal %d\n",
passenger_type, initial_terminal, destination_terminal );
return 1;
}任何帮助/建议都是很棒的!
运行Ubuntu 14.04,内核版本3.16.4
发布于 2014-10-12 05:00:00
您可以检查Makefile。
因此,此Makefile中的定义变为:
obj-m := terminal.o
terminal-objs := syscall.o primarymodule.o或查看以下内容:
http://www.linuxchix.org/content/courses/kernel_hacking/lesson8
发布于 2014-10-12 14:29:29
您不能使用模块中未导出的符号。使用EXPORT_SYMBOL。
https://stackoverflow.com/questions/26318704
复制相似问题