RetroArch
platform.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_PLATFORM_H
24 #define MBEDTLS_PLATFORM_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #if defined(MBEDTLS_HAVE_TIME)
33 #include "platform_time.h"
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
48 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS)
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <time.h>
52 #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF)
53 #if defined(_WIN32)
54 #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf
55 #else
56 #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf
57 #endif
58 #endif
59 #if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
60 #define MBEDTLS_PLATFORM_STD_PRINTF printf
61 #endif
62 #if !defined(MBEDTLS_PLATFORM_STD_FPRINTF)
63 #define MBEDTLS_PLATFORM_STD_FPRINTF fprintf
64 #endif
65 #if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
66 #define MBEDTLS_PLATFORM_STD_CALLOC calloc
67 #endif
68 #if !defined(MBEDTLS_PLATFORM_STD_FREE)
69 #define MBEDTLS_PLATFORM_STD_FREE free
70 #endif
71 #if !defined(MBEDTLS_PLATFORM_STD_EXIT)
72 #define MBEDTLS_PLATFORM_STD_EXIT exit
73 #endif
74 #if !defined(MBEDTLS_PLATFORM_STD_TIME)
75 #define MBEDTLS_PLATFORM_STD_TIME time
76 #endif
77 #if !defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
78 #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS EXIT_SUCCESS
79 #endif
80 #if !defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
81 #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE EXIT_FAILURE
82 #endif
83 #if defined(MBEDTLS_FS_IO)
84 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ)
85 #define MBEDTLS_PLATFORM_STD_NV_SEED_READ mbedtls_platform_std_nv_seed_read
86 #endif
87 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE)
88 #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE mbedtls_platform_std_nv_seed_write
89 #endif
90 #if !defined(MBEDTLS_PLATFORM_STD_NV_SEED_FILE)
91 #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile"
92 #endif
93 #endif /* MBEDTLS_FS_IO */
94 #else /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
95 #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR)
96 #include MBEDTLS_PLATFORM_STD_MEM_HDR
97 #endif
98 #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
99 
100 
101 /* \} name SECTION: Module settings */
102 
103 /*
104  * The function pointers for calloc and free
105  */
106 #if defined(MBEDTLS_PLATFORM_MEMORY)
107 #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \
108  defined(MBEDTLS_PLATFORM_CALLOC_MACRO)
109 #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO
110 #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO
111 #else
112 /* For size_t */
113 #include <stddef.h>
114 extern void * (*mbedtls_calloc)( size_t n, size_t size );
115 extern void (*mbedtls_free)( void *ptr );
116 
125 int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
126  void (*free_func)( void * ) );
127 #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */
128 #else /* !MBEDTLS_PLATFORM_MEMORY */
129 #define mbedtls_free free
130 #define mbedtls_calloc calloc
131 #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */
132 
133 /*
134  * The function pointers for fprintf
135  */
136 #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
137 /* We need FILE * */
138 #include <stdio.h>
139 extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... );
140 
148 int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
149  ... ) );
150 #else
151 #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO)
152 #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO
153 #else
154 #define mbedtls_fprintf fprintf
155 #endif /* MBEDTLS_PLATFORM_FPRINTF_MACRO */
156 #endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
157 
158 /*
159  * The function pointers for printf
160  */
161 #if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
162 extern int (*mbedtls_printf)( const char *format, ... );
163 
171 int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) );
172 #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */
173 #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO)
174 #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO
175 #else
176 #define mbedtls_printf printf
177 #endif /* MBEDTLS_PLATFORM_PRINTF_MACRO */
178 #endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
179 
180 /*
181  * The function pointers for snprintf
182  *
183  * The snprintf implementation should conform to C99:
184  * - it *must* always correctly zero-terminate the buffer
185  * (except when n == 0, then it must leave the buffer untouched)
186  * - however it is acceptable to return -1 instead of the required length when
187  * the destination buffer is too short.
188  */
189 #if defined(_WIN32)
190 /* For Windows (inc. MSYS2), we provide our own fixed implementation */
191 int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... );
192 #endif
193 
194 #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
195 extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... );
196 
204 int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
205  const char * format, ... ) );
206 #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
207 #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO)
208 #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO
209 #else
210 #define mbedtls_snprintf snprintf
211 #endif /* MBEDTLS_PLATFORM_SNPRINTF_MACRO */
212 #endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
213 
214 /*
215  * The function pointers for exit
216  */
217 #if defined(MBEDTLS_PLATFORM_EXIT_ALT)
218 extern void (*mbedtls_exit)( int status );
219 
227 int mbedtls_platform_set_exit( void (*exit_func)( int status ) );
228 #else
229 #if defined(MBEDTLS_PLATFORM_EXIT_MACRO)
230 #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO
231 #else
232 #define mbedtls_exit exit
233 #endif /* MBEDTLS_PLATFORM_EXIT_MACRO */
234 #endif /* MBEDTLS_PLATFORM_EXIT_ALT */
235 
236 /*
237  * The default exit values
238  */
239 #if defined(MBEDTLS_PLATFORM_STD_EXIT_SUCCESS)
240 #define MBEDTLS_EXIT_SUCCESS MBEDTLS_PLATFORM_STD_EXIT_SUCCESS
241 #else
242 #define MBEDTLS_EXIT_SUCCESS 0
243 #endif
244 #if defined(MBEDTLS_PLATFORM_STD_EXIT_FAILURE)
245 #define MBEDTLS_EXIT_FAILURE MBEDTLS_PLATFORM_STD_EXIT_FAILURE
246 #else
247 #define MBEDTLS_EXIT_FAILURE 1
248 #endif
249 
250 /*
251  * The function pointers for reading from and writing a seed file to
252  * Non-Volatile storage (NV) in a platform-independent way
253  *
254  * Only enabled when the NV seed entropy source is enabled
255  */
256 #if defined(MBEDTLS_ENTROPY_NV_SEED)
257 #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO)
258 /* Internal standard platform definitions */
259 int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len );
260 int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len );
261 #endif
262 
263 #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT)
264 extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len );
265 extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len );
266 
275 int mbedtls_platform_set_nv_seed(
276  int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ),
277  int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len )
278  );
279 #else
280 #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \
281  defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO)
282 #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO
283 #define mbedtls_nv_seed_write MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO
284 #else
285 #define mbedtls_nv_seed_read mbedtls_platform_std_nv_seed_read
286 #define mbedtls_nv_seed_write mbedtls_platform_std_nv_seed_write
287 #endif
288 #endif /* MBEDTLS_PLATFORM_NV_SEED_ALT */
289 #endif /* MBEDTLS_ENTROPY_NV_SEED */
290 
291 #if !defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
292 
299 typedef struct {
300  char dummy;
301 }
303 
304 #else
305 #include "platform_alt.h"
306 #endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */
307 
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 
343 #endif /* platform.h */
#define mbedtls_exit
Definition: platform.h:232
const GLvoid * ptr
Definition: nx_glsym.h:242
Configuration options (set of defines)
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
GLsizeiptr size
Definition: glext.h:6559
int mbedtls_platform_setup(mbedtls_platform_context *ctx)
Perform any platform initialisation operations.
Definition: platform.c:311
GLdouble s
Definition: glext.h:6390
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
#define mbedtls_snprintf
Definition: platform.h:210
AVFormatContext * ctx
Definition: record_ffmpeg.c:247
#define mbedtls_free
Definition: platform.h:129
Platform context structure.
Definition: platform.h:299
char dummy
Definition: platform.h:300
#define FILE
Definition: file_stream_transforms.h:35
#define free_func
Definition: ps3_defines.h:288
GLuint GLuint stream
Definition: glext.h:8189
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:6293
mbed TLS Platform time abstraction
#define mbedtls_fprintf
Definition: platform.h:154
void mbedtls_platform_teardown(mbedtls_platform_context *ctx)
Perform any platform teardown operations.
Definition: platform.c:321
GLdouble n
Definition: glext.h:8396
#define mbedtls_printf
Definition: platform.h:176