2

I'll walk you through step by step

First I edit 3 files in my Linux kernel directory

  1. Open LINUX_DIRECTORY/arch/x86/syscalls/syscall_64.tbl and add the custom calls i'm implementing – using the appropriate format

  2. Declare them here: LINUX_DIRECTORY/include/linux/syscalls.h – using the appropriate format:

  3. Open LINUX_DIRECTORY/Makefile and add the directory I'm storing my new system calls to the core-y line:

    core-y := usr/ my_system_call_directory/

Here's where I'm having issues. Inside LINUX_DIRECTORY/my_system_call_directory I add a C file with my custom system call definitions and its corresponding Makefile. I leave the definitions empty because inside the C file for my kernel module I declare an extern function (my custom system call) and define a separate function which is set to my extern function:

extern long (*start_shuttle)(void); 

long my_start_shuttle(void) {

  // stuff here 

}


int init_module(void) {

  // stuff here

  start_shuttle = my_start_shuttle;

  // more stuff
}

After recompiling the kernel I try to make the kernel module and get a no definition for start_shuttle error.

Is this because I left the definition for start_shuttle blank in my_system_call_directory? Should it match exactly the my_start_shuttle I defined in the kernel module or is there something special I'm supposed to add? I'm asking dumb questions in advance because it takes so long for my machine to recompile Linux and I'm not sure what to change. Thanks

1 Answer 1

1

Figured it out. For anyone as slow as me, you have to use a wrapper and a stub.

So for this example, in the my_system_call_directory, in the c file for your new system call definitions, you need something like this:

#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/export.h>

// initialize the stub function to be NULL

long (*start_shuttle)(void) = NULL;

EXPORT_SYMBOL(start_shuttle);

// wrapper

asmlinkage long sys_start_shuttle(void)
{
if (start_shuttle)
    return start_shuttle();
else 
    return -ENOSYS;
}
Sign up to request clarification or add additional context in comments.

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.