<div dir="ltr">Thanks Valdis.<div>Yes , custom kernel module has struct proto_ops pointing to the routines<br>in the module.</div><div>my kernel module routines do not cal any of linux provided socket* calls.</div><div>it gets data from different app and provide that data back to app calling socket* APIs.</div><div><br><div>i understand linux kernel calls 32 bit version of syscall handler from sys call table .</div><div><a href="https://kernel.org/doc/html/latest/process/adding-syscalls.html">https://kernel.org/doc/html/latest/process/adding-syscalls.html</a><br></div><div><br></div><div>but how do i do this in custom kernel module.</div><div>how to differentiate 32 bit and 64 app in my kernel module.</div><div><br></div><div>do i need all stuff from compat.h and compat.c (if i use same files will that work) ?</div><div>do i need to change some files in std kernel files too like <span style="background-color:rgb(252,252,252);color:rgb(64,64,64);font-family:consolas,"andale mono wt","andale mono","lucida console","lucida sans typewriter","dejavu sans mono","bitstream vera sans mono","liberation mono","nimbus mono l",monaco,"courier new",courier,monospace;font-size:13.6px;white-space:nowrap">syscall_32.tbl file , and recompile kernel ?</span></div><div><span style="background-color:rgb(252,252,252);color:rgb(64,64,64);font-family:consolas,"andale mono wt","andale mono","lucida console","lucida sans typewriter","dejavu sans mono","bitstream vera sans mono","liberation mono","nimbus mono l",monaco,"courier new",courier,monospace;font-size:13.6px;white-space:nowrap"><br></span></div><div>It would be great if there is any example / any web links for this to understad</div><div>Thanks</div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 10:10 AM, <span dir="ltr"><<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank">Valdis.Kletnieks@vt.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Wed, 04 Jan 2017 09:34:58 +0530, Pradeepa Kumar said:<br>
<br>
> I have a custom kernel module providing new protocol and providing socket system calls.<br>
<br>
</span>In general, a loadable module can provide a new protocol, but can't add new<br>
syscalls. However, adding support for socket(), connect(), recvmsg() and<br>
so on for a new protocol *can* be done from a module, as long as the<br>
protocol provides a suitable struct proto_ops pointing to the routines<br>
in the module.<br>
<span class="gmail-"><br>
> i am seeing issues when 32 bit app runs (for exp recvmsg() call does not<br>
> work if msg has cmsghdrs as struct size of cmsghdr is different in 32 bit<br>
> and 64 bit).<br>
<br>
</span>That's a good reason to double-check your code to ensure that you don't<br>
make that same mistake.<br>
<span class="gmail-"><br>
> This is because my custom kernel module does not have 32 bit compatibility<br>
> layer ( but linux kernel has this in compat.c etc).<br>
<br>
</span>Hold that thought.<br>
<span class="gmail-"><br>
> is it simple to add compatibility layer to my custom kernel module<br>
<br>
</span>Given your previous sentence, you should be able to figure that out.<br>
<span class="gmail-"><br>
> how do i do this (any links ?)<br>
<br>
</span>/*<br>
* linux/kernel/compat.c<br>
*<br>
* Kernel compatibililty routines for e.g. 32 bit syscall support<br>
* on 64 bit kernels.<br>
*<br>
* Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation<br>
<br>
May already have the functions you need. If not, use the code as a guide<br>
to writing the stuff you're still lacking.<br>
<br>
Note that in particular, recvmsg() combatability is already done for you via<br>
this chunk of code in net/compat.c:<br>
<br>
COMPAT_SYSCALL_DEFINE3(<wbr>recvmsg, int, fd, struct compat_msghdr __user *, msg, unsigned int, flags)<br>
{<br>
return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | MSG_CMSG_COMPAT);<br>
}<br>
<br>
Go look and see what the MSG_CMSG_COMPAT flag does if you want the gory details.<br>
<br>
</blockquote></div><br></div></div></div>