VirtualBox

source: vbox/trunk/src/VBox/RDP/client/vrdp/runtime.h@ 31354

Last change on this file since 31354 was 31354, checked in by vboxsync, 15 years ago

RDP/client: disable debug flag which was accidentally left on

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/** @file
2 *
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef __RUNTIME__H
18#define __RUNTIME__H
19
20#include <endian.h>
21#include <byteswap.h>
22#include <stdint.h>
23#include <ctype.h>
24#include <errno.h>
25
26#ifndef cpu_to_le16
27#if __BYTE_ORDER == __LITTLE_ENDIAN
28#define cpu_to_le16(_le16) (_le16)
29#elif __BYTE_ORDER == __BIG_ENDIAN
30#define cpu_to_le16(_le16) bswap_16(_le16)
31#else
32#error Unsupported host byte order!
33#endif
34#endif /* cpu_to_le16 */
35
36//#include <asm/byteorder.h>
37//#define cpu_to_le16 __cpu_to_le16
38
39#if 0
40#define uint8_t uint8
41#define uint16_t uint16
42#define uint32_t uint32
43#define uint64_t long long
44#endif
45#define bool int
46#define false 0
47#define true 1
48
49#define OPSTATIC
50// #define RDPUSB_DEBUG
51#ifdef RDPUSB_DEBUG
52#define DoLog(a) do { \
53 printf("Time %llu: ", RTTimeMilliTS()); \
54 printf a; \
55} while(0)
56
57#define LogFlow(a) DoLog(a)
58#define Log(a) DoLog(a)
59#define Log2(a) DoLog(a)
60#else
61#define LogFlow(a) do {} while (0)
62#define Log(a) do {} while (0)
63#define Log2(a) do {} while (0)
64#endif
65
66#define LogRel(a) printf a
67
68/* Runtime wrappers. */
69#define RTMemAlloc xmalloc
70#define RTMemRealloc xrealloc
71#define RTMemFree xfree
72
73#define _1K 1024
74
75#ifdef RT_BIG_ENDIAN
76# define RT_H2LE_U16(u16) RT_BSWAP_U16(u16)
77# define RT_LE2H_U16(u16) RT_BSWAP_U16(u16)
78#else
79# define RT_H2LE_U16(u16) (u16)
80# define RT_LE2H_U16(u16) (u16)
81#endif
82#define RT_BSWAP_U16(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
83#define RT_MAKE_U16(Lo, Hi) \
84 ((uint16_t)( (uint16_t)((uint8_t)(Hi)) << 8 \
85 | (uint8_t)(Lo) ))
86#define RT_LOBYTE(a) ( (a) & 0xff )
87#define RT_HIBYTE(a) ( (a) >> 8 )
88
89#define VINF_SUCCESS 0
90#define VERR_NO_MEMORY (-8)
91#define VERR_UNRESOLVED_ERROR (-35)
92#define VERR_NOT_SUPPORTED (-37)
93#define VERR_ACCESS_DENIED (-38)
94#define VERR_VUSB_USBFS_PERMISSION (-2005)
95
96static inline int RTErrConvertFromErrno(int iErrno)
97{
98 return iErrno == 0 ? VINF_SUCCESS
99 : iErrno == ENOMEM ? VERR_NO_MEMORY
100 : iErrno == ENODEV ? VERR_NOT_SUPPORTED
101 : iErrno == ENOSYS ? VERR_NOT_SUPPORTED
102 : iErrno == EPERM ? VERR_ACCESS_DENIED
103 : iErrno == EACCES ? VERR_ACCESS_DENIED
104 : VERR_UNRESOLVED_ERROR;
105}
106
107#define RT_SUCCESS(_rc) ((_rc) >= 0)
108
109#define RTFILE int
110#define RTCRITSECT void *
111
112#define Assert(_expr) do { \
113 if (!(_expr)) \
114 { \
115 Log(("Assertion failed: {%s}!!!\n", #_expr)); \
116 } \
117} while (0)
118
119#define AssertMsgFailed(_msg) do { \
120 Log(("Assertion failed msg:!!!\n")); \
121 Log(_msg); \
122} while (0)
123
124#define AssertReturn(_expr, _retval) do { \
125 if (!(_expr)) \
126 { \
127 Log(("Assertion failed: {%s}, returning 0x%08X!!!\n", #_expr, _retval)); \
128 return (_retval); \
129 } \
130} while (0)
131
132#define AssertRC(_rc) Assert(RT_SUCCESS(_rc))
133
134#define RT_FAILURE(_rc) (!RT_SUCCESS(_rc))
135
136#define NOREF(_a) ((void)_a)
137
138#define RT_C_DECLS_BEGIN
139#define RT_C_DECLS_END
140
141#define RTCALL
142#define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
143#define DECLINLINE(type) static __inline__ type
144#define DECLCALLBACK(type) type RTCALL
145#define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
146#define RTDECL(type) RTCALL type
147
148#define RT_BIT(bit) ( 1U << (bit) )
149#define RT_MAX(Value1, Value2) ( (Value1) >= (Value2) ? (Value1) : (Value2) )
150#define RT_MIN(Value1, Value2) ( (Value1) <= (Value2) ? (Value1) : (Value2) )
151typedef uint32_t RTGCPHYS32;
152typedef uint32_t RTMSINTERVAL;
153
154static inline uint64_t RTTimeMilliTS (void)
155{
156 struct timeval tv;
157 gettimeofday (&tv, NULL);
158 return (uint64_t)tv.tv_sec * (uint64_t)(1000)
159 + (uint64_t)(tv.tv_usec / 1000);
160}
161
162static inline int RTCritSectInit (RTCRITSECT *pCritSect)
163{
164 return VINF_SUCCESS;
165}
166
167static inline int RTCritSectDelete (RTCRITSECT *pCritSect)
168{
169 return VINF_SUCCESS;
170}
171
172static inline int RTCritSectEnter (RTCRITSECT *pCritSect)
173{
174 return VINF_SUCCESS;
175}
176
177static inline int RTCritSectLeave (RTCRITSECT *pCritSect)
178{
179 return VINF_SUCCESS;
180}
181
182static inline void *RTMemDupEx (const void *pvSrc, size_t cbSrc, size_t cbExtra)
183{
184 void *p = RTMemAlloc (cbSrc + cbExtra);
185
186 if (p)
187 {
188 memcpy (p, pvSrc, cbSrc);
189 memset ((char *)p + cbSrc, 0, cbExtra);
190 }
191
192 return p;
193}
194
195static inline void *RTMemAllocZ (size_t cb)
196{
197 void *p = RTMemAlloc (cb);
198
199 if (p)
200 {
201 memset (p, 0, cb);
202 }
203
204 return p;
205}
206
207static inline void *RTMemAllocZVar (size_t cbUnaligned)
208{
209 return RTMemAllocZ(cbUnaligned);
210}
211
212static inline int RTStrToUInt32Ex (const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
213{
214 *pu32 = strtoul (pszValue, ppszNext, uBase);
215 return VINF_SUCCESS;
216}
217
218#define PRTSTREAM FILE *
219
220static inline int RTStrmOpen (const char *pszFileName, const char *pszMode, PRTSTREAM *ppStream)
221{
222 *ppStream = fopen (pszFileName, pszMode);
223
224 if (*ppStream)
225 {
226 return VINF_SUCCESS;
227 }
228
229 return VERR_NOT_SUPPORTED;
230}
231
232static inline int RTStrmClose (PRTSTREAM pStream)
233{
234 fclose (pStream);
235 return VINF_SUCCESS;
236}
237
238static inline int RTStrmGetLine (PRTSTREAM pStream, char *pszString, size_t cchString)
239{
240 if (fgets (pszString, cchString, pStream))
241 {
242 return VINF_SUCCESS;
243 }
244
245 return VERR_NOT_SUPPORTED;
246}
247
248static inline char *RTStrStripL (const char *psz)
249{
250 while (isspace (*psz))
251 psz++;
252 return (char *)psz;
253}
254
255#define NIL_RTFILE -1
256
257#define RTFILE_O_READWRITE 0x00000003
258#define RTFILE_O_OPEN 0x00000000
259#define RTFILE_O_DENY_NONE 0x00000000
260
261static inline int RTFileOpen (RTFILE *pFile, const char *pszFileName, unsigned fOpen)
262{
263 Assert (fOpen == RTFILE_O_READWRITE);
264
265 *pFile = open (pszFileName, O_RDWR, 00600);
266
267 if (*pFile != -1)
268 {
269 return VINF_SUCCESS;
270 }
271
272 return VERR_ACCESS_DENIED;
273}
274
275static inline int RTFileClose (RTFILE file)
276{
277 close (file);
278 return VINF_SUCCESS;
279}
280#endif /* __RUNTIME__H */
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