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>
30 #include "wine/library.h"
31 #include "wine/debug.h"
32 #include "ntdll_misc.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
38 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
40 if (!oa
) return "<null>";
41 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
42 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
43 oa
->RootDirectory
, oa
->SecurityDescriptor
);
46 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
48 if (!us
) return "<null>";
49 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
52 /*********************************************************************
53 * wine_get_version (NTDLL.@)
55 const char * CDECL
NTDLL_wine_get_version(void)
57 return wine_get_version();
60 /*********************************************************************
61 * wine_get_build_id (NTDLL.@)
63 const char * CDECL
NTDLL_wine_get_build_id(void)
65 return wine_get_build_id();
68 /*********************************************************************
69 * wine_get_host_version (NTDLL.@)
71 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
73 #ifdef HAVE_SYS_UTSNAME_H
74 static struct utsname buf
;
75 static BOOL init_done
;
82 if (sysname
) *sysname
= buf
.sysname
;
83 if (release
) *release
= buf
.release
;
85 if (sysname
) *sysname
= "";
86 if (release
) *release
= "";
90 /*********************************************************************
93 int CDECL
NTDLL_abs( int i
)
98 /*********************************************************************
101 LONG CDECL
NTDLL_labs( LONG i
)
106 /*********************************************************************
109 double CDECL
NTDLL_atan( double d
)
114 /*********************************************************************
117 double CDECL
NTDLL_ceil( double d
)
122 /*********************************************************************
125 double CDECL
NTDLL_cos( double d
)
130 /*********************************************************************
133 double CDECL
NTDLL_fabs( double d
)
138 /*********************************************************************
141 double CDECL
NTDLL_floor( double d
)
146 /*********************************************************************
149 double CDECL
NTDLL_log( double d
)
154 /*********************************************************************
157 double CDECL
NTDLL_pow( double x
, double y
)
162 /*********************************************************************
165 double CDECL
NTDLL_sin( double d
)
170 /*********************************************************************
173 double CDECL
NTDLL_sqrt( double d
)
178 /*********************************************************************
181 double CDECL
NTDLL_tan( double d
)
186 #if defined(__GNUC__) && defined(__i386__)
188 #define FPU_DOUBLE(var) double var; \
189 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
190 #define FPU_DOUBLES(var1,var2) double var1,var2; \
191 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
192 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
194 /*********************************************************************
197 double CDECL
NTDLL__CIcos(void)
203 /*********************************************************************
206 double CDECL
NTDLL__CIlog(void)
212 /*********************************************************************
215 double CDECL
NTDLL__CIpow(void)
218 return NTDLL_pow(x
,y
);
221 /*********************************************************************
224 double CDECL
NTDLL__CIsin(void)
230 /*********************************************************************
233 double CDECL
NTDLL__CIsqrt(void)
236 return NTDLL_sqrt(x
);
239 /*********************************************************************
242 LONGLONG CDECL
NTDLL__ftol(void)
248 #endif /* defined(__GNUC__) && defined(__i386__) */
251 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
252 size_t left
, size_t right
)
256 m
=left
+(right
-left
)/2;
257 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
258 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
260 #define X(a,i) ((char*)a+elemsize*(i))
261 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
262 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
263 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
266 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
271 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
273 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
275 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
280 /*********************************************************************
283 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
284 int(__cdecl
*compar
)(const void *, const void *) )
287 if (nmemb
< 2 || size
== 0) return;
288 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
289 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
290 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
293 /*********************************************************************
297 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
298 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
301 ssize_t max
= nmemb
- 1;
305 ssize_t cursor
= min
+ (max
- min
) / 2;
306 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
308 return (char*)base
+(cursor
*size
);
318 /*********************************************************************
321 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
322 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
324 size_t i
, n
= *nmemb
;
327 if (!compar(key
,(char*)base
+(size
*i
)))
328 return (char*)base
+(size
*i
);
332 /*********************************************************************
333 * WinSqmIsOptedIn (NTDLL.@)
335 BOOL WINAPI
WinSqmIsOptedIn(void)
341 /******************************************************************************
342 * EtwRegisterTraceGuidsW (NTDLL.@)
344 * Register an event trace provider and the event trace classes that it uses
345 * to generate events.
348 * RequestAddress [I] ControlCallback function
349 * RequestContext [I] Optional provider-defined context
350 * ControlGuid [I] GUID of the registering provider
351 * GuidCount [I] Number of elements in the TraceGuidReg array
352 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
353 * MofImagePath [I] not supported, set to NULL
354 * MofResourceName [I] not supported, set to NULL
355 * RegistrationHandle [O] Provider's registration handle
358 * Success: ERROR_SUCCESS
359 * Failure: System error code
361 ULONG WINAPI
EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
362 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
363 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const WCHAR
*MofImagePath
,
364 const WCHAR
*MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
366 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
367 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
368 debugstr_w(MofResourceName
), RegistrationHandle
);
373 for (i
= 0; i
< GuidCount
; i
++)
375 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg
[i
].Guid
));
376 TraceGuidReg
[i
].RegHandle
= (HANDLE
)0xdeadbeef;
379 *RegistrationHandle
= (TRACEHANDLE
)0xdeadbeef;
380 return ERROR_SUCCESS
;
383 /******************************************************************************
384 * EtwRegisterTraceGuidsA (NTDLL.@)
386 ULONG WINAPI
EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
387 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
388 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const char *MofImagePath
,
389 const char *MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
391 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
392 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
393 debugstr_a(MofResourceName
), RegistrationHandle
);
394 return ERROR_SUCCESS
;