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
[];
35 /* some useful helpers from ntdll */
36 NTSYSAPI
const char *ntdll_get_build_dir(void);
37 NTSYSAPI
const char *ntdll_get_data_dir(void);
38 NTSYSAPI DWORD
ntdll_umbstowcs( const char *src
, DWORD srclen
, WCHAR
*dst
, DWORD dstlen
);
39 NTSYSAPI
int ntdll_wcstoumbs( const WCHAR
*src
, DWORD srclen
, char *dst
, DWORD dstlen
, BOOL strict
);
40 NTSYSAPI
int ntdll_wcsicmp( const WCHAR
*str1
, const WCHAR
*str2
);
41 NTSYSAPI
int ntdll_wcsnicmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
);
43 /* exception handling */
47 NTSYSAPI
void ntdll_set_exception_jmp_buf( jmp_buf jmp
);
52 for (;;) if (!__first) \
58 ntdll_set_exception_jmp_buf( NULL ); \
61 if (setjmp( __jmp )) { \
68 ntdll_set_exception_jmp_buf( __jmp ); \
73 NTSYSAPI BOOLEAN
KeAddSystemServiceTable( ULONG_PTR
*funcs
, ULONG_PTR
*counters
, ULONG limit
,
74 BYTE
*arguments
, ULONG index
);
75 NTSYSAPI NTSTATUS
KeUserModeCallback( ULONG id
, const void *args
, ULONG len
, void **ret_ptr
, ULONG
*ret_len
);
77 /* wide char string functions */
79 static inline int ntdll_iswspace( WCHAR wc
)
81 return ('\t' <= wc
&& wc
<= '\r') || wc
== ' ' || wc
== 0xa0;
84 static inline size_t ntdll_wcslen( const WCHAR
*str
)
91 static inline WCHAR
*ntdll_wcscpy( WCHAR
*dst
, const WCHAR
*src
)
94 while ((*p
++ = *src
++));
98 static inline WCHAR
*ntdll_wcscat( WCHAR
*dst
, const WCHAR
*src
)
100 ntdll_wcscpy( dst
+ ntdll_wcslen(dst
), src
);
104 static inline int ntdll_wcscmp( const WCHAR
*str1
, const WCHAR
*str2
)
106 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
107 return *str1
- *str2
;
110 static inline int ntdll_wcsncmp( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
112 if (n
<= 0) return 0;
113 while ((--n
> 0) && *str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
114 return *str1
- *str2
;
117 static inline WCHAR
*ntdll_wcschr( const WCHAR
*str
, WCHAR ch
)
119 do { if (*str
== ch
) return (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
123 static inline WCHAR
*ntdll_wcsrchr( const WCHAR
*str
, WCHAR ch
)
126 do { if (*str
== ch
) ret
= (WCHAR
*)(ULONG_PTR
)str
; } while (*str
++);
130 static inline WCHAR
*ntdll_wcspbrk( const WCHAR
*str
, const WCHAR
*accept
)
132 for ( ; *str
; str
++) if (ntdll_wcschr( accept
, *str
)) return (WCHAR
*)(ULONG_PTR
)str
;
136 static inline SIZE_T
ntdll_wcsspn( const WCHAR
*str
, const WCHAR
*accept
)
139 for (ptr
= str
; *ptr
; ptr
++) if (!ntdll_wcschr( accept
, *ptr
)) break;
143 static inline SIZE_T
ntdll_wcscspn( const WCHAR
*str
, const WCHAR
*reject
)
146 for (ptr
= str
; *ptr
; ptr
++) if (ntdll_wcschr( reject
, *ptr
)) break;
150 static inline LONG
ntdll_wcstol( const WCHAR
*s
, WCHAR
**end
, int base
)
152 BOOL negative
= FALSE
, empty
= TRUE
;
155 if (base
< 0 || base
== 1 || base
> 36) return 0;
156 if (end
) *end
= (WCHAR
*)s
;
157 while (ntdll_iswspace(*s
)) s
++;
164 else if (*s
== '+') s
++;
166 if ((base
== 0 || base
== 16) && s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
171 if (base
== 0) base
= s
[0] != '0' ? 10 : 8;
177 if ('0' <= *s
&& *s
<= '9') v
= *s
- '0';
178 else if ('A' <= *s
&& *s
<= 'Z') v
= *s
- 'A' + 10;
179 else if ('a' <= *s
&& *s
<= 'z') v
= *s
- 'a' + 10;
181 if (v
>= base
) break;
182 if (negative
) v
= -v
;
186 if (!negative
&& (ret
> MAXLONG
/ base
|| ret
* base
> MAXLONG
- v
))
188 else if (negative
&& (ret
< (LONG
)MINLONG
/ base
|| ret
* base
< (LONG
)(MINLONG
- v
)))
191 ret
= ret
* base
+ v
;
194 if (end
&& !empty
) *end
= (WCHAR
*)s
;
198 static inline ULONG
ntdll_wcstoul( const WCHAR
*s
, WCHAR
**end
, int base
)
200 BOOL negative
= FALSE
, empty
= TRUE
;
203 if (base
< 0 || base
== 1 || base
> 36) return 0;
204 if (end
) *end
= (WCHAR
*)s
;
205 while (ntdll_iswspace(*s
)) s
++;
212 else if (*s
== '+') s
++;
214 if ((base
== 0 || base
== 16) && s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
219 if (base
== 0) base
= s
[0] != '0' ? 10 : 8;
225 if ('0' <= *s
&& *s
<= '9') v
= *s
- '0';
226 else if ('A' <= *s
&& *s
<= 'Z') v
= *s
- 'A' + 10;
227 else if ('a' <= *s
&& *s
<= 'z') v
= *s
- 'a' + 10;
229 if (v
>= base
) break;
233 if (ret
> MAXDWORD
/ base
|| ret
* base
> MAXDWORD
- v
)
236 ret
= ret
* base
+ v
;
239 if (end
&& !empty
) *end
= (WCHAR
*)s
;
240 return negative
? -ret
: ret
;
243 #define iswspace(ch) ntdll_iswspace(ch)
244 #define wcslen(str) ntdll_wcslen(str)
245 #define wcscpy(dst,src) ntdll_wcscpy(dst,src)
246 #define wcscat(dst,src) ntdll_wcscat(dst,src)
247 #define wcscmp(s1,s2) ntdll_wcscmp(s1,s2)
248 #define wcsncmp(s1,s2,n) ntdll_wcsncmp(s1,s2,n)
249 #define wcschr(str,ch) ntdll_wcschr(str,ch)
250 #define wcsrchr(str,ch) ntdll_wcsrchr(str,ch)
251 #define wcspbrk(str,ac) ntdll_wcspbrk(str,ac)
252 #define wcsspn(str,ac) ntdll_wcsspn(str,ac)
253 #define wcscspn(str,rej) ntdll_wcscspn(str,rej)
254 #define wcsicmp(s1, s2) ntdll_wcsicmp(s1,s2)
255 #define wcsnicmp(s1, s2,n) ntdll_wcsnicmp(s1,s2,n)
256 #define wcstol(str,e,b) ntdll_wcstol(str,e,b)
257 #define wcstoul(str,e,b) ntdll_wcstoul(str,e,b)
259 #else /* WINE_UNIX_LIB */
261 extern unixlib_handle_t __wine_unixlib_handle
;
262 extern NTSTATUS (WINAPI
*__wine_unix_call_dispatcher
)( unixlib_handle_t
, unsigned int, void * );
263 extern NTSTATUS WINAPI
__wine_init_unix_call(void);
266 NTSTATUS
__wine_unix_call_arm64ec( unixlib_handle_t handle
, unsigned int code
, void *args
);
267 static inline NTSTATUS
__wine_unix_call( unixlib_handle_t handle
, unsigned int code
, void *args
)
269 return __wine_unix_call_arm64ec( handle
, code
, args
);
272 static inline NTSTATUS
__wine_unix_call( unixlib_handle_t handle
, unsigned int code
, void *args
)
274 return __wine_unix_call_dispatcher( handle
, code
, args
);
278 #define WINE_UNIX_CALL(code,args) __wine_unix_call( __wine_unixlib_handle, (code), (args) )
280 #endif /* WINE_UNIX_LIB */
282 #endif /* __WINE_WINE_UNIXLIB_H */