VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPR3HardenedNoCrt.cpp@ 54998

Last change on this file since 54998 was 52160, checked in by vboxsync, 10 years ago

SUP: some cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: SUPR3HardenedNoCrt.cpp 52160 2014-07-24 09:47:27Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Hardened main() no-crt routines.
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.virtualbox.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#if RT_OS_WINDOWS
31# include <Windows.h>
32#endif
33
34#include <VBox/sup.h>
35
36#include "SUPLibInternal.h"
37
38
39#ifdef SUP_HARDENED_NEED_CRT_FUNCTIONS /** @todo this crap is obsolete. */
40
41/** memcmp */
42DECLHIDDEN(int) suplibHardenedMemComp(void const *pvDst, const void *pvSrc, size_t cbToComp)
43{
44 size_t const *puDst = (size_t const *)pvDst;
45 size_t const *puSrc = (size_t const *)pvSrc;
46 while (cbToComp >= sizeof(size_t))
47 {
48 if (*puDst != *puSrc)
49 break;
50 puDst++;
51 puSrc++;
52 cbToComp -= sizeof(size_t);
53 }
54
55 uint8_t const *pbDst = (uint8_t const *)puDst;
56 uint8_t const *pbSrc = (uint8_t const *)puSrc;
57 while (cbToComp > 0)
58 {
59 if (*pbDst != *pbSrc)
60 {
61 if (*pbDst < *pbSrc)
62 return -1;
63 return 1;
64 }
65
66 pbDst++;
67 pbSrc++;
68 cbToComp--;
69 }
70
71 return 0;
72}
73
74
75/** memcpy */
76DECLHIDDEN(void *) suplibHardenedMemCopy(void *pvDst, const void *pvSrc, size_t cbToCopy)
77{
78 size_t *puDst = (size_t *)pvDst;
79 size_t const *puSrc = (size_t const *)pvSrc;
80 while (cbToCopy >= sizeof(size_t))
81 {
82 *puDst++ = *puSrc++;
83 cbToCopy -= sizeof(size_t);
84 }
85
86 uint8_t *pbDst = (uint8_t *)puDst;
87 uint8_t const *pbSrc = (uint8_t const *)puSrc;
88 while (cbToCopy > 0)
89 {
90 *pbDst++ = *pbSrc++;
91 cbToCopy--;
92 }
93
94 return pvDst;
95}
96
97
98/** memset */
99DECLHIDDEN(void *) suplibHardenedMemSet(void *pvDst, int ch, size_t cbToSet)
100{
101 uint8_t *pbDst = (uint8_t *)pvDst;
102 while (cbToSet > 0)
103 {
104 *pbDst++ = (uint8_t)ch;
105 cbToSet--;
106 }
107
108 return pvDst;
109}
110
111
112/** strcpy */
113DECLHIDDEN(char *) suplibHardenedStrCopy(char *pszDst, const char *pszSrc)
114{
115 char *pszRet = pszDst;
116 char ch;
117 do
118 {
119 ch = *pszSrc++;
120 *pszDst++ = ch;
121 } while (ch);
122 return pszRet;
123}
124
125
126/** strlen */
127DECLHIDDEN(size_t) suplibHardenedStrLen(const char *psz)
128{
129 const char *pszStart = psz;
130 while (*psz)
131 psz++;
132 return psz - pszStart;
133}
134
135
136/** strcat */
137DECLHIDDEN(char *) suplibHardenedStrCat(char *pszDst, const char *pszSrc)
138{
139 char *pszRet = pszDst;
140 while (*pszDst)
141 pszDst++;
142 suplibHardenedStrCopy(pszDst, pszSrc);
143 return pszRet;
144}
145
146
147/** strcmp */
148DECLHIDDEN(int) suplibHardenedStrCmp(const char *psz1, const char *psz2)
149{
150 for (;;)
151 {
152 char ch1 = *psz1++;
153 char ch2 = *psz2++;
154 if (ch1 != ch2)
155 return ch1 < ch2 ? -1 : 1;
156 if (ch1 == 0)
157 return 0;
158 }
159}
160
161
162/** strncmp */
163DECLHIDDEN(int) suplibHardenedStrNCmp(const char *psz1, const char *psz2, size_t cchMax)
164{
165 while (cchMax-- > 0)
166 {
167 char ch1 = *psz1++;
168 char ch2 = *psz2++;
169 if (ch1 != ch2)
170 return ch1 < ch2 ? -1 : 1;
171 if (ch1 == 0)
172 break;
173 }
174 return 0;
175}
176
177#endif /* SUP_HARDENED_NEED_CRT_FUNCTIONS */
178
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