|
Advocacy
Dojo (HowTo)
Reference
Markets
Museum
News
Other
|
|
|
Understanding Memory ProtectionMemory protection is a way for an OS [Read Dojo Remember that Memory Protection is just a set of tools to help make the OS more stable -- assuming that programmers have already failed in their job of writing quality (relatively bug-free) Apps. When an Application crashes (or crashes the System) it is 95% the fault OF THE DEVELOPER! It is not the System's fault. The System can (and should) help prevent an App from taking down other Apps or the System (and camoflauge the symptom), but it can almost never stop crashes completely, nor can it cure the problem (which is a poorly written app). We should not make excuses for bad QA, bad development processes, and lazy programmers(1). We should blame companies who don't test their software enough or who don't value quality Apps enough! There are plenty of good tools to stop these crashes (find those bugs), if Developers would take the time to use them.
ComparisonFor the drawings, green memory is "safe" (protected) and yellow memory is "open" (Danger Will Robinson! This area can be stomped).The blue areas is where no-memory is mapped, so is "protected". Both MacOS and Win95 have many "modes" and behaviors. So I must generalize quite a bit. Both have exceptions (Windows has far more than the Mac). All the memory maps are only to give general ideas of what is going on, and are not completely "pure". Both machines have memory maps are more complex than expressed.
There are a few modes in the Mac -- basically I describe new Mac programs, using the CodeFragmentManager, with Virtual Memory turned on.
![]() On the Mac all code blocks are protected as read only. So Code segments in the System AND all Applications are protected from one another (this started with the PowerPC's and something called CodeFragmentManager, which has been ported to the 68000's). Devices are usually mapped to hi-mem. In the Mac jumping to an odd address is a failure (2) -- so jumping to a bad address (at random) has a greater than 50% chance of failure. (This is why I show the yellow areas as striped -- bad addresses are half protected). Memory failures are detected if you go into the memory map where there is no RAM available (most of the memory map -- all the blue area -- which is much larger than it appears) (3).
The Mac also has stack-heap collision detection (60 times a second, the Mac checks to see if the stack has walked into the heap -- if it does then you get a Type-28 error). The Mac also protects a few areas of memory completely; the RAM disk exists completely in protected memory, and some files (mostly System stuff) are "file-mapped" and protected. Overall the System is not FULLY protected -- so an App can stomp on another app's data (but not code) -- at runtime. The Mac has great debugging tools to help catch all of these errors at debug time. The Mac even has full memory protection for developers (to help detect errors). At debug time the Mac can even do parameter validation to help programmers get all the bugs out. But these tools are performance intensive and impractical for users. The problem is that many aren't using the tools that are available (again see those at MS , Netscape and Novell-- even Adobe and some others deserve blame here).
Win95 / 98Windows is a kludgy Operating System, built on a kludgy processor, with lots of kludgy hacks. There are a few rules, and many exceptions, and literally dozens of modes. So it is hard to say what it does, or doesn't do -- because everything is sometimes true, but usually not true. An example is addressing: Different instructions have many different ways of addressing memory, some old and ugly, some new and clean. It is quite frustrating to work with -- and helps add bugs to Applications (and causes more need for memory protection). Windows is still slapped on top of DOS (and still has some 640K limits and other legacy "uglies"), it is just that MS has hidden the symptoms of the problems better. But camoflauging symptoms is not a cure! 32 Bit Apps ![]() In Windows a 32 bit app is protected from squashing all other apps (and much of the System). But Windows Applications can write over their own code (code is not always read-only). This is because some programmers in Windows world still use self-modifying code, or have data embedded inside their code (both bad programming techniques). This reduces the intra-application memory protection. COM / OLE / ActiveX, DNA (or whatever it is being called this week) forces you to share small parts of your memory with other Apps (and the System) -- opening up security and data holes. So 32 bit Apps can crash other apps if they aren't real cautious about these "gaps". They also can do the same thing with Libraries, and they can often have full access to the System (and can often corrupt the System or other applications). Libraries are also NOT unloaded when an App quits -- so there are serious security holes there as well,but let's stay on memory protection for now. There is some System protection, and there are guard pages in lo-mem (more than MacOS 7/8). However, Windows uses lo-mem global pools of shared data (across applications). The "pools" have information about all the Windows, Menus, graphics and other resources. This is another reason why Windows has such lousy security -- anyone can access other people's resources (but I'm getting off track). All applications and the system have access to those shared "pools" (e.g. no memory protection for them). If programmers make an error in these pools, they can easily squash structures that other apps need. A program can also "leak" (4) and fill up all available space in those pools and crash the System and other Applications. So an App's code and most data has protection, but its most critical resources often do not.
There is limited stack-heap collision in 16 bit Windows (done less frequently than on the Mac) -- but I'm not sure about Win32. There is less intra-Application protection for Win95 (compared to the Mac) and COM / OLE make this much worse. This is all compounded by worse developer tools (there are many tools for Windows, but most have lower quality and worse documentation, etc.). Even despite the negatives, Win95 has pretty good memory protection for 32 bit apps -- if this was all there was. But there are a lot more negatives to this story! 16 Bit Apps ![]() In Windows a large number of Apps are still 16 bit -- and so are many drivers (and parts of the System). All DOS Apps, most Games, and all legacy Apps are 16 bit. Even many new apps, use older 16 bit libraries, drivers or TSR's and so on. When running the 32 bit apps, you get the memory protection -- but when you run the 16 bit Apps (or libraries, or drivers...), the memory protection basically evaporates. (There are ways to protect, a little, 16 bit apps, but that is not the way they work by default). As soon as a 16 bit App or driver kicks in, the memory protection turns off. It is also not obvious to the average user which Apps, drivers or parts of the System are 16 bit -- so they can't tell when they are endangering their System. There is better System protection in Win95 (for 16 bit apps) than there was in Win3.1 (some low-memory protection, and larger global pools to reduce how frequently the apps run out of space) -- and things have improved since Windows 3.1 (a little). But a 16 bit App can definitely step on any other 16 bit app (5).
Overall Windows95 / 98 has blotchy protection. 32 bit apps aren't bad, 16 bit apps are. I have found most of the Windows developer tools are inferior to that of the Mac's, causing much more difficulty in creating good programs in the first place (and increasing the need for memory protection). They also slow down productivity in general (like having to debug in a postage stamp sizedWindows on the PC -- as compared to multilple monitor support, and multiple Windows on the Mac). To further complicate the issues, MS has some of the worst documentation that it has been my misfortune to work with (poorly written and often WRONG). Then you often have to pick different tools depending on whether you are writing 32 bit Apps, or 16 bit Apps (Microsoft abandoned 16 bit developers and won't update their tools). Then there are all the pitfalls of using the wrong technologies on Windows. Like when Microsoft made something called Win32S (a way to run Win32 Apps on 16 bit Windows), except it doesn't work, and never has. Developers only found that out after investing up to millions of dollars to learn the hard way. Of course there are about 10 other technologies that Microsoft promised that never worked as well. (At least Apple gets the technologies working before they stop developing them -- which is quite different). Microsoft doesn't care about these errors or complexities because it generates them more revenue answering developer support questions -- which have much higher fees than Apple has on the Mac side. Plus, if Microsoft can make it harder to develop for Windows, it increases their competitive advantages! This is compounded by an OS that has lots of "undocumented" features/behaviors which increase the likelihood of an error, and the need for memory protection. One of the most glaring examples of how bad Windows Development really is, is developer productivity. In the last couple cross-platform companies I've worked at, the Mac teams are often half the size of the Windows teams. Still the Mac progammers not only achieve feature parity, but often feature superiority. All while releasing more quality products -- and sometimes on tighter schedules. And I don't think the Windows programmers I worked with are the bad ones -- many (most) seemed highly competant. Overall, I am surprised by how stable Windows 95 is, in spite of its many glaring flaws -- which implies that I may be too hard on DOS/Windows programmers. (I still think of most of them as either ignorant, masochistic, or whores. I just know that I can't stand working in Windows because of how kludgy and "unclean" everything is). But surprisingly, if you get a Win95 machine installed correctly (which can be quite a chore), and you don't change your configuration (add any devices or change software), it can be quite stable. It can just be a real pain to get it in that stable state. ConclusionWhat people really care about is overall stability.
[Read Myths
Windows95 is not really as stable as many pretend -- and the MacOS is not as unstable as those same people pretend. You can destabilize a Mac by adding lots of Inits and extensions -- but in most cases you can't even get complex configurations with lots of TSR's and Drivers to work right at all in Windows95 -- and you need professionals to configure and Fix PC's far far more often. Which is more stable? The real problem is that people are willing to try much more, or install much more, on their Mac -- which leads to more instability. They put on UI-replacement tools, or Speed-Doubler, RAM doubler (which changes the memory model), or other tools that alter the system-- then wonder why the System is unstable. These are all things that aren't even possible in Windows. Windows users are too scared to try most of this (with simpler stuff), or they don't have the tools in the first place -- and so are less likely to have the problems that come with that power and flexibility. In both environments there are bad Apps -- which cause instability.
The point to all this is, that stability has as much (or more) to do with the quality of the Applications that you are running (and configuration), and the quality of the System as a whole -- not just memory protection. Memory Protection is still a valuable tool (especially for developers at debug time), and Systems CAN be more stable with it than without it -- but never forget it is still only a small part of a complex equation that results in System stability. Both companies could have made their OS's far more stable than they are now, WITHOUT memory protection -- and both need to. The argument that Windows95 is more stable than MacOS because it has memory protection is wrong on both counts. I find it less stable, unless you are very selective (and limited) -- but when you put the same criteria on the Mac, you get the same results (more stability). Also, the System's stability has a little to do with the memory protection -- but also has more to do with application quality and other issues. And I still find Windows Memory Protection is inferior to the Mac's in many ways (and superior in few). I do know that a good article would be to follow this one up with WinNT vs Rhapsody/Unix. The trouble is the specifics are far harder to get than on MacOS vs Win95 -- and I don't get down and dirty as much any more (because I don't have to). So it may happen, especially if someone who is a good low-level cross platform person wants to help.
|