<div dir="ltr">Hi Le,<div><br></div><div>You can do that by exporting a function pointer from the kvm code that is only called if it is not null. Then, when you load your module, you set that exported function pointer (I'm assuming that you want to call your module's function from the kvm code... ). Here is a post on how to do that:</div>
<div><br></div><div><a href="http://stackoverflow.com/questions/11463184/how-to-use-exported-symbols-in-the-linux-kernel">http://stackoverflow.com/questions/11463184/how-to-use-exported-symbols-in-the-linux-kernel</a><br>
</div><div><a href="http://stackoverflow.com/questions/1196944/can-i-replace-a-linux-kernel-function-with-a-module">http://stackoverflow.com/questions/1196944/can-i-replace-a-linux-kernel-function-with-a-module</a><br></div>
<div><div><br></div><div>Best,</div></div><div class="gmail_extra"><div><div dir="ltr"><div>--</div>Henrique Rodrigues<br><div><a href="http://www.dcc.ufmg.br/~hsr" target="_blank">http://www.dcc.ufmg.br/~hsr</a></div></div>
</div>
<br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 2:47 AM, Le Tan <span dir="ltr"><<a href="mailto:tamlokveer@gmail.com" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=tamlokveer@gmail.com&cc=&bcc=&su=&body=','_blank');return false;">tamlokveer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hello! I am writing a device driver module. I define some functions in the module, for example print_record(). I am doing something in the kvm, so I want to call print_record() in the file of kvm module, for example, I may call print_record() in file /arch/x86/kvm/x86.c to put something into my device driver module.<div>
Now comes the question.</div><div>1. Where should I put the codes of my device driver module? It's the first time I write the device driver.</div><div>2. After compiling my module, I encounter an error when I compile the kvm module.</div>
<div> ERROR: "print_record" [arch/x86/kvm/kvm.ko] undefined!</div><div> I use EXPORT_SYMBOL(print_record) in my module file. I use "extern" to declare print_record() and then call print_record() in file x86.c. </div>
<div> To solve this problem, I have tried to copy the Module.symvers from my module folder to /arch/x86/kvm/. But it doesn't work. I have also tried to add <strong style="vertical-align:baseline;line-height:18px;font-size:14px;font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;margin:0px;border:0px;padding:0px">KBUILD_EXTRA_SYMBOLS </strong>to the Makefile of kvm. It doesn't work either.</div>
<div> I cat /proc/kallsyms and find that the type of symbol "print_record" is "t" ( local text). What should I do? How to call functions defined in my own module from kvm? Maybe there is something wrong in Makefiles?</div>
<div><br></div><div>Any suggestion is appreciated!</div><div>Thanks!</div></div>
<br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=Kernelnewbies@kernelnewbies.org&cc=&bcc=&su=&body=','_blank');return false;">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br></div></div>