<?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"
	>

<channel>
	<title>Evan Teran's Blog</title>
	<atom:link href="http://blog.codef00.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codef00.com</link>
	<description>Just some thoughts from a computer geek</description>
	<pubDate>Thu, 26 Jun 2008 23:58:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>GTA IV Actually Discourages Attacking Police</title>
		<link>http://blog.codef00.com/2008/06/25/gta-iv-actually-discourages-attacking-police/</link>
		<comments>http://blog.codef00.com/2008/06/25/gta-iv-actually-discourages-attacking-police/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 20:41:04 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.codef00.com/2008/06/25/gta-iv-actually-discourages-attacking-police/</guid>
		<description><![CDATA[I&#8217;ve been a huge fan of the GTA series ever since GTA 3 came out. It is a genuinely fun game which gives you your money&#8217;s worth of entertainment. The plots have been good and the missions are hard enough to be challenging, but not so hard that you&#8217;ll wanna stop playing. I&#8217;ve always gotten [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been a huge fan of the GTA series ever since GTA 3 came out. It is a genuinely fun game which gives you your money&#8217;s worth of entertainment. The plots have been good and the missions are hard enough to be challenging, but not so hard that you&#8217;ll wanna stop playing. I&#8217;ve always gotten a little amusement from the people who claim that games like GTA encourage violence, particularly violence towards law enforcement. As of today, I&#8217;m about 50% done with the game, and have come to a conclusion. GTA IV actually discourages violence towards the police!</p>
<p><span id="more-11"></span></p>
<p>I know this sounds crazy, and I know that the game itself centers around violent and criminal behavior&#8230;but hear me out. To give you some background, here&#8217;s how the wanted level system works in GTA. You can get stars, each of which on a scale of 0 through 6 which roughly translates to &quot;how pissed are the police.&quot; The more overtly your criminal activity, the more stars you get. One or two stars are pretty easy to evade. At three it starts to get hard. Four or more and I wish you luck getting away alive.</p>
<p>Throughout the game there are plenty of &quot;kill the bad guys, steal their stuff, get away clean&quot; missions. Usually the police will show up shortly after the &quot;steal the stuff&quot; with two stars. Here&#8217;s the thing, the moment you do anything violent towards the police, the stars jump up the three or four. This makes escape much more annoying. The path of least resistance is pretty much always to just get in a vehicle and get away as fast as possible. Forget shooting the police, just get away and get away fast.</p>
<p>The bottom line of this is that your tend to be much more successful in the game if you just <strong>avoid</strong> the police instead of trying to brute force your way through them and killing all in your way.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2008/06/25/gta-iv-actually-discourages-attacking-police/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How Microsoft Could Have Handled Compatibility In Vista</title>
		<link>http://blog.codef00.com/2008/06/08/how-microsoft-could-have-handled-compatibility-in-vista/</link>
		<comments>http://blog.codef00.com/2008/06/08/how-microsoft-could-have-handled-compatibility-in-vista/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 23:31:35 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.codef00.com/2008/06/08/how-microsoft-could-have-handled-compatibility-in-vista/</guid>
		<description><![CDATA[So I&#8217;ve been using Windows Vista for a while on my desktop and have been generally happy. The system is stable, most features work as expected, and let&#8217;s be honest, it looks really nice. One thing that has constantly frustrated me is the shear size of each release of Windows. Every release is noticeably larger [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been using Windows Vista for a while on my desktop and have been generally happy. The system is stable, most features work as expected, and let&#8217;s be honest, it looks really nice. One thing that has constantly frustrated me is the shear <strong>size</strong> of each release of Windows. Every release is noticeably larger than the previous. I certainly understand that each release adds more features, and more features means bigger. But I think it&#8217;s about time that Microsoft started to trim the fat.</p>
<p><span id="more-10"></span></p>
<p>The primary place that comes to mind with trimming the fat is backwards compatibility. One of Windows strengths in the past has been that upgrades usually keep your programs running. But at this point, after all these versions, I think it has become a weakness. Not to fret, I have an idea :).</p>
<p>In essence, I think that compatibility should be far more modular and optional. A good way to do this would be to run older programs in something that functions like the UNIX &quot;chroot.&quot; Microsoft could create a few new folders, something like &quot;C:\WindowsXP\&quot; and &quot;C:\Windows2K&quot;, etc. Each of these would function like a virtual &quot;C:\&quot; drive for each compatibility module. Inside of each of these would be an entirely functional file structure which matches the previous versions of windows. This would be complete with older versions of various dlls so programs can&#8217;t tell the difference between the fake XP mode and the original.</p>
<p>A few things such as user document folders could be handled with something that can function like symbolic links. In addition to this, each compatibility mode would probably need to have it&#8217;s own registry tree.</p>
<p>Actual installation could be handled a few ways with various levels of compatibility.</p>
<ol>
<li>Have a &quot;Run in Windows XP mode&quot; right click menu similar to &quot;Run as Administrator.&quot;</li>
<li>Have a new flag in the PE header to indicate newest supported version of Windows. Lack of this flag would imply some common denominator.</li>
<li>Have the system detect writes to program folders and registry keys, and provide a user prompt asking which mode to run it in.</li>
<li>Have a program database of some sort.</li>
</ol>
<p>Installation is the toughest part of this system, but I think can be handled. This idea is actually inspired by two things I&#8217;ve already seen. <a title="Wine" href="http://www.winehq.org/" target="_blank" title="Wine">Wine</a> and how Apple handled the migration of OS9 to OSX by being able to virtually run OS9 in OSX.</p>
<p>Basically, in essence, what I am talking about is a Win32 port of Wine that would be supported by the system on a kernel level. This would allow the compatibility to be <strong>optional</strong> which could be a huge saver of resources and space on the system if you intend to be up to date on your programs and only run applications intended for the newer OS. Best part, if you don&#8217;t need it, you don&#8217;t have it. It can be that simple!</p>
<p>All in all, I can see few downsides to this concept. It&#8217;s already in practice on linux systems which run wine. Since Windows XP is an iterative build on top of NT and 2K, the PE flag idea would work well (compatibility mode would be either on or off). In the end you have a virtual Windows XP environment which is sandboxed and let&#8217;s face it, who is better equipped to build this system than the designers of the original?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2008/06/08/how-microsoft-could-have-handled-compatibility-in-vista/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Time to update older UI toolkits?</title>
		<link>http://blog.codef00.com/2008/04/05/time-to-update-older-ui-toolkits/</link>
		<comments>http://blog.codef00.com/2008/04/05/time-to-update-older-ui-toolkits/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 05:35:45 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.blog.codef00.com/2008/04/05/time-to-update-older-ui-toolkits/</guid>
		<description><![CDATA[My favorite editor of choice for the past 10 years has been nedit, it is a wonderfully simple yet complete GUI based text editor with a focus on development. It has all of the basics that I need; syntax highlighting, relatively smart indenting, brace matching, the ability to highlight an include and open the file [...]]]></description>
			<content:encoded><![CDATA[<p>My favorite editor of choice for the past 10 years has been <a href="http://www.nedit.org/" title="nedit" target="_blank">nedit</a>, it is a wonderfully simple yet complete GUI based text editor with a focus on development. It has all of the basics that I need; syntax highlighting, relatively smart indenting, brace matching, the ability to highlight an include and open the file it refers to. All of the basics are there, so as an editor it suites my needs and development habits. There is only one thing, it&#8217;s ugly. And this is no fault of the developers, it&#8217;s the fault of how Motif looks.</p>
<p><span id="more-9"></span> You can improve things a little bit by playing with X resources, in fact on nedit&#8217;s site, there is <a href="http://www.nedit.org/technotes/looks-1.php" title="How to take 15 years off NEdit's looks" target="_blank">an article about it</a>. This works ok, but on my <a href="http://www.kde.org" title="kde" target="_blank">KDE</a> or <a href="http://www.gnome.org" title="gnome" target="_blank">Gnome</a> desktops which use modern GUI toolkits it still stands out, it simply isn&#8217;t a pretty app. The nedit developers have actually expressed some interest in a port to other toolkits in the FAQs, but feel it is too large of a task, and to be honest, I agree. Rewriting all of that code just to update the toolkit is a bit much to ask for, especially since it functions so well.</p>
<p>What I propose is something different, which I feel is a bit more practical. Rewrite older UI toolkits on top of newer ones! This has several benefits. First and foremost, it allows applications to get a face lift simply by installing a new library, you probably wouldn&#8217;t even need to recompile your apps! Related to this, all of the &#8220;common dialogs&#8221; will be updated as well. This will provide a more cohesive user experience. More subtly, there would be a lot more code reuse. If I write my hypothetical &#8220;GTKTiff&#8221; library which implements a binary and source compatible API for Motif on top of GTK, all of the core functionality is already done. All of these toolkits implement the same core features; buttons, frames, tabs, file dialogs, etc. So this &#8220;GTKTiff&#8221; would likely be smaller and more maintainable than a full &#8220;from the ground up&#8221; implementation such as <a href="http://www.openmotif.org/" title="openmotif" target="_blank">OpenMotif</a> or <a href="http://www.lesstif.org/" title="lesstiff" target="_blank">LessTiff</a>.</p>
<p>For the more traditionalist users, well pretty much every major toolkit provides theming, and there could easily be a &#8220;Motif Classic&#8221; theme.</p>
<p>Don&#8217;t get me wrong, I think that the OpenMotif and LessTiff projects are wonderful, they let me run my favorite editor on GNU/Linux after all! But I do think that there is an opportunity to consolidate some code and provide a better user experience. The current state of the UNIX or GNU/Linux desktop is not just a mish-mash of applications, but instead is a collection of applications designed to share a look and feel in order to provide a good user experience.</p>
<p>Having many GUI APIs has its pros and cons. Operating Systems such as GNU/Linux are founded on the concept of choice, which is a wonderful thing. I just think that older APIs shouldn&#8217;t lock applications in the &#8220;stone age.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2008/04/05/time-to-update-older-ui-toolkits/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linux&#8217;s ptrace API sucks!</title>
		<link>http://blog.codef00.com/2008/01/29/linuxs-ptrace-api-sucks/</link>
		<comments>http://blog.codef00.com/2008/01/29/linuxs-ptrace-api-sucks/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 00:01:05 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.blog.codef00.com/2008/01/29/linuxs-ptrace-api-sucks/</guid>
		<description><![CDATA[I love Linux, as a developer, I find the tools available suit my style of work perfectly. Sometimes the tool that I want isn&#8217;t available. That&#8217;s OK though, because whenever I can, I try to contribute.
I do a lot of reverse engineering work and thus the lack of anything like Ollydbg spawned off my EDB [...]]]></description>
			<content:encoded><![CDATA[<p>I love Linux, as a developer, I find the tools available suit my style of work perfectly. Sometimes the tool that I want isn&#8217;t available. That&#8217;s OK though, because whenever I can, I try to contribute.</p>
<p>I do a lot of reverse engineering work and thus the lack of anything like <a title="Ollydbg" href="http://www.ollydbg.de/" target="_blank" title="Ollydbg">Ollydbg</a> spawned off my <a title="EDB" href="http://www.codef00.com/projects.php#Debugger" title="EDB">EDB</a> project. It&#8217;s a debugger designed to focus on applications at a machine code level.  This project is coming along nicely but there is one thing that I really wish I could change&#8230;ptrace sucks, and it sucks a lot.</p>
<p><span id="more-8"></span></p>
<p>First of all, it has no inherent support for threads. This is a huge problem as many modern applications are multi threaded. Instead, since Linux treats threads as independent processes which happen to share the the majority of there address spaces, you are supposed to ptrace each thread individually. So, you need to attach to all &quot;pids&quot; found in &quot;/proc/&lt;pid&gt;/task/&quot;. On top of this, you have to set an option in ptrace to attach to new threads as they are created with the clone system call. It is entirely undocumented whether you need to do this on a per process basis or a per-thread basis. Finally, you need track threads exiting so you know to stop looking for events on those. That&#8217;s an awful lot of effort just to be able to debug threads. By the way, the information necessary to know which bits of the status code tell you if it was a clone event (new thread) is also entirely undocumented.</p>
<p>Did i mention the potential race condition with attaching to all threads in the /proc/&lt;pid&gt;/task/ directory? Since the threads could be spawning more threads while you are enumerating the directories. Threads could even exit during this time. So you have to loop continually trying to attach until the you are sure the thread count is stabilized and all are attached to. The only saving grace here is that attaching stops a thread so it is possible to get them all if you think it through.</p>
<p>Next, I wish that the PTRACE_PEEK* and PTRACE_POKE* request types had support for non-word width granularity. It makes setting a breakpoint more annoying than it has to be since you really only want to read/write a single byte in that case. Not only that, but reading/writing from the edges of region boundaries is equally annoying. A much better interface would have been similar to the file API where you can specify and address and a length. In addition to this, you need to pay careful attention to the various gotchas due to the fact that the return value is both an error code and a result. So if it returns (long)-1, then you need to check errno just to make sure that it isn&#8217;t an error.</p>
<p>The usage of wait for debug events is just awkward. It works great for single threaded command line debuggers like gdb, but for a GUI, where you want things to be interactive while the debugger is waiting for the next event, it is a disaster. Sure you can use a separate thread to capture events and deliver them to the GUI,  but then you have issues properly shutting down that thread, since it will pretty much always be blocked! Also, wait has no timeout, so if you aren&#8217;t careful it is possible to get hung forever waiting for an even that will never happen. There is SIGCHLD, which sounds promising at first, but the fun part is that without sigprocmask trickery, you can&#8217;t predict which of your threads will get the signal. Grr!</p>
<p>Finally, there is lots of information that would be better suited being part of the debugging API. A great example of this is x86 segments. This really should be in the user area. You can get the segment values from the user area or even a PTRACE_GETREGS request. But the segment values are nearly worthless without being able to look at things like the segment base and limits. I understand not all platforms have this data, and x86-64 has much less usage of segments, but that&#8217;s why it should be in the user area.</p>
<p>A better API would first of all, be at a process level. I don&#8217;t care how it works under the hood, I want to attach to &quot;processes.&quot; There should also be a function to enumerate threads, this would only be valid when the process is stopped. This way you could get/set the context of each thread by passing a tid. Just these changes would make things much easier.</p>
<p>Overall, the user space API provided by ptrace could use a large overhaul. I understand the desire to be consistent with other unix&#8217;s debugging APIs, but  this should not get in the way of making something usable.</p>
<p><a title="utrace" href="http://people.redhat.com/roland/utrace/" target="_blank" title="utrace">utrace</a> sounds ok, but as far as I know, it is designed to be kernel level changes. In fact, it appears there are plans to have ptrace implemented on top of utrace in the future. That&#8217;s great and all, but the user space API needs an update! I can only hope that utrace bring along a new user space API as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2008/01/29/linuxs-ptrace-api-sucks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Windows Vista doesn&#8217;t suck</title>
		<link>http://blog.codef00.com/2008/01/03/windows-vista-doesnt-suck/</link>
		<comments>http://blog.codef00.com/2008/01/03/windows-vista-doesnt-suck/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 20:31:13 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.blog.codef00.com/2008/01/03/windows-vista-doesnt-suck/</guid>
		<description><![CDATA[First let me say that I wouldn&#8217;t classify myself as a Microsoft advocate. I have a Linux box I use for my daily work and a Windows machine for both work and play. I am however, an early adopter. So pretty much as soon as I could get my hands on it, I installed Windows [...]]]></description>
			<content:encoded><![CDATA[<p>First let me say that I wouldn&#8217;t classify myself as a Microsoft advocate. I have a Linux box I use for my daily work and a Windows machine for both work and play. I am however, an early adopter. So pretty much as soon as I could get my hands on it, I installed Windows Vista.</p>
<p><span id="more-7"></span><br />
I&#8217;ll start out with what I don&#8217;t like in order to be fair. I really am annoyed that there is no longer a &#8220;navigate up&#8221; button in windows explorer. I find myself missing it all the time. I understand that they are trying to go with the &#8220;breadcrumb&#8221; navigation scheme, but with long path names, it just takes more work.</p>
<p>Also, Vista tends to be a slug on a lot of hardware, particularly if you are short on ram. This is likely a combination of a few things, the aggressive ram usage for caching, the pretty GUI, etc. You just don&#8217;t get the same performance out of that Pentium4 with 1GB of RAM as you did with XP. However, on brand new hardware loaded with RAM I find it <strong>more responsive</strong> than XP. The bottom line here is that there seems to be a tipping point where given enough room to play, Vista starts to feel faster.</p>
<p>Backwards compatibility is a tough thing here. Too compatibility and you lose the ability to add new useful features. I have only encountered one program which I simply could not get to work in Vista, and it was an older game. Programs I actually care about work just fine. I like that fact that running as a less privileged user is the default. However, I would have liked to see the option to run old applications in a more compatible sandbox of sorts. I am thinking of something where you right click and choose &#8220;Install in compatibility mode&#8221; and it would copy a minimal directory tree structure into a special directory and run the program &#8220;chrooted&#8221; there. It would have it&#8217;s own registry, it&#8217;s own filesystem, etc. Under the hood file system hardlinks could reduce the wasted filesystem usage. Almost how wine works with a virtual drive c, so could a compatibility mode.<br />
Finally, I don&#8217;t like how some things are different just for the sake of being different. I used to be able to get at my network settings by just right clicking on an icon in the system tray and choosing &#8220;Status.&#8221; Now that information is hidden behind at least 2 extra dialogs. I understand that they are trying to provide a unified look at networking even on systems with many network cards&#8230;but when I just want to know the IP of an interface, clicking through several new (and confusing) dialogs or opening a command prompt and typing ipconfig is simply slower. I nice middle ground would have been to have right click have a submenu for each interface each of which would have a status menu. This would be simple, functional, and fast.</p>
<p>On to what I like <img src='http://blog.codef00.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>First of all, as everyone points out, it&#8217;s pretty&#8230;very pretty. The eye candy is done well and is usually functional from a usability perspective (the 3D flip is an exception I can think of) . The default look of XP just looks like a Fisher Price toy to me. Of course if you are running Windows Vista Basic edition then you are probably going to be missing out on this. But that&#8217;s OK, but it&#8217;s not what makes the OS good</p>
<p>Vista is also much more stable on average than XP. My new system had some issues, but it turned out to be faulty hardware. After Dell replaced my motherboard and CPU, haven&#8217;t had a single crash.</p>
<p>The most useful addition I found is the way that search/running is just a single button push away. You simply hit the windows key and start typing. Immediately the start menu will filter out the entries which don&#8217;t match the keywords. In addition to that, it&#8217;ll start displaying files it found. Finally if you hit enter when done it will try to execute the search string as a command if found. So the run dialog, desktop search and start menu have all be integrated in a way which work really well. I know a lot of people are going to say &#8220;well OSX had something like this for a while now.&#8221; This is true, but just because you didn&#8217;t do it first, doesn&#8217;t mean it isn&#8217;t a good idea, it just isn&#8217;t innovative. Someone was first to offer airbags in cars, I don&#8217;t see people giving the other car companies a hard time because they also offer this feature.</p>
<p>The software compatibility wizard also is very nice. Whenever Vista detects that an installer tried to do something that may or may not play nice with the limited privilege concept, it will ask &#8220;did that work correctly.&#8221; If you say no, it will try again with more backwards compatible settings and potentially store information about it in it&#8217;s issue manager for later resolution.</p>
<p>Many features exist under the hood where people don&#8217;t see any visible difference, mostly in the name of security. There is <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization" title="ASLR" target="_blank">Address Space Layout Randomization</a> (ASLR), which is very effective in reducing the severity of buffer overflows because it makes finding a viable &#8220;offset&#8221; much more difficult. It also makes <a href="http://en.wikipedia.org/wiki/Return-to-libc_attack" title="Return into libc" target="_blank">return-into-libc attacks</a> a lot less likely to succeed. The net result here is that while code execution is technically possible, it is more likely going to be a <a href="http://en.wikipedia.org/wiki/DoS" title="DoS" target="_blank">DoS</a> which is bad, but a lot less bad. The user space heap has been hardened beyond what was done in XP SP2. This once again tends to turn what was arbitrary execution into a DoS instead. These two things combined with the non-executable stack capabilities effectively make standard buffer overflow attacks much harder to pull off. In addition to these direct approaches, they have also made many improvements to the compilers used. Modern versions of Visual Studio will warn the developers about the usage of potentially unsafe functions. Not only that, but Visual C++ by default will disable the &#8220;%n&#8221; functionality of the printf family of functions. Once again this turns a vulnerability which would have the possibility of arbitrary code execution into a DoS. In the format string case, there is no longer any possibility of execution using existing techniques because there is no way to corrupt memory.</p>
<p>Finally the much debated <a href="http://en.wikipedia.org/wiki/User_Account_Control" title="UAC" target="_blank">UAC</a>. People seem to hate this, but you know what, it&#8217;s a good feature. Coming from the UNIX world where I have to type &#8220;sudo &lt;command&gt;&#8221; whenever I need to do something priviledged, this was a welcomed change. I understand that it is inconvenient, but the fact of the matter is that most users can&#8217;t be trusted to be administrator all of the time, particularly in a corporate environment.I feel that it is in the business world that UAC will shine. Simply set the UAC to require the system password instead of just a prompt and the vast majority of Trojan horse installs will disappear.</p>
<p>The real problem is that both users and developers are too used to being administrator, this has created horribly bad habits. Microsoft has tried to meet halfway here by virtualizing reads and writes to files in what are now protected locations to a local store. This is done seamlessly and improves backwards compatibility.</p>
<p>In the end, I feel that Vista is an improvement over XP, if you have a new machine. I would not recommend upgrading anything with less than 2GB of RAM to it. Certainly there is no need to upgrade from XP, but if you have the horse power it runs like a champ.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2008/01/03/windows-vista-doesnt-suck/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why do AMD and Intel insist on making virtualization complex?</title>
		<link>http://blog.codef00.com/2007/12/20/why-do-amd-and-intel-insist-on-making-virtualization-complex/</link>
		<comments>http://blog.codef00.com/2007/12/20/why-do-amd-and-intel-insist-on-making-virtualization-complex/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 16:38:24 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.blog.codef00.com/2007/12/20/why-do-amd-and-intel-insist-on-making-virtualization-complex/</guid>
		<description><![CDATA[OK, So I was reading up on the new virtualization architectures that both AMD and Intel introduced. My first reaction&#8230;why the heck did they make it so unnecessarily complex?
 Here&#8217;s the thing, in the x86 architecture, there are a handful of instructions that make virtualization hard, 17 of them to be exact. What I mean [...]]]></description>
			<content:encoded><![CDATA[<p>OK, So I was reading up on the new virtualization architectures that both AMD and Intel introduced. My first reaction&#8230;why the heck did they make it so unnecessarily complex?</p>
<p><span id="more-6"></span> Here&#8217;s the thing, in the x86 architecture, there are a handful of instructions that make virtualization hard, <a href="http://en.wikipedia.org/wiki/Popek_and_Goldberg_virtualization_requirements#IA-32_.28x86.29" title="Senstive Instructions" target="_blank">17 of them</a> to be exact. What I mean by this is that these instructions don&#8217;t throw an exception when run in user mode (ring 3), but either act differently than in system mode (ring 0) or expose sensitive information.</p>
<p><a href="http://www.vmware.com/" title="vmware" target="_blank">VMware</a> and other virtualization technologies on x86 address this by using dynamic translation techniques. This isn&#8217;t a new idea, if you are from the emulation world then this is just a combination of an emulator and a just in time compiler. People writing emulators tend to call this technique &#8220;<a href="http://en.wikipedia.org/wiki/Dynamic_recompilation" title="Dynarec" target="_blank">dynamic recompilation</a>.&#8221; This way you can put a break on any instruction you like, and you can run the code at nearly native speed.</p>
<p>However, to get the real speed gains, user mode code is run unchanged, natively. This means that if user mode executes a sensitive instruction that doesn&#8217;t throw an exception, no way to intercept it. Software can leverage this fact to find out information that you would normally want hidden from the guest OS.</p>
<p>A classic example of this is the &#8220;<a href="http://www.invisiblethings.org/papers/redpill.html" title="Redpill" target="_blank">redpill</a>&#8221; code. What it basically does is call the sidt instruction from user mode. In kernel mode, VMware would trap this, emulate the desired result and continue with the OS none-the-wiser. However, when executed in user mode, there is no trap, it just works. In fact, it should provide the caller with the <strong>real</strong> IDT of the host system. Aside from the fact that if an attacker ever figures out a way to write to memory in the host this would be useful information, the discrepancy between the two results is a clear cut sign of virtualization. This is just one of the many instructions that can be used to detect virtualization.</p>
<p>So what&#8217;s the solution? According to both Intel and AMD the solution is a new mode of operation which is more privileged than ring 0. A much more simple approach would be to add a new flag to a system register that when set, makes all sensitive operations cause an exception in user mode. This would allow the guest kernel code to run unmodified in user mode. No more dynamic translation, making the whole virtualization concept a lot simpler.</p>
<p>If this is done, there are only a few challenges left. The first would be protecting the guest OS code from the guest user code. Since they are both running at user mode, page level protection don&#8217;t work. If we are looking at x86 only and not x86-64, then segmentation is a viable solution. (I did hear that certain models of the AMD bring back segmentation limits). The rest of the concerns are fairly usual when it comes to virtualization such as properly emulating devices and such. For these the usual strategies of page fault trapping and I/O port trapping should work well as they have in the past.</p>
<p>I&#8217;m not the only one to think of this, the folks at <a href="http://www.pagetable.com" title="pagetable.com" target="_blank">pagetable.com</a> came to a <a href="http://www.pagetable.com/?p=15" target="_blank">very similar conclusion</a>. The question is, why wouldn&#8217;t Intel/AMD think of this, they are pretty smart. And even so, if I worked for VMware I&#8217;d probably push for a technology like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2007/12/20/why-do-amd-and-intel-insist-on-making-virtualization-complex/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Windows on x86 and 4GB of RAM</title>
		<link>http://blog.codef00.com/2007/12/19/windows-on-x86-and-4gb-of-ram/</link>
		<comments>http://blog.codef00.com/2007/12/19/windows-on-x86-and-4gb-of-ram/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 20:24:46 +0000</pubDate>
		<dc:creator>Evan Teran</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.blog.codef00.com/2007/12/19/windows-on-x86-and-4gb-of-ram/</guid>
		<description><![CDATA[A few months ago I decided to get a shiny new gaming system from Dell. I eventually decided to go with the XPS 720 with pretty much all the bells and whistles I thought were reasonable. One of which was going with 4GB of RAM. After all, just about everyone agrees that more RAM leads [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I decided to get a shiny new gaming system from Dell. I eventually decided to go with the <a href="http://www.dell.com/content/products/productdetails.aspx/xpsdt_720?c=us&amp;cs=19&amp;l=en&amp;s=dhs" title="Dell XPS 720" target="_blank">XPS 720</a> with pretty much all the bells and whistles I thought were reasonable. One of which was going with 4GB of RAM. After all, just about everyone agrees that more RAM leads to better performance. This machine also came with Windows Vista Home Premium, I&#8217;m the early adopter type so I saw no issue in this.</p>
<p><span id="more-4"></span></p>
<p>To my surprise Windows only saw 3GB of RAM! Since I do a little <a href="http://www.codef00.com/projects.php#evanOS" title="evanOS" target="_blank">hobby OS development</a>, I immediately had an idea of what could cause this. I jumped to the conclusion that <a href="http://en.wikipedia.org/wiki/Physical_Address_Extension" title="PAE" target="_blank">PAE</a> was not properly enabled, and started sifting through different sites to find the proper way to enable PAE. Of course if this were the solution, I wouldn&#8217;t really have much to say here&#8230; It turns out that PAE is in fact enabled by default on Windows Vista if your system supports it, after all, you need to in order to make use of the <a href="http://en.wikipedia.org/wiki/NX_bit" title="NX" target="_blank">no-execute bit</a> on x86.</p>
<p>At this point, I should probably explain what PAE is and why it should make 4GB available without a problem. Basically there are two ways to look at memory on an x86 system. There is &#8220;<strong>physical memory</strong>,&#8221; which is your system memory start to finish in order. Note, this includes memory mapped devices. This is how the memory would look if you used an OS which does not use paging. Then there is &#8220;<strong>virtual memory</strong>.&#8221; The idea here is that your physical memory is viewed as blocks (&#8221;pages&#8221;) that can be mapped to any location you wish in your virtual memory space. For example, as the OS writer, I could ask the system to map the 4K of memory at physical address 0&#215;11223000 to address 0&#215;00000000. In this case, any reads and writes that programs do in first 4K of memory will occur at the physical address associated with it. Virtual memory is also what allows modern OSes to protect one application from another. It does this by switching the virtual memory layout during task switch so that each process has a unique view of what memory looks like.</p>
<p>The problem is that memory mapped devices occupy physical address space as well, so if you have a 512MB video card, then that&#8217;s half a gig of of that 4GB physical memory space which can&#8217;t be RAM.  Here&#8217;s where PAE comes in. Before PAE, your physical memory was limited to 4GB and your virtual memory was limited to 4GB  (per process) . PAE changes this to be 64GB (36-bits) of physical address while keeping the 4GB of virtual addresses. Sure, no single process can use more than 4GB at a time, but all the RAM could be put to use.  There is one catch though, your memory mapped devices must still be below the 4GB mark because they use 32-bit addressing when doing <a href="http://en.wikipedia.org/wiki/Direct_memory_access" title="DMA" target="_blank">DMA</a>. So the natural solution is to relocate the RAM that is displaced by devices to above the 4GB mark. Most modern motherboards support this.</p>
<p>It turns out that for &#8220;<a href="http://support.microsoft.com/kb/929605" title="Microsoft" target="_blank">compatibility reasons</a>&#8221; Microsoft has opted to simply ignore any RAM it sees above 4GB.  Some people are convinced it is a <a href="http://www.codinghorror.com/blog/archives/000811.html" title="codinghorror" target="_blank">hardware problem</a>, saying:</p>
<blockquote><p>To be perfectly clear, this isn&#8217;t a Windows problem&#8211; <strong>it&#8217;s an x86 hardware problem</strong>. The memory hole is quite literally invisible to the CPU, no matter what 32-bit operating system you choose. The following diagram from Intel illustrates just where the memory hole is:</p></blockquote>
<p>This simply isn&#8217;t the case (Sorry Jeff, I love your blog BTW). It is a design choice by the windows engineers to take the easy way out. A perfectly viable solution is to divide your memory up into types, namely &#8220;suitable for DMA&#8221; and &#8220;not suitable for DMA.&#8221; I know this works, because Linux does it. In fact, here&#8217;s a screen shot of my shiny new dell using <strong>all</strong> 4GB of my RAM.</p>
<p><img src="http://www.blog.codef00.com/wp-content/uploads/2007/12/kinfocenter.png" alt="kinfocenter showing 4GB" align="absmiddle" height="484" width="602" /></p>
<p>This isn&#8217;t a 64-bit build, it&#8217;s 32-bit (arch reports &#8220;i686&#8243; not &#8220;x86-64&#8243;) with the 64GB support config option used (which basically means enable PAE). There are plenty of people saying online that all 32-bit operating systems have this problem. <strong>This isn&#8217;t true</strong>.</p>
<p>Jeff gets it right with this statement though:</p>
<blockquote><p>As far as 32-bit Vista is concerned, the world ends at 4,096 megabytes. That&#8217;s it. That&#8217;s all there is. No más.</p>
<p>Addressing more than 4 GB of memory is <em>possible</em> in a 32-bit operating system, but it takes nasty hardware hacks like 36-bit <a href="http://en.wikipedia.org/wiki/Physical_Address_Extension">PAE</a> extensions in the CPU, together with nasty software hacks like the <a href="http://en.wikipedia.org/wiki/Address_Windowing_Extensions">AWE API</a>. Unless the application is specifically coded to be take advantage of these hacks, it&#8217;s confined to 4 GB. Well, actually, <a href="http://www.brianmadden.com/content/content.asp?ID=69">it&#8217;s stuck with even less&#8211; 2 GB or 3 GB of virtual address space</a>, at least on Windows.</p></blockquote>
<p>Except that PAE isn&#8217;t a nasty hack by any stretch, in fact, Vista uses it already as previously mentioned. User space software doesn&#8217;t need to be specially programed to take advantage of the extra memory since it will only see 4GB at a time anyway (minus kernel land). Also AWE-API is used to address the <strong>4GB of virtual memory limitation</strong> not the physical limitations! What AWE does is allow an application to selectively map physical RAM locations to user space virtual locations. A program can thus can access much more than the 2GB user space that windows will give it by default, just not all at the same time.</p>
<p>Microsoft of course does support upwards of 4GB on it&#8217;s x86-64 builds, that&#8217;s all fine and dandy, but my Dell didn&#8217;t come with that. And to my knowledge Dell (as a company, not the hardware) doesn&#8217;t support x86-64 officially yet. So maybe I&#8217;ll take that up with them and demand a 64-bit copy.</p>
<p>All in all, it&#8217;s a little lame that Windows doesn&#8217;t support all the RAM that it could on 32-bit builds. It really wouldn&#8217;t be hard, but it would likely require that driver writers start passing a flag to the allocator specifying that the memory be OK for DMA. I see that this is a problem since there are simply tons of drivers. But at the least, the extra RAM could have been used for things where DMA is clearly not involved (pretty much all user space uses since only drivers should be doing DMA). Also Microsoft could have done something clever like add a new flag to the driver&#8217;s PE header which when not present would make the allocator only return addresses below 4GB and if set would allow the driver to use a more robust allocator API.</p>
<p>I hope this shed some light on the subject, because there is unfortunately a lot of mis-information out there.</p>
<p>Evan</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codef00.com/2007/12/19/windows-on-x86-and-4gb-of-ram/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
