How Cedega Works

By Loyd Case  |  Posted 2004-07-28 Print this article Print

We wanted to find out more about how Cedega actually makes Windows games run on Linux and TransGamings Vikas Gupta and Gavriel State were kind enough to take us through some of Cedegas inner workings. ET: How does Cedega take Win32 code and translate into something you can run on Linux?
Cedega does not use a virtual machine architecture. It actually loads and runs Win32 programs directly on the system.
There are essentially two main things that need to happen when running a Windows executable on Linux: The binary has to be loaded into memory on the Linux system and then dynamically linked to code that provides an implementation of the Win32 APIs that the program is using. The binary loader aspect is relatively straightforward but the real magic and complexity is in the implementation of the APIs. The APIs that Windows games are mostly built on top of are primarily based on Microsofts DirectX system. These APIs include facilities for handling 3D graphics (Direct3D), mouse and keyboard input (DirectInput), audio (DirectSound), and so on. TransGaming creates compatible versions of Windows APIs that work on top of Linux equivalents, such as the OpenGL and X11 graphic APIs and the OSS and ALSA audio APIs. Cedega 4.0 is the culmination of over four years of effort on these APIs. ET: What are the key components in Cedegas architecture that make it work? Cedega needs to implement the Win32 APIs that are involved in running all the software that comes on a typical game CD. That doesnt just mean the game code itself, but also components such as the installer and any copy protection code the game uses. For the games themselves, the most important set of APIs are the various DirectX components: Direct3D, DirectSound, DirectInput, etc. But for the rest of it - the installers, updaters, etc - weve had to implement everything from network protocols to APIs as complex as DCOM. That was quite a big job, but it was absolutely required for us to be able to run games built with InstallShield installers, as InstallShield uses a client-server architecture which is based on DCOM. One of the other key components of the architecture is the implementation of the kernel level primitives. In the architecture used in previous versions, processing of Windows kernel level objects took place in a separate process that ran alongside the application processes. Communication with this process was relatively slow, making any code that made heavy use of kernel level synchronization primitives perform poorly. In Cedega 4.0, weve changed this architecture and effectively lifted the kernel level objects into a shared user space. Each process running under Cedega can essentially "become" the Win32 kernel temporarily. This provides a significant performance boost for some applications. We wrote up a Cedega white paper on Reducing WineServer Overhead via a Shared-Memory approach some time ago, when it was in an early prototype stage: ET: Do you have a kind of D3D-to-OpenGL wrapper that takes D3D calls and converts them into OpenGL calls to do 3D rendering? Internally, Cedega deals with 3D by implementing the D3D HAL architecture and providing a D3D driver underneath. This allows us to do several things. Firstly, it means that we can consolidate our driver code in a single place, rather then having separate implementations of each of the D3D API versions. It also allows us the flexibility to use the best choice of graphics back-end available on the target system. On Linux and Mac OS X, we use a back-end driver that implements the D3D HAL calls on top of OpenGL. On other platforms, we have the flexibility to go directly to hardware if we like. ET: Which sound server do you use and how do you translate Dsound/Dsound3D calls? Are you using OpenAL? Again, we use a flexible back-end architecture here, so we have support for multiple back ends. These include both ALSA and OSS APIs on Linux and CoreAudio on Mac OS X. Depending on the flexibility of the underlying hardware and API were using, we can send buffers directly to the hardware to be mixed, or we can do the mixing ourselves. Weve looked at OpenAL, but it lacks some of the functionality we would need to implement DirectSound, unfortunately. Weve had some discussions with various people about adding OpenAL extensions that would allow us to do an OpenAL back end, but ultimately that wouldnt buy us that much, as we are already using the lower level APIs on our various target platforms. ET: Did you have to reverse-engineer the Windows kernel(s) to make Cedega work? Not at all. TransGaming never attempts to disassemble Microsofts code, whether its in the kernel, DirectX, or elsewhere. We obtain the majority of our information from publicly available sources such as online documentation, header files, as well as the occasional technical paper by a game developer. We also write test cases that we use to determine what the API behavior is supposed to be like when the documentation isnt specific enough. We use all of this information to craft the APIs and then we extensively test our versions of the APIs against various games. We do use tracing tools that allow us to monitor exactly which APIs are called by a program and what parameters are passed. This is the primary tool we use when we see a divergence between expected and observed behavior. It does leave us scratching our heads in some cases though, because we can only guess at the underlying logic being used by the program. Nonetheless, our knowledge and expertise with the APIs is so extensive that weve become quite proficient at tracking down issues and getting support enabled very quickly. TransGamings knowledge of DirectX is probably second only to Microsofts own. ET: How about PS 1.4 and PS 2.0. When will they be supported? Fully supporting PS 2.0 on Linux requires features from the OpenGL 2.0 specification, which are not quite ready yet: the first drivers supporting OpenGL 2.0 features have only just started appearing on Linux in the last month. PS 1.4 will be easier to support, but we need to clear up a few issues with hardware vendors about the way their drivers do certain things. We dont have an ETA yet, but these are definitely very high on our priority list. ET: Whats the latest/greatest list of supported games (officially and unofficially) that have a 4 or 5 rating? Were extremely pleased that we have support for some of the hottest, triple-A blockbuster titles, including a number of DirectX 9.0 based games. Among the over 300 titles we support, the most popular and most important are EAs Battlefield Vietnam, Eidos Hitman: Contracts, and LucasArts Star Wars Galaxies. With our most recent release, Cedega 4.0, we also have unprecedented support for NCSofts recently released massive multiplayer online game City of Heroes and Blizzard Entertainments unreleased but highly anticipated World of WarCraft. ET: How much does Cedega cost? Is it subscription only, or can you pay a one-time fee to get one version of the bits? Cedega is available through a subscription service for $5 per month. As part of the subscription and monthly fee, our subscribers receive regular updates and releases, access to technical support, online discussion forums, and the very unique ability to vote on what games or technologies they would like us to work on next. Subscribers also receive discounts on products that we sell through our webstore. Were currently revamping our webstore and will be reopening it this fall with a number of exciting new products. We dont have a one-time fee option directly although as we sign up more resellers and distributors who are interested in bundling or OEM deals, end-users will be able to purchase our product through these organizations or may receive a version bundled into their operating system.

Loyd Case came to computing by way of physical chemistry. He began modestly on a DEC PDP-11 by learning the intricacies of the TROFF text formatter while working on his master's thesis. After a brief, painful stint as an analytical chemist, he took over a laboratory network at Lockheed in the early 80's and never looked back. His first 'real' computer was an HP 1000 RTE-6/VM system.

In 1988, he figured out that building his own PC was vastly more interesting than buying off-the-shelf systems ad he ditched his aging Compaq portable. The Sony 3.5-inch floppy drive from his first homebrew rig is still running today. Since then, he's done some programming, been a systems engineer for Hewlett-Packard, worked in technical marketing in the workstation biz, and even dabbled in 3-D modeling and Web design during the Web's early years.

Loyd was also bitten by the writing bug at a very early age, and even has dim memories of reading his creative efforts to his third grade class. Later, he wrote for various user group magazines, culminating in a near-career ending incident at his employer when a humor-impaired senior manager took exception at one of his more flippant efforts. In 1994, Loyd took on the task of writing the first roundup of PC graphics cards for Computer Gaming World -- the first ever written specifically for computer gamers. A year later, Mike Weksler, then tech editor at Computer Gaming World, twisted his arm and forced him to start writing CGW's tech column. The gaming world -- and Loyd -- has never quite recovered despite repeated efforts to find a normal job. Now he's busy with the whole fatherhood thing, working hard to turn his two daughters into avid gamers. When he doesn't have his head buried inside a PC, he dabbles in downhill skiing, military history and home theater.

Submit a Comment

Loading Comments...
Manage your Newsletters: Login   Register My Newsletters

Rocket Fuel