2 * Definitions for Unix libraries
4 * Copyright (C) 2021 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WINE_UNIXLIB_H
22 #define __WINE_WINE_UNIXLIB_H
26 typedef UINT64 unixlib_handle_t
;
30 typedef NTSTATUS (*unixlib_entry_t
)( void *args
);
32 extern DECLSPEC_EXPORT
const unixlib_entry_t __wine_unix_call_funcs
[];
33 extern DECLSPEC_EXPORT
const unixlib_entry_t __wine_unix_call_wow64_funcs
[];
34 extern DECLSPEC_EXPORT SYSTEM_SERVICE_TABLE KeServiceDescriptorTable
[4];
36 /* some useful helpers from ntdll */
37 NTSYSAPI
const char *ntdll_get_build_dir(void);
38 NTSYSAPI
const char *ntdll_get_data_dir(void);
39 NTSYSAPI DWORD
ntdll_umbstowcs( const char *src
, DWORD srclen
, WCHAR
*dst
, DWORD dstlen
);
40 NTSYSAPI
int ntdll_wcstoumbs( const WCHAR
*src
, DWORD srclen
, char *dst
, DWORD dstlen
, BOOL strict
);
41 NTSYSAPI
int ntdll_wcsicmp( const WCHAR
*str1
, const WCHAR
*str2
);
42 NTSYSAPI
int ntdll_wcsnicmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
);
44 /* exception handling */
47 typedef struct { int reg
[16]; } __wine_jmp_buf
;
48 #elif defined(__x86_64__)
49 typedef struct { DECLSPEC_ALIGN(16) struct { unsigned __int64 Part
[2]; } reg
[16]; } __wine_jmp_buf
;
50 #elif defined(__arm__)
51 typedef struct { int reg
[28]; } __wine_jmp_buf
;
52 #elif defined(__aarch64__)
53 typedef struct { __int64 reg
[24]; } __wine_jmp_buf
;
55 typedef struct { int reg
; } __wine_jmp_buf
;
58 NTSYSAPI
int __attribute__ ((__nothrow__
,__returns_twice__
)) __wine_setjmpex( __wine_jmp_buf
*buf
,
59 EXCEPTION_REGISTRATION_RECORD
*frame
);
60 NTSYSAPI
void DECLSPEC_NORETURN
__wine_longjmp( __wine_jmp_buf
*buf
, int retval
);
61 NTSYSAPI
void ntdll_set_exception_jmp_buf( __wine_jmp_buf
*jmp
);
64 do { __wine_jmp_buf __jmp; \
66 for (;;) if (!__first) \
72 ntdll_set_exception_jmp_buf( NULL ); \
75 if (__wine_setjmpex( &__jmp, NULL )) { \
82 ntdll_set_exception_jmp_buf( &__jmp ); \
87 NTSYSAPI NTSTATUS
KeUserModeCallback( ULONG id
, const void *args
, ULONG len
, void **ret_ptr
, ULONG
*ret_len
);
89 /* wide char string functions */
91 static inline int ntdll_iswspace( WCHAR wc
)
93 return ('\t' <= wc
&& wc
<= '\r') || wc
== ' ' || wc
== 0xa0;
96 static inline size_t ntdll_wcslen( const WCHAR
*str
)
103 static inline WCHAR
*ntdll_wcscpy( WCHAR
*dst
, const WCHAR
*src
)
106 while ((*p
++ = *src
++));
110 static inline WCHAR
*ntdll_wcscat( WCHAR
*dst
, const WCHAR
*src
)
112 ntdll_wcscpy( dst
+ ntdll_wcslen(dst
), src
);
116 static inline int ntdll_wcscmp( const WCHAR
*str1
, const WCHAR
*str2
)
118 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
119 return *str1
- *str2
;
122 static inline int ntdll_wcsncmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
124 if (n
<= 0) return 0;
125 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
126 return *str1
- *str2
;
129 static inline WCHAR
*ntdll_wcschr( const WCHAR
*str
, WCHAR ch
)
131 do { if (*str
== ch
) return (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
135 static inline WCHAR
*ntdll_wcsrchr( const WCHAR
*str
, WCHAR ch
)
138 do { if (*str
== ch
) ret
= (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
142 static inline WCHAR
*ntdll_wcspbrk( const WCHAR
*str
, const WCHAR
*accept
)
144 for ( ; *str
; str
++) if (ntdll_wcschr( accept
, *str
)) return (WCHAR
*)(ULONG_PTR
)str
;
148 static inline SIZE_T
ntdll_wcsspn( const WCHAR
*str
, const WCHAR
*accept
)
151 for (ptr
= str
; *ptr
; ptr
++) if (!ntdll_wcschr( accept
, *ptr
)) break;
155 static inline SIZE_T
ntdll_wcscspn( const WCHAR
*str
, const WCHAR
*reject
)
158 for (ptr
= str
; *ptr
; ptr
++) if (ntdll_wcschr( reject
, *ptr
)) break;
162 static inline LONG
ntdll_wcstol( const WCHAR
*s
, WCHAR
**end
, int base
)
164 BOOL negative
= FALSE
, empty
= TRUE
;
167 if (base
< 0 || base
== 1 || base
> 36) return 0;
168 if (end
) *end
= (WCHAR
*)s
;
169 while (ntdll_iswspace(*s
)) s
++;
176 else if (*s
== '+') s
++;
178 if ((base
== 0 || base
== 16) && s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
183 if (base
== 0) base
= s
[0] != '0' ? 10 : 8;
189 if ('0' <= *s
&& *s
<= '9') v
= *s
- '0';
190 else if ('A' <= *s
&& *s
<= 'Z') v
= *s
- 'A' + 10;
191 else if ('a' <= *s
&& *s
<= 'z') v
= *s
- 'a' + 10;
193 if (v
>= base
) break;
194 if (negative
) v
= -v
;
198 if (!negative
&& (ret
> MAXLONG
/ base
|| ret
* base
> MAXLONG
- v
))
200 else if (negative
&& (ret
< (LONG
)MINLONG
/ base
|| ret
* base
< (LONG
)(MINLONG
- v
)))
203 ret
= ret
* base
+ v
;
206 if (end
&& !empty
) *end
= (WCHAR
*)s
;
210 static inline ULONG
ntdll_wcstoul( const WCHAR
*s
, WCHAR
**end
, int base
)
212 BOOL negative
= FALSE
, empty
= TRUE
;
215 if (base
< 0 || base
== 1 || base
> 36) return 0;
216 if (end
) *end
= (WCHAR
*)s
;
217 while (ntdll_iswspace(*s
)) s
++;
224 else if (*s
== '+') s
++;
226 if ((base
== 0 || base
== 16) && s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
231 if (base
== 0) base
= s
[0] != '0' ? 10 : 8;
237 if ('0' <= *s
&& *s
<= '9') v
= *s
- '0';
238 else if ('A' <= *s
&& *s
<= 'Z') v
= *s
- 'A' + 10;
239 else if ('a' <= *s
&& *s
<= 'z') v
= *s
- 'a' + 10;
241 if (v
>= base
) break;
245 if (ret
> MAXDWORD
/ base
|| ret
* base
> MAXDWORD
- v
)
248 ret
= ret
* base
+ v
;
251 if (end
&& !empty
) *end
= (WCHAR
*)s
;
252 return negative
? -ret
: ret
;
255 #define iswspace(ch) ntdll_iswspace(ch)
256 #define wcslen(str) ntdll_wcslen(str)
257 #define wcscpy(dst,src) ntdll_wcscpy(dst,src)
258 #define wcscat(dst,src) ntdll_wcscat(dst,src)
259 #define wcscmp(s1,s2) ntdll_wcscmp(s1,s2)
260 #define wcsncmp(s1,s2,n) ntdll_wcsncmp(s1,s2,n)
261 #define wcschr(str,ch) ntdll_wcschr(str,ch)
262 #define wcsrchr(str,ch) ntdll_wcsrchr(str,ch)
263 #define wcspbrk(str,ac) ntdll_wcspbrk(str,ac)
264 #define wcsspn(str,ac) ntdll_wcsspn(str,ac)
265 #define wcscspn(str,rej) ntdll_wcscspn(str,rej)
266 #define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2)
267 #define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n)
268 #define wcstol(str,e,b) ntdll_wcstol(str,e,b)
269 #define wcstoul(str,e,b) ntdll_wcstoul(str,e,b)
271 #else /* WINE_UNIX_LIB */
273 NTSYSAPI NTSTATUS WINAPI
__wine_unix_call( unixlib_handle_t handle
, unsigned int code
, void *args
);
274 extern unixlib_handle_t __wine_unixlib_handle
;
275 extern NTSTATUS (WINAPI
*__wine_unix_call_dispatcher
)( unixlib_handle_t
, unsigned int, void * );
276 extern NTSTATUS WINAPI
__wine_init_unix_call(void);
278 #define WINE_UNIX_CALL(code,args) __wine_unix_call_dispatcher( __wine_unixlib_handle, (code), (args) )
280 #endif /* WINE_UNIX_LIB */
282 #endif /* __WINE_WINE_UNIXLIB_H */