xref: /reactos/sdk/lib/crt/wine/msvcrt.h (revision 3a61dd7f)
1 /*
2  * Copyright 2001 Jon Griffiths
3  * Copyright 2004 Dimitrie O. Paun
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19 
20 #ifndef __WINE_MSVCRT_H
21 #define __WINE_MSVCRT_H
22 
23 #include <errno.h>
24 #include <stdarg.h>
25 #include <stdint.h>
26 #define _NO_CRT_STDIO_INLINE
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <wchar.h>
30 
31 #include "windef.h"
32 #include "winbase.h"
33 #undef strncpy
34 #undef wcsncpy
35 
36 #ifdef __REACTOS__
37 typedef long __msvcrt_long;
38 typedef unsigned long __msvcrt_ulong;
39 #endif
40 
41 extern BOOL sse2_supported DECLSPEC_HIDDEN;
42 
43 #define DBL80_MAX_10_EXP 4932
44 #define DBL80_MIN_10_EXP -4951
45 
46 typedef void (__cdecl *terminate_function)(void);
47 typedef void (__cdecl *unexpected_function)(void);
48 typedef void (__cdecl *_se_translator_function)(unsigned int code, struct _EXCEPTION_POINTERS *info);
49 void __cdecl terminate(void);
50 
51 typedef void (__cdecl *MSVCRT_security_error_handler)(int, void *);
52 
53 typedef struct {ULONG x80[3];} MSVCRT__LDOUBLE; /* Intel 80 bit FP format has sizeof() 12 */
54 
55 typedef struct __lc_time_data {
56     union {
57         const char *str[43];
58         struct {
59             const char *short_wday[7];
60             const char *wday[7];
61             const char *short_mon[12];
62             const char *mon[12];
63             const char *am;
64             const char *pm;
65             const char *short_date;
66             const char *date;
67             const char *time;
68         } names;
69     } str;
70 #if _MSVCR_VER < 110
71     LCID lcid;
72 #endif
73     int unk;
74     int refcount;
75 #if _MSVCR_VER == 0 || _MSVCR_VER >= 100
76     union {
77         const wchar_t *wstr[43];
78         struct {
79             const wchar_t *short_wday[7];
80             const wchar_t *wday[7];
81             const wchar_t *short_mon[12];
82             const wchar_t *mon[12];
83             const wchar_t *am;
84             const wchar_t *pm;
85             const wchar_t *short_date;
86             const wchar_t *date;
87             const wchar_t *time;
88         } names;
89     } wstr;
90 #endif
91 #if _MSVCR_VER >= 110
92     const wchar_t *locname;
93 #endif
94     char data[1];
95 } __lc_time_data;
96 
97 typedef struct threadmbcinfostruct {
98     int refcount;
99     int mbcodepage;
100     int ismbcodepage;
101     int mblcid;
102     unsigned short mbulinfo[6];
103     unsigned char mbctype[257];
104     unsigned char mbcasemap[256];
105 } threadmbcinfo;
106 
107 typedef struct _frame_info
108 {
109     void *object;
110     struct _frame_info *next;
111 } frame_info;
112 
113 typedef struct
114 {
115     frame_info frame_info;
116     EXCEPTION_RECORD *rec;
117     CONTEXT *context;
118 } cxx_frame_info;
119 
120 frame_info* __cdecl _CreateFrameInfo(frame_info *fi, void *obj);
121 BOOL __cdecl __CxxRegisterExceptionObject(EXCEPTION_POINTERS*, cxx_frame_info*);
122 void __cdecl __CxxUnregisterExceptionObject(cxx_frame_info*, BOOL);
123 void CDECL __DestructExceptionObject(EXCEPTION_RECORD*);
124 
125 /* TLS data */
126 extern DWORD msvcrt_tls_index DECLSPEC_HIDDEN;
127 
128 #define LOCALE_FREE     0x1
129 #define LOCALE_THREAD   0x2
130 
131 /* Keep in sync with msvcr90/tests/msvcr90.c */
132 struct __thread_data {
133     DWORD                           tid;
134     HANDLE                          handle;
135     int                             thread_errno;
136     __msvcrt_ulong                  thread_doserrno;
137     int                             unk1;
138     unsigned int                    random_seed;        /* seed for rand() */
139     char                           *strtok_next;        /* next ptr for strtok() */
140     wchar_t                        *wcstok_next;        /* next ptr for wcstok() */
141     unsigned char                  *mbstok_next;        /* next ptr for mbstok() */
142     char                           *strerror_buffer;    /* buffer for strerror */
143     wchar_t                        *wcserror_buffer;    /* buffer for wcserror */
144     char                           *tmpnam_buffer;      /* buffer for tmpname() */
145     wchar_t                        *wtmpnam_buffer;     /* buffer for wtmpname() */
146     void                           *unk2[2];
147     char                           *asctime_buffer;     /* buffer for asctime */
148     wchar_t                        *wasctime_buffer;    /* buffer for wasctime */
149     struct tm                      *time_buffer;        /* buffer for localtime/gmtime */
150     char                           *efcvt_buffer;       /* buffer for ecvt/fcvt */
151     int                             unk3[2];
152     void                           *unk4[3];
153     EXCEPTION_POINTERS             *xcptinfo;
154     int                             fpecode;
155     pthreadmbcinfo                  mbcinfo;
156     pthreadlocinfo                  locinfo;
157     int                             locale_flags;
158     int                             unk5[1];
159     terminate_function              terminate_handler;
160     unexpected_function             unexpected_handler;
161     _se_translator_function         se_translator;      /* preserve offset to exc_record and processing_throw */
162     void                           *unk6;
163     EXCEPTION_RECORD               *exc_record;
164     CONTEXT                        *ctx_record;
165     int                             processing_throw;
166     frame_info                     *frame_info_head;
167     void                           *unk8[6];
168     LCID                            cached_lcid;
169     BOOL                            cached_sname;
170     int                             unk9[2];
171     DWORD                           cached_cp;
172     char                            cached_locale[131];
173     void                           *unk10[100];
174 #if _MSVCR_VER >= 140
175     _invalid_parameter_handler      invalid_parameter_handler;
176     HMODULE                         module;
177 #endif
178 };
179 
180 typedef struct __thread_data thread_data_t;
181 
182 extern thread_data_t *CDECL msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
183 
184 LCID locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN;
185 extern _locale_t MSVCRT_locale DECLSPEC_HIDDEN;
186 extern __lc_time_data cloc_time_data DECLSPEC_HIDDEN;
187 extern unsigned int MSVCRT___lc_codepage;
188 extern int MSVCRT___lc_collate_cp;
189 extern WORD MSVCRT__ctype [257];
190 extern BOOL initial_locale DECLSPEC_HIDDEN;
191 extern WORD *MSVCRT__pwctype;
192 
193 void msvcrt_set_errno(int) DECLSPEC_HIDDEN;
194 #if _MSVCR_VER >= 80
195 void throw_bad_alloc(void) DECLSPEC_HIDDEN;
196 #endif
197 
198 void __cdecl _purecall(void);
199 void __cdecl _amsg_exit(int errnum);
200 
201 extern char **MSVCRT__environ;
202 extern wchar_t **MSVCRT__wenviron;
203 
204 extern char ** msvcrt_SnapshotOfEnvironmentA(char **) DECLSPEC_HIDDEN;
205 extern wchar_t ** msvcrt_SnapshotOfEnvironmentW(wchar_t **) DECLSPEC_HIDDEN;
206 
207 wchar_t *msvcrt_wstrdupa(const char *) DECLSPEC_HIDDEN;
208 
209 extern unsigned int MSVCRT__commode;
210 
211 /* FIXME: This should be declared in new.h but it's not an extern "C" so
212  * it would not be much use anyway. Even for Winelib applications.
213  */
214 void* __cdecl operator_new(size_t);
215 void __cdecl operator_delete(void*);
216 int __cdecl _set_new_mode(int mode);
217 
218 typedef void* (__cdecl *malloc_func_t)(size_t);
219 typedef void  (__cdecl *free_func_t)(void*);
220 
221 /* Setup and teardown multi threaded locks */
222 extern void msvcrt_init_mt_locks(void) DECLSPEC_HIDDEN;
223 extern void msvcrt_free_locks(void) DECLSPEC_HIDDEN;
224 
225 extern void msvcrt_init_exception(void*) DECLSPEC_HIDDEN;
226 extern BOOL msvcrt_init_locale(void) DECLSPEC_HIDDEN;
227 extern void msvcrt_init_math(void*) DECLSPEC_HIDDEN;
228 extern void msvcrt_init_io(void) DECLSPEC_HIDDEN;
229 extern void msvcrt_free_io(void) DECLSPEC_HIDDEN;
230 extern void msvcrt_free_console(void) DECLSPEC_HIDDEN;
231 extern void msvcrt_init_args(void) DECLSPEC_HIDDEN;
232 extern void msvcrt_free_args(void) DECLSPEC_HIDDEN;
233 extern void msvcrt_init_signals(void) DECLSPEC_HIDDEN;
234 extern void msvcrt_free_signals(void) DECLSPEC_HIDDEN;
235 extern void msvcrt_free_popen_data(void) DECLSPEC_HIDDEN;
236 extern BOOL msvcrt_init_heap(void) DECLSPEC_HIDDEN;
237 extern void msvcrt_destroy_heap(void) DECLSPEC_HIDDEN;
238 extern void msvcrt_init_clock(void) DECLSPEC_HIDDEN;
239 
240 #if _MSVCR_VER >= 100
241 extern void msvcrt_init_concurrency(void*) DECLSPEC_HIDDEN;
242 extern void msvcrt_free_concurrency(void) DECLSPEC_HIDDEN;
243 extern void msvcrt_free_scheduler_thread(void) DECLSPEC_HIDDEN;
244 #endif
245 
246 extern BOOL msvcrt_create_io_inherit_block(WORD*, BYTE**) DECLSPEC_HIDDEN;
247 
248 /* run-time error codes */
249 #define _RT_STACK       0
250 #define _RT_NULLPTR     1
251 #define _RT_FLOAT       2
252 #define _RT_INTDIV      3
253 #define _RT_EXECMEM     5
254 #define _RT_EXECFORM    6
255 #define _RT_EXECENV     7
256 #define _RT_SPACEARG    8
257 #define _RT_SPACEENV    9
258 #define _RT_ABORT       10
259 #define _RT_NPTR        12
260 #define _RT_FPTR        13
261 #define _RT_BREAK       14
262 #define _RT_INT         15
263 #define _RT_THREAD      16
264 #define _RT_LOCK        17
265 #define _RT_HEAP        18
266 #define _RT_OPENCON     19
267 #define _RT_QWIN        20
268 #define _RT_NOMAIN      21
269 #define _RT_NONCONT     22
270 #define _RT_INVALDISP   23
271 #define _RT_ONEXIT      24
272 #define _RT_PUREVIRT    25
273 #define _RT_STDIOINIT   26
274 #define _RT_LOWIOINIT   27
275 #define _RT_HEAPINIT    28
276 #define _RT_DOMAIN      120
277 #define _RT_SING        121
278 #define _RT_TLOSS       122
279 #define _RT_CRNL        252
280 #define _RT_BANNER      255
281 
282 extern FILE MSVCRT__iob[];
283 
284 #define MSVCRT_NO_CONSOLE_FD (-2)
285 #define MSVCRT_NO_CONSOLE ((HANDLE)MSVCRT_NO_CONSOLE_FD)
286 
287 #define MSVCRT_stdin       (MSVCRT__iob+STDIN_FILENO)
288 #define MSVCRT_stdout      (MSVCRT__iob+STDOUT_FILENO)
289 #define MSVCRT_stderr      (MSVCRT__iob+STDERR_FILENO)
290 
291 /* internal file._flag flags */
292 #define MSVCRT__USERBUF  0x0100
293 #define MSVCRT__IOCOMMIT 0x4000
294 
295 #ifdef __REACTOS__
296 typedef void (__cdecl *__sighandler_t)(int);
297 #endif
298 
299 #define _MAX__TIME64_T    (((__time64_t)0x00000007 << 32) | 0x93406FFF)
300 
301 _locale_t CDECL get_current_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
302 void CDECL free_locale_noalloc(_locale_t locale) DECLSPEC_HIDDEN;
303 pthreadlocinfo CDECL get_locinfo(void) DECLSPEC_HIDDEN;
304 pthreadmbcinfo CDECL get_mbcinfo(void) DECLSPEC_HIDDEN;
305 threadmbcinfo* create_mbcinfo(int, LCID, threadmbcinfo*) DECLSPEC_HIDDEN;
306 void free_locinfo(pthreadlocinfo) DECLSPEC_HIDDEN;
307 void free_mbcinfo(pthreadmbcinfo) DECLSPEC_HIDDEN;
308 int __cdecl __crtLCMapStringA(LCID, DWORD, const char*, int, char*, int, unsigned int, int) DECLSPEC_HIDDEN;
309 
310 enum fpmod {
311     FP_ROUND_ZERO, /* only used when dropped part contains only zeros */
312     FP_ROUND_DOWN,
313     FP_ROUND_EVEN,
314     FP_ROUND_UP,
315     FP_VAL_INFINITY,
316     FP_VAL_NAN
317 };
318 
319 struct fpnum {
320     int sign;
321     int exp;
322     ULONGLONG m;
323     enum fpmod mod;
324 };
325 struct fpnum fpnum_parse(wchar_t (*)(void*), void (*)(void*),
326         void*, pthreadlocinfo, BOOL) DECLSPEC_HIDDEN;
327 int fpnum_double(struct fpnum*, double*) DECLSPEC_HIDDEN;
328 /* Maybe one day we'll enable the invalid parameter handlers with the full set of information (msvcrXXd)
329  *      #define MSVCRT_INVALID_PMT(x) MSVCRT_call_invalid_parameter_handler(x, __FUNCTION__, __FILE__, __LINE__, 0)
330  *      #define MSVCRT_CHECK_PMT(x)   ((x) ? TRUE : MSVCRT_INVALID_PMT(#x),FALSE)
331  * Until this is done, just keep the same semantics for CHECK_PMT(), but without generating / sending
332  * any information
333  * NB : MSVCRT_call_invalid_parameter_handler is a wrapper around _invalid_parameter in order
334  * to do the Ansi to Unicode transformation
335  */
336 #define MSVCRT_INVALID_PMT(x,err)   (*_errno() = (err), _invalid_parameter(NULL, NULL, NULL, 0, 0))
337 #define MSVCRT_CHECK_PMT_ERR(x,err) ((x) || (MSVCRT_INVALID_PMT( 0, (err) ), FALSE))
338 #define MSVCRT_CHECK_PMT(x)         MSVCRT_CHECK_PMT_ERR((x), EINVAL)
339 
340 typedef int (*puts_clbk_a)(void*, int, const char*);
341 typedef int (*puts_clbk_w)(void*, int, const wchar_t*);
342 typedef union _printf_arg
343 {
344     void *get_ptr;
345     int get_int;
346     LONGLONG get_longlong;
347     double get_double;
348 } printf_arg;
349 typedef printf_arg (*args_clbk)(void*, int, int, va_list*);
350 int pf_printf_a(puts_clbk_a, void*, const char*, _locale_t,
351         DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN;
352 int pf_printf_w(puts_clbk_w, void*, const wchar_t*, _locale_t,
353         DWORD, args_clbk, void*, va_list*) DECLSPEC_HIDDEN;
354 int create_positional_ctx_a(void*, const char*, va_list) DECLSPEC_HIDDEN;
355 int create_positional_ctx_w(void*, const wchar_t*, va_list) DECLSPEC_HIDDEN;
356 printf_arg arg_clbk_valist(void*, int, int, va_list*) DECLSPEC_HIDDEN;
357 printf_arg arg_clbk_positional(void*, int, int, va_list*) DECLSPEC_HIDDEN;
358 
359 extern char* __cdecl __unDName(char *,const char*,int,malloc_func_t,free_func_t,unsigned short int);
360 
361 /* __unDName/__unDNameEx flags */
362 #define UNDNAME_COMPLETE                 (0x0000)
363 #define UNDNAME_NO_LEADING_UNDERSCORES   (0x0001) /* Don't show __ in calling convention */
364 #define UNDNAME_NO_MS_KEYWORDS           (0x0002) /* Don't show calling convention at all */
365 #define UNDNAME_NO_FUNCTION_RETURNS      (0x0004) /* Don't show function/method return value */
366 #define UNDNAME_NO_ALLOCATION_MODEL      (0x0008)
367 #define UNDNAME_NO_ALLOCATION_LANGUAGE   (0x0010)
368 #define UNDNAME_NO_MS_THISTYPE           (0x0020)
369 #define UNDNAME_NO_CV_THISTYPE           (0x0040)
370 #define UNDNAME_NO_THISTYPE              (0x0060)
371 #define UNDNAME_NO_ACCESS_SPECIFIERS     (0x0080) /* Don't show access specifier (public/protected/private) */
372 #define UNDNAME_NO_THROW_SIGNATURES      (0x0100)
373 #define UNDNAME_NO_MEMBER_TYPE           (0x0200) /* Don't show static/virtual specifier */
374 #define UNDNAME_NO_RETURN_UDT_MODEL      (0x0400)
375 #define UNDNAME_32_BIT_DECODE            (0x0800)
376 #define UNDNAME_NAME_ONLY                (0x1000) /* Only report the variable/method name */
377 #define UNDNAME_NO_ARGUMENTS             (0x2000) /* Don't show method arguments */
378 #define UNDNAME_NO_SPECIAL_SYMS          (0x4000)
379 #define UNDNAME_NO_COMPLEX_TYPE          (0x8000)
380 
381 #define UCRTBASE_PRINTF_MASK ( \
382         _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION | \
383         _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR | \
384         _CRT_INTERNAL_PRINTF_LEGACY_WIDE_SPECIFIERS | \
385         _CRT_INTERNAL_PRINTF_LEGACY_MSVCRT_COMPATIBILITY | \
386         _CRT_INTERNAL_PRINTF_LEGACY_THREE_DIGIT_EXPONENTS | \
387         _CRT_INTERNAL_PRINTF_STANDARD_ROUNDING )
388 
389 #define MSVCRT_PRINTF_POSITIONAL_PARAMS                  (0x0100)
390 #define MSVCRT_PRINTF_INVOKE_INVALID_PARAM_HANDLER       (0x0200)
391 
392 #define UCRTBASE_SCANF_MASK ( \
393         _CRT_INTERNAL_SCANF_SECURECRT | \
394         _CRT_INTERNAL_SCANF_LEGACY_WIDE_SPECIFIERS | \
395         _CRT_INTERNAL_SCANF_LEGACY_MSVCRT_COMPATIBILITY )
396 
397 #define COOPERATIVE_TIMEOUT_INFINITE ((unsigned int)-1)
398 #define COOPERATIVE_WAIT_TIMEOUT     ~0
399 
400 #define INHERIT_THREAD_PRIORITY 0xF000
401 
402 
403 #ifdef __REACTOS__
404 #define __wine_longjmp longjmp
405 #define __wine_jmp_buf _JBTYPE
406 
407 #ifdef _M_IX86
408 // ASM wrapper for Wine code. See rosglue_i386.s for implementation.
409 void
410 WINAPI
411 __wine__RtlUnwind(
412     struct _EXCEPTION_REGISTRATION_RECORD* pEndFrame,
413     PVOID targetIp,
414     struct _EXCEPTION_RECORD* pRecord,
415     PVOID retval);
416 #define RtlUnwind __wine__RtlUnwind
417 #endif /* _M_IX86 */
418 
419 #endif
420 
421 #endif /* __WINE_MSVCRT_H */
422