基本上,对于我的操作系统课程,我正在编写一个内核模块,模拟带有5个终端的机场班车。到目前为止,我已经能够实现系统调用并验证它们是否正常工作。但是,我试图将这些系统调用链接到一个模块中。对于每个内核Stub和函数,当我尝试使模块插入时,它说它未定义。此外,作为副产品,当我运行此命令时模块不会插入: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
答案 0 :(得分:3)
您可以查看Makefile。
因此,此Makefile中的定义转为:
obj-m := terminal.o
terminal-objs := syscall.o primarymodule.o
或查看此内容:
http://www.linuxchix.org/content/courses/kernel_hacking/lesson8
答案 1 :(得分:3)
您不能使用模块中未导出的符号。使用EXPORT_SYMBOL。