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
28 #define WIN32_NO_STATUS
29 #include "wine/debug.h"
30 #include "ntdll_misc.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
37 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
39 if (!oa
) return "<null>";
40 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
41 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
42 oa
->RootDirectory
, oa
->SecurityDescriptor
);
45 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
47 if (!us
) return "<null>";
48 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
51 /*********************************************************************
52 * wine_get_version (NTDLL.@)
54 const char * CDECL
NTDLL_wine_get_version(void)
56 return unix_funcs
->get_version();
59 /*********************************************************************
60 * wine_get_build_id (NTDLL.@)
62 const char * CDECL
NTDLL_wine_get_build_id(void)
64 return unix_funcs
->get_build_id();
67 /*********************************************************************
68 * wine_get_host_version (NTDLL.@)
70 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
72 return unix_funcs
->get_host_version( sysname
, release
);
75 /*********************************************************************
78 int CDECL
NTDLL_abs( int i
)
83 /*********************************************************************
86 LONG CDECL
NTDLL_labs( LONG i
)
91 /*********************************************************************
94 double CDECL
NTDLL_atan( double d
)
99 /*********************************************************************
102 double CDECL
NTDLL_ceil( double d
)
107 /*********************************************************************
110 double CDECL
NTDLL_cos( double d
)
115 /*********************************************************************
118 double CDECL
NTDLL_fabs( double d
)
123 /*********************************************************************
126 double CDECL
NTDLL_floor( double d
)
131 /*********************************************************************
134 double CDECL
NTDLL_log( double d
)
139 /*********************************************************************
142 double CDECL
NTDLL_pow( double x
, double y
)
147 /*********************************************************************
150 double CDECL
NTDLL_sin( double d
)
155 /*********************************************************************
158 double CDECL
NTDLL_sqrt( double d
)
163 /*********************************************************************
166 double CDECL
NTDLL_tan( double d
)
171 #if defined(__GNUC__) && defined(__i386__)
173 #define FPU_DOUBLE(var) double var; \
174 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
175 #define FPU_DOUBLES(var1,var2) double var1,var2; \
176 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
177 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
179 /*********************************************************************
182 double CDECL
NTDLL__CIcos(void)
188 /*********************************************************************
191 double CDECL
NTDLL__CIlog(void)
197 /*********************************************************************
200 double CDECL
NTDLL__CIpow(void)
203 return NTDLL_pow(x
,y
);
206 /*********************************************************************
209 double CDECL
NTDLL__CIsin(void)
215 /*********************************************************************
218 double CDECL
NTDLL__CIsqrt(void)
221 return NTDLL_sqrt(x
);
224 /*********************************************************************
227 LONGLONG CDECL
NTDLL__ftol(void)
233 #endif /* defined(__GNUC__) && defined(__i386__) */
236 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
237 size_t left
, size_t right
)
241 m
=left
+(right
-left
)/2;
242 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
243 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
245 #define X(a,i) ((char*)a+elemsize*(i))
246 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
247 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
248 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
251 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
256 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
258 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
260 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
265 /*********************************************************************
268 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
269 int(__cdecl
*compar
)(const void *, const void *) )
272 if (nmemb
< 2 || size
== 0) return;
273 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
274 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
275 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
278 /*********************************************************************
282 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
283 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
286 ssize_t max
= nmemb
- 1;
290 ssize_t cursor
= min
+ (max
- min
) / 2;
291 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
293 return (char*)base
+(cursor
*size
);
303 /*********************************************************************
306 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
307 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
309 size_t i
, n
= *nmemb
;
312 if (!compar(key
,(char*)base
+(size
*i
)))
313 return (char*)base
+(size
*i
);
317 /******************************************************************************
318 * WinSqmEndSession (NTDLL.@)
320 NTSTATUS WINAPI
WinSqmEndSession(HANDLE session
)
322 FIXME("(%p): stub\n", session
);
323 return STATUS_NOT_IMPLEMENTED
;
326 /*********************************************************************
327 * WinSqmIncrementDWORD (NTDLL.@)
329 void WINAPI
WinSqmIncrementDWORD(DWORD unk1
, DWORD unk2
, DWORD unk3
)
331 FIXME("(%d, %d, %d): stub\n", unk1
, unk2
, unk3
);
334 /*********************************************************************
335 * WinSqmIsOptedIn (NTDLL.@)
337 BOOL WINAPI
WinSqmIsOptedIn(void)
343 /******************************************************************************
344 * WinSqmStartSession (NTDLL.@)
346 HANDLE WINAPI
WinSqmStartSession(GUID
*sessionguid
, DWORD sessionid
, DWORD unknown1
)
348 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid
, sessionid
, unknown1
);
349 return INVALID_HANDLE_VALUE
;
352 /***********************************************************************
353 * WinSqmSetDWORD (NTDLL.@)
355 void WINAPI
WinSqmSetDWORD(HANDLE session
, DWORD datapoint_id
, DWORD datapoint_value
)
357 FIXME("(%p, %d, %d): stub\n", session
, datapoint_id
, datapoint_value
);
360 /******************************************************************************
361 * EtwEventActivityIdControl (NTDLL.@)
363 ULONG WINAPI
EtwEventActivityIdControl(ULONG code
, GUID
*guid
)
367 if (!once
++) FIXME("0x%x, %p: stub\n", code
, guid
);
368 return ERROR_SUCCESS
;
371 /******************************************************************************
372 * EtwEventProviderEnabled (NTDLL.@)
374 BOOLEAN WINAPI
EtwEventProviderEnabled( REGHANDLE handle
, UCHAR level
, ULONGLONG keyword
)
376 FIXME("%s, %u, %s: stub\n", wine_dbgstr_longlong(handle
), level
, wine_dbgstr_longlong(keyword
));
380 /******************************************************************************
381 * EtwEventRegister (NTDLL.@)
383 ULONG WINAPI
EtwEventRegister( LPCGUID provider
, PENABLECALLBACK callback
, PVOID context
,
386 FIXME("(%s, %p, %p, %p) stub.\n", debugstr_guid(provider
), callback
, context
, handle
);
388 if (!handle
) return ERROR_INVALID_PARAMETER
;
390 *handle
= 0xdeadbeef;
391 return ERROR_SUCCESS
;
394 /******************************************************************************
395 * EtwEventUnregister (NTDLL.@)
397 ULONG WINAPI
EtwEventUnregister( REGHANDLE handle
)
399 FIXME("(%s) stub.\n", wine_dbgstr_longlong(handle
));
400 return ERROR_SUCCESS
;
403 /*********************************************************************
404 * EtwEventSetInformation (NTDLL.@)
406 ULONG WINAPI
EtwEventSetInformation( REGHANDLE handle
, EVENT_INFO_CLASS
class, void *info
,
409 FIXME("(%s, %u, %p, %u) stub\n", wine_dbgstr_longlong(handle
), class, info
, length
);
410 return ERROR_SUCCESS
;
413 /******************************************************************************
414 * EtwEventWriteString (NTDLL.@)
416 ULONG WINAPI
EtwEventWriteString( REGHANDLE handle
, UCHAR level
, ULONGLONG keyword
, PCWSTR string
)
418 FIXME("%s, %u, %s, %s: stub\n", wine_dbgstr_longlong(handle
), level
,
419 wine_dbgstr_longlong(keyword
), debugstr_w(string
));
420 return ERROR_SUCCESS
;
423 /******************************************************************************
424 * EtwEventWriteTransfer (NTDLL.@)
426 ULONG WINAPI
EtwEventWriteTransfer( REGHANDLE handle
, PCEVENT_DESCRIPTOR descriptor
, LPCGUID activity
,
427 LPCGUID related
, ULONG count
, PEVENT_DATA_DESCRIPTOR data
)
429 FIXME("%s, %p, %s, %s, %u, %p: stub\n", wine_dbgstr_longlong(handle
), descriptor
,
430 debugstr_guid(activity
), debugstr_guid(related
), count
, data
);
431 return ERROR_SUCCESS
;
434 /******************************************************************************
435 * EtwRegisterTraceGuidsW (NTDLL.@)
437 * Register an event trace provider and the event trace classes that it uses
438 * to generate events.
441 * RequestAddress [I] ControlCallback function
442 * RequestContext [I] Optional provider-defined context
443 * ControlGuid [I] GUID of the registering provider
444 * GuidCount [I] Number of elements in the TraceGuidReg array
445 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
446 * MofImagePath [I] not supported, set to NULL
447 * MofResourceName [I] not supported, set to NULL
448 * RegistrationHandle [O] Provider's registration handle
451 * Success: ERROR_SUCCESS
452 * Failure: System error code
454 ULONG WINAPI
EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
455 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
456 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const WCHAR
*MofImagePath
,
457 const WCHAR
*MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
459 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
460 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
461 debugstr_w(MofResourceName
), RegistrationHandle
);
466 for (i
= 0; i
< GuidCount
; i
++)
468 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg
[i
].Guid
));
469 TraceGuidReg
[i
].RegHandle
= (HANDLE
)0xdeadbeef;
472 *RegistrationHandle
= (TRACEHANDLE
)0xdeadbeef;
473 return ERROR_SUCCESS
;
476 /******************************************************************************
477 * EtwRegisterTraceGuidsA (NTDLL.@)
479 ULONG WINAPI
EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
480 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
481 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const char *MofImagePath
,
482 const char *MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
484 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
485 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
486 debugstr_a(MofResourceName
), RegistrationHandle
);
487 return ERROR_SUCCESS
;
490 /******************************************************************************
491 * EtwUnregisterTraceGuids (NTDLL.@)
493 ULONG WINAPI
EtwUnregisterTraceGuids( TRACEHANDLE RegistrationHandle
)
495 if (!RegistrationHandle
)
496 return ERROR_INVALID_PARAMETER
;
498 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle
));
499 return ERROR_SUCCESS
;
502 /******************************************************************************
503 * EtwEventEnabled (NTDLL.@)
505 BOOLEAN WINAPI
EtwEventEnabled( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
)
507 FIXME("(%s, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
);
511 /******************************************************************************
512 * EtwEventWrite (NTDLL.@)
514 ULONG WINAPI
EtwEventWrite( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
, ULONG count
,
515 EVENT_DATA_DESCRIPTOR
*data
)
517 FIXME("(%s, %p, %u, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
, count
, data
);
518 return ERROR_SUCCESS
;
521 /******************************************************************************
522 * EtwGetTraceEnableFlags (NTDLL.@)
524 ULONG WINAPI
EtwGetTraceEnableFlags( TRACEHANDLE handle
)
526 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle
));
530 /******************************************************************************
531 * EtwGetTraceEnableLevel (NTDLL.@)
533 UCHAR WINAPI
EtwGetTraceEnableLevel( TRACEHANDLE handle
)
535 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle
));
536 return TRACE_LEVEL_VERBOSE
;
539 /******************************************************************************
540 * EtwGetTraceLoggerHandle (NTDLL.@)
542 TRACEHANDLE WINAPI
EtwGetTraceLoggerHandle( PVOID buf
)
544 FIXME("(%p) stub\n", buf
);
545 return INVALID_PROCESSTRACE_HANDLE
;
548 /******************************************************************************
549 * EtwLogTraceEvent (NTDLL.@)
551 ULONG WINAPI
EtwLogTraceEvent( TRACEHANDLE SessionHandle
, PEVENT_TRACE_HEADER EventTrace
)
553 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle
), EventTrace
);
554 return ERROR_CALL_NOT_IMPLEMENTED
;
557 /******************************************************************************
558 * EtwTraceMessageVa (NTDLL.@)
560 ULONG WINAPI
EtwTraceMessageVa( TRACEHANDLE handle
, ULONG flags
, LPGUID guid
, USHORT number
,
563 FIXME("(%s %x %s %d) : stub\n", wine_dbgstr_longlong(handle
), flags
, debugstr_guid(guid
), number
);
564 return ERROR_SUCCESS
;
567 /******************************************************************************
568 * EtwTraceMessage (NTDLL.@)
570 ULONG WINAPIV
EtwTraceMessage( TRACEHANDLE handle
, ULONG flags
, LPGUID guid
, USHORT number
, ... )
575 __ms_va_start( valist
, number
);
576 ret
= EtwTraceMessageVa( handle
, flags
, guid
, number
, valist
);
577 __ms_va_end( valist
);
581 NTSTATUS WINAPI
NtCreateLowBoxToken(HANDLE
*token_handle
, HANDLE existing_token_handle
, ACCESS_MASK desired_access
,
582 OBJECT_ATTRIBUTES
*object_attributes
, SID
*package_sid
, ULONG capability_count
,
583 SID_AND_ATTRIBUTES
*capabilities
, ULONG handle_count
, HANDLE
*handle
)
585 FIXME("(%p, %p, %x, %p, %p, %u, %p, %u, %p): stub\n", token_handle
, existing_token_handle
, desired_access
,
586 object_attributes
, package_sid
, capability_count
, capabilities
, handle_count
, handle
);
588 /* We need to return a NULL handle since later it will be passed to CloseHandle and that must not fail */
589 *token_handle
= NULL
;
590 return STATUS_SUCCESS
;
593 /*********************************************************************
594 * ApiSetQueryApiSetPresence (NTDLL.@)
596 BOOL WINAPI
ApiSetQueryApiSetPresence(const UNICODE_STRING
*namespace, BOOLEAN
*present
)
598 FIXME("(%s, %p) stub!\n", debugstr_us(namespace), present
);