1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the w64 mingw-runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 
7 #ifndef _INC_INTERNAL
8 #define _INC_INTERNAL
9 
10 #include <crtdefs.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include <stdarg.h>
17 #include <limits.h>
18 #include <windef.h>
19 #include <winbase.h>
20 
21 #ifdef __REACTOS__
22 #include "malloc.h"
23 struct _exception;
24 _CRTIMP void __cdecl __setusermatherr(int (__cdecl *)(struct _exception *));
25 #define __mingw_fprintf fprintf
26 #define __mingw_vfprintf vfprintf
27 #endif
28 
29 #pragma pack(push,_CRT_PACKING)
30 
31 #ifndef __INTERNAL_FUNC_DEFINED
32 #define __INTERNAL_FUNC_DEFINED
33   typedef void (__cdecl *_PVFV)(void);
34   typedef int (__cdecl *_PIFV)(void);
35   typedef void (__cdecl *_PVFI)(int);
36 #endif
37 
38 #if defined (SPECIAL_CRTEXE) && (defined (_DLL) || defined (__GNUC__))
39   extern int _commode;
40 #else
41   _CRTIMP extern int _commode;
42 #endif
43 
44 #define __IOINFO_TM_ANSI 0
45 #define __IOINFO_TM_UTF8 1
46 #define __IOINFO_TM_UTF16LE 2
47 
48 #ifdef _MSC_VER
49 #pragma warning(push)
50 #pragma warning(disable:4214)
51 #pragma warning(disable:4820)
52 #endif
53 
54   typedef struct {
55     intptr_t osfhnd;
56     char osfile;
57     char pipech;
58     int lockinitflag;
59     CRITICAL_SECTION lock;
60     char textmode : 7;
61     char unicode : 1;
62     char pipech2[2];
63   } ioinfo;
64 
65 #ifdef _MSC_VER
66 #pragma warning(pop)
67 #endif
68 
69 #define IOINFO_ARRAY_ELTS (1 << 5)
70 
71 #define _pioinfo(i) (__pioinfo[(i) >> 5] + ((i) & (IOINFO_ARRAY_ELTS - 1)))
72 #define _osfile(i) (_pioinfo(i)->osfile)
73 #define _pipech2(i) (_pioinfo(i)->pipech2)
74 #define _textmode(i) (_pioinfo(i)->textmode)
75 #define _tm_unicode(i) (_pioinfo(i)->unicode)
76 #define _pioinfo_safe(i) ((((i) != -1) && ((i) != -2)) ? _pioinfo(i) : &__badioinfo)
77 #define _osfhnd_safe(i) (_pioinfo_safe(i)->osfhnd)
78 #define _osfile_safe(i) (_pioinfo_safe(i)->osfile)
79 #define _pipech_safe(i) (_pioinfo_safe(i)->pipech)
80 #define _pipech2_safe(i) (_pioinfo_safe(i)->pipech2)
81 #define _textmode_safe(i) (_pioinfo_safe(i)->textmode)
82 #define _tm_unicode_safe(i) (_pioinfo_safe(i)->unicode)
83 
84 #ifndef __badioinfo
85 _CRTIMP  extern ioinfo * __badioinfo[];
86 #endif
87 
88 #ifndef __pioinfo
89 _CRTIMP  extern ioinfo ** __pioinfo[];
90 #endif
91 
92 #define _NO_CONSOLE_FILENO (intptr_t)-2
93 
94 #ifndef _FILE_DEFINED
95 #define _FILE_DEFINED
96   struct _iobuf {
97     char *_ptr;
98     int _cnt;
99     char *_base;
100     int _flag;
101     int _file;
102     int _charbuf;
103     int _bufsiz;
104     char *_tmpfname;
105   };
106   typedef struct _iobuf FILE;
107 #endif
108 
109 #if !defined (_FILEX_DEFINED) && defined (_WINDOWS_)
110 #define _FILEX_DEFINED
111   typedef struct {
112     FILE f;
113     CRITICAL_SECTION lock;
114   } _FILEX;
115 #endif
116 
117   extern int _dowildcard;
118   extern int _newmode;
119 
120 _CRTIMP extern wchar_t ** __winitenv;
121 _CRTIMP extern char ** __initenv;
122 _CRTIMP extern char * _acmdln;
123 _CRTIMP extern  char * _wcmdln;
124 
125   _CRTIMP __declspec(noreturn) void __cdecl _amsg_exit(int);
126 
127   int __CRTDECL _setargv(void);
128   int __CRTDECL __setargv(void);
129   int __CRTDECL _wsetargv(void);
130   int __CRTDECL __wsetargv(void);
131 
132   int __CRTDECL main(int _Argc, char **_Argv, char **_Env);
133   int __CRTDECL wmain(int _Argc, wchar_t **_Argv, wchar_t **_Env);
134 
135 #ifndef _STARTUP_INFO_DEFINED
136 #define _STARTUP_INFO_DEFINED
137   typedef struct {
138     int newmode;
139   } _startupinfo;
140 #endif
141 
142   _CRTIMP int __cdecl __getmainargs(int * _Argc, char *** _Argv, char ***_Env, int _DoWildCard, _startupinfo *_StartInfo);
143   _CRTIMP int __cdecl __wgetmainargs(int * _Argc, wchar_t ***_Argv, wchar_t ***_Env, int _DoWildCard, _startupinfo *_StartInfo);
144 
145 #define _CONSOLE_APP 1
146 #define _GUI_APP 2
147 
148   typedef enum __enative_startup_state {
149     __uninitialized = 0, __initializing, __initialized
150   } __enative_startup_state;
151 
152   extern volatile __enative_startup_state __native_startup_state;
153   extern volatile void *__native_startup_lock;
154 
155   extern volatile unsigned int __native_dllmain_reason;
156   extern volatile unsigned int __native_vcclrit_reason;
157 
158   _CRTIMP void __cdecl __set_app_type (int);
159 
160   typedef LONG NTSTATUS;
161 
162 #include <crtdbg.h>
163 #include <errno.h>
164 
165   void * __cdecl _encode_pointer(void *);
166   void * __cdecl _encoded_null();
167   void * __cdecl _decode_pointer(void *);
168 
169   BOOL __cdecl _ValidateImageBase (PBYTE pImageBase);
170   PIMAGE_SECTION_HEADER __cdecl _FindPESection (PBYTE pImageBase, DWORD_PTR rva);
171   BOOL __cdecl _IsNonwritableInCurrentImage (PBYTE pTarget);
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #pragma pack(pop)
178 #endif
179