если для ядра написал модуль. он скомпилировался 0отдельно работает.
как например в net/ipv4/tcp.c использовать какую-либо функцию этого модуля?
как использовать в коде ядра функции других модулей
Модератор: Модераторы разделов
Re: как использовать в коде ядра функции других модулей
в модуле: EXPORT_SYMBOL(имя_функции)
LightLang Team
Re: как использовать в коде ядра функции других модулей
net/ipv4/hello_proc.c:14: warning: function declaration isn’t a prototype
net/ipv4/hello_proc.c:85: warning: data definition has no type or storage class
net/ipv4/hello_proc.c:85: warning: type defaults to ‘int’ in declaration of ‘EXPROT_SYMBOL’
net/ipv4/hello_proc.c:85: warning: parameter names (without types) in function declaration
net/ipv4/hello_proc.c:21: warning: ‘save_exp’ defined but not used
ругается на static int save_exp(int id,unsigned long long tsc)
net/ipv4/hello_proc.c:85: warning: data definition has no type or storage class
net/ipv4/hello_proc.c:85: warning: type defaults to ‘int’ in declaration of ‘EXPROT_SYMBOL’
net/ipv4/hello_proc.c:85: warning: parameter names (without types) in function declaration
net/ipv4/hello_proc.c:21: warning: ‘save_exp’ defined but not used
ругается на static int save_exp(int id,unsigned long long tsc)
Re: как использовать в коде ядра функции других модулей
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#define SIZE 5000
static struct
{
int id;
unsigned long long tsc;
} exp[SIZE];
static int pos;
#define SIZE 5000
static int move()
{
pos++;
if(pos>=SIZE) return 0;
return 1;
}
static int save_exp(int id,unsigned long long tsc)
{
exp[pos].id=id;
exp[pos].tsc=tsc;
return 1;
}
static int hello_read_proc(char *buffer, char **start, off_t offset, int size, int *eof, void *data)
{
char hello_str[sizeof(int)*100+SIZE+sizeof(unsigned long long)*100+SIZE+1];
char help[sizeof(int)+1+sizeof(unsigned long long)];
int i=0;
int len=0;
hello_str[0]=0;
for(i=0;i<SIZE;i++)
{
sprintf(help,"%d %llu\n",exp[i].id,exp[i].tsc);
strcat(hello_str,help);
}
len=strlen(hello_str);
if (offset != 0)
return 0;
strcpy(buffer, hello_str);
*eof = 1;
return len;
}
static int __init
hello_init(void)
{
pos=0;
if (create_proc_read_entry("hello_world", 0, NULL, hello_read_proc,
NULL) == 0) {
printk(KERN_ERR
"Unable to register \"Hello, world!\" proc file\n");
return -ENOMEM;
}
return 0;
}module_init(hello_init);
static void __exit
hello_exit(void)
{
remove_proc_entry("hello_world", NULL);
}
module_exit(hello_exit);
EXPORT_SYMBOL(move);
EXPROT_SYMBOL(save_exp);
Re: как использовать в коде ядра функции других модулей
Если кратко, то экспортируемая функция не должна быть обьявлена как static.
LightLang Team
Re: как использовать в коде ядра функции других модулей
Ну правильно, не вижу прототипа функции, желательно обьявить ее в загаловочном файле как extern. Ну собственно данные с которыми работают функции не должны быть static и скорее всего их тоже надо обьявлять.
LightLang Team
Re: как использовать в коде ядра функции других модулей
zvoice писал(а): ↑04.04.2008 12:12net/ipv4/hello_proc.c:14: warning: function declaration isn’t a prototype
net/ipv4/hello_proc.c:85: warning: data definition has no type or storage class
net/ipv4/hello_proc.c:85: warning: type defaults to ‘int’ in declaration of ‘EXPROT_SYMBOL’
net/ipv4/hello_proc.c:85: warning: parameter names (without types) in function declaration
net/ipv4/hello_proc.c:21: warning: ‘save_exp’ defined but not used
ругается на static int save_exp(int id,unsigned long long tsc)
static не экспортируется. ознакомьтесь с документацией для подробностей.