adding 32 bit compatibility layer in custom kernel module
Pradeepa Kumar
cdpradeepa at gmail.com
Wed Jan 4 00:39:27 EST 2017
Thanks Valdis.
Yes , custom kernel module has struct proto_ops pointing to the routines
in the module.
my kernel module routines do not cal any of linux provided socket* calls.
it gets data from different app and provide that data back to app calling
socket* APIs.
i understand linux kernel calls 32 bit version of syscall handler from sys
call table .
https://kernel.org/doc/html/latest/process/adding-syscalls.html
but how do i do this in custom kernel module.
how to differentiate 32 bit and 64 app in my kernel module.
do i need all stuff from compat.h and compat.c (if i use same files will
that work) ?
do i need to change some files in std kernel files too like syscall_32.tbl
file , and recompile kernel ?
It would be great if there is any example / any web links for this to
understad
Thanks
On Wed, Jan 4, 2017 at 10:10 AM, <Valdis.Kletnieks at vt.edu> wrote:
> On Wed, 04 Jan 2017 09:34:58 +0530, Pradeepa Kumar said:
>
> > I have a custom kernel module providing new protocol and providing
> socket system calls.
>
> In general, a loadable module can provide a new protocol, but can't add new
> syscalls. However, adding support for socket(), connect(), recvmsg() and
> so on for a new protocol *can* be done from a module, as long as the
> protocol provides a suitable struct proto_ops pointing to the routines
> in the module.
>
> > i am seeing issues when 32 bit app runs (for exp recvmsg() call does not
> > work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit
> > and 64 bit).
>
> That's a good reason to double-check your code to ensure that you don't
> make that same mistake.
>
> > This is because my custom kernel module does not have 32 bit
> compatibility
> > layer ( but linux kernel has this in compat.c etc).
>
> Hold that thought.
>
> > is it simple to add compatibility layer to my custom kernel module
>
> Given your previous sentence, you should be able to figure that out.
>
> > how do i do this (any links ?)
>
> /*
> * linux/kernel/compat.c
> *
> * Kernel compatibililty routines for e.g. 32 bit syscall support
> * on 64 bit kernels.
> *
> * Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
>
> May already have the functions you need. If not, use the code as a guide
> to writing the stuff you're still lacking.
>
> Note that in particular, recvmsg() combatability is already done for you
> via
> this chunk of code in net/compat.c:
>
> COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *,
> msg, unsigned int, flags)
> {
> return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags |
> MSG_CMSG_COMPAT);
> }
>
> Go look and see what the MSG_CMSG_COMPAT flag does if you want the gory
> details.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170104/5d3700e8/attachment.html
More information about the Kernelnewbies
mailing list