3

Basically, for my OS class, I'm writing a kernel module that simulates an airport shuttle with 5 terminals. So far, I've been able to implement system calls and verify that they work properly. However, I'm trying to link these system calls into a module. For each kernel Stub and function when I try to make the module for insertion, it says it's undefined. Also, as a by product, the module won't insert when I run this command: make; sudo insmod terminal.ko due to an unknown symbol in the module, which is an error I've found little or none documentation on.

Here's the output when I try to make and insert it:

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

Primary Module Code:

#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);

Here's the syscall.h file:

#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 );

Here's the corresponding c file, 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;
}

Any and all help/advice would be awesome!

Running Ubuntu 14.04, kernel version 3.16.4

2 Answers 2

4

You can't use not exported symbols from modules. Use EXPORT_SYMBOL.

Sign up to request clarification or add additional context in comments.

Comments

3

You can check the Makefile.

Thus the definitions in this Makefile turn to:

obj-m := terminal.o
terminal-objs := syscall.o primarymodule.o

or view this:

http://www.linuxchix.org/content/courses/kernel_hacking/lesson8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.