VirtualBox, 32bit host, 64bit guest, surpassing the 3584MB limit

VirtualBox limits the maximum amount of ram a VM can use on a 32bit host to 3584MB. There is no technical reason for this specific limit, whilst its true most 32bit hosts are limited to ~3.5GB of ram, servers with PAE enabled can far surpass this limit. My desktop runs win2k3 server, and can utilize all 16GB of installed ram. Wanting to run a 64bit guest with a decent amount of ram I set about to fix this pointless limitation.

After downloading the source for VirtualBox I was able to locate the problem code, when built for 32bit the constant MM_RAM_MAX_IN_MB is set to 3584. It was believed that to fix this it would be a simple matter of increasing MM_RAM_MAX_IN_MB and recompiling.

#if HC_ARCH_BITS == 64
# define MM_RAM_MAX_IN_MB           UINT32_C(2097152)
#else
# define MM_RAM_MAX_IN_MB           UINT32_C(3584)
#endif

A simple matter in theory; there was however no way I was going to actually try to build this from source, as with most large projects, it would take forever just to setup the build environment and dependencies, it would then likely fail to build in a numerous inexplicable ways.

Since only a single constant was required to be changed it was decided to modify the binary instead. A simple find and replace, 3584 -> 16384 was applied to VBoxSVC.exe, this was facilitated by a simple patch tool written for this purpose, the tool takes confirmation for each address to prevent altering unrelated code (in my case every instance of 3584 was replaced, this might not be the case for every VBoxSVC.exe version so checking the disassemble is a must). Testing found it to work fully, a 64bit guest was run and was able to utilize 12GB of memory on the 32bit host.  http://mjsstuf.x10host.com/files/vbox-mod.rar

32bit-host-64bit-guest-b

Posted in Uncategorized | Leave a comment

xp/2k3 on modern machines: the i7 and Hyper-threading

After some time running with win2k3 on the i7-4790k, I finally noticed that threads were not being correctly scheduled for hyper-threading. This caused a major performance hit when running 4 threads since the OS was making no effort to keep them on separate cores.

After a great deal of research and experimentation, I finally utilized the CPU enumeration API (which I had not previously known to exist) and discovered that the OS detected the CPU as a “single core with 8 HT units instead of 4 cores each with 2 HT units” (such insanity).  On finding this thread it became obvious that the problem was cpuid related. It seems that Intel in their infinite wisdom decided to change the meaning of one of the fields in the cpuid data.

The only solution that could be determined was to patch the Kernel to force a topology of two logical threads per core. ntkrnlpa.exe was disassembled and all occurrences of the cpuid instruction were located, thank god for IDA-pro without it I would be fucked. A single function was located which retrieved the cpuid data, that function was replaced and the relevant field was overridden with the desired value.

extern "C"
int __stdcall CPUID(int a1, int* a2, int* a3, int* a4, int* a5)
{
    int EAX, EBX, ECX, EDX;
    asm("cpuid" : "=a"(EAX), "=b"(EBX),
        "=c"(ECX), "=d"(EDX) : "a"(a1));
    if(a1 == 1) {
        EBX = (EBX & 0xFF00FFFF) | 0x00020000; }
    *a2 = EAX; *a3 = EBX;
    *a4 = ECX; *a5 = EDX;
}

This patch was applied using my exe modifier utility, and then the original Kernel was replaced with my patched version. On reboot the machine still worked and when running the CPU enumeration again it now correctly detected the 4 cores with two threads each. When testing with 4 threads the correct scheduling was observed, each core was now given a single thread consistently. ntoskrnl_HT_FIX.rar

Posted in Uncategorized | Leave a comment

xp/2k3 on modern machines

I use win2k3 32bit on my modern machine with i7-4790k CPU and 16GB ram. Using a 10+ year-old OS has problems and I would love to upgrade but win2k3 is the last real version of windows. This thing has suffered numerous freezes/blue-screens, some caused by the crappy ATI drivers for my aging x300. It might be the 16GB of ram which causes the problems, the ATI drivers are not said to work with win2k3 let alone more than 4GB of ram. I like to avoid OpenGl since crashes are very likely when running that.

win2k3

Posted in Uncategorized | Leave a comment

I have no idea what I am doing

Posted in Uncategorized | Leave a comment