<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aiur - ZelluX 的技术博客 &#187; Programming</title>
	<atom:link href="http://techblog.iamzellux.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.iamzellux.com</link>
	<description>Security, Kernel, Virtualization, Programming Languages</description>
	<lastBuildDate>Wed, 25 Aug 2010 06:56:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>gcc内联汇编中%c的用法</title>
		<link>http://techblog.iamzellux.com/2010/08/gcc-operand-substitution/</link>
		<comments>http://techblog.iamzellux.com/2010/08/gcc-operand-substitution/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 06:54:27 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Assembly]]></category>
		<category><![CDATA[gcc]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62848</guid>
		<description><![CDATA[这几天看KVM代码的时候看到里面有个内联汇编的语法很陌生（下面的代码截取了部分内联汇编片段）。stackoverf'low上问了下才知道这是gcc的operand substitution语法，%c后面跟上常量名，就能在内联汇编中使用这个常量了。]]></description>
			<content:encoded><![CDATA[<p>这几天看KVM代码的时候看到里面有个内联汇编的语法很陌生（下面的代码截取了部分内联汇编片段）：</p>
<pre class="brush: asm" lang="asm">    asm (
        "mov %c[rax](%3), %%rax \n\t"
        "mov %c[rbx](%3), %%rbx \n\t"
        "mov %c[rdx](%3), %%rdx \n\t"
        "mov %c[rsi](%3), %%rsi \n\t"
        "mov %c[rdi](%3), %%rdi \n\t"
          : "=q" (fail)
          : "r"(vcpu-&gt;launched), "d"((unsigned long)HOST_RSP),
        "c"(vcpu),
        [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])),
        [rbx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBX])),
        [rcx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RCX]))
          : "cc", "memory" );</pre>
<p>stackoverf&#8217;low上问了下才知道这是gcc的<a href="http://gcc.gnu.org/onlinedocs/gccint/Output-Template.html#Output-Template" target="_blank">operand substitution语法</a>，%c后面跟上常量名，就能在内联汇编中使用这个常量了。</p>
<p>以这段代码为例，vcpu是struct kvm_vcpu类型，<span style="text-decoration: underline;">[rax]&#8220;i&#8221;(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])</span>这句话把vcpu-&gt;regs[VCPU_REGS_RAX]相对于vcpu的偏移赋值给了rax这一常量。接下来回到第一行<span style="text-decoration: underline;">mov %c[rax](%3), %%eax</span>，%c[rax]等于前面得到的偏移量，加上vcpu并取值后就是vcpu-&gt;regs[VCPU_REGS_RAX]中保存的值了，这个指令会把这个值保存在%rax寄存器中，从而完成了vcpu的rax寄存器恢复工作。</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/02/08 -- <a href="http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/" title="gcc中设置特定代码块的优化级别">gcc中设置特定代码块的优化级别</a></li><li>2008/08/26 -- <a href="http://techblog.iamzellux.com/2008/08/x86-real-mode-graphics/" title="x86汇编图形编程资料">x86汇编图形编程资料</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/asmlinkage-and-regparm/" title="[zz]asmlinkage &amp; regparm">[zz]asmlinkage &amp; regparm</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/export-symbols-in-asm/" title="汇编文件中导出函数符号">汇编文件中导出函数符号</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/08/gcc-operand-substitution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>因为1个异常导入190个包</title>
		<link>http://techblog.iamzellux.com/2010/02/ubuntu-python-aport-bug/</link>
		<comments>http://techblog.iamzellux.com/2010/02/ubuntu-python-aport-bug/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 16:32:49 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62782</guid>
		<description><![CDATA[Ubuntu Apport系统中的一个bug导致了Python发生异常的时侯会额外的import 190个包。]]></description>
			<content:encoded><![CDATA[<p>今天reddit programming上的<a href="http://www.reddit.com/r/programming/comments/b6qho/ubuntu_python_raise_an_exception_import_190/" target="_blank">一个帖子</a>，提到了ubuntu上python-apport包的一个bug。</p>
<p>重现这个bug很简单：</p>
<pre class="brush: python">Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import sys
&gt;&gt;&gt; len(sys.modules)
35
&gt;&gt;&gt; foo
Traceback (most recent call last):
  File "", line 1, in
NameError: name 'foo' is not defined
&gt;&gt;&gt; len(sys.modules)
225
&gt;&gt;&gt;</pre>
<p>在执行foo之前，当前导入的包只有35个，执行之后却有了225个。问题出在Ubuntu的<a href="https://wiki.ubuntu.com/Apport" target="_blank">Apport</a>系统，它为Python添加了一个异常处理方法，这里面的bug导致了这些多余的包被导入。</p>
<p><a href="https://bugs.launchpad.net/ubuntu/+source/apport/+bug/528355" target="_blank">这个bug</a>已经被人提交并被确认，目前暂时还没有补丁，最简单的避免方法就是把python-apport包卸载 <img src='http://techblog.iamzellux.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>原文地址： <a href="http://rhodesmill.org/brandon/2010/ubuntu-exception-190-modules/">http://rhodesmill.org/brandon/2010/ubuntu-exception-190-modules/</a></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2009/12/17 -- <a href="http://techblog.iamzellux.com/2009/12/linux-xen-compiling-error-in-ubuntu/" title="Ubuntu下编译Linux-xen的问题">Ubuntu下编译Linux-xen的问题</a></li><li>2009/06/16 -- <a href="http://techblog.iamzellux.com/2009/06/svn-sms-notification/" title="SVN更新短信通知脚本">SVN更新短信通知脚本</a></li><li>2009/04/10 -- <a href="http://techblog.iamzellux.com/2009/04/tuple-pronunciation/" title="关于tuple的读音">关于tuple的读音</a></li><li>2009/04/07 -- <a href="http://techblog.iamzellux.com/2009/04/xen-test-script/" title="Xen DomainU自动测试脚本">Xen DomainU自动测试脚本</a></li><li>2008/11/17 -- <a href="http://techblog.iamzellux.com/2008/11/daily-notes-on-python1117-1123/" title="Daily Notes on Python[11.17-11.23]">Daily Notes on Python[11.17-11.23]</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/02/ubuntu-python-aport-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SICP里提到的画图语言</title>
		<link>http://techblog.iamzellux.com/2010/02/the-sicp-picture-language/</link>
		<comments>http://techblog.iamzellux.com/2010/02/the-sicp-picture-language/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 12:15:03 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Scheme]]></category>
		<category><![CDATA[SICP]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62771</guid>
		<description><![CDATA[使用PLT Scheme中的sicp.plt包实现SICP上的图形程序]]></description>
			<content:encoded><![CDATA[<p>SICP第二章里提到了一种用来画图的Lisp方言，用来演示数据抽象和闭包的表达能力（见<a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4">http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.4</a>）。</p>
<p>最近尝试了下，发现soegaard同学已经在PLT Scheme中实现了一个类似的库，可以很方便的在DrScheme上使用。</p>
<p>sicp.plt包使用很简单，在Language-&gt;Choose Language中选择Module，然后在需要用到这个包的时候用</p>
<pre class="brush: lisp">(require (planet soegaard/sicp:2:1/sicp))</pre>
<p>声明即可。第一次运行时DrScheme会自动下载这个包并安装，如果网络有限制可以先从<a href="http://planet.plt-scheme.org/display.ss?package=sicp.plt&amp;owner=soegaard">http://planet.plt-scheme.org/display.ss?package=sicp.plt&amp;owner=soegaard</a>下载然后在DrScheme中选择本地包安装。</p>
<p>另外SICP上使用的两个painter（wave和rogers）没有在这个包里提供，取而代之是diagonal-shading和einstein。</p>
<p>下面这个程序显示了一个简单的分形图像：</p>
<pre class="brush: lisp">#lang scheme

(require (planet "sicp.ss" ("soegaard" "sicp.plt" 2 1)))

(define (right-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (right-split painter (- n 1))))
        (beside painter (below smaller smaller)))))

(define (up-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (up-split painter (- n 1))))
        (below painter (beside smaller smaller)))))

(define (corner-split painter n)
  (if (= n 0)
      painter
      (let ((up (up-split painter (- n 1)))
            (right (right-split painter (- n 1))))
        (let ((top-left (beside up up))
              (bottom-right (below right right))
              (corner (corner-split painter (- n 1))))
          (beside (below painter top-left)
                  (below bottom-right corner))))))

(paint (corner-split diagonal-shading 4))</pre>
<p>程序输出：</p>
<p><a href="http://techblog.iamzellux.com/wp-content/uploads/2010/02/corner-split.png" rel="shadowbox[post-62771];player=img;"><img class="alignnone size-full wp-image-62772" title="corner-split" src="http://techblog.iamzellux.com/wp-content/uploads/2010/02/corner-split.png" alt="" width="128" height="128" /></a></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/02/the-sicp-picture-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gcc中设置特定代码块的优化级别</title>
		<link>http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/</link>
		<comments>http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:16:34 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[gcc]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62740</guid>
		<description><![CDATA[gcc 4.4的特性<a href="http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Function-Specific-Option-Pragmas.html" target="_blank">Function Specific Option Pragmas</a>，在特定代码前保存当前的编译选项，然后对特定的代码使用O0优化级别，最后再恢复之前保存的编译选项。]]></description>
			<content:encoded><![CDATA[<p>今天碰到一个gcc优化相关的问题，为了让一个页变成脏页（页表中dirty位被置上），需要执行下面这段代码：</p>
<pre class="brush: c">uint32_t *page;
// ...
page[0] = page[0];</pre>
<p>最后一行代码很有可能被gcc优化掉，因为这段代码看起来没有任何实际的作用。那么如何防止gcc对这段代码做优化呢？</p>
<p>设置gcc编译时优化级别为-O0肯定是不合适的，这样对程序性能影响会比较大。stackoverflow上的Dietrich Epp给出了一个强制类型转换的方案：</p>
<pre class="brush: c">((unsigned char volatile *)page)[0] = page[0];</pre>
<p>通过volatile关键字禁止gcc的优化，和我之前采用的方法类似。</p>
<p>Plow同学给出了另一个利用gcc 4.4特性的方法：</p>
<pre class="brush: c">#pragma GCC push_options
#pragma GCC optimize ("O0")

your code

#pragma GCC pop_options</pre>
<p>这里用到了gcc 4.4的特性<a href="http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Function-Specific-Option-Pragmas.html" target="_blank">Function Specific Option Pragmas</a>，在特定代码前保存当前的编译选项，然后对特定的代码使用O0优化级别，最后再恢复之前保存的编译选项。</p>
<p>俺觉得这个特性有些场合下挺好用的，在这里分享下，虽然因为编译器版本问题最后我还是用了前面一种方法。</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/08/25 -- <a href="http://techblog.iamzellux.com/2010/08/gcc-operand-substitution/" title="gcc内联汇编中%c的用法">gcc内联汇编中%c的用法</a></li><li>2010/01/28 -- <a href="http://techblog.iamzellux.com/2010/01/obfuscated-c/" title="这样也能算圆周率">这样也能算圆周率</a></li><li>2010/01/26 -- <a href="http://techblog.iamzellux.com/2010/01/force-int-0x80-for-syscall/" title="强制程序使用int 0&#215;80做系统调用">强制程序使用int 0&#215;80做系统调用</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/asmlinkage-and-regparm/" title="[zz]asmlinkage &amp; regparm">[zz]asmlinkage &amp; regparm</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/export-symbols-in-asm/" title="汇编文件中导出函数符号">汇编文件中导出函数符号</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>这样也能算圆周率</title>
		<link>http://techblog.iamzellux.com/2010/01/obfuscated-c/</link>
		<comments>http://techblog.iamzellux.com/2010/01/obfuscated-c/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 03:22:30 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62485</guid>
		<description><![CDATA[reddit programming版面最近的热帖，下面这个程序输出的结果是一个近似的圆周率(3.156)。 #define _ F--&#62;00 &#124;&#124; F-OO--; long F=00,OO=00; main(){F_OO();printf("%1.3f\n", 4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_ } 乍看下这个程序有点莫名其妙，分析一下宏后就知道它的方法了。两个全局变量F和OO分别记录 圆的面积和直径 的相反数，根据4*面积/直径/直径就能得到近似的圆周率了。 至于面积和直径的计算，F在会在每一个_展开的地方减一，这样就得到了圆的面积。直径的计算要展开几行代码才能看得更清楚： F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 &#124;&#124; F-OO--; F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 &#124;&#124; F-OO--; -F--&#62;00 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.reddit.com/r/programming/comments/auqpc/the_sickest_obfuscated_and_the_most_beautiful_way/" target="_blank">reddit programming版面最近的热帖</a>，下面这个程序输出的结果是一个近似的圆周率(3.156)。</p>
<pre class="brush: c">#define _ F--&gt;00 || F-OO--;
long F=00,OO=00;
main(){F_OO();printf("%1.3f\n", 4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
       _-_-_-_-_-_-_-_-_
            _-_-_-_
}</pre>
<p>乍看下这个程序有点莫名其妙，分析一下宏后就知道它的方法了。两个全局变量F和OO分别记录 圆的面积和直径 的相反数，根据4*面积/直径/直径就能得到近似的圆周率了。</p>
<p>至于面积和直径的计算，F在会在每一个_展开的地方减一，这样就得到了圆的面积。直径的计算要展开几行代码才能看得更清楚：</p>
<pre class="brush: c">F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;

F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;
-F--&gt;00 || F-OO--;</pre>
<p>这是用cpp展开圆形前两行代码的结果，因为或运算的特殊性，F- OO- -只会在每一段的第一行执行，所以OO- -执行的次数就等于圆的直径了。</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/02/08 -- <a href="http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/" title="gcc中设置特定代码块的优化级别">gcc中设置特定代码块的优化级别</a></li><li>2010/01/26 -- <a href="http://techblog.iamzellux.com/2010/01/force-int-0x80-for-syscall/" title="强制程序使用int 0&#215;80做系统调用">强制程序使用int 0&#215;80做系统调用</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/asmlinkage-and-regparm/" title="[zz]asmlinkage &amp; regparm">[zz]asmlinkage &amp; regparm</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/export-symbols-in-asm/" title="汇编文件中导出函数符号">汇编文件中导出函数符号</a></li><li>2008/04/15 -- <a href="http://techblog.iamzellux.com/2008/04/count-1-bits-in-an-int32/" title="《编程之美》一个二进制趣题的讨论">《编程之美》一个二进制趣题的讨论</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/01/obfuscated-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>强制程序使用int 0&#215;80做系统调用</title>
		<link>http://techblog.iamzellux.com/2010/01/force-int-0x80-for-syscall/</link>
		<comments>http://techblog.iamzellux.com/2010/01/force-int-0x80-for-syscall/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:56:55 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[linking]]></category>

		<guid isPermaLink="false">http://techblog.iamzellux.com/?p=62453</guid>
		<description><![CDATA[因为大多数情况下程序都是通过libc间接地发出系统调用的，所以只要编译一个只使用int 0x80的glibc库，然后在执行程序的时候用LD_LIBRARY_PATH或其他方法指定使用新编译的glibc库即可。
]]></description>
			<content:encoded><![CDATA[<p>因为大多数情况下程序都是通过libc间接地发出系统调用的，所以只要编译一个只使用int 0&#215;80的glibc库，然后在执行程序的时候用LD_LIBRARY_PATH或其他方法指定使用新编译的glibc库即可。</p>
<p>以glibc-2.9, Linux i386为例，在sysdeps/unix/sysv/linux/i386/syscall.S中可以看到</p>
<pre class="brush: c"> ENTRY (syscall)

     PUSHARGS_6      /* Save register contents.  */
     _DOARGS_6(44)       /* Load arguments.  */
     movl 20(%esp), %eax /* Load syscall number into %eax.  */
     ENTER_KERNEL        /* Do the system call.  */
     POPARGS_6       /* Restore register contents.  */
     cmpl $-4095, %eax   /* Check %eax for error.  */
     jae SYSCALL_ERROR_LABEL /* Jump to error handler if error.  */</pre>
<p>这里使用了ENTER_KERNEL这个宏做系统调用，接下来在sysdeps/unix/sysv/linux/i386/sysdep.h里可以找到这个宏的定义</p>
<pre class="brush: c">/* The original calling convention for system calls on Linux/i386 is
   to use int $0x80.  */
#ifdef I386_USE_SYSENTER
# ifdef SHARED
#  define ENTER_KERNEL call *%gs:SYSINFO_OFFSET
# else
#  define ENTER_KERNEL call *_dl_sysinfo
# endif
#else
# define ENTER_KERNEL int $0x80
#endif</pre>
<p>而I386_USE_SYSENTER这个宏也是在同一个头文件中定义的</p>
<pre class="brush: c">#if defined USE_DL_SYSINFO \
    &amp;&amp; (!defined NOT_IN_libc || defined IS_IN_libpthread)
# define I386_USE_SYSENTER   1
#else
# undef I386_USE_SYSENTER
#endif</pre>
<p>把这个条件宏改成</p>
<pre class="brush: c">#undef I386_USE_SYSENTER</pre>
<p>就能强制glibc使用int 0&#215;80了。</p>
<p>这个方法只能过滤通过glibc做的系统调用。对于程序里写死使用sysenter的情况就要使用反汇编或者其他手段了。</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/02/08 -- <a href="http://techblog.iamzellux.com/2010/02/code-specific-optimizations-in-gcc/" title="gcc中设置特定代码块的优化级别">gcc中设置特定代码块的优化级别</a></li><li>2010/01/28 -- <a href="http://techblog.iamzellux.com/2010/01/obfuscated-c/" title="这样也能算圆周率">这样也能算圆周率</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/asmlinkage-and-regparm/" title="[zz]asmlinkage &amp; regparm">[zz]asmlinkage &amp; regparm</a></li><li>2008/08/20 -- <a href="http://techblog.iamzellux.com/2008/08/export-symbols-in-asm/" title="汇编文件中导出函数符号">汇编文件中导出函数符号</a></li><li>2008/04/15 -- <a href="http://techblog.iamzellux.com/2008/04/count-1-bits-in-an-int32/" title="《编程之美》一个二进制趣题的讨论">《编程之美》一个二进制趣题的讨论</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2010/01/force-int-0x80-for-syscall/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SVN更新短信通知脚本</title>
		<link>http://techblog.iamzellux.com/2009/06/svn-sms-notification/</link>
		<comments>http://techblog.iamzellux.com/2009/06/svn-sms-notification/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 10:57:44 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://techblog.zellux.czm.cn/?p=771</guid>
		<description><![CDATA[主要功能：开发人员执行svn commit后自动将开发人id、修订版本号和日志内容通过短信的方式通知所有人。 首先修改svn服务器对应项目目录hook/post-commit文件 #!/bin/bash export LANG=en_US.utf8 REPOS="$1" REV="$2" cd /home/svn/repositories/sebank/hooks ./sms.py commit $REPOS $REV 注意别忘了这里的export LANG，我一开始测试的时候发现中文一直有乱码，后来才意识到shell的环境变量里缺这个。 hook/sms.py #!/usr/bin/python # -*- coding: utf-8 -*- import sys, urllib, os from subprocess import * user = 'your mobile number' pword = 'fetion password' phone = [ '13764444444', '13813333333', ] repo = sys.argv[2] rev = sys.argv[3] cmdlog = 'svnlook [...]]]></description>
			<content:encoded><![CDATA[<p>主要功能：开发人员执行svn commit后自动将开发人id、修订版本号和日志内容通过短信的方式通知所有人。</p>
<p>首先修改svn服务器对应项目目录hook/post-commit文件</p>
<pre class="brush: bash" lang="bash" name="code">#!/bin/bash

export LANG=en_US.utf8
REPOS="$1"
REV="$2"

cd /home/svn/repositories/sebank/hooks
./sms.py commit $REPOS $REV</pre>
<p>注意别忘了这里的export LANG，我一开始测试的时候发现中文一直有乱码，后来才意识到shell的环境变量里缺这个。<br />
hook/sms.py</p>
<pre class="brush: python" lang="python" name="code">#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, urllib, os
from subprocess import *

user = 'your mobile number'
pword = 'fetion password'
phone = [
        '13764444444',
        '13813333333',
        ]

repo = sys.argv[2]
rev = sys.argv[3]
cmdlog = 'svnlook log -r %s %s'%(rev, repo)
cmdauthor = 'svnlook author -r %s %s'%(rev, repo)
log = Popen(cmdlog, stdout=PIPE, shell=True).stdout.read().strip()
author = Popen(cmdauthor, stdout=PIPE, shell=True).stdout.read().strip()

msg = 'sebank #%s %s: %s' % (rev, author, log)

for number in phone:
    url = 'http://sms.api.bz/fetion.php?username=%s&amp;password=%s&amp;sendto=%s&amp;message=%s' % (user, pword, number, urllib.quote_plus(msg))
    cmd = 'curl "%s"' % url
    send = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    send.wait()</pre>
<p>这里user是发送者的手机号，且该用户的飞信好友需包含其他用户，pword为飞信密码，phone为用户手机号码列表。<br />
最后设置下这两个文件的权限，保证http/svn用户能执行即可。另外由于sms.py中飞信密码是明文保存的，注意控制它的读权限。</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/02/27 -- <a href="http://techblog.iamzellux.com/2010/02/ubuntu-python-aport-bug/" title="因为1个异常导入190个包">因为1个异常导入190个包</a></li><li>2009/04/10 -- <a href="http://techblog.iamzellux.com/2009/04/tuple-pronunciation/" title="关于tuple的读音">关于tuple的读音</a></li><li>2009/04/08 -- <a href="http://techblog.iamzellux.com/2009/04/colorful-svn-diff/" title="彩色版svn diff">彩色版svn diff</a></li><li>2009/04/07 -- <a href="http://techblog.iamzellux.com/2009/04/xen-test-script/" title="Xen DomainU自动测试脚本">Xen DomainU自动测试脚本</a></li><li>2008/11/17 -- <a href="http://techblog.iamzellux.com/2008/11/daily-notes-on-python1117-1123/" title="Daily Notes on Python[11.17-11.23]">Daily Notes on Python[11.17-11.23]</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2009/06/svn-sms-notification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于tuple的读音</title>
		<link>http://techblog.iamzellux.com/2009/04/tuple-pronunciation/</link>
		<comments>http://techblog.iamzellux.com/2009/04/tuple-pronunciation/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 08:17:45 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Joke]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://techblog.zellux.czm.cn/?p=609</guid>
		<description><![CDATA[水木上有个帖子讨论tuple这个词该怎么读，于是有人翻出来这个三年前的新闻组邮件 http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-02/msg01915.html I used to pronounce it toople. But the people that taught me Python found it both comical and confusing. At first they thought I meant a 2 element tuple. So they wondered if a 3 element tuple was a threeple, etc. After much harrassing, I changed my wayward ways and pronounced it tuhple [...]]]></description>
			<content:encoded><![CDATA[<p>水木上有个帖子讨论tuple这个词该怎么读，于是有人翻出来这个三年前的新闻组邮件</p>
<p><a href="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-02/msg01915.html">http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-02/msg01915.html</a></p>
<blockquote><p>I used to pronounce it toople.  But the people that taught me Python<br />
found it both comical and confusing.  At first they thought I meant a 2<br />
element tuple.  So they wondered if a 3 element tuple was a threeple,<br />
etc.  After much harrassing, I changed my wayward ways and pronounced<br />
it tuhple to fit in with the cool Python guys. <img src='http://techblog.iamzellux.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Then we went to hear Guido speak about Python 2.2 at a ZPUG meeting in<br />
Washington, DC.  When he said toople I almost fell out of my chair<br />
laughing, particularly because the people who taught me to say it the<br />
&#8220;right&#8221; way were with me.  When I looked over, they just hung their<br />
head in shame.</p>
<p>I work with Guido now and I&#8217;m conflicted.  I&#8217;m still conditioned to say<br />
tuhple.  Whenever he says toople, I just get a smile on my face.  I<br />
think most of the PythonLabs guys pronounce it toople.</p></blockquote>
<p>有意思，嘿嘿</p>
<p>我一直习惯把这个词读成<span class="IPA">/tʌpəl/，估计是受tunnel这个词的影响，然后查了下<a href="http://en.wiktionary.org/wiki/tuple#Pronunciation_2">http://en.wiktionary.org/wiki/tuple#Pronunciation_2</a> 发现</span><span class="IPA">/tuːpəl/和</span><span class="IPA">/tʌpəl/都可以</span></p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2010/02/27 -- <a href="http://techblog.iamzellux.com/2010/02/ubuntu-python-aport-bug/" title="因为1个异常导入190个包">因为1个异常导入190个包</a></li><li>2009/06/16 -- <a href="http://techblog.iamzellux.com/2009/06/svn-sms-notification/" title="SVN更新短信通知脚本">SVN更新短信通知脚本</a></li><li>2009/04/07 -- <a href="http://techblog.iamzellux.com/2009/04/xen-test-script/" title="Xen DomainU自动测试脚本">Xen DomainU自动测试脚本</a></li><li>2008/11/17 -- <a href="http://techblog.iamzellux.com/2008/11/daily-notes-on-python1117-1123/" title="Daily Notes on Python[11.17-11.23]">Daily Notes on Python[11.17-11.23]</a></li><li>2008/11/13 -- <a href="http://techblog.iamzellux.com/2008/11/pyxpcomext/" title="pyxpcomext">pyxpcomext</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2009/04/tuple-pronunciation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CGO 09 一篇关于DCL检测的论文</title>
		<link>http://techblog.iamzellux.com/2009/04/cgo-09-multi-race/</link>
		<comments>http://techblog.iamzellux.com/2009/04/cgo-09-multi-race/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 14:33:38 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Paper]]></category>

		<guid isPermaLink="false">http://techblog.zellux.czm.cn/?p=604</guid>
		<description><![CDATA[Double-Checked Lock是一个常见的由于程序员把内存模型默认为sequential momery consistency导致的问题，具体见我去年写的一篇博文http://techblog.iamzellux.com/2008/07/singleton-pattern-and-double-checked-lock/ 虽然Java 5解决了这个问题，但是C++等语言中这个问题依然存在，依然有很多因为程序员假设sequential consistency而编译器做了错误的指令调度后导致的bug，见http://www.newsmth.net/bbscon.php?bid=335&#38;id=250203 CGO 09的这篇paper Detecting and Eliminating Potential Violations of Sequential Consistency for Concurrent C/C++ Programs针对这个问题进行了深入研究，通过加fence指令的方法解决了因编译器的指令调度造成的违背程序员原义的问题，可以在http://ppi.fudan.edu.cn/yuelu_duan下载到。没有认真读过，俺在这里就不误人子弟了 O.O Related Posts2009/04/20 -- PPoPP 08 &#8211; FastForward2008/11/30 -- OSDI 08 &#8211; CHESS2010/03/03 -- 跨站脚本攻击和BluePrint2009/06/09 -- 云计算2009/05/12 -- ISCA 09 &#8211; Multi-Execution]]></description>
			<content:encoded><![CDATA[<p>Double-Checked Lock是一个常见的由于程序员把内存模型默认为sequential momery consistency导致的问题，具体见我去年写的一篇博文<a href="http://techblog.iamzellux.com/2008/07/singleton-pattern-and-double-checked-lock/" target="_blank">http://techblog.iamzellux.com/2008/07/singleton-pattern-and-double-checked-lock/</a></p>
<p>虽然Java 5解决了这个问题，但是C++等语言中这个问题依然存在，依然有很多因为程序员假设sequential consistency而编译器做了错误的指令调度后导致的bug，见<a href="http://www.newsmth.net/bbscon.php?bid=335&amp;id=250203" target="_blank">http://www.newsmth.net/bbscon.php?bid=335&amp;id=250203</a></p>
<p>CGO 09的这篇paper Detecting and Eliminating Potential Violations of Sequential Consistency for Concurrent C/C++ Programs针对这个问题进行了深入研究，通过加fence指令的方法解决了因编译器的指令调度造成的违背程序员原义的问题，可以在<a href="http://ppi.fudan.edu.cn/yuelu_duan" target="_blank">http://ppi.fudan.edu.cn/yuelu_duan</a>下载到。没有认真读过，俺在这里就不误人子弟了 O.O</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2009/04/20 -- <a href="http://techblog.iamzellux.com/2009/04/ppopp-08-fastforward/" title="PPoPP 08 &#8211; FastForward">PPoPP 08 &#8211; FastForward</a></li><li>2008/11/30 -- <a href="http://techblog.iamzellux.com/2008/11/finding-and-reproducing-heisenbugs-in-concurrent-programs/" title="OSDI 08 &#8211; CHESS">OSDI 08 &#8211; CHESS</a></li><li>2010/03/03 -- <a href="http://techblog.iamzellux.com/2010/03/blueprint/" title="跨站脚本攻击和BluePrint">跨站脚本攻击和BluePrint</a></li><li>2009/06/09 -- <a href="http://techblog.iamzellux.com/2009/06/above-the-clouds/" title="云计算">云计算</a></li><li>2009/05/12 -- <a href="http://techblog.iamzellux.com/2009/05/isca-09-multi-execution/" title="ISCA 09 &#8211; Multi-Execution">ISCA 09 &#8211; Multi-Execution</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2009/04/cgo-09-multi-race/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>到底啥才是Type Safety呢</title>
		<link>http://techblog.iamzellux.com/2008/12/what-is-type-safety/</link>
		<comments>http://techblog.iamzellux.com/2008/12/what-is-type-safety/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 07:16:09 +0000</pubDate>
		<dc:creator>zellux</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[Type Safety]]></category>

		<guid isPermaLink="false">http://10.132.140.73/wordpress/?p=430</guid>
		<description><![CDATA[水木的FuncProgram上最近为这个问题引发了一场大水（其实也不大，在那个版上算比较大了 XD），里面有一个很不错的引用，现摘录如下： * Type theorists&#8217; view: It&#8217;s about primitives. Type safety is not directly related to memory.  If you read the literatures in the research of programming language type systems, you will find little explicit mentioning of memory concerns, unless the paper is explicit addressing memory management. For a language to be interesting, there must [...]]]></description>
			<content:encoded><![CDATA[<p>水木的FuncProgram上最近为这个问题引发了一场大水（其实也不大，在那个版上算比较大了 XD），里面有一个很不错的引用，现摘录如下： <span id="more-60777"></span> * Type theorists&#8217; view: It&#8217;s about primitives.</p>
<p>Type safety is not directly related to memory.  If you read the literatures in the research of programming language type systems, you will find little explicit mentioning of memory concerns, unless the paper is explicit addressing memory management.</p>
<p>For a language to be interesting, there must be some pre-defined primitives values/functions.  This is parallel to mathematical induction, where you must have base cases/axioms.  Programming is really just a way to synthesize such primitives using combinators to form composites of more complicated functionalities.  For instance, usually a general purpose language will provide arithmatic operations, such as &#8220;+&#8221;.  &#8221;+&#8221; takes two numbers as inputs and generate a number as output.  Note that &#8220;+&#8221; will only work appropriately if provided two numbers.  If the inputs are not numbers, &#8220;+&#8221; will not make sense and will malfunction.  With this understanding in mind, here come types:</p>
<p>Classic type systems assure one thing: at run-time, all the primitives will be guaranteed to function appropriately, i.e., you will NOT get a type error at run-time.</p>
<p>For instance, if a program is well-typed, then by whatever complicated way you use the function &#8220;+&#8221;, the inputs to it are guaranteed to be two numbers, and there is absolutely no way for it to malfunction in any possible run-time trace.</p>
<p>* Programmers&#8217; view: It&#8217;s about memory interpretation.</p>
<p>In programmers&#8217; eyes, primitives correpond to language built-in functions. For instance, the &#8220;printf&#8221; funcition in C, the &#8220;bind&#8221; function in Haskell. These functions correspond to code stored as bits in memory code segments. When executed, they operate on some certain data, which is also stored as bits in memory data segments.  In such operations, the function needs to interpret the bits in some certain ways, because usually the bits do not interpret themselves (in common statically typed langauges).  For instance, the function &#8220;+&#8221; will interprets its first argument (represented by some bits) as a number.</p>
<p>From this point of view, what type systems assure is truly the correctness of memory interpretation, that is, if some bits are to be interpreted by the run-time system as a number, then these bits truly represents a number but not a string or a pointer to a linked list.</p>
<p>In fact, it is very hard for a type system to assure the consistency of memory access in a language with explicit memory manipulation such as C. There are many proposals on how to prevent accessing dangling pointers in<br />
such languages, but they are either too restricted or too complicated to be practical.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>2008/10/16 -- <a href="http://techblog.iamzellux.com/2008/10/programming-language-pragmatics-note-1/" title="Programming Language Pragmatics 笔记 [1]">Programming Language Pragmatics 笔记 [1]</a></li><li>2008/09/08 -- <a href="http://techblog.iamzellux.com/2008/09/compilers-and-more-parallel-programming-made-easy/" title="Parallel Programming Made Easy?">Parallel Programming Made Easy?</a></li><li>2008/07/19 -- <a href="http://techblog.iamzellux.com/2008/07/leaksurvivor/" title="Usenix 08 &#8211; LeakSurvivor">Usenix 08 &#8211; LeakSurvivor</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://techblog.iamzellux.com/2008/12/what-is-type-safety/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
