0

I'm trying to access a structure within my module in kernel code, the struct I want access to is task_struct which defined in the <linux/sched.h> header file. And then use current->parent for example, I tried to access the struct inside the init_module function.

I get one warning and one error

error: function declaration isn’t a prototype [-Werror=strict-prototypes]
struct task_struct *current;
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
struct task_struct *current;
#include <linux/init.h>
#include <linux/module.h>
#include <linux/sched.h>

MODULE_LICENSE("GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "My-Module: Hello, World\n");
    struct task_struct *current;
    return 0;
}

static void hello_exit(void)
{
    printk(KERN_ALERT "My-Module: Goodbye, cruel world.\n");
}

module_init(hello_init);
module_exit(hello_exit);
// gcc
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Dudu Faruk
  • 43
  • 1
  • 5

0 Answers0