1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 | //
// This file is part of the aMule Project.
//
// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
#ifndef ARCHSPECIFIC_H
#define ARCHSPECIFIC_H
#include "Types.h"
#include "config.h"
#define ENDIAN_SWAP_16(x) (wxUINT16_SWAP_ON_BE(x))
#define ENDIAN_SWAP_I_16(x) x = wxUINT16_SWAP_ON_BE(x)
#define ENDIAN_SWAP_32(x) (wxUINT32_SWAP_ON_BE(x))
#define ENDIAN_SWAP_I_32(x) x = wxUINT32_SWAP_ON_BE(x)
#if ((defined __GNUC__) && __GNUC__ >= 2) || defined (_MSC_VER) || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550))
#define ENDIAN_SWAP_64(x) (wxUINT64_SWAP_ON_BE(x))
#define ENDIAN_SWAP_I_64(x) x = wxUINT64_SWAP_ON_BE(x)
#endif
// ntohs
#define ENDIAN_NTOHS(x) ( wxUINT16_SWAP_ON_LE(x) )
// ntohl
#define ENDIAN_NTOHL(x) ( wxUINT32_SWAP_ON_LE(x) )
// new
#define ENDIAN_NTOHLL(x) ( wxUINT64_SWAP_ON_LE(x) )
// htons
#define ENDIAN_HTONS(x) ( wxUINT16_SWAP_ON_LE(x) )
// htonl
#define ENDIAN_HTONL(x) ( wxUINT32_SWAP_ON_LE(x) )
// new
#define ENDIAN_HTONLL(x) ( wxUINT64_SWAP_ON_LE(x) )
/**
* Returns the value in the given bytestream.
*
* The value is returned exactly as it is found.
*/
// \{
inline uint16 RawPeekUInt16(const void* p);
inline uint32 RawPeekUInt32(const void* p);
inline uint64 RawPeekUInt64(const void* p);
// \}
/**
* Writes the specified value into the bytestream.
*
* The value is written exactly as it is.
*/
// \{
inline void RawPokeUInt16(void* p, uint16 nVal);
inline void RawPokeUInt32(void* p, uint32 nVal);
inline void RawPokeUInt64(void* p, uint64 nVal);
// \}
/**
* Returns the value in the given bytestream.
*
* The value is returned as little-endian.
*/
// \{
inline uint8 PeekUInt8(const void* p);
inline uint16 PeekUInt16(const void* p);
inline uint32 PeekUInt32(const void* p);
inline uint64 PeekUInt64(const void* p);
// \}
/**
* Writes the specified value into the bytestream.
*
* The value is written as little-endian.
*/
// \{
inline void PokeUInt8(void* p, uint8 nVal);
inline void PokeUInt16(void* p, uint16 nVal);
inline void PokeUInt32(void* p, uint32 nVal);
inline void PokeUInt64(void* p, uint64 nVal);
// \}
#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(GCC_USES_STRICT_ALIASING)
#define ARCHSPECIFIC_USE_MEMCPY
#endif
///////////////////////////////////////////////////////////////////////////////
// Peek - helper functions for read-accessing memory without modifying the memory pointer
inline uint16 RawPeekUInt16(const void* p)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
return *((uint16*)p);<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
uint16 value;
memcpy( &value, p, sizeof( uint16 ) );
return value;
#endif
}
inline uint32 RawPeekUInt32(const void* p)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
return *((uint32*)p);<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
uint32 value;
memcpy( &value, p, sizeof( uint32 ) );
return value;
#endif
}
inline uint64 RawPeekUInt64(const void* p)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
return *((uint64*)p);<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
uint64 value;
memcpy( &value, p, sizeof( uint64 ) );
return value;
#endif
}
inline uint8 PeekUInt8(const void* p)
{
return *((uint8*)p);<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
}
inline uint16 PeekUInt16(const void* p)
{
return ENDIAN_SWAP_16( RawPeekUInt16( p ) );
}
inline uint32 PeekUInt32(const void* p)
{
return ENDIAN_SWAP_32( RawPeekUInt32( p ) );
}
inline uint64 PeekUInt64(const void* p)
{
return ENDIAN_SWAP_64( RawPeekUInt64( p ) );
}
///////////////////////////////////////////////////////////////////////////////
// Poke - helper functions for write-accessing memory without modifying the memory pointer
inline void RawPokeUInt16(void* p, uint16 nVal)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
*((uint16*)p) = nVal;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
memcpy( p, &nVal, sizeof(uint16) );
#endif
}
inline void RawPokeUInt32(void* p, uint32 nVal)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
*((uint32*)p) = nVal;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
memcpy( p, &nVal, sizeof(uint32) );
#endif
}
inline void RawPokeUInt64(void* p, uint64 nVal)
{
#ifndef ARCHSPECIFIC_USE_MEMCPY
*((uint64*)p) = nVal;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
#else
memcpy( p, &nVal, sizeof(uint64) );
#endif
}
inline void PokeUInt8(void* p, uint8 nVal)
{
*((uint8*)p) = nVal;<--- C-style pointer casting [+]C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
}
inline void PokeUInt16(void* p, uint16 nVal)
{
RawPokeUInt16( p, ENDIAN_SWAP_16( nVal ) );
}
inline void PokeUInt32(void* p, uint32 nVal)
{
RawPokeUInt32( p, ENDIAN_SWAP_32( nVal ) );
}
inline void PokeUInt64(void* p, uint64 nVal)
{
RawPokeUInt64( p, ENDIAN_SWAP_64( nVal ) );
}
// Don't pollute the preprocessor namespace
#undef ARCHSPECIFIC_USE_MEMCPY
#endif
// File_checked_for_headers
|