VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedNoCrt-win.cpp@ 52523

最後變更 在這個檔案從52523是 51770,由 vboxsync 提交於 11 年 前

Merged in iprt++ dev branch.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.4 KB
 
1/* $Id: SUPR3HardenedNoCrt-win.cpp 51770 2014-07-01 18:14:02Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Hardened main(), windows bits.
4 */
5
6/*
7 * Copyright (C) 2006-2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/nt/nt-and-windows.h>
31#include <AccCtrl.h>
32#include <AclApi.h>
33#ifndef PROCESS_SET_LIMITED_INFORMATION
34# define PROCESS_SET_LIMITED_INFORMATION 0x2000
35#endif
36
37#include <VBox/sup.h>
38#include <VBox/err.h>
39#include <iprt/assert.h>
40#include <iprt/ctype.h>
41#include <iprt/string.h>
42#include <iprt/initterm.h>
43#include <iprt/param.h>
44#include <iprt/mem.h>
45
46#include "SUPLibInternal.h"
47#include "win/SUPHardenedVerify-win.h"
48
49
50/*
51 * assert.cpp
52 */
53
54RTDATADECL(char) g_szRTAssertMsg1[1024];
55RTDATADECL(char) g_szRTAssertMsg2[4096];
56RTDATADECL(const char * volatile) g_pszRTAssertExpr;
57RTDATADECL(const char * volatile) g_pszRTAssertFile;
58RTDATADECL(uint32_t volatile) g_u32RTAssertLine;
59RTDATADECL(const char * volatile) g_pszRTAssertFunction;
60
61RTDECL(bool) RTAssertMayPanic(void)
62{
63 return true;
64}
65
66
67RTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
68{
69 /*
70 * Fill in the globals.
71 */
72 g_pszRTAssertExpr = pszExpr;
73 g_pszRTAssertFile = pszFile;
74 g_pszRTAssertFunction = pszFunction;
75 g_u32RTAssertLine = uLine;
76 RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
77 "\n!!Assertion Failed!!\n"
78 "Expression: %s\n"
79 "Location : %s(%d) %s\n",
80 pszExpr, pszFile, uLine, pszFunction);
81}
82
83
84RTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
85{
86 RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, va);
87 if (g_enmSupR3HardenedMainState < SUPR3HARDENEDMAINSTATE_CALLED_TRUSTED_MAIN)
88 supR3HardenedFatalMsg(g_pszRTAssertExpr, kSupInitOp_Misc, VERR_INTERNAL_ERROR,
89 "%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
90 else
91 supR3HardenedError(VERR_INTERNAL_ERROR, false/*fFatal*/, "%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
92}
93
94
95/*
96 * Memory allocator.
97 */
98
99RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
100{
101 return RTMemAllocTag(cb, pszTag);
102}
103
104
105RTDECL(void *) RTMemTmpAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
106{
107 return RTMemAllocZTag(cb, pszTag);
108}
109
110
111RTDECL(void) RTMemTmpFree(void *pv) RT_NO_THROW
112{
113 RTMemFree(pv);
114}
115
116
117RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
118{
119 return suplibHardenedAllocZ(cb);
120}
121
122
123RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
124{
125 return suplibHardenedAllocZ(cb);
126}
127
128
129RTDECL(void *) RTMemAllocVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
130{
131 size_t cbAligned;
132 if (cbUnaligned >= 16)
133 cbAligned = RT_ALIGN_Z(cbUnaligned, 16);
134 else
135 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
136 return RTMemAllocTag(cbAligned, pszTag);
137}
138
139
140RTDECL(void *) RTMemAllocZVarTag(size_t cbUnaligned, const char *pszTag) RT_NO_THROW
141{
142 size_t cbAligned;
143 if (cbUnaligned >= 16)
144 cbAligned = RT_ALIGN_Z(cbUnaligned, 16);
145 else
146 cbAligned = RT_ALIGN_Z(cbUnaligned, sizeof(void *));
147 return RTMemAllocZTag(cbAligned, pszTag);
148}
149
150
151RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW
152{
153 return suplibHardenedReAlloc(pvOld, cbNew);
154}
155
156
157RTDECL(void) RTMemFree(void *pv) RT_NO_THROW
158{
159 suplibHardenedFree(pv);
160}
161
162
163/*
164 * Simplified version of RTMemWipeThoroughly that avoids dragging in the
165 * random number code.
166 */
167
168RTDECL(void) RTMemWipeThoroughly(void *pv, size_t cb, size_t cMinPasses) RT_NO_THROW
169{
170 size_t cPasses = RT_MIN(cMinPasses, 6);
171 static const uint32_t s_aPatterns[] = { 0x00, 0xaa, 0x55, 0xff, 0xf0, 0x0f, 0xcc, 0x3c, 0xc3 };
172 uint32_t iPattern = 0;
173 do
174 {
175 memset(pv, s_aPatterns[iPattern], cb);
176 iPattern = (iPattern + 1) % RT_ELEMENTS(s_aPatterns);
177 ASMMemoryFence();
178
179 memset(pv, s_aPatterns[iPattern], cb);
180 iPattern = (iPattern + 1) % RT_ELEMENTS(s_aPatterns);
181 ASMMemoryFence();
182
183 memset(pv, s_aPatterns[iPattern], cb);
184 iPattern = (iPattern + 1) % RT_ELEMENTS(s_aPatterns);
185 ASMMemoryFence();
186 } while (cPasses-- > 0);
187
188 memset(pv, 0xff, cb);
189 ASMMemoryFence();
190}
191
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette