Ok, so I have successfully added some system calls to kernel space. Currently I have their primary intention commented out, I wanted to be sure data was being passed from user space to kernel space successfully and as expected. I am currently having an issue where a declare a variable in user space as unsigned long, and when it is printed via printk, the value is not the same. I have viewed other issues on this topic which seem to be relevant and they were no help, i think the people were just using printk wrong. I had previous tested this with the kernel space only printing a string, all was fine, so then I added the data being passed from user space and hit this issue, So...
User space:
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <linux/kernel.h>
#include <sys/syscall.h>
#define __NR_createQueue 350
long createQueue_syscall(unsigned long id){
return syscall(__NR_createQueue);
}
int main(int argc, char *argv[]){
unsigned long qid = 47; // ID for a queue
createQueue_syscall(qid);
return 0;
}
Kernel Space:
#include linux/kernel.h
asmlinkage long createQueue(unsigned long id){
printk(" The queue ID is: %lu \n", id);
return 0;
}
All compiles fine, no warnings or errors. But when i run: dmesg | tail -20
, I get a value like 1334886164 instead of the 47 I was expecting. (yes I did all of the make
, make module_install install
, reboot
, etc required). It is as though it is grabbing garbage/over running the memory or something. But I am at a loss. Any thoughts/ideas?
Many Thanks!