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 #ifdef HAVE_SYS_UTSNAME_H
27 #include <sys/utsname.h>
31 #define WIN32_NO_STATUS
32 #include "wine/library.h"
33 #include "wine/debug.h"
34 #include "ntdll_misc.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
41 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
43 if (!oa
) return "<null>";
44 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
45 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
46 oa
->RootDirectory
, oa
->SecurityDescriptor
);
49 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
51 if (!us
) return "<null>";
52 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
55 /*********************************************************************
56 * wine_get_version (NTDLL.@)
58 const char * CDECL
NTDLL_wine_get_version(void)
60 return wine_get_version();
63 /*********************************************************************
64 * wine_get_build_id (NTDLL.@)
66 const char * CDECL
NTDLL_wine_get_build_id(void)
68 return wine_get_build_id();
71 /*********************************************************************
72 * wine_get_host_version (NTDLL.@)
74 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
76 #ifdef HAVE_SYS_UTSNAME_H
77 static struct utsname buf
;
78 static BOOL init_done
;
85 if (sysname
) *sysname
= buf
.sysname
;
86 if (release
) *release
= buf
.release
;
88 if (sysname
) *sysname
= "";
89 if (release
) *release
= "";
93 /*********************************************************************
96 int CDECL
NTDLL_abs( int i
)
101 /*********************************************************************
104 LONG CDECL
NTDLL_labs( LONG i
)
109 /*********************************************************************
112 double CDECL
NTDLL_atan( double d
)
117 /*********************************************************************
120 double CDECL
NTDLL_ceil( double d
)
125 /*********************************************************************
128 double CDECL
NTDLL_cos( double d
)
133 /*********************************************************************
136 double CDECL
NTDLL_fabs( double d
)
141 /*********************************************************************
144 double CDECL
NTDLL_floor( double d
)
149 /*********************************************************************
152 double CDECL
NTDLL_log( double d
)
157 /*********************************************************************
160 double CDECL
NTDLL_pow( double x
, double y
)
165 /*********************************************************************
168 double CDECL
NTDLL_sin( double d
)
173 /*********************************************************************
176 double CDECL
NTDLL_sqrt( double d
)
181 /*********************************************************************
184 double CDECL
NTDLL_tan( double d
)
189 #if defined(__GNUC__) && defined(__i386__)
191 #define FPU_DOUBLE(var) double var; \
192 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
193 #define FPU_DOUBLES(var1,var2) double var1,var2; \
194 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
195 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
197 /*********************************************************************
200 double CDECL
NTDLL__CIcos(void)
206 /*********************************************************************
209 double CDECL
NTDLL__CIlog(void)
215 /*********************************************************************
218 double CDECL
NTDLL__CIpow(void)
221 return NTDLL_pow(x
,y
);
224 /*********************************************************************
227 double CDECL
NTDLL__CIsin(void)
233 /*********************************************************************
236 double CDECL
NTDLL__CIsqrt(void)
239 return NTDLL_sqrt(x
);
242 /*********************************************************************
245 LONGLONG CDECL
NTDLL__ftol(void)
251 #endif /* defined(__GNUC__) && defined(__i386__) */
254 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
255 size_t left
, size_t right
)
259 m
=left
+(right
-left
)/2;
260 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
261 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
263 #define X(a,i) ((char*)a+elemsize*(i))
264 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
265 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
266 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
269 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
274 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
276 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
278 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
283 /*********************************************************************
286 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
287 int(__cdecl
*compar
)(const void *, const void *) )
290 if (nmemb
< 2 || size
== 0) return;
291 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
292 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
293 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
296 /*********************************************************************
300 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
301 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
304 ssize_t max
= nmemb
- 1;
308 ssize_t cursor
= min
+ (max
- min
) / 2;
309 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
311 return (char*)base
+(cursor
*size
);
321 /*********************************************************************
324 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
325 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
327 size_t i
, n
= *nmemb
;
330 if (!compar(key
,(char*)base
+(size
*i
)))
331 return (char*)base
+(size
*i
);
335 /******************************************************************************
336 * WinSqmEndSession (NTDLL.@)
338 NTSTATUS WINAPI
WinSqmEndSession(HANDLE session
)
340 FIXME("(%p): stub\n", session
);
341 return STATUS_NOT_IMPLEMENTED
;
344 /*********************************************************************
345 * WinSqmIsOptedIn (NTDLL.@)
347 BOOL WINAPI
WinSqmIsOptedIn(void)
353 /******************************************************************************
354 * WinSqmStartSession (NTDLL.@)
356 HANDLE WINAPI
WinSqmStartSession(GUID
*sessionguid
, DWORD sessionid
, DWORD unknown1
)
358 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid
, sessionid
, unknown1
);
359 return INVALID_HANDLE_VALUE
;
362 /******************************************************************************
363 * EtwEventRegister (NTDLL.@)
365 ULONG WINAPI
EtwEventRegister( LPCGUID provider
, PENABLECALLBACK callback
, PVOID context
,
368 FIXME("(%s, %p, %p, %p) stub.\n", debugstr_guid(provider
), callback
, context
, handle
);
370 *handle
= 0xdeadbeef;
371 return ERROR_SUCCESS
;
374 /******************************************************************************
375 * EtwEventUnregister (NTDLL.@)
377 ULONG WINAPI
EtwEventUnregister( REGHANDLE handle
)
379 FIXME("(%s) stub.\n", wine_dbgstr_longlong(handle
));
380 return ERROR_SUCCESS
;
383 /*********************************************************************
384 * EtwEventSetInformation (NTDLL.@)
386 ULONG WINAPI
EtwEventSetInformation( REGHANDLE handle
, EVENT_INFO_CLASS
class, void *info
,
389 FIXME("(%s, %u, %p, %u) stub\n", wine_dbgstr_longlong(handle
), class, info
, length
);
390 return ERROR_SUCCESS
;
393 /******************************************************************************
394 * EtwRegisterTraceGuidsW (NTDLL.@)
396 * Register an event trace provider and the event trace classes that it uses
397 * to generate events.
400 * RequestAddress [I] ControlCallback function
401 * RequestContext [I] Optional provider-defined context
402 * ControlGuid [I] GUID of the registering provider
403 * GuidCount [I] Number of elements in the TraceGuidReg array
404 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
405 * MofImagePath [I] not supported, set to NULL
406 * MofResourceName [I] not supported, set to NULL
407 * RegistrationHandle [O] Provider's registration handle
410 * Success: ERROR_SUCCESS
411 * Failure: System error code
413 ULONG WINAPI
EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
414 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
415 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const WCHAR
*MofImagePath
,
416 const WCHAR
*MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
418 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
419 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
420 debugstr_w(MofResourceName
), RegistrationHandle
);
425 for (i
= 0; i
< GuidCount
; i
++)
427 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg
[i
].Guid
));
428 TraceGuidReg
[i
].RegHandle
= (HANDLE
)0xdeadbeef;
431 *RegistrationHandle
= (TRACEHANDLE
)0xdeadbeef;
432 return ERROR_SUCCESS
;
435 /******************************************************************************
436 * EtwRegisterTraceGuidsA (NTDLL.@)
438 ULONG WINAPI
EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
439 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
440 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const char *MofImagePath
,
441 const char *MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
443 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
444 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
445 debugstr_a(MofResourceName
), RegistrationHandle
);
446 return ERROR_SUCCESS
;
449 /******************************************************************************
450 * EtwUnregisterTraceGuids (NTDLL.@)
452 ULONG WINAPI
EtwUnregisterTraceGuids( TRACEHANDLE RegistrationHandle
)
454 if (!RegistrationHandle
)
455 return ERROR_INVALID_PARAMETER
;
457 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle
));
458 return ERROR_SUCCESS
;
461 /******************************************************************************
462 * EtwEventEnabled (NTDLL.@)
464 BOOLEAN WINAPI
EtwEventEnabled( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
)
466 FIXME("(%s, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
);
470 /******************************************************************************
471 * EtwEventWrite (NTDLL.@)
473 ULONG WINAPI
EtwEventWrite( REGHANDLE handle
, const EVENT_DESCRIPTOR
*descriptor
, ULONG count
,
474 EVENT_DATA_DESCRIPTOR
*data
)
476 FIXME("(%s, %p, %u, %p): stub\n", wine_dbgstr_longlong(handle
), descriptor
, count
, data
);
477 return ERROR_SUCCESS
;