Index: trunk/src/VBox/Runtime/common/ldr/ldrELF.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrELF.cpp	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrELF.cpp	(revision 16933)
@@ -114,7 +114,9 @@
  * @returns iprt status code.
  * @param   pReader     The loader reader instance which will provide the raw image bits.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     Architecture specifier.
  * @param   phLdrMod    Where to store the handle.
  */
-int rtldrELFOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
+int rtldrELFOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
 {
     const char *pszLogName = pReader->pfnLogName(pReader); NOREF(pszLogName);
@@ -145,7 +147,7 @@
     }
     if (e_ident[EI_CLASS] == ELFCLASS32)
-        rc = rtldrELF32Open(pReader, phLdrMod);
+        rc = rtldrELF32Open(pReader, fFlags, enmArch, phLdrMod);
     else
-        rc = rtldrELF64Open(pReader, phLdrMod);
+        rc = rtldrELF64Open(pReader, fFlags, enmArch, phLdrMod);
     return rc;
 }
Index: trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h	(revision 16933)
@@ -721,5 +721,5 @@
  * @param   cbRawImage  The size of the raw image.
  */
-static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage)
+static int RTLDRELF_NAME(ValidateElfHeader)(const Elf_Ehdr *pEhdr, const char *pszLogName, uint64_t cbRawImage, PRTLDRARCH penmArch)
 {
     Log3(("RTLdrELF:     e_ident: %.*Rhxs\n"
@@ -806,8 +806,11 @@
         case EM_386:
         case EM_486:
+            *penmArch = RTLDRARCH_X86_32;
+            break;
 #elif ELF_MODE == 64
         case EM_X86_64:
+            *penmArch = RTLDRARCH_AMD64;
+            break;
 #endif
-            break;
         default:
             Log(("RTLdrELF: %s: machine type %u is not supported!\n", pEhdr->e_machine));
@@ -986,7 +989,9 @@
  * @returns iprt status code.
  * @param   pReader     The loader reader instance which will provide the raw image bits.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     Architecture specifier.
  * @param   phLdrMod    Where to store the handle.
  */
-static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
+static int RTLDRELF_NAME(Open)(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
 {
     const char *pszLogName = pReader->pfnLogName(pReader);
@@ -1015,9 +1020,18 @@
 
     /*
-     * Read and validate the ELF header.
+     * Read and validate the ELF header and match up the CPU architecture.
      */
     int rc = pReader->pfnRead(pReader, &pModElf->Ehdr, sizeof(pModElf->Ehdr), 0);
     if (RT_SUCCESS(rc))
-        rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage);
+    {
+        RTLDRARCH enmArchImage;
+        rc = RTLDRELF_NAME(ValidateElfHeader)(&pModElf->Ehdr, pszLogName, cbRawImage, &enmArchImage);
+        if (RT_SUCCESS(rc))
+        {
+            if (    enmArch != RTLDRARCH_WHATEVER
+                &&  enmArch != enmArchImage)
+                rc = VERR_LDR_ARCH_MISMATCH;
+        }
+    }
     if (RT_SUCCESS(rc))
     {
Index: trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp	(revision 16933)
@@ -49,7 +49,9 @@
  * @returns iprt status code.
  * @param   pReader     The loader reader instance which will provide the raw image bits.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     Architecture specifier.
  * @param   phMod       Where to store the handle.
  */
-int rtldrOpenWithReader(PRTLDRREADER pReader, PRTLDRMOD phMod)
+int rtldrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod)
 {
     /*
@@ -105,5 +107,5 @@
     if (uSign.u32 == IMAGE_NT_SIGNATURE)
 #ifdef LDR_WITH_PE
-        rc = rtldrPEOpen(pReader, offHdr, phMod);
+        rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod);
 #else
         rc = VERR_PE_EXE_NOT_SUPPORTED;
@@ -111,5 +113,5 @@
     else if (uSign.u32 == IMAGE_ELF_SIGNATURE)
 #if defined(LDR_WITH_ELF)
-        rc = rtldrELFOpen(pReader, phMod);
+        rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod);
 #else
         rc = VERR_ELF_EXE_NOT_SUPPORTED;
@@ -117,5 +119,5 @@
     else if (uSign.au16[0] == IMAGE_LX_SIGNATURE)
 #ifdef LDR_WITH_LX
-        rc = rtldrLXOpen(pReader, offHdr, phMod);
+        rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod);
 #else
         rc = VERR_LX_EXE_NOT_SUPPORTED;
@@ -123,5 +125,5 @@
     else if (uSign.au16[0] == IMAGE_LE_SIGNATURE)
 #ifdef LDR_WITH_LE
-        rc = rtldrLEOpen(pReader, phMod);
+        rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod);
 #else
         rc = VERR_LE_EXE_NOT_SUPPORTED;
@@ -129,5 +131,5 @@
     else if (uSign.au16[0] == IMAGE_NE_SIGNATURE)
 #ifdef LDR_WITH_NE
-        rc = rtldrNEOpen(pReader, phMod);
+        rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod);
 #else
         rc = VERR_NE_EXE_NOT_SUPPORTED;
@@ -135,5 +137,5 @@
     else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE)
 #ifdef LDR_WITH_MZ
-        rc = rtldrMZOpen(pReader, phMod);
+        rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod);
 #else
         rc = VERR_MZ_EXE_NOT_SUPPORTED;
@@ -143,5 +145,5 @@
              0)
 #ifdef LDR_WITH_AOUT
-        rc = rtldrAOUTOpen(pReader, phMod);
+        rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod);
 #else
         rc = VERR_AOUT_EXE_NOT_SUPPORTED;
@@ -158,5 +160,5 @@
     /* Try kLdr if it's a format we don't recognize. */
     if (rc <= VERR_INVALID_EXE_SIGNATURE && rc > VERR_BAD_EXE_FORMAT)
-        rc = rtldrkLdrOpen(pReader, phMod);
+        rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod);
 #endif
 
Index: trunk/src/VBox/Runtime/common/ldr/ldrFile.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrFile.cpp	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrFile.cpp	(revision 16933)
@@ -241,14 +241,30 @@
 
 /**
- * Open a binary image file.
+ * Open a binary image file, extended version.
  *
  * @returns iprt status code.
  * @param   pszFilename Image filename.
- * @param   phLdrMod    Where to store the handle to the loaded module.
- */
-RTDECL(int) RTLdrOpen(const char *pszFilename, PRTLDRMOD phLdrMod)
-{
-    LogFlow(("RTLdrOpen: pszFilename=%p:{%s} phLdrMod=%p\n",
-             pszFilename, pszFilename, phLdrMod));
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     CPU architecture specifier for the image to be loaded.
+ * @param   phLdrMod    Where to store the handle to the loader module.
+ */
+RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
+{
+    LogFlow(("RTLdrOpen: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n",
+             pszFilename, pszFilename, fFlags, enmArch, phLdrMod));
+    AssertMsgReturn(!fFlags, ("%#x\n", fFlags), VERR_INVALID_PARAMETER);
+    AssertMsgReturn(enmArch > RTLDRARCH_INVALID && enmArch < RTLDRARCH_END, ("%d\n", enmArch), VERR_INVALID_PARAMETER);
+
+    /*
+     * Resolve RTLDRARCH_HOST.
+     */
+    if (enmArch == RTLDRARCH_HOST)
+#if   defined(RT_ARCH_AMD64)
+        enmArch = RTLDRARCH_AMD64;
+#elif defined(RT_ARCH_X86)
+        enmArch = RTLDRARCH_X86_32;
+#else
+        enmArch = RTLDRARCH_WHATEVER;
+#endif
 
     /*
@@ -259,5 +275,5 @@
     if (RT_SUCCESS(rc))
     {
-        rc = rtldrOpenWithReader(pReader, phLdrMod);
+        rc = rtldrOpenWithReader(pReader, fFlags, enmArch, phLdrMod);
         if (RT_SUCCESS(rc))
         {
@@ -277,13 +293,27 @@
  *
  * @returns iprt status code.
- * @param   pszFilename     Image filename.
- * @param   phLdrMod        Where to store the handle to the loaded module.
+ * @param   pszFilename Image filename.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     CPU architecture specifier for the image to be loaded.
+ * @param   phLdrMod    Where to store the handle to the loaded module.
  * @remark  Primarily for testing the loader.
  */
-RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, PRTLDRMOD phLdrMod)
+RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
 {
 #ifdef LDR_WITH_KLDR
-    LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} phLdrMod=%p\n",
-             pszFilename, pszFilename, phLdrMod));
+    LogFlow(("RTLdrOpenkLdr: pszFilename=%p:{%s} fFlags=%#x enmArch=%d phLdrMod=%p\n",
+             pszFilename, pszFilename, fFlags, enmArch, phLdrMod));
+
+    /*
+     * Resolve RTLDRARCH_HOST.
+     */
+    if (enmArch == RTLDRARCH_HOST)
+# if   defined(RT_ARCH_AMD64)
+        enmArch = RTLDRARCH_AMD64;
+# elif defined(RT_ARCH_X86)
+        enmArch = RTLDRARCH_X86_32;
+# else
+        enmArch = RTLDRARCH_WHATEVER;
+# endif
 
     /*
@@ -294,5 +324,5 @@
     if (RT_SUCCESS(rc))
     {
-        rc = rtldrkLdrOpen(pReader, phLdrMod);
+        rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phLdrMod);
         if (RT_SUCCESS(rc))
         {
@@ -307,5 +337,5 @@
 
 #else
-    return RTLdrOpen(pszFilename, phLdrMod);
+    return RTLdrOpen(pszFilename, fFlags, enmArch, phLdrMod);
 #endif
 }
Index: trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp	(revision 16933)
@@ -944,6 +944,7 @@
  * @param   pFileHdr    Pointer to the file header that needs validating.
  * @param   pszLogName  The log name to  prefix the errors with.
- */
-int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName)
+ * @param   penmArch    Where to store the CPU architecture.
+ */
+int rtldrPEValidateFileHeader(PIMAGE_FILE_HEADER pFileHdr, const char *pszLogName, PRTLDRARCH penmArch)
 {
     size_t cbOptionalHeader;
@@ -952,7 +953,9 @@
         case IMAGE_FILE_MACHINE_I386:
             cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER32);
+            *penmArch = RTLDRARCH_X86_32;
             break;
         case IMAGE_FILE_MACHINE_AMD64:
             cbOptionalHeader = sizeof(IMAGE_OPTIONAL_HEADER64);
+            *penmArch = RTLDRARCH_AMD64;
             break;
 
@@ -960,4 +963,5 @@
             Log(("rtldrPEOpen: %s: Unsupported Machine=%#x\n",
                  pszLogName, pFileHdr->Machine));
+            *penmArch = RTLDRARCH_INVALID;
             return VERR_BAD_EXE_FORMAT;
     }
@@ -1417,8 +1421,10 @@
  * @returns iprt status code.
  * @param   pReader     The loader reader instance which will provide the raw image bits.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     Architecture specifier.
  * @param   offNtHdrs   The offset of the NT headers (where you find "PE\0\0").
  * @param   phLdrMod    Where to store the handle.
  */
-int rtldrPEOpen(PRTLDRREADER pReader, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod)
+int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod)
 {
     /*
@@ -1429,8 +1435,16 @@
     if (RT_FAILURE(rc))
         return rc;
+    RTLDRARCH enmArchImage;
     const char *pszLogName = pReader->pfnLogName(pReader);
-    rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName);
+    rc = rtldrPEValidateFileHeader(&FileHdr, pszLogName, &enmArchImage);
     if (RT_FAILURE(rc))
         return rc;
+
+    /*
+     * Match the CPU architecture.
+     */
+    if (    enmArch != RTLDRARCH_WHATEVER
+        &&  enmArch != enmArchImage)
+        return VERR_LDR_ARCH_MISMATCH;
 
     /*
Index: trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp	(revision 16823)
+++ trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp	(revision 16933)
@@ -636,8 +636,27 @@
  * @returns iprt status code.
  * @param   pReader     The loader reader instance which will provide the raw image bits.
+ * @param   fFlags      Reserved, MBZ.
+ * @param   enmArch     CPU architecture specifier for the image to be loaded.
  * @param   phLdrMod    Where to store the handle.
  */
-int rtldrkLdrOpen(PRTLDRREADER pReader, PRTLDRMOD phLdrMod)
-{
+int rtldrkLdrOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod)
+{
+    /* Convert enmArch to k-speak. */
+    KCPUARCH enmCpuArch;
+    switch (enmArch)
+    {
+        case RTLDRARCH_WHATEVER:
+            enmCpuArch = KCPUARCH_UNKNOWN;
+            break;
+        case RTLDRARCH_X86_32:
+            enmCpuArch = KCPUARCH_X86_32;
+            break;
+        case RTLDRARCH_AMD64:
+            enmCpuArch = KCPUARCH_AMD64;
+            break;
+        default:
+            return VERR_INVALID_PARAMETER;
+    }
+
     /* Create a rtkldrRdr instance. */
     PRTKLDRRDR pRdr = (PRTKLDRRDR)RTMemAllocZ(sizeof(*pRdr));
