<?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>Strainu onLine &#187; kernel</title>
	<atom:link href="http://www.strainu.ro/tag/kernel/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.strainu.ro</link>
	<description>Blogul unui automatist</description>
	<lastBuildDate>Wed, 18 Aug 2010 10:49:30 +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>Operating Systems design homeworks</title>
		<link>http://www.strainu.ro/software/29/</link>
		<comments>http://www.strainu.ro/software/29/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 13:20:46 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[Operating Systems]]></category>

		<guid isPermaLink="false">http://www.strainu.ro/site/?p=438</guid>
		<description><![CDATA[Operating Systems design homeworks from the Automatics and Computer Science Faculty, UPB, 4th year, prof. Octavian Purdilă. Themes: system calls, UART driver, file system driver, firewall, RAID software. The software is distributed under CC-GNU GPL license. Download Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p><strong>Operating Systems design homeworks</strong> from the Automatics and Computer Science Faculty, UPB, 4th year, prof. Octavian Purdilă. Themes: system calls, UART driver, file system driver, firewall, RAID software.<br />
<span id="more-438"></span></p>
<p>The software is distributed under <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL license</a>.</p>
<p><a href="http://www.strainu.ro/tracker/downi.php?id=teme_pso" target="_blank"><strong>Download</strong></a> </p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel='nofollow' target='_blank'  href='http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;t=Operating%20Systems%20design%20homeworks'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png' class='sociable-img sociable-hovers ' title='Facebook' alt='Facebook' /></a></li><li><a rel='nofollow' target='_blank'  href='http://twitter.com/home?status=Operating%20Systems%20design%20homeworks%20-%20http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png' class='sociable-img sociable-hovers ' title='Twitter' alt='Twitter' /></a></li><li><a rel='nofollow' target='_blank'  href='http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png' class='sociable-img sociable-hovers ' title='Identi.ca' alt='Identi.ca' /></a></li><li><a rel='nofollow' target='_blank'  href='mailto:?subject=Operating%20Systems%20design%20homeworks&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png' class='sociable-img sociable-hovers ' title='email' alt='email' /></a></li><li><a rel='nofollow' target='_blank' title='Add to favorites' href='javascript:AddToFavorites();'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png' class='sociable-img sociable-hovers ' title='Add to favorites' alt='Add to favorites' /></a></li><li><a rel='nofollow' target='_blank'  href='http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;title=Operating%20Systems%20design%20homeworks&amp;bodytext=Operating%20Systems%20design%20homeworks%20from%20the%20Automatics%20and%20Computer%20Science%20Faculty%2C%20UPB%2C%204th%20year%2C%20prof.%20Octavian%20Purdil%C4%83.%20Themes%3A%20system%20calls%2C%20UART%20driver%2C%20file%20system%20driver%2C%20firewall%2C%20RAID%20software.%0D%0A%0D%0A%0D%0AThe%20software%20is%20distributed%20under%20CC-GNU'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png' class='sociable-img sociable-hovers ' title='Digg' alt='Digg' /></a></li><li><a rel='nofollow' target='_blank'  href='http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fsoftware%2F29%2F&amp;title=Operating%20Systems%20design%20homeworks'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png' class='sociable-img sociable-hovers ' title='StumbleUpon' alt='StumbleUpon' /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/software/29/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple debugging in kernel programming</title>
		<link>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/</link>
		<comments>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/#comments</comments>
		<pubDate>Thu, 17 May 2007 07:17:07 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[kernel]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/simple-debugging-in-kernel-programming/</guid>
		<description><![CDATA[When programming Linux kernel modules, you have limited debugging options. The main way is to use the printk function (the kernel equivalent of printf). If you want to give as much information as possible, you could use some of the macros that the language offers you, such as __FILE__ or __line__. Here is a small [...]]]></description>
			<content:encoded><![CDATA[<p>When programming Linux kernel modules, you have limited debugging options. The main way is to use the <strong>printk</strong> function (the kernel equivalent of printf). If you want to give as much information as possible, you could use some of the macros that the language offers you, such as <em>__FILE__</em> or <em>__line__</em>. Here is a small snippet you could use in your modules:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define DEBUG 1</span><br />
<span style="color: #339933;">#if DEBUG</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) \<br />
printk (KERN_ALERT &quot;[%s]:FUNC:%s:line:%d: &quot; format, __FILE__, \<br />
__func__, __LINE__, __VA_ARGS__)</span><br />
<span style="color: #339933;">#else</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) do {}while(0)</span><br />
<span style="color: #339933;">#endif</span></div></div>
<p>You can use the same code in userspace programs by replacing <strong>printk</strong> with <strong>printf</strong>. And just in case you&#8217;re wondering what&#8217;s with the empty <strong>do-while</strong>, you might want to take a look at <a href="http://codertricks.strainu.ro/c/2007/05/04/macros-using-dowhile0/" target="_blank">this older article</a>.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel='nofollow' target='_blank'  href='http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;t=Simple%20debugging%20in%20kernel%20programming'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png' class='sociable-img sociable-hovers ' title='Facebook' alt='Facebook' /></a></li><li><a rel='nofollow' target='_blank'  href='http://twitter.com/home?status=Simple%20debugging%20in%20kernel%20programming%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png' class='sociable-img sociable-hovers ' title='Twitter' alt='Twitter' /></a></li><li><a rel='nofollow' target='_blank'  href='http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png' class='sociable-img sociable-hovers ' title='Identi.ca' alt='Identi.ca' /></a></li><li><a rel='nofollow' target='_blank'  href='mailto:?subject=Simple%20debugging%20in%20kernel%20programming&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png' class='sociable-img sociable-hovers ' title='email' alt='email' /></a></li><li><a rel='nofollow' target='_blank' title='Add to favorites' href='javascript:AddToFavorites();'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png' class='sociable-img sociable-hovers ' title='Add to favorites' alt='Add to favorites' /></a></li><li><a rel='nofollow' target='_blank'  href='http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming&amp;bodytext=When%20programming%20Linux%20kernel%20modules%2C%20you%20have%20limited%20debugging%20options.%20The%20main%20way%20is%20to%20use%20the%20printk%20function%20%28the%20kernel%20equivalent%20of%20printf%29.%20If%20you%20want%20to%20give%20as%20much%20information%20as%20possible%2C%20you%20could%20use%20some%20of%20the%20macros%20that%20the%20la'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png' class='sociable-img sociable-hovers ' title='Digg' alt='Digg' /></a></li><li><a rel='nofollow' target='_blank'  href='http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png' class='sociable-img sociable-hovers ' title='StumbleUpon' alt='StumbleUpon' /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macros using do{}while(0);</title>
		<link>http://www.strainu.ro/programming/c/macros-using-dowhile0/</link>
		<comments>http://www.strainu.ro/programming/c/macros-using-dowhile0/#comments</comments>
		<pubDate>Fri, 04 May 2007 09:10:47 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[kernel]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/macros-using-dowhile0/</guid>
		<description><![CDATA[If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this: #define foo(params) \ do{ \ &#160; &#160; //instructions \ }while(0) This basicly means that the code is executed exactly once, so the first idea is that do{}while(0); is useless. In fact, there are a [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define foo(params) \<br />
do{ \<br />
&nbsp; &nbsp; //instructions \<br />
}while(0)</span></div></div>
<p>This basicly means that the code is executed exactly once, so the first idea is that <em>do{}while(0);</em> is useless.<br />
In fact, there are a number of reasons for writing the macros this way:</p>
<ul>
<li>Empty statements give warnings from the compilers, so rather than writing
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define FOO</span></div></div>
<p>you might want to write</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define FOO do{}while(0)</span></div></div>
</li>
<li> It gives you a basic block in which to declare local variables. You could simply use curly brackets, but this could cause serious problems in conditional statements. Let&#8217;s take the following example:
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define exch(a,b) {int t; t = a; a = b; b = t;}</span></div></div>
<p>You then use the macro in the following code:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>a <span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; exch<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; ready <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span></div></div>
<p>This is what the copiler will get:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>a <span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> t<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; t <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; a<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; ready <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span></div></div>
<p>This is interpreted as an <strong>if</strong> statement whithout <strong>else</strong> and you will get an error like <em>&#8220;else without matching if&#8221;</em>. However, if you write the macro like this:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define exch(a,b) do{int t; t = a; a = b; b = t;}while(0)</span></div></div>
<p>the code will behave as expected.</a></code></a></code></li>
</ul>
<p>You can find more informations about this in the <a href="http://kernelnewbies.org/FAQ/DoWhile0" target="_blank">Kernelnewbies FAQ</a>.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel='nofollow' target='_blank'  href='http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;t=Macros%20using%20do%7B%7Dwhile%280%29%3B'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png' class='sociable-img sociable-hovers ' title='Facebook' alt='Facebook' /></a></li><li><a rel='nofollow' target='_blank'  href='http://twitter.com/home?status=Macros%20using%20do%7B%7Dwhile%280%29%3B%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png' class='sociable-img sociable-hovers ' title='Twitter' alt='Twitter' /></a></li><li><a rel='nofollow' target='_blank'  href='http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png' class='sociable-img sociable-hovers ' title='Identi.ca' alt='Identi.ca' /></a></li><li><a rel='nofollow' target='_blank'  href='mailto:?subject=Macros%20using%20do%7B%7Dwhile%280%29%3B&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png' class='sociable-img sociable-hovers ' title='email' alt='email' /></a></li><li><a rel='nofollow' target='_blank' title='Add to favorites' href='javascript:AddToFavorites();'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png' class='sociable-img sociable-hovers ' title='Add to favorites' alt='Add to favorites' /></a></li><li><a rel='nofollow' target='_blank'  href='http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;title=Macros%20using%20do%7B%7Dwhile%280%29%3B&amp;bodytext=If%20you%20ever%20had%20the%20chance%20to%20look%20in%20the%20Linux%20kernel%20sources%2C%20you%20might%20have%20seen%20macros%20defined%20like%20this%3A%0D%0A%0D%0A%23define%20foo%28params%29%20%5C%0D%0Ado%7B%20%5C%0D%0A%20%20%20%20%2F%2Finstructions%20%5C%0D%0A%7Dwhile%280%29%0D%0AThis%20basicly%20means%20that%20the%20code%20is%20executed%20exactly%20once%2C%20so%20the%20first%20id'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png' class='sociable-img sociable-hovers ' title='Digg' alt='Digg' /></a></li><li><a rel='nofollow' target='_blank'  href='http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fmacros-using-dowhile0%2F&amp;title=Macros%20using%20do%7B%7Dwhile%280%29%3B'><img src='http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png' class='sociable-img sociable-hovers ' title='StumbleUpon' alt='StumbleUpon' /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/macros-using-dowhile0/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
