Add PInvoke/SizeParamIndex tests (#19348)
[platform/upstream/coreclr.git] / tests / src / Common / Platform / platformdefines.h
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 //
4
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <cstdint>
10
11 #ifndef _PLATFORMDEFINES__H
12 #define _PLATFORMDEFINES__H
13
14 //
15 // types and constants
16 //
17 #ifdef WINDOWS
18 #include <windows.h>
19
20 #define FS_SEPERATOR L"\\"
21 #define PATH_DELIMITER L";"
22 #define L(t) L##t
23 #define W(str)  L##str
24
25 typedef unsigned error_t;
26 typedef HANDLE THREAD_ID;
27
28 #define DLL_EXPORT __declspec(dllexport)
29
30 #else // !WINDOWS
31 #include <pthread.h>
32
33 typedef char16_t WCHAR;
34 typedef unsigned int DWORD;
35 typedef int BOOL;
36 typedef WCHAR *LPWSTR, *PWSTR;
37 typedef const WCHAR *LPCWSTR, *PCWSTR;
38
39 typedef int HRESULT;
40 #define LONGLONG long long
41 #define ULONGLONG unsigned LONGLONG
42 typedef unsigned int ULONG, *PULONG;
43 #define S_OK                    0x0
44 #define SUCCEEDED(_hr)          ((HRESULT)(_hr) >= 0)
45 #define FAILED(_hr)             ((HRESULT)(_hr) < 0)
46
47 #ifdef ULONG_MAX
48 #undef ULONG_MAX
49 #endif
50 #define ULONG_MAX     0xffffffffUL
51 #define CCH_BSTRMAX 0x7FFFFFFF  // 4 + (0x7ffffffb + 1 ) * 2 ==> 0xFFFFFFFC
52 #define CB_BSTRMAX 0xFFFFFFFa   // 4 + (0xfffffff6 + 2) ==> 0xFFFFFFFC
53
54 #ifdef RC_INVOKED
55 #define _HRESULT_TYPEDEF_(_sc) _sc
56 #else // RC_INVOKED
57 #define _HRESULT_TYPEDEF_(_sc) ((HRESULT)_sc)
58 #endif // RC_INVOKED
59 #define E_INVALIDARG                     _HRESULT_TYPEDEF_(0x80070057L)
60 #define UInt32x32To64(a, b) ((unsigned __int64)((ULONG)(a)) * (unsigned __int64)((ULONG)(b)))
61
62 #define ARRAYSIZE(x) (sizeof(x)/sizeof(*x))
63
64 #ifndef TRUE
65 #define TRUE 1
66 #endif
67
68 #ifndef FALSE
69 #define FALSE 0
70 #endif
71
72 #ifndef WINAPI
73 #define WINAPI  __stdcall
74 #endif
75
76 #ifndef _MSC_VER
77 #if __i386__
78 #define __stdcall __attribute__((stdcall))
79 #define _cdecl __attribute__((cdecl))
80 #define __cdecl __attribute__((cdecl))
81 #else
82 #define __stdcall
83 #define _cdecl
84 #define __cdecl
85 #endif
86 #endif
87
88 #if __GNUC__ >= 4
89 #define DLL_EXPORT __attribute__ ((visibility ("default")))
90 #else
91 #define DLL_EXPORT
92 #endif
93
94 LPWSTR HackyConvertToWSTR(const char* pszInput);
95
96 #define FS_SEPERATOR L("/")
97 #define PATH_DELIMITER L(":")
98 #define L(t) HackyConvertToWSTR(t)
99 #define W(str)  u##str
100 #define MAX_PATH 260
101
102 typedef pthread_t THREAD_ID;
103 typedef void* (*MacWorker)(void*);
104 typedef DWORD __stdcall (*LPTHREAD_START_ROUTINE)(void*);
105 #ifdef UNICODE
106 typedef WCHAR TCHAR;
107 #else // ANSI
108 typedef char TCHAR;
109 #endif // UNICODE
110 typedef char* LPSTR;
111 typedef const char* LPCSTR;
112 typedef TCHAR* LPTSTR;
113 typedef const TCHAR* LPCTSTR;
114 typedef void* FARPROC;
115 typedef void* HMODULE;
116 typedef void* ULONG_PTR;
117 typedef int error_t;
118 typedef void* LPVOID;
119 typedef unsigned char BYTE;
120 typedef WCHAR OLECHAR;
121 #endif
122
123 typedef ULONG_PTR DWORD_PTR;
124
125 //
126 // Method declarations
127 //
128 error_t TP_scpy_s(LPWSTR strDestination, size_t sizeInWords, LPCWSTR strSource);
129 error_t TP_scat_s(LPWSTR strDestination, size_t sizeInWords, LPCWSTR strSource);
130 size_t TP_slen(LPCWSTR str);
131 int TP_scmp_s(LPCSTR str1, LPCSTR str2);
132 int TP_wcmp_s(LPCWSTR str1, LPCWSTR str2);
133 error_t TP_getenv_s(size_t* pReturnValue, LPWSTR buffer, size_t sizeInWords, LPCWSTR varname);
134 error_t TP_putenv_s(LPTSTR name, LPTSTR value);
135 void TP_ZeroMemory(LPVOID buffer, size_t sizeInBytes);
136 error_t TP_itow_s(int num, LPWSTR buffer, size_t sizeInCharacters, int radix);
137 error_t TP_itoa_s(int num, LPSTR buffer, size_t sizeInCharacters, int radix);
138 LPWSTR TP_sstr(LPWSTR str, LPWSTR searchStr);
139 LPSTR  HackyConvertToSTR(LPWSTR pwszInput);
140 DWORD TP_CreateThread(THREAD_ID* tThread, LPTHREAD_START_ROUTINE worker,  LPVOID lpParameter);
141 void TP_JoinThread(THREAD_ID tThread);
142 void TP_DebugBreak();
143 DWORD TP_GetFullPathName(LPWSTR fileName, DWORD nBufferLength, LPWSTR lpBuffer);
144
145 typedef WCHAR* BSTR;
146 BSTR TP_SysAllocStringByteLen(LPCSTR psz, size_t len);
147 void TP_SysFreeString(BSTR bstr);
148 size_t TP_SysStringByteLen(BSTR bstr);
149 BSTR TP_SysAllocStringLen(LPWSTR psz, size_t len);
150 BSTR TP_SysAllocString(LPWSTR psz);
151
152 //
153 // Method redirects
154 //
155 #ifdef WINDOWS
156 #define TP_LoadLibrary(l) LoadLibrary(l)
157 #define TP_LoadLibraryW(l) LoadLibraryW(l)
158 #define TP_LoadLibraryA(l) LoadLibraryA(l)
159 #define TP_GetProcAddress(m,e) GetProcAddress(m,e)
160 #define TP_CoTaskMemAlloc(t) CoTaskMemAlloc(t)
161 #define TP_CoTaskMemFree(t) CoTaskMemFree(t)
162 #define TP_DebugBreak() DebugBreak()
163 #define TP_rand rand
164 #define TP_srand srand
165 #else
166 #define fopen_s(FILEHANDLE, FILENAME, MODE) *(FILEHANDLE) = fopen(FILENAME, MODE)
167 #define _fsopen(FILENAME, MODE, ACCESS) fopen(FILENAME, MODE)
168 #define GetCurrentDirectory(BUFSIZ, BUF) getcwd(BUF, BUFSIZ)
169 #define DeleteFile unlink
170 #define GlobalFree free
171 #define sprintf_s snprintf
172 #define fwscanf_s fwscanf
173 #define strcat_s(DST,SIZ,SRC) strlcat(DST,SRC,SIZ)
174 #define TP_LoadLibrary(l) dlopen(l, 0)
175 #define TP_LoadLibraryW(l) dlopen(l, 0)
176 #define TP_LoadLibraryA(l) dlopen(l, 0)
177 #define TP_GetProcAddress(m,e) dlsym(m,e)
178 #define TP_CoTaskMemAlloc(t) malloc(t)
179 #define TP_CoTaskMemFree(t) free(t)
180 #define TP_rand arc4random
181 #define TP_srand srandom
182 #define wcscpy_s TP_scpy_s
183 #define wcscat_s TP_scat_s
184 #define GetFullPathNameW(fname,buflen,buf,filepart)  TP_GetFullPathName(fname,buflen,buf)
185 #define wcslen TP_slen
186 #define _wgetenv_s TP_getenv_s
187 #define _putenv_s TP_putenv_s
188 #define ZeroMemory TP_ZeroMemory
189 #define _itow_s TP_itow_s
190 #define _itoa_s TP_itoa_s
191 #define wcsstr TP_sstr
192 #define strcmp TP_scmp_s
193 #define wcscmp TP_wcmp_s
194 #endif
195
196 #endif
197