Index: trunk/src/VBox/Runtime/r3/win/nocrt-atexit-win.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-atexit-win.asm	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-atexit-win.asm	(revision 95831)
@@ -0,0 +1,34 @@
+; $Id$
+;; @file
+; IPRT - Alias atexit to rtnocrt_atexit in nocrt-startup-exe-win.cpp.
+;
+
+;
+; Copyright (C) 2022 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+
+%include "iprt/asmdefs.mac"
+
+extern  rtnocrt_atexit
+BEGINPROC atexit
+        jmp     rtnocrt_atexit
+ENDPROC   atexit
+
Index: trunk/src/VBox/Runtime/r3/win/nocrt-atexit.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-atexit.asm	(revision 95820)
+++ 	(revision )
@@ -1,34 +1,0 @@
-; $Id$
-;; @file
-; IPRT - Alias atexit to rtnocrt_atexit in nocrt-startup-exe-win.cpp.
-;
-
-;
-; Copyright (C) 2022 Oracle Corporation
-;
-; This file is part of VirtualBox Open Source Edition (OSE), as
-; available from http://www.virtualbox.org. This file is free software;
-; you can redistribute it and/or modify it under the terms of the GNU
-; General Public License (GPL) as published by the Free Software
-; Foundation, in version 2 as it comes in the "COPYING" file of the
-; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
-; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
-;
-; The contents of this file may alternatively be used under the terms
-; of the Common Development and Distribution License Version 1.0
-; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
-; VirtualBox OSE distribution, in which case the provisions of the
-; CDDL are applicable instead of those of the GPL.
-;
-; You may elect to license modified versions of this file under the
-; terms and conditions of either the GPL or the CDDL or both.
-;
-
-
-%include "iprt/asmdefs.mac"
-
-extern  rtnocrt_atexit
-BEGINPROC atexit
-        jmp     rtnocrt_atexit
-ENDPROC   atexit
-
Index: trunk/src/VBox/Runtime/r3/win/nocrt-guard-win.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-guard-win.asm	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-guard-win.asm	(revision 95831)
@@ -0,0 +1,98 @@
+; $Id$
+;; @file
+; IPRT - Control Flow Guard related Visual C++ support routines.
+;
+
+;
+; Copyright (C) 2022 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+
+
+;*********************************************************************************************************************************
+;*      Header Files                                                                                                             *
+;*********************************************************************************************************************************
+%include "iprt/asmdefs.mac"
+%include "iprt/x86.mac"
+
+
+
+;*********************************************************************************************************************************
+;*  Global Variables                                                                                                             *
+;*********************************************************************************************************************************
+
+;
+; Points to a NOP icall checker by default.
+; The loader will replace this when we start advertising it in the load config.
+;
+section .0000cfg rdata align=8
+
+GLOBALNAME __guard_check_icall_fptr
+        RTCCPTR_DEF     __guard_check_icall_nop
+
+%ifdef RT_ARCH_AMD64
+GLOBALNAME __guard_dispatch_icall_fptr
+        RTCCPTR_DEF     __guard_dispatch_icall_nop
+
+; xfg stuff (haven't seen it generated or used yet).
+GLOBALNAME __guard_xfg_check_icall_fptr
+        RTCCPTR_DEF     __guard_check_icall_nop
+
+GLOBALNAME __guard_xfg_dispatch_icall_fptr
+        RTCCPTR_DEF     __guard_xfg_dispatch_icall_nop
+
+GLOBALNAME __guard_xfg_table_dispatch_icall_fptr
+        RTCCPTR_DEF     __guard_xfg_dispatch_icall_nop
+
+%endif
+
+
+BEGINCODE
+;;
+; Check that doesn't do anything.
+;
+; This is for older windows versions which doesn't support call flow guard stuff.
+;
+BEGINPROC __guard_check_icall_nop
+        ret
+ENDPROC   __guard_check_icall_nop
+
+%ifdef RT_ARCH_AMD64
+;;
+; Target function in RAX
+;
+; This is for older windows versions which doesn't support call flow guard stuff.
+;
+BEGINPROC __guard_dispatch_icall_nop
+        jmp     rax
+ENDPROC   __guard_dispatch_icall_nop
+%endif
+
+%ifdef RT_ARCH_AMD64
+;;
+; Target function in RAX
+;
+; This is for windows versions which doesn't support extended call flow guard stuff.
+;
+BEGINPROC __guard_xfg_dispatch_icall_nop
+        jmp     [__guard_dispatch_icall_nop wrt RIP]
+ENDPROC   __guard_xfg_dispatch_icall_nop
+%endif
+
Index: trunk/src/VBox/Runtime/r3/win/nocrt-loadcfg-win.c
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-loadcfg-win.c	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-loadcfg-win.c	(revision 95831)
@@ -0,0 +1,145 @@
+/* $Id$ */
+/** @file
+ * IPRT - No-CRT - PE/Windows Load Configuration.
+ *
+ * @note This is a C file and not C++ because the compiler generates fixups
+ *       that upsets the linker (ADDR32 + ADDR32_4 instead of ADDR64).
+ */
+
+/*
+ * Copyright (C) 2022 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "internal/iprt.h"
+#include <iprt/formats/pecoff.h>
+
+
+/*********************************************************************************************************************************
+*   Global Variables                                                                                                             *
+*********************************************************************************************************************************/
+extern uintptr_t    __security_cookie;          /**< nocrt-stack-win.asm */
+#ifdef RT_ARCH_X86
+extern uintptr_t    __safe_se_handler_table[];  /**< Linker generated. */
+extern uint8_t      __safe_se_handler_count;    /**< Absolute "address" defined by the linker representing the table size. */
+#endif
+extern uintptr_t    __guard_check_icall_fptr;   /**< nocrt-guard-win.asm */
+#ifdef RT_ARCH_AMD64
+extern uintptr_t    __guard_dispatch_icall_fptr;/**< nocrt-guard-win.asm */
+#endif
+extern uintptr_t    __guard_fids_table[];       /**< Linker generated. */
+extern uint8_t      __guard_fids_count;         /** Another absolute "address" generated by the linker for a table size. */
+extern uint8_t      __guard_flags;              /** Another absolute "address" generated by the linker, flags value this time. */
+extern uintptr_t    __guard_iat_table[];        /**< Linker generated. */
+extern uint8_t      __guard_iat_count;          /** Another absolute "address" generated by the linker for a table size. */
+extern uintptr_t    __guard_longjmp_table[];    /**< Linker generated. */
+extern uint8_t      __guard_longjmp_count;      /** Another absolute "address" generated by the linker for a table size. */
+extern uint8_t      __enclave_config;           /** Another absolute "address" generated by the linker, flags value this time. */
+extern uintptr_t    __guard_eh_cont_table[];    /**< Linker generated. */
+extern uint8_t      __guard_eh_cont_count;      /** Another absolute "address" generated by the linker for a table size. */
+#ifdef RT_ARCH_AMD64
+extern uintptr_t    __guard_xfg_check_icall_fptr;           /**< nocrt-guard-win.asm */
+extern uintptr_t    __guard_xfg_dispatch_icall_fptr;        /**< nocrt-guard-win.asm */
+extern uintptr_t    __guard_xfg_table_dispatch_icall_fptr;  /**< nocrt-guard-win.asm */
+#endif
+
+extern RT_CONCAT(IMAGE_LOAD_CONFIG_DIRECTORY, ARCH_BITS) const  _load_config_used;
+
+
+/**
+ * The load configuration for the PE image.
+ *
+ * The name of this is dictated by the linker, as it looks for a
+ * _load_config_used symbol and puts it's address and (somehow) size in the load
+ * config data dir entry.
+ *
+ * @todo use _MSC_VER to reduce this for older linkers which doesn't support all
+ *       the machinactions we include here for the 2019 (14.29.30139.0) linker.
+ */
+const IMAGE_LOAD_CONFIG_DIRECTORY64 _load_config_used =
+{
+    /* .Size                                = */    sizeof(_load_config_used),
+    /* .TimeDateStamp                       = */    0,
+    /* .MajorVersion                        = */    0,
+    /* .MinorVersion                        = */    0,
+    /* .GlobalFlagsClear                    = */    0,
+    /* .GlobalFlagsSet                      = */    0,
+    /* .CriticalSectionDefaultTimeout       = */    0,
+    /* .DeCommitFreeBlockThreshold          = */    0,
+    /* .DeCommitTotalFreeThreshold          = */    0,
+    /* .LockPrefixTable                     = */    0,
+    /* .MaximumAllocationSize               = */    0,
+    /* .VirtualMemoryThreshold              = */    0,
+    /* .ProcessHeapFlags                    = */    0,
+    /* .ProcessAffinityMask                 = */    0,
+    /* .CSDVersion                          = */    0,
+    /* .DependentLoadFlags                  = */    0,
+    /* .EditList                            = */    0,
+    /* .SecurityCookie                      = */    (uintptr_t)&__security_cookie,
+#ifdef RT_ARCH_X86
+    /* .SEHandlerTable                      = */    (uintptr_t)&__safe_se_handler_table[0],
+    /* .SEHandlerCount                      = */    (uintptr_t)&__safe_se_handler_count,    /* Absolute "address", remember. */
+#else
+    /* .SEHandlerTable                      = */    0,
+    /* .SEHandlerCount                      = */    0,
+#endif
+    /* .GuardCFCCheckFunctionPointer        = */    (uintptr_t)&__guard_check_icall_fptr,
+#ifdef RT_ARCH_AMD64
+    /* .GuardCFDispatchFunctionPointer      = */    (uintptr_t)&__guard_dispatch_icall_fptr,
+#else
+    /* .GuardCFDispatchFunctionPointer      = */    0,
+#endif
+    /* .GuardCFFunctionTable                = */    (uintptr_t)&__guard_fids_table[0],
+    /* .GuardCFFunctionCount                = */    (uintptr_t)&__guard_fids_count,         /* Absolute "address", remember. */
+    /* .GuardFlags                          = */    (uint32_t)(uintptr_t)&__guard_flags,    /* Ditto. */
+    /* .CodeIntegrity                       = */    { 0, 0, 0, 0 },
+    /* .GuardAddressTakenIatEntryTable      = */    (uintptr_t)__guard_iat_table,
+    /* .GuardAddressTakenIatEntryCount      = */    (uintptr_t)&__guard_iat_count,          /* The same. */
+    /* .GuardLongJumpTargetTable            = */    (uintptr_t)&__guard_longjmp_table[0],
+    /* .GuardLongJumpTargetCount            = */    (uintptr_t)&__guard_longjmp_count,      /* Another one. */
+    /* .DynamicValueRelocTable              = */    0,
+    /* .CHPEMetadataPointer                 = */    0, /** @todo ARM */
+    /* .GuardRFFailureRoutine               = */    0,
+    /* .GuardRFFailureRoutineFunctionPointer= */    0,
+    /* .DynamicValueRelocTableOffset        = */    0,
+    /* .DynamicValueRelocTableSection       = */    0,
+    /* .Reserved2                           = */    0,
+    /* .GuardRFVerifyStackPointerFunctionPointer=*/ 0,
+    /* .HotPatchTableOffset                 = */    0,
+    /* .Reserved3                           = */    0,
+    /* .EnclaveConfigurationPointer         = */    (uintptr_t)&__enclave_config,           /* And another one. */
+    /* .VolatileMetadataPointer             = */    0,
+    /* .GuardEHContinuationTable            = */    (uintptr_t)&__guard_eh_cont_table[0],
+    /* .GuardEHContinuationCount            = */    (uintptr_t)&__guard_eh_cont_count,      /* Yet another one. */
+#ifdef RT_ARCH_AMD64
+    /* .GuardXFGCheckFunctionPointer        = */    (uintptr_t)&__guard_xfg_check_icall_fptr,
+    /* .GuardXFGDispatchFunctionPointer     = */    (uintptr_t)&__guard_xfg_dispatch_icall_fptr,
+    /* .GuardXFGTableDispatchFunctionPointer= */    (uintptr_t)&__guard_xfg_table_dispatch_icall_fptr,
+#else
+    /* .GuardXFGCheckFunctionPointer        = */    0,
+    /* .GuardXFGDispatchFunctionPointer     = */    0,
+    /* .GuardXFGTableDispatchFunctionPointer= */    0,
+#endif
+    /* .CastGuardOsDeterminedFailureMode    = */    0,
+};
+
Index: trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup-win.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup-win.asm	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup-win.asm	(revision 95831)
@@ -0,0 +1,34 @@
+; $Id$
+;; @file
+; IPRT - Alias mainCRTStartup to CustomMainEntrypoint in nocrt-startup-exe-win.cpp.
+;
+
+;
+; Copyright (C) 2022 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+
+%include "iprt/asmdefs.mac"
+
+extern  CustomMainEntrypoint
+BEGINPROC mainCRTStartup
+        jmp     CustomMainEntrypoint
+ENDPROC   mainCRTStartup
+
Index: trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup.asm	(revision 95820)
+++ 	(revision )
@@ -1,34 +1,0 @@
-; $Id$
-;; @file
-; IPRT - Alias mainCRTStartup to CustomMainEntrypoint in nocrt-startup-exe-win.cpp.
-;
-
-;
-; Copyright (C) 2022 Oracle Corporation
-;
-; This file is part of VirtualBox Open Source Edition (OSE), as
-; available from http://www.virtualbox.org. This file is free software;
-; you can redistribute it and/or modify it under the terms of the GNU
-; General Public License (GPL) as published by the Free Software
-; Foundation, in version 2 as it comes in the "COPYING" file of the
-; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
-; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
-;
-; The contents of this file may alternatively be used under the terms
-; of the Common Development and Distribution License Version 1.0
-; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
-; VirtualBox OSE distribution, in which case the provisions of the
-; CDDL are applicable instead of those of the GPL.
-;
-; You may elect to license modified versions of this file under the
-; terms and conditions of either the GPL or the CDDL or both.
-;
-
-
-%include "iprt/asmdefs.mac"
-
-extern  CustomMainEntrypoint
-BEGINPROC mainCRTStartup
-        jmp     CustomMainEntrypoint
-ENDPROC   mainCRTStartup
-
Index: trunk/src/VBox/Runtime/r3/win/nocrt-stack-win.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-stack-win.asm	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-stack-win.asm	(revision 95831)
@@ -0,0 +1,355 @@
+; $Id$
+;; @file
+; IPRT - Stack related Visual C++ support routines.
+;
+
+;
+; Copyright (C) 2022 Oracle Corporation
+;
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+;
+; The contents of this file may alternatively be used under the terms
+; of the Common Development and Distribution License Version 1.0
+; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+; VirtualBox OSE distribution, in which case the provisions of the
+; CDDL are applicable instead of those of the GPL.
+;
+; You may elect to license modified versions of this file under the
+; terms and conditions of either the GPL or the CDDL or both.
+;
+
+
+
+;*********************************************************************************************************************************
+;*      Header Files                                                                                                             *
+;*********************************************************************************************************************************
+%include "iprt/asmdefs.mac"
+%include "iprt/x86.mac"
+
+
+;*********************************************************************************************************************************
+;*      Structures and Typedefs                                                                                                  *
+;*********************************************************************************************************************************
+
+;; Variable descriptor.
+struc RTC_VAR_DESC_T
+        .offFrame               resd 1
+        .cbVar                  resd 1
+        alignb                  RTCCPTR_CB
+        .pszName                RTCCPTR_RES 1
+endstruc
+
+;; Frame descriptor.
+struc RTC_FRAME_DESC_T
+        .cVars                  resd 1
+        alignb                  RTCCPTR_CB
+        .paVars                 RTCCPTR_RES 1   ; Array of RTC_VAR_DESC_T.
+endstruc
+
+;; An alloca allocation.
+struc RTC_ALLOCA_ENTRY_T
+        .uGuard1                resd 1
+        .pNext                  RTCCPTR_RES 1   ; Misaligned.
+%if ARCH_BITS == 32
+        .pNextPad               resd 1
+%endif
+        .cb                     RTCCPTR_RES 1   ; Misaligned.
+%if ARCH_BITS == 32
+        .cbPad                  resd 1
+%endif
+        .auGuard2               resd 3
+endstruc
+
+%ifdef RT_ARCH_X86
+ %define FASTCALL_NAME(a_Name, a_cbArgs)        @ %+ a_Name %+ @ %+ a_cbArgs
+%else
+ %define FASTCALL_NAME(a_Name, a_cbArgs)        NAME(a_Name)
+%endif
+
+
+;*********************************************************************************************************************************
+;*      Defined Constants And Macros                                                                                             *
+;*********************************************************************************************************************************
+%define VARIABLE_MARKER_PRE     0xcccccccc
+%define VARIABLE_MARKER_POST    0xcccccccc
+
+%define ALLOCA_FILLER_BYTE      0xcc
+%define ALLOCA_FILLER_32        0xcccccccc
+
+
+;*********************************************************************************************************************************
+;*  Global Variables                                                                                                             *
+;*********************************************************************************************************************************
+BEGINDATA
+GLOBALNAME __security_cookie
+        dd  0xdeadbeef
+        dd  0x0c00ffe0
+
+
+;*********************************************************************************************************************************
+;*  External Symbols                                                                                                             *
+;*********************************************************************************************************************************
+BEGINCODE
+extern NAME(_RTC_StackVarCorrupted)
+extern NAME(_RTC_SecurityCookieMismatch)
+
+
+BEGINPROC __GSHandlerCheck
+        int3
+ENDPROC   __GSHandlerCheck
+
+;;
+; Probe stack to trigger guard faults.
+;
+; @param    eax     Frame size.
+; @uses     Nothing (because we don't quite now the convention).
+;
+ALIGNCODE(32)
+BEGINPROC __chkstk
+        push    xBP
+        mov     xBP, xSP
+        pushf
+        push    xAX
+        push    xBX
+
+        xor     ebx, ebx
+.again:
+        sub     xBX, PAGE_SIZE
+        mov     [xBP + xBX], bl
+        sub     eax, PAGE_SIZE
+        jnl     .again
+
+        pop     xBX
+        pop     xAX
+        popf
+        leave
+        ret
+ENDPROC   __chkstk
+
+
+BEGINPROC _RTC_InitBase
+        int3
+ENDPROC   _RTC_InitBase
+
+
+BEGINPROC _RTC_Shutdown
+        int3
+ENDPROC   _RTC_Shutdown
+
+
+
+
+;;
+; Checks stack variable markers.
+;
+; This seems to be a regular C function in the CRT, but x86 is conveniently
+; using the fastcall convention which makes it very similar to amd64.
+;
+; We try make this as sleek as possible, leaving all the trouble for when we
+; find a corrupted stack variable and need to call a C function to complain.
+;
+; @param        pStackFrame     The caller RSP/ESP.  [RCX/ECX]
+; @param        pFrameDesc      Frame descriptor.    [RDX/EDX]
+;
+ALIGNCODE(64)
+BEGINPROC FASTCALL_NAME(_RTC_CheckStackVars, 8)
+        push    xBP
+
+        ;
+        ; Load the variable count into eax and check that it's not zero.
+        ;
+        mov     eax, [xDX + RTC_FRAME_DESC_T.cVars]
+        test    eax, eax
+        jz      .return
+
+        ;
+        ; Make edx/rdx point to the current variable and xBP be the frame pointer.
+        ; The latter frees up xCX for scratch use and incidentally make stack access
+        ; go via SS instead of DS (mostly irrlevant in 64-bit and 32-bit mode).
+        ;
+        mov     xDX, [xDX + RTC_FRAME_DESC_T.paVars]
+        mov     xBP, xCX
+
+        ;
+        ; Loop thru the variables and check that their markers/fences haven't be
+        ; trampled over.
+        ;
+.next_var:
+        ; Marker before the variable.
+%if ARCH_BITS == 64
+        movsxd  rcx, dword [xDX + RTC_VAR_DESC_T.offFrame]
+%else
+        mov     xCX, dword [xDX + RTC_VAR_DESC_T.offFrame]
+%endif
+        cmp     dword [xBP + xCX - 4], VARIABLE_MARKER_PRE
+        jne     .corrupted
+
+        ; Marker after the variable.
+        add     ecx, dword [xDX + RTC_VAR_DESC_T.cbVar]
+%if ARCH_BITS == 64
+        movsxd  rcx, ecx
+%endif
+        cmp     dword [xBP + xCX], VARIABLE_MARKER_POST
+        jne     .corrupted
+
+        ;
+        ; Advance to the next variable.
+        ;
+.advance:
+        add     xDX, RTC_VAR_DESC_T_size
+        dec     eax
+        jnz     .next_var
+
+        ;
+        ; Return.
+        ;
+.return:
+        pop     xBP
+        ret
+
+        ;
+        ; Complain about corrupt variable.
+        ;
+.corrupted:
+        push    xAX
+        push    xDX
+%ifdef RT_ARCH_AMD64
+        sub     xSP, 28h
+        mov     xCX, xBP                ; frame pointer + variable descriptor.
+%else
+        push    xBP                     ; save EBP
+        push    xDX                     ; parameter 2 - variable descriptor
+        push    xBP                     ; parameter 1 - frame pointer.
+        lea     xBP, [xSP + 3*xCB]      ; turn it into a frame pointer during the call for better unwind.
+%endif
+
+        call    NAME(_RTC_StackVarCorrupted)
+
+%ifdef RT_ARCH_AMD64
+        add     xSP, 28h
+%else
+        add     xSP, xCB * 4            ; parameters
+        pop     xBP
+%endif
+        pop     xDX
+        pop     xAX
+        jmp     .advance
+ENDPROC   FASTCALL_NAME(_RTC_CheckStackVars, 8)
+
+
+;;
+; Initialize an alloca allocation list entry and add it to it.
+;
+; When this is call, presumably _RTC_CheckStackVars2 is used to verify the frame.
+;
+; @param        pNewEntry       Pointer to the new entry.               [RCX/ECX]
+; @param        cbEntry         The entry size, including header.       [RDX/EDX]
+; @param        ppHead          Pointer to the list head pointer.       [R8/stack]
+;
+ALIGNCODE(64)
+BEGINPROC FASTCALL_NAME(_RTC_AllocaHelper, 12)
+        ;
+        ; Check that input isn't NULL or the size isn't zero.
+        ;
+        test    xCX, xCX
+        jz      .return
+        test    xDX, xDX
+        jz      .return
+%if ARCH_BITS == 64
+        test    r8, r8
+%else
+        cmp     dword [xSP + xCB], 0
+%endif
+        jz      .return
+
+        ;
+        ; Memset the memory to ALLOCA_FILLER
+        ;
+%if ARCH_BITS == 64
+        mov     r10, rdi                ; save rdi
+        mov     r11, rcx                ; save pNewEntry
+%else
+        push    xDI
+        push    xCX
+        cld                             ; paranoia
+%endif
+
+        mov     al, ALLOCA_FILLER_BYTE
+        mov     xDI, xCX                ; entry pointer
+        mov     xCX, xDX                ; entry size (in bytes)
+        rep stosb
+
+%if ARCH_BITS == 64
+        mov     rdi, r10
+%else
+        pop     xCX
+        pop     xDI
+%endif
+
+        ;
+        ; Fill in the entry and link it as onto the head of the chain.
+        ;
+%if ARCH_BITS == 64
+        mov     [r11 + RTC_ALLOCA_ENTRY_T.cb], xDX
+        mov     xAX, [r8]
+        mov     [r11 + RTC_ALLOCA_ENTRY_T.pNext], xAX
+        mov     [r8], r11
+%else
+        mov     [xCX + RTC_ALLOCA_ENTRY_T.cb], xDX
+        mov     xAX, [xSP + xCB]        ; ppHead
+        mov     xDX, [xAX]
+        mov     [xCX + RTC_ALLOCA_ENTRY_T.pNext], xDX
+        mov     [xAX], xCX
+%endif
+
+.return:
+%if ARCH_BITS == 64
+        ret
+%else
+        ret     4
+%endif
+ENDPROC   FASTCALL_NAME(_RTC_AllocaHelper, 12)
+
+
+;;
+; Checks if the secuity cookie ok, complaining and terminating if it isn't.
+;
+ALIGNCODE(16)
+BEGINPROC FASTCALL_NAME(__security_check_cookie, 4)
+        cmp     xCX, [__security_cookie xWrtRIP]
+        jne     .corrupted
+        ;; amd64 version checks if the top 16 bits are zero, we skip that for now.
+        ret
+
+.corrupted:
+%ifdef RT_ARCH_AMD64
+        jmp     NAME(_RTC_SecurityCookieMismatch)
+%else
+        push    ebp
+        mov     ebp, esp
+        push    ecx
+        call    NAME(_RTC_SecurityCookieMismatch)
+        pop     ecx
+        leave
+        ret
+%endif
+ENDPROC   FASTCALL_NAME(__security_check_cookie, 4)
+
+
+
+; Not stack related stubs.
+BEGINPROC __C_specific_handler
+        int3
+ENDPROC   __C_specific_handler
+
+
+BEGINPROC __report_rangecheckfailure
+        int3
+ENDPROC   __report_rangecheckfailure
+
Index: trunk/src/VBox/Runtime/r3/win/nocrt-stack.asm
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-stack.asm	(revision 95820)
+++ 	(revision )
@@ -1,97 +1,0 @@
-; $Id$
-;; @file
-; IPRT - Stack related Visual C++ support routines.
-;
-
-;
-; Copyright (C) 2022 Oracle Corporation
-;
-; This file is part of VirtualBox Open Source Edition (OSE), as
-; available from http://www.virtualbox.org. This file is free software;
-; you can redistribute it and/or modify it under the terms of the GNU
-; General Public License (GPL) as published by the Free Software
-; Foundation, in version 2 as it comes in the "COPYING" file of the
-; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
-; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
-;
-; The contents of this file may alternatively be used under the terms
-; of the Common Development and Distribution License Version 1.0
-; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
-; VirtualBox OSE distribution, in which case the provisions of the
-; CDDL are applicable instead of those of the GPL.
-;
-; You may elect to license modified versions of this file under the
-; terms and conditions of either the GPL or the CDDL or both.
-;
-
-
-%include "iprt/asmdefs.mac"
-
-
-;*********************************************************************************************************************************
-;*  Global Variables                                                                                                             *
-;*********************************************************************************************************************************
-BEGINDATA
-GLOBALNAME __security_cookie
-        dd  0xdeadbeef
-        dd  0x0c00ffe
-
-
-BEGINCODE
-
-BEGINPROC __GSHandlerCheck
-        int3
-ENDPROC   __GSHandlerCheck
-
-
-BEGINPROC __chkstk
-        int3
-ENDPROC   __chkstk
-
-
-BEGINPROC _RTC_AllocaHelper
-        int3
-ENDPROC   _RTC_AllocaHelper
-
-
-BEGINPROC _RTC_InitBase
-        int3
-ENDPROC   _RTC_InitBase
-
-
-BEGINPROC _RTC_CheckStackVars
-        int3
-ENDPROC   _RTC_CheckStackVars
-
-
-BEGINPROC _RTC_CheckStackVars2
-        int3
-ENDPROC   _RTC_CheckStackVars2
-
-
-BEGINPROC _RTC_Shutdown
-        int3
-ENDPROC   _RTC_Shutdown
-
-
-BEGINPROC __security_check_cookie
-        int3
-ENDPROC   __security_check_cookie
-
-
-
-; Not stack related stubs.
-BEGINPROC __C_specific_handler
-        int3
-ENDPROC   __C_specific_handler
-
-
-BEGINPROC __report_rangecheckfailure
-        int3
-ENDPROC   __report_rangecheckfailure
-
-
-BEGINPROC __guard_dispatch_icall_fptr
-        int3
-ENDPROC   __guard_dispatch_icall_fptr
-
Index: trunk/src/VBox/Runtime/r3/win/nocrt-stacksup-win.cpp
===================================================================
--- trunk/src/VBox/Runtime/r3/win/nocrt-stacksup-win.cpp	(revision 95831)
+++ trunk/src/VBox/Runtime/r3/win/nocrt-stacksup-win.cpp	(revision 95831)
@@ -0,0 +1,134 @@
+/* $Id$ */
+/** @file
+ * IPRT - No-CRT - Basic allocators, Windows.
+ */
+
+/*
+ * Copyright (C) 2006-2022 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "internal/iprt.h"
+#include <iprt/assert.h>
+
+
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
+/** Variable descriptor. */
+typedef struct RTC_VAR_DESC_T
+{
+    int32_t     offFrame;
+    uint32_t    cbVar;
+    const char *pszName;
+} RTC_VAR_DESC_T;
+
+/** Frame descriptor. */
+typedef struct RTC_FRAME_DESC_T
+{
+    uint32_t                cVars;
+    RTC_VAR_DESC_T const   *paVars;
+} RTC_FRAME_DESC_T;
+
+#define VARIABLE_MARKER_PRE     0xcccccccc
+#define VARIABLE_MARKER_POST    0xcccccccc
+
+
+/**
+ * Alloca allocation entry.
+ * @note For whatever reason the pNext and cb members are misaligned on 64-bit
+ *       targets.  32-bit targets OTOH adds padding to keep the structure size
+ *       and pNext + cb offsets the same.
+ */
+#pragma pack(4)
+typedef struct RTC_ALLOC_ENTRY
+{
+    uint32_t            uGuard1;
+    RTC_ALLOC_ENTRY    *pNext;
+#if ARCH_BITS == 32
+    uint32_t            pNextPad;
+#endif
+    size_t              cb;
+#if ARCH_BITS == 32
+    uint32_t            cbPad;
+#endif
+    uint32_t            auGuard2[3];
+} RTC_ALLOC_ENTRY;
+#pragma pack()
+
+#define ALLOCA_FILLER_BYTE      0xcc
+#define ALLOCA_FILLER_32        0xcccccccc
+
+
+/*********************************************************************************************************************************
+*   External Symbols                                                                                                             *
+*********************************************************************************************************************************/
+extern "C" void __fastcall _RTC_CheckStackVars(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar); /* nocrt-stack.asm */
+extern "C" uintptr_t __security_cookie;
+
+
+DECLASM(void) _RTC_StackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar)
+{
+    RTAssertMsg2("\n\n!!Stack corruption!!\n\n"
+                 "%p LB %#x - %s\n",
+                 pbFrame + pVar->offFrame, pVar->cbVar, pVar->pszName);
+    RT_BREAKPOINT();
+}
+
+
+DECLASM(void) _RTC_SecurityCookieMismatch(uintptr_t uCookie)
+{
+    RTAssertMsg2("\n\n!!Stack cookie corruption!!\n\n"
+                 "expected %p, found %p\n",
+                 __security_cookie, uCookie);
+    RT_BREAKPOINT();
+}
+
+
+/** @todo reimplement in assembly (feeling too lazy right now). */
+extern "C" void __fastcall _RTC_CheckStackVars2(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar, RTC_ALLOC_ENTRY *pHead)
+{
+    while (pHead)
+    {
+        if (   pHead->uGuard1     == ALLOCA_FILLER_32
+#if 1 && ARCH_BITS == 32
+            && pHead->pNextPad    == ALLOCA_FILLER_32
+            && pHead->cbPad       == ALLOCA_FILLER_32
+#endif
+            && pHead->auGuard2[0] == ALLOCA_FILLER_32
+            && pHead->auGuard2[1] == ALLOCA_FILLER_32
+            && pHead->auGuard2[2] == ALLOCA_FILLER_32
+            && *(uint32_t const *)((uint8_t const *)pHead + pHead->cb - sizeof(uint32_t)) == ALLOCA_FILLER_32)
+        { /* likely */ }
+        else
+        {
+            RTAssertMsg2("\n\n!!Stack corruption (alloca)!!\n\n"
+                         "%p LB %#x\n",
+                         pHead, pHead->cb);
+            RT_BREAKPOINT();
+        }
+        pHead = pHead->pNext;
+    }
+
+    _RTC_CheckStackVars(pbFrame, pVar);
+}
