Results 1 to 4 of 4
Where should I declare the global variable
Hi,
I have added a new system call that is used to initialize a global variable through userspace program. After initialization, I need ...
- 05-03-2007 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 31
Where should I declare the global variable
Where should I declare the global variable
Hi,
I have added a new system call that is used to initialize a global variable through userspace program. After initialization, I need to use that global variable in ~/net/ipv6/tcp_ipv6.c file. let say printing the value of that global variable.
So where should I declare that global variable.
Right now I have declare it in system call but the following error occured
__________________________________________________ _____
CC [M] net/ipv6/tcp_ipv6.o
net/ipv6/tcp_ipv6.c: In function ‘tcp_v6_rcv’:
net/ipv6/tcp_ipv6.c:1313: error: ‘global_fd’ undeclared (first use in this function)
net/ipv6/tcp_ipv6.c:1313: error: (Each undeclared identifier is reported only once
net/ipv6/tcp_ipv6.c:1313: error: for each function it appears in.)
make[2]: *** [net/ipv6/tcp_ipv6.o] Error 1
make[1]: *** [net/ipv6] Error 2
make: *** [net] Error 2
__________________________________
Regards,
Irfan
- 05-03-2007 #2Just Joined!
- Join Date
- Jan 2006
- Location
- India
- Posts
- 52
I think you must declare the global varibale in the file where you are accessing it. The compiler must know the global varibale data type, if it is not defined in the lcoal files. In your case you must declare it in "tcp_ipv6.c" file.
--Regards,
rajesh
- 05-03-2007 #3Just Joined!
- Join Date
- Feb 2007
- Posts
- 31
Hi,
I am need to use one global variable in two files.
One is ~/net/ipv6/tcp_ipv6.c where I have defined the global variable as extern int global_fd;
Second is my custom system call code. Its code is as follows
__________
#include<linux/linkage.h>
#include<linux/kernel.h>
int global_fd;
asmlinkage int sys_mycall(int fd)
{
global_fd = fd;
return fd;
}
___________
Now I am still getting the follwing error
___________________________
CHK include/linux/version.h
CHK include/linux/utsrelease.h
Building modules, stage 2.
MODPOST
WARNING: drivers/atm/he.o - Section mismatch: reference to .init.text: from .text between 'he_start' (at offset 0x2074) and 'he_service_tbrq'
WARNING: "global_fd" [net/ipv6/ipv6.ko] undefined!
WARNING: "sys_write" [net/ipv6/ipv6.ko] undefined!
[root@localhost linux-2.6.18.2]#
________________
Anther thing that I want to ask about sys_write . Can I use it in kernel code other than kernel module. and how can I solve the undefined problem of sys_write even I have also added the syscalls.h header file.
Regards,
Irfan
- 05-17-2007 #4Just Joined!
- Join Date
- Feb 2007
- Posts
- 31
Still stuck ..The problem is that system call is in kernel and tcp_ipv6.c is kernel module file. I have defined global variable in kernel i.e in system call and try to access it in kernel module IPv6. But still I am getting the same
WARNING: "global_fd" [net/ipv6/ipv6.ko] undefined!
The code for both the files is as follows
For System call
#include<linux/linkage.h>
#include<linux/kernel.h>
int global_fd = 0;
EXPORT_SYMBOL(global_fd);
asmlinkage int sys_mycall(int fd)
{
global_fd = fd;
return fd;
}
For tcp_ipv6.c
<Include files ............>
extern int global_fd ;
...
...
..
static int tcp_v6_rcv(struct sk_buff **pskb)
{
printk("\n%d done\n",global_fd);
..
...


Reply With Quote