<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-2022-jp">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:SimSun;
        mso-fareast-language:ZH-CN;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:ZH-CN;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:ZH-CN;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">
</span><span lang="ZH-CN" style="font-size:10.0pt">王瘢雹哲</span><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> [mailto:wangzhe5004@gmail.com]
<br>
<b>Sent:</b> Wednesday, June 20, 2012 1:16 AM<br>
<b>To:</b> Jeff Haran<br>
<b>Cc:</b> kernelnewbies<br>
<b>Subject:</b> Re: A confusion about invoking my syscall<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">2012/6/20 Jeff Haran &lt;<a href="mailto:jharan@bytemobile.com" target="_blank">jharan@bytemobile.com</a>&gt;<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">
</span><span lang="JA" style="font-size:10.0pt;mso-fareast-language:JA">王瘢雹哲</span><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> [mailto:<a href="mailto:wangzhe5004@gmail.com" target="_blank">wangzhe5004@gmail.com</a>]
<br>
<b>Sent:</b> Monday, June 18, 2012 9:32 PM<br>
<b>To:</b> Jeff Haran<br>
<b>Cc:</b> kernelnewbies<br>
<b>Subject:</b> Re: A confusion about invoking my syscall</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">&nbsp;<o:p></o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">2012/6/19 Jeff Haran &lt;<a href="mailto:jharan@bytemobile.com" target="_blank">jharan@bytemobile.com</a>&gt;<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">
<a href="mailto:kernelnewbies-bounces@kernelnewbies.org" target="_blank">kernelnewbies-bounces@kernelnewbies.org</a> [mailto:<a href="mailto:kernelnewbies-bounces@kernelnewbies.org" target="_blank">kernelnewbies-bounces@kernelnewbies.org</a>]
<b>On Behalf Of </b>??<br>
<b>Sent:</b> Monday, June 18, 2012 6:40 PM<br>
<b>To:</b> kernelnewbies<br>
<b>Subject:</b> A confusion about invoking my syscall</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">&nbsp;<o:p></o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">Hello everyone:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I append a simple syscall in kernel. and the function is as follows:<br>
<br>
&nbsp; asmlinkage&nbsp; long sys_mysyscall(long data)<br>
&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printk(&quot;This is my syscall!\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return data;<br>
&nbsp; }<br>
<br>
and i test it sucessfully in user space . and the test program:<br>
<br>
&nbsp;&nbsp; #include &lt;linux/unistd.h&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
&nbsp;&nbsp; #include &lt;syscall.h&gt;<br>
&nbsp;&nbsp; #include &lt;sys/types.h&gt;<br>
&nbsp;&nbsp; #include &lt;stdio.h&gt;<br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp; int main(void)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp; long n = 0,m = 0,pid1,pid2;<br>
&nbsp;&nbsp; n = syscall(345,190);// #define __NR_mysyscall&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 345<br>
&nbsp;&nbsp; printf(&quot;n = %ld\n&quot;,n);<br>
&nbsp;&nbsp; pid1 = syscall(SYS_getpid);&nbsp; //getpid<br>
&nbsp;&nbsp; printf(&quot;pid = %ld\n&quot;,pid1);<br>
&nbsp;&nbsp; pid2 = syscall(20);&nbsp; //getpid<br>
&nbsp;&nbsp; printf(&quot;pid = %ld\n&quot;,pid2);<br>
&nbsp;&nbsp; return 0;<br>
&nbsp; }<br>
and the result:<br>
n = 190<br>
pid = 4097<br>
pid = 4097<br>
<br>
but if the test program is:<br>
#include &lt;linux/unistd.h&gt;<br>
#include &lt;syscall.h&gt;<br>
#include &lt;sys/types.h&gt;<br>
#include &lt;stdio.h&gt;<br>
<br>
<br>
<br>
int main(void)<br>
{<br>
&nbsp;long n = 0,m = 0,pid1,pid2;<br>
&nbsp;n = syscall(345,190);// #define __NR_mysyscall&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 345<br>
&nbsp;printf(&quot;n = %ld\n&quot;,n);<br>
&nbsp;m = syscall(SYS_mysyscall,190);<br>
&nbsp;printf(&quot;m = %ld\n&quot;,m);<br>
&nbsp;pid1 = syscall(SYS_getpid);&nbsp; //getpid<br>
&nbsp;printf(&quot;pid = %ld\n&quot;,pid1);<br>
&nbsp;pid2 = syscall(20);&nbsp; //getpid<br>
&nbsp;printf(&quot;pid = %ld\n&quot;,pid2);<br>
&nbsp;return 0;<br>
}<br>
and the result:<br>
wanny@wanny-C-Notebook-XXXX:~/syscall/src$ gcc test1.c <br>
test1.c: In function <span lang="ZH-CN">‘</span>main<span lang="ZH-CN">’</span>:<br>
test1.c:13:14: error: <span lang="ZH-CN">‘</span>SYS_mysyscall<span lang="ZH-CN">’</span> undeclared (first use in this function)<br>
test1.c:13:14: note: each undeclared identifier is reported only once for each function it appears in<br>
<br>
<br>
why i can't invoke my syscall with &quot;SYS_mysyscall&quot;?<br>
<br>
Thanks in advance!<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="color:#1F497D">Because it appears you never defined the symbol SYS_mysyscall.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="color:#1F497D">&nbsp;I think so,but where shoud i defne the &nbsp;symbol SYS_mysyscall ?</span><span style="color:#888888">&nbsp;</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="color:#1F497D">&nbsp; and where is the symbol&nbsp;</span><span style="color:#888888">SYS_getpid defined?&nbsp;</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="color:#1F497D">On my system /usr/include/bits/syscall.h, which is&nbsp;being included in your program because it includes syscall.h.</span><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 83 #define SYS_getpid __NR_getpid&nbsp; <span lang="ZH-CN">
,</span>so SYS_getpid is replaced by __NR_getpid. and __NR_getpid was defined in the kernel(arch/x86/include/asm/unistd_32.h). and my syscall was also defined there.#define SYS_mysyscall __NR_mysyscall, i don't kown why it doesn't works.<br>
&nbsp;<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">My sources contain no reference to SYS_mysyscall nor __NR_mysyscall, so I assume you’ve added them to the Linux include files that you built your module from.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">User space programs like your main() program above generally aren’t going to include Linux source tree include files. When you include &lt;syscall.h&gt; from a user
 space program in a typical development environment, the compiler is by default going to look for syscall.h in /usr/include, not in the Linux source tree where presumably you’ve made your modifications. Of course you can always tell the compiler to look there
 using the &#8211;I command line option to gcc, if you want to. The usual practice however is to keep kernel code and user code include files completely separate. That means some duplication of effort, like having to define SYS_mysyscall in two different places,
 but that’s the usual practice because most people aren’t building kernels and thus haven’t installed the kernel source include files.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Jeff Haran<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
</div>
</div>
</div>
</div>
<font face="monospace"></font></body>
</html>