2 * Helper functions for ntdll
4 * Copyright 2000 Juergen Schmied
5 * Copyright 2010 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_NO_STATUS
27 #include "wine/debug.h"
28 #include "ntdll_misc.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
35 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
37 if (!us
) return "<null>";
38 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
41 /*********************************************************************
44 int CDECL
abs( int i
)
46 return i
>= 0 ? i
: -i
;
49 /*********************************************************************
52 double CDECL
atan( double d
)
54 return unix_funcs
->atan( d
);
57 /*********************************************************************
60 double CDECL
ceil( double d
)
62 return unix_funcs
->ceil( d
);
65 /*********************************************************************
68 double CDECL
cos( double d
)
70 return unix_funcs
->cos( d
);
73 /*********************************************************************
76 double CDECL
fabs( double d
)
78 return unix_funcs
->fabs( d
);
81 /*********************************************************************
84 double CDECL
floor( double d
)
86 return unix_funcs
->floor( d
);
89 /*********************************************************************
92 double CDECL
log( double d
)
94 return unix_funcs
->log( d
);
97 /*********************************************************************
100 double CDECL
pow( double x
, double y
)
102 return unix_funcs
->pow( x
, y
);
105 /*********************************************************************
108 double CDECL
sin( double d
)
110 return unix_funcs
->sin( d
);
113 /*********************************************************************
116 double CDECL
sqrt( double d
)
118 return unix_funcs
->sqrt( d
);
121 /*********************************************************************
124 double CDECL
tan( double d
)
126 return unix_funcs
->tan( d
);
129 #if (defined(__GNUC__) || defined(__clang__)) && defined(__i386__)
131 #define FPU_DOUBLE(var) double var; \
132 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
133 #define FPU_DOUBLES(var1,var2) double var1,var2; \
134 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
135 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
137 /*********************************************************************
140 double CDECL
_CIcos(void)
146 /*********************************************************************
149 double CDECL
_CIlog(void)
155 /*********************************************************************
158 double CDECL
_CIpow(void)
164 /*********************************************************************
167 double CDECL
_CIsin(void)
173 /*********************************************************************
176 double CDECL
_CIsqrt(void)
182 /*********************************************************************
185 LONGLONG CDECL
_ftol(void)
191 #endif /* (defined(__GNUC__) || defined(__clang__)) && defined(__i386__) */
194 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
195 size_t left
, size_t right
)
199 m
=left
+(right
-left
)/2;
200 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
201 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
203 #define X(a,i) ((char*)a+elemsize*(i))
204 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
205 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
206 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
209 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
214 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
216 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
218 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
223 /*********************************************************************
226 void __cdecl
qsort( void *base
, size_t nmemb
, size_t size
,
227 int (__cdecl
*compar
)(const void *, const void *) )
230 if (nmemb
< 2 || size
== 0) return;
231 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
232 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
233 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
236 /*********************************************************************
239 void * __cdecl
bsearch( const void *key
, const void *base
, size_t nmemb
,
240 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
243 ssize_t max
= nmemb
- 1;
247 ssize_t cursor
= min
+ (max
- min
) / 2;
248 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
250 return (char*)base
+(cursor
*size
);
260 /*********************************************************************
263 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
264 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
266 size_t i
, n
= *nmemb
;
269 if (!compar(key
,(char*)base
+(size
*i
)))
270 return (char*)base
+(size
*i
);
274 /******************************************************************************
275 * WinSqmEndSession (NTDLL.@)
277 NTSTATUS WINAPI
WinSqmEndSession(HANDLE session
)
279 FIXME("(%p): stub\n", session
);
280 return STATUS_NOT_IMPLEMENTED
;
283 /*********************************************************************
284 * WinSqmIncrementDWORD (NTDLL.@)
286 void WINAPI
WinSqmIncrementDWORD(DWORD unk1
, DWORD unk2
, DWORD unk3
)
288 FIXME("(%d, %d, %d): stub\n", unk1
, unk2
, unk3
);
291 /*********************************************************************
292 * WinSqmIsOptedIn (NTDLL.@)
294 BOOL WINAPI
WinSqmIsOptedIn(void)
300 /******************************************************************************
301 * WinSqmStartSession (NTDLL.@)
303 HANDLE WINAPI
WinSqmStartSession(GUID
*sessionguid
, DWORD sessionid
, DWORD unknown1
)
305 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid
, sessionid
, unknown1
);
306 return INVALID_HANDLE_VALUE
;
309 /***********************************************************************
310 * WinSqmSetDWORD (NTDLL.@)
312 void WINAPI
WinSqmSetDWORD(HANDLE session
, DWORD datapoint_id
, DWORD datapoint_value
)
314 FIXME("(%p, %d, %d): stub\n", session
, datapoint_id
, datapoint_value
);
317 /******************************************************************************
318 * EtwEventActivityIdControl (NTDLL.@)
320 ULONG WINAPI
EtwEventActivityIdControl(ULONG code
, GUID
*guid
)
324 if (!once
++) FIXME("0x%x, %p: stub\n", code
, guid
);
325 return ERROR_SUCCESS
;
328 /******************************************************************************
329 * EtwEventProviderEnabled (NTDLL.@)
331 BOOLEAN WINAPI
EtwEventProviderEnabled( REGHANDLE handle
, UCHAR level
, ULONGLONG keyword
)
333 WARN("%s, %u, %s: stub\n", wine_dbgstr_longlong(handle
), level
, wine_dbgstr_longlong(keyword
));
337 /******************************************************************************
338 * EtwEventRegister (NTDLL.@)
340 ULONG WINAPI
EtwEventRegister( LPCGUID provider
, PENABLECALLBACK callback
, PVOID context
,
343 WARN("(%s, %p, %p, %p) stub.\n", debugstr_guid(provider
), callback
, context
, handle
);
345 if (!handle
) return ERROR_INVALID_PARAMETER
;
347 *handle
= 0xdeadbeef;
348 return ERROR_SUCCESS
;
351 /******************************************************************************
352 * EtwEventUnregister (NTDLL.@)
354 ULONG WINAPI
EtwEventUnregister( REGHANDLE handle
)
356 WARN("(%s) stub.\n", wine_dbgstr_longlong(handle
));
357 return ERROR_SUCCESS
;
360 /*********************************************************************
361 * EtwEventSetInformation (NTDLL.@)
363 ULONG WINAPI
EtwEventSetInformation( REGHANDLE handle
, EVENT_INFO_CLASS
class, void *info
,
366 FIXME("(%s, %u, %p, %u) stub\n", wine_dbgstr_longlong(handle
), class, info
, length
);
367 return ERROR_SUCCESS
;
370 /******************************************************************************
371 * EtwEventWriteString (NTDLL.@)
373 ULONG WINAPI
EtwEventWriteString( REGHANDLE handle
, UCHAR level
, ULONGLONG keyword
, PCWSTR string
)
375 FIXME("%s, %u, %s, %s: stub\n", wine_dbgstr_longlong(handle
), level
,
376 wine_dbgstr_longlong(keyword
), debugstr_w(string
));
377 return ERROR_SUCCESS
;
380 /******************************************************************************
381 * EtwEventWriteTransfer (NTDLL.@)
383 ULONG WINAPI
EtwEventWriteTransfer( REGHANDLE handle
, PCEVENT_DESCRIPTOR descriptor
, LPCGUID activity
,
384 LPCGUID related
, ULONG count
, PEVENT_DATA_DESCRIPTOR data
)
386 FIXME("%s, %p, %s, %s, %u, %p: stub\n", wine_dbgstr_longlong(handle
), descriptor
,
387 debugstr_guid(activity
), debugstr_guid(related
), count
, data
);
388 return ERROR_SUCCESS
;
391 /******************************************************************************
392 * EtwRegisterTraceGuidsW (NTDLL.@)
394 * Register an event trace provider and the event trace classes that it uses
395 * to generate events.
398 * RequestAddress [I] ControlCallback function
399 * RequestContext [I] Optional provider-defined context
400 * ControlGuid [I] GUID of the registering provider
401 * GuidCount [I] Number of elements in the TraceGuidReg array
402 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
403 * MofImagePath [I] not supported, set to NULL
404 * MofResourceName [I] not supported, set to NULL
405 * RegistrationHandle [O] Provider's registration handle
408 * Success: ERROR_SUCCESS
409 * Failure: System error code
411 ULONG WINAPI
EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
412 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
413 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const WCHAR
*MofImagePath
,
414 const WCHAR
*MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
416 WARN("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
417 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
418 debugstr_w(MofResourceName
), RegistrationHandle
);
423 for (i
= 0; i
< GuidCount
; i
++)
425 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg
[i
].Guid
));
426 TraceGuidReg
[i
].RegHandle
= (HANDLE
)0xdeadbeef;
429 *RegistrationHandle
= (TRACEHANDLE
)0xdeadbeef;
430 return ERROR_SUCCESS
;
433 /******************************************************************************
434 * EtwRegisterTraceGuidsA (NTDLL.@)
436 ULONG WINAPI
EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
437 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
438 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const char *MofImagePath
,
439 const char *MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
441 WARN("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
442 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
443 debugstr_a(MofResourceName
), RegistrationHandle
);
444 return ERROR_SUCCESS
;
447 /******************************************************************************
448 * EtwUnregisterTraceGuids (NTDLL.@)
450 ULONG WINAPI
EtwUnregisterTraceGuids( TRACEHANDLE RegistrationHandle
)
452 if (!RegistrationHandle
)
453 return ERROR_INVALID_PARAMETER
;
455 WARN("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle
));
456 return ERROR_SUCCESS
;
459 /******************************************************************************
460 * EtwEventEnabled (NTDLL.@)
462 BOOLEAN WINAPI
EtwEventEnabled( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
)
464 WARN("(%s, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
);
468 /******************************************************************************
469 * EtwEventWrite (NTDLL.@)
471 ULONG WINAPI
EtwEventWrite( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
, ULONG count
,
472 EVENT_DATA_DESCRIPTOR
*data
)
474 FIXME("(%s, %p, %u, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
, count
, data
);
475 return ERROR_SUCCESS
;
478 /******************************************************************************
479 * EtwGetTraceEnableFlags (NTDLL.@)
481 ULONG WINAPI
EtwGetTraceEnableFlags( TRACEHANDLE handle
)
483 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle
));
487 /******************************************************************************
488 * EtwGetTraceEnableLevel (NTDLL.@)
490 UCHAR WINAPI
EtwGetTraceEnableLevel( TRACEHANDLE handle
)
492 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle
));
493 return TRACE_LEVEL_VERBOSE
;
496 /******************************************************************************
497 * EtwGetTraceLoggerHandle (NTDLL.@)
499 TRACEHANDLE WINAPI
EtwGetTraceLoggerHandle( PVOID buf
)
501 FIXME("(%p) stub\n", buf
);
502 return INVALID_PROCESSTRACE_HANDLE
;
505 /******************************************************************************
506 * EtwLogTraceEvent (NTDLL.@)
508 ULONG WINAPI
EtwLogTraceEvent( TRACEHANDLE SessionHandle
, PEVENT_TRACE_HEADER EventTrace
)
510 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle
), EventTrace
);
511 return ERROR_CALL_NOT_IMPLEMENTED
;
514 /******************************************************************************
515 * EtwTraceMessageVa (NTDLL.@)
517 ULONG WINAPI
EtwTraceMessageVa( TRACEHANDLE handle
, ULONG flags
, LPGUID guid
, USHORT number
,
520 FIXME("(%s %x %s %d) : stub\n", wine_dbgstr_longlong(handle
), flags
, debugstr_guid(guid
), number
);
521 return ERROR_SUCCESS
;
524 /******************************************************************************
525 * EtwTraceMessage (NTDLL.@)
527 ULONG WINAPIV
EtwTraceMessage( TRACEHANDLE handle
, ULONG flags
, LPGUID guid
, /*USHORT*/ ULONG number
, ... )
532 __ms_va_start( valist
, number
);
533 ret
= EtwTraceMessageVa( handle
, flags
, guid
, number
, valist
);
534 __ms_va_end( valist
);
538 /*********************************************************************
539 * ApiSetQueryApiSetPresence (NTDLL.@)
541 BOOL WINAPI
ApiSetQueryApiSetPresence(const UNICODE_STRING
*namespace, BOOLEAN
*present
)
543 FIXME("(%s, %p) stub!\n", debugstr_us(namespace), present
);