query about the usage of kmalloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I use kmalloc,but an error occurs,Can anyone help me?
I use kmalloc in modules named "main.c"like this:
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h> /* printk() */
#include <linux/malloc.h> /* kmalloc() */
int init_module(void)
{
 printk("init-module");
        kmalloc(1024,GFP_KERNEL);
}
void cleanup_module(void)
{
    printk("cleanup_module");
}
when I gcc -c main.c
the compiler says:
main.c: In function `init_module':
main.c:20: `GFP_KERNEL' undeclared (first use in this function)
main.c:20: (Each undeclared identifier is reported only once
main.c:20: for each function it appears in.)
 
I don't know why
then i check my /usr/include/linux/kernel.h,the content look like this:
#ifndef _LINUX_KERNEL_H
#define _LINUX_KERNEL_H
 
/*
 * 'kernel.h' contains some often-used function prototypes etc
 */
#define SI_LOAD_SHIFT 16
struct sysinfo {
 long uptime;   /* Seconds since boot */
 unsigned long loads[3];  /* 1, 5, and 15 minute load averages */
 unsigned long totalram;  /* Total usable main memory size */
 unsigned long freeram;  /* Available memory size */
 unsigned long sharedram; /* Amount of shared memory */
 unsigned long bufferram; /* Memory used by buffers */
 unsigned long totalswap; /* Total swap space size */
 unsigned long freeswap;  /* swap space still available */
 unsigned short procs;  /* Number of current processes */
 unsigned short pad;  /* explicit padding for m68k */
 unsigned long totalhigh; /* Total high memory size */
 unsigned long freehigh;  /* Available high memory size */
 unsigned int mem_unit;  /* Memory unit size in bytes */
 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
#endif


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux