"WARNING, putname undefined" when complie my kernel module - linux

I was writing a kernel module that will check some thing in VFS . In this module, I need to use the kernel API "putname" which is defined as:
#ifdef CONFIG_AUDITSYSCALL
void putname(const char *name)
{
if (unlikely(!audit_dummy_context()))
audit_putname(name);
else
__putname(name);
}
EXPORT_SYMBOL(putname);
When I complied it in Fedora 18 with kernel 3.6.10, Everything is OK, the module works fine, but when I switch it to kernel 3.11.4. The complier gave me a warnning "putname is undefined", When I replace "putname" with "__putname", the kernel module can be complied but when it was running, something will go wrong. the backtrace shows that it was in __putname. Is there anybody can help me on this issue?
Thanks

See the commit #91a27b2a756784714e924e5e854b919273082d26 from Jeff:
This patchset converts the getname()/putname() interfaces to return a struct instead of a string. For now, the struct just tracks the string in kernel space and the original userland pointer for it.
The interface was changed right after the v3.6. So you have to rework your code taking this change into account.

Related

When making a Linux fielsystem, what to pass for the user_namespace parameter for inode_init_owner

I'm writing a Linux filesystem driver, and found this code in a tutorial. From there, I came across this modified version of the previous code, which makes it compile on 3.x kernels. However it seems that again the filesystem API has changed, and one of the functions (inode_init_owner) takes a new parameter. The new signature of this function (in linux/fs.h) is:
void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
const struct inode *dir, umode_t mode);
This mnt_userns parameter isn't given in the example code, and I can't seem to find any documentation for this function online whatsoever. I tried passing NULL for it, in case it would then just ignore it and revert to previous behaviour, but unsurprisingly this led to a crash (dereferencing NULL pointer).
What should this parameter be set to? What does it even mean? Thanks in advance :)
I've found a solution to this, though I'm not sure if it's the correct one.
inode_init_owner(sb->s_user_ns, root, NULL, S_IFDIR | 0755);
It seems that the superblock has a namespace field which I can use and everything works. This does the trick, but I still don't really understand it :)

Can we use structure of structure in opencl?

I'm using structure as follows.
struct domain_data
{
int *no_h_domains,
*no_v_domains,
*domain_hsize,
*domain_vsize,
*domain_hstep,
*domain_vstep;
struct domain_pixels
{
int dom_x, dom_y;
double sum,sum2;
int sym;
} ***pixel;
} domain;
But when I try
domain.pixel= (struct domain_pixels ***) malloc(i*sizeof(struct domain_pixels **));
then it gives following errors.
error C2440: '=' : cannot convert from 'domain_pixels ' to 'domain_data::domain_pixels'
and
a value of type "domain_pixels *" cannot be assigned to an entity of type "domain_data::domain_pixels *"
But the same code is executed perfectly fine in win32 application.
Can anyone tell me, whether I can do this in opencl? if yes then how?
The problem is not in the structure of structure, the problem is in the pointers and triple pointers of your struct.
No pointers are allowed to be passed in OpenCL.
Even without that it will never work, since malloc is not allowed in OpenCL.
Please read a guide and a tutorial, before trying to copy-paste a monster C code expecting it to work directly.
It should be doable using OpenCL 2.0 & SVM with Fine-Grain buffers.
Intel is planning to start SVM support with BDW.
When I created another OpenCl project and copied same code over there, then that error is removed ! So thanks everyone for their reply!

export per cpu symbol for kernel module

I'm trying to export a per-cpu symbol "x86_cpu_to_logical_apicid" from kernel so that my kernel module can access it. In "arch/x86/kernel/apic/x2apic_cluster.c", I did
//static DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid);
DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid); //I remove static
EXPORT_PER_CPU_SYMBOL(x86_cpu_to_logical_apicid); // I add this
And after I recompile the kernel, the /proc/kallsyms shows
0000000000011fc0 V x86_cpu_to_logical_apicid
0000000000012288 V x86_cpu_to_node_map
ffffffff8187df50 r __ksymtab_x86_cpu_to_apicid
Then I try to access the "x86_cpu_to_logical_apicid" in my kernel module, by using
int apicid = per_cpu(x86_cpu_to_logical_apicid, 2)
However, when I loaded it, it fails to load it due to "Unknown symbol in module". The flag "V" means weak object, however I'm not sure whether this is the reason I fails to export the symbol. Can anyone give me some suggestions? Thank you!
I realize that the OP perhaps is not interested in the answer anymore, but today I had a similar issue, and I thought it might help others as well.
Before using an exported per_cpu variable in a module, you have to declare it first. For your case:
DECLARE_PER_CPU(u32, x86_cpu_to_logical_apicid);
Then you can use get_cpu_var and put_cpu_var to safely access the current processor's copy of the variable. You can read more here.

Compiling kernel error: stdio.h: No such file or directory

I am making SYSTEM CALL for linux 2.6.39 kernel.
I have completed all the edits in the files. Now When i am trying to compile the kernel it is showing this error :
error: stdio.h: No such file or directory
If i remove stdio.h, Will the system call work ???
My code is
#include<stdio.h>
#include <linux/linkage.h>
asmlinkage long sys_atvfcfs(int at[], int bt[], int n)
{
int i=0;
int j,t,wt[n],sum,q;
float avgwt;
for(j=i+1;j<n;j++)
{
if(at[i]>at[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
}
}
wt[0]=0;
sum=0;
for(i=0;i<n-1;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i+1]-at[i]);
}
avgwt=sum/n;
return avgwt;
}
I have no idea what your system call is supposed to do, but it doesn't call any functions declared in stdio.h. (It doesn't call any functions at all, in fact.) So it should be safe to remove that line.
stdio.h is a C library header. It's available in ordinary C programs, but a kernel is different. A kernel is self-contained; it can't depend on userspace libraries, because userspace libraries depend on the kernel to do their work. Instead, the kernel has its own internal library of useful functions that you'll want to learn about if you're doing kernel development.
I do'nt see any io functions used in your code, so you don't need to include stdio.h
You don't need stdio.h in kernel programming. If you need to print something, use printk instead of printf.

Compiling mDNSResponder for Linux?

I've been trying to compile the open source Bonjour framework developed by Apple for Linux. The problem I have is that when I run make with the option os=linux I get the following compile error:
struct sockaddr has no member named 'sa_len'
I've checked the struct sockddr and it indeed has no member named sa_len... So I'm confused as to why the framework is thinking that it should do!
Could anyone please give me some advice as to how I should be compiling mDNSResponder for Linux? Many thanks.
Looking in mDNSUNP.h one can see that if sa_len does not exist (such as on Linux), a macro NOT_HAVE_SA_LEN should be defined. If it's not defined in your case, try adding -DNOT_HAVE_SA_LEN to your compilation flags.
The Linux implementation of sockaddr doesn't have sa_len as a member, but the FreeBSD version does. Apple's implementation is based off of the FreeBSD version (parts of OS X pull from FreeBSD and NetBSD), hence why you're receiving that error. You can use an #ifdef to workaround it or add the compilation flag, as previously suggested.

Resources