VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 5 days ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Runtime/testcase/tstRTMemEf.cpp70973
    /branches/VBox-4.2/src/VBox/Runtime/testcase/tstRTMemEf.cpp91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Runtime/testcase/tstRTMemEf.cpp91223
    /branches/VBox-4.3/trunk/src/VBox/Runtime/testcase/tstRTMemEf.cpp91223
    /branches/dsen/gui/src/VBox/Runtime/testcase/tstRTMemEf.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Runtime/testcase/tstRTMemEf.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Runtime/testcase/tstRTMemEf.cpp79645-79692
File size: 3.5 KB
Line 
1/* $Id: tstRTMemEf.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IPRT - Testcase for the RTMemEf* functions.
4 */
5
6/*
7 * Copyright (C) 2010-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/mem.h>
42
43#define RT_ASM_INCLUDE_PAGE_SIZE
44#include <iprt/asm-mem.h>
45#include <iprt/initterm.h>
46#include <iprt/stream.h>
47#include <iprt/string.h>
48
49
50/*********************************************************************************************************************************
51* Global Variables *
52*********************************************************************************************************************************/
53static unsigned g_cErrors = 0;
54
55
56static int tstMemAllocEfAccess()
57{
58 /* Trivial alloc fence test - allocate a single word and access both
59 * the word after the allocated block and the word before. One of them
60 * will crash no matter whether the fence is at the bottom or on top. */
61 int32_t *p = (int32_t *)RTMemEfAllocNP(sizeof(int32_t), RTMEM_TAG);
62 RTPrintf("tstRTMemAllocEfAccess: allocated int32_t at %#p\n", p);
63 RTPrintf("tstRTMemAllocEfAccess: triggering buffer overrun...\n");
64 ASMProbeReadByte(p + 1);
65 RTPrintf("tstRTMemAllocEfAccess: triggering buffer underrun...\n");
66 ASMProbeReadByte((char *)p - 1);
67
68 /* Reaching this is a severe error. */
69 return 0;
70}
71
72int main()
73{
74 RTR3InitExeNoArguments(0);
75 RTPrintf("tstRTMemEf: TESTING...\n");
76
77#define CHECK_EXPR(expr) \
78 do { bool const f = !!(expr); if (!f) { RTPrintf("tstRTMemEf(%d): %s!\n", __LINE__, #expr); g_cErrors++; } } while (0)
79
80 /*
81 * Some simple stuff.
82 */
83 {
84 CHECK_EXPR(tstMemAllocEfAccess());
85 }
86
87 /*
88 * Summary.
89 */
90 if (!g_cErrors)
91 RTPrintf("tstMemAutoPtr: SUCCESS\n");
92 else
93 RTPrintf("tstMemAutoPtr: FAILED - %d errors\n", g_cErrors);
94 return !!g_cErrors;
95}
Note: See TracBrowser for help on using the repository browser.

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