1
0
mirror of https://github.com/bashrc/LKMPG.git synced 2018-06-11 03:06:54 +02:00

resolved a compilation error in gcc-6 and a GPL issue

This commit is contained in:
Hui Chen
2018-02-09 13:25:47 -05:00
parent d694ae729c
commit a81037baec
3 changed files with 18 additions and 11 deletions

View File

@@ -16,6 +16,8 @@
#include <linux/poll.h>
#include <linux/cdev.h>
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/

View File

@@ -15,6 +15,8 @@
#include <linux/poll.h>
#include <linux/cdev.h>
MODULE_LICENSE("GPL");
#include "chardev.h"
#define SUCCESS 0
#define DEVICE_NAME "char_dev"

View File

@@ -25,7 +25,7 @@
#include <linux/sched.h>
#include <linux/uaccess.h>
unsigned long **sys_call_table;
sys_call_ptr_t *sys_call_table_ptr;
unsigned long original_cr0;
/*
@@ -87,15 +87,18 @@ asmlinkage int our_sys_open(const char *filename, int flags, int mode)
return original_call(filename, flags, mode);
}
static unsigned long **aquire_sys_call_table(void)
static sys_call_ptr_t *aquire_sys_call_table(void)
{
unsigned long int offset = PAGE_OFFSET;
unsigned long **sct;
/* unsigned long **sct; */
sys_call_ptr_t *sct;
while (offset < ULLONG_MAX) {
sct = (unsigned long **)offset;
/* sct = (unsigned long **)offset; */
sct = (sys_call_ptr_t *)offset;
if (sct[__NR_close] == (unsigned long *) sys_close)
/* if (sct[__NR_close] == (unsigned long *) sys_close) */
if (sct[__NR_close] == (sys_call_ptr_t) sys_close)
return sct;
offset += sizeof(void *);
@@ -106,7 +109,7 @@ static unsigned long **aquire_sys_call_table(void)
static int __init syscall_start(void)
{
if(!(sys_call_table = aquire_sys_call_table()))
if(!(sys_call_table_ptr = aquire_sys_call_table()))
return -1;
original_cr0 = read_cr0();
@@ -114,10 +117,10 @@ static int __init syscall_start(void)
write_cr0(original_cr0 & ~0x00010000);
/* keep track of the original open function */
original_call = (void*)sys_call_table[__NR_open];
original_call = (void*)sys_call_table_ptr[__NR_open];
/* use our open function instead */
sys_call_table[__NR_open] = (unsigned long *)our_sys_open;
sys_call_table_ptr[__NR_open] = (sys_call_ptr_t)our_sys_open;
write_cr0(original_cr0);
@@ -128,14 +131,14 @@ static int __init syscall_start(void)
static void __exit syscall_end(void)
{
if(!sys_call_table) {
if(!sys_call_table_ptr) {
return;
}
/*
* Return the system call back to normal
*/
if (sys_call_table[__NR_open] != (unsigned long *)our_sys_open) {
if (sys_call_table_ptr[__NR_open] != (sys_call_ptr_t) our_sys_open) {
pr_alert("Somebody else also played with the ");
pr_alert("open system call\n");
pr_alert("The system may be left in ");
@@ -143,7 +146,7 @@ static void __exit syscall_end(void)
}
write_cr0(original_cr0 & ~0x00010000);
sys_call_table[__NR_open] = (unsigned long *)original_call;
sys_call_table_ptr[__NR_open] = (sys_call_ptr_t)original_call;
write_cr0(original_cr0);
msleep(2000);