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"
38 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
40 LPCSTR
debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES
*oa
)
42 if (!oa
) return "<null>";
43 return wine_dbg_sprintf( "{name=%s, attr=0x%08x, hRoot=%p, sd=%p}\n",
44 debugstr_us(oa
->ObjectName
), oa
->Attributes
,
45 oa
->RootDirectory
, oa
->SecurityDescriptor
);
48 LPCSTR
debugstr_us( const UNICODE_STRING
*us
)
50 if (!us
) return "<null>";
51 return debugstr_wn(us
->Buffer
, us
->Length
/ sizeof(WCHAR
));
54 /*********************************************************************
55 * wine_get_version (NTDLL.@)
57 const char * CDECL
NTDLL_wine_get_version(void)
59 return wine_get_version();
62 /*********************************************************************
63 * wine_get_build_id (NTDLL.@)
65 const char * CDECL
NTDLL_wine_get_build_id(void)
67 return wine_get_build_id();
70 /*********************************************************************
71 * wine_get_host_version (NTDLL.@)
73 void CDECL
NTDLL_wine_get_host_version( const char **sysname
, const char **release
)
75 #ifdef HAVE_SYS_UTSNAME_H
76 static struct utsname buf
;
77 static BOOL init_done
;
84 if (sysname
) *sysname
= buf
.sysname
;
85 if (release
) *release
= buf
.release
;
87 if (sysname
) *sysname
= "";
88 if (release
) *release
= "";
92 /*********************************************************************
95 int CDECL
NTDLL_abs( int i
)
100 /*********************************************************************
103 LONG CDECL
NTDLL_labs( LONG i
)
108 /*********************************************************************
111 double CDECL
NTDLL_atan( double d
)
116 /*********************************************************************
119 double CDECL
NTDLL_ceil( double d
)
124 /*********************************************************************
127 double CDECL
NTDLL_cos( double d
)
132 /*********************************************************************
135 double CDECL
NTDLL_fabs( double d
)
140 /*********************************************************************
143 double CDECL
NTDLL_floor( double d
)
148 /*********************************************************************
151 double CDECL
NTDLL_log( double d
)
156 /*********************************************************************
159 double CDECL
NTDLL_pow( double x
, double y
)
164 /*********************************************************************
167 double CDECL
NTDLL_sin( double d
)
172 /*********************************************************************
175 double CDECL
NTDLL_sqrt( double d
)
180 /*********************************************************************
183 double CDECL
NTDLL_tan( double d
)
188 #if defined(__GNUC__) && defined(__i386__)
190 #define FPU_DOUBLE(var) double var; \
191 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var) : )
192 #define FPU_DOUBLES(var1,var2) double var1,var2; \
193 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var2) : ); \
194 __asm__ __volatile__( "fstpl %0;fwait" : "=m" (var1) : )
196 /*********************************************************************
199 double CDECL
NTDLL__CIcos(void)
205 /*********************************************************************
208 double CDECL
NTDLL__CIlog(void)
214 /*********************************************************************
217 double CDECL
NTDLL__CIpow(void)
220 return NTDLL_pow(x
,y
);
223 /*********************************************************************
226 double CDECL
NTDLL__CIsin(void)
232 /*********************************************************************
235 double CDECL
NTDLL__CIsqrt(void)
238 return NTDLL_sqrt(x
);
241 /*********************************************************************
244 LONGLONG CDECL
NTDLL__ftol(void)
250 #endif /* defined(__GNUC__) && defined(__i386__) */
253 NTDLL_mergesort( void *arr
, void *barr
, size_t elemsize
, int(__cdecl
*compar
)(const void *, const void *),
254 size_t left
, size_t right
)
258 m
=left
+(right
-left
)/2;
259 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, left
, m
);
260 NTDLL_mergesort( arr
, barr
, elemsize
, compar
, m
+1, right
);
262 #define X(a,i) ((char*)a+elemsize*(i))
263 for (k
=left
, i
=left
, j
=m
+1; i
<=m
&& j
<=right
; k
++) {
264 if (compar(X(arr
, i
), X(arr
,j
)) <= 0) {
265 memcpy(X(barr
,k
), X(arr
, i
), elemsize
);
268 memcpy(X(barr
,k
), X(arr
, j
), elemsize
);
273 memcpy(X(barr
,k
), X(arr
,i
), (m
-i
+1)*elemsize
);
275 memcpy(X(barr
,k
), X(arr
,j
), (right
-j
+1)*elemsize
);
277 memcpy(X(arr
, left
), X(barr
, left
), (right
-left
+1)*elemsize
);
282 /*********************************************************************
285 void __cdecl
NTDLL_qsort( void *base
, size_t nmemb
, size_t size
,
286 int(__cdecl
*compar
)(const void *, const void *) )
289 if (nmemb
< 2 || size
== 0) return;
290 secondarr
= RtlAllocateHeap (GetProcessHeap(), 0, nmemb
*size
);
291 NTDLL_mergesort( base
, secondarr
, size
, compar
, 0, nmemb
-1 );
292 RtlFreeHeap (GetProcessHeap(),0, secondarr
);
295 /*********************************************************************
299 NTDLL_bsearch( const void *key
, const void *base
, size_t nmemb
,
300 size_t size
, int (__cdecl
*compar
)(const void *, const void *) )
303 ssize_t max
= nmemb
- 1;
307 ssize_t cursor
= min
+ (max
- min
) / 2;
308 int ret
= compar(key
,(const char *)base
+(cursor
*size
));
310 return (char*)base
+(cursor
*size
);
320 /*********************************************************************
323 void * __cdecl
_lfind( const void *key
, const void *base
, unsigned int *nmemb
,
324 size_t size
, int(__cdecl
*compar
)(const void *, const void *) )
326 size_t i
, n
= *nmemb
;
329 if (!compar(key
,(char*)base
+(size
*i
)))
330 return (char*)base
+(size
*i
);
334 /******************************************************************************
335 * WinSqmEndSession (NTDLL.@)
337 NTSTATUS WINAPI
WinSqmEndSession(HANDLE session
)
339 FIXME("(%p): stub\n", session
);
340 return STATUS_NOT_IMPLEMENTED
;
343 /*********************************************************************
344 * WinSqmIsOptedIn (NTDLL.@)
346 BOOL WINAPI
WinSqmIsOptedIn(void)
352 /******************************************************************************
353 * WinSqmStartSession (NTDLL.@)
355 HANDLE WINAPI
WinSqmStartSession(GUID
*sessionguid
, DWORD sessionid
, DWORD unknown1
)
357 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid
, sessionid
, unknown1
);
358 return INVALID_HANDLE_VALUE
;
361 /******************************************************************************
362 * EtwRegisterTraceGuidsW (NTDLL.@)
364 * Register an event trace provider and the event trace classes that it uses
365 * to generate events.
368 * RequestAddress [I] ControlCallback function
369 * RequestContext [I] Optional provider-defined context
370 * ControlGuid [I] GUID of the registering provider
371 * GuidCount [I] Number of elements in the TraceGuidReg array
372 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
373 * MofImagePath [I] not supported, set to NULL
374 * MofResourceName [I] not supported, set to NULL
375 * RegistrationHandle [O] Provider's registration handle
378 * Success: ERROR_SUCCESS
379 * Failure: System error code
381 ULONG WINAPI
EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress
,
382 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
383 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const WCHAR
*MofImagePath
,
384 const WCHAR
*MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
386 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
387 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_w(MofImagePath
),
388 debugstr_w(MofResourceName
), RegistrationHandle
);
393 for (i
= 0; i
< GuidCount
; i
++)
395 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg
[i
].Guid
));
396 TraceGuidReg
[i
].RegHandle
= (HANDLE
)0xdeadbeef;
399 *RegistrationHandle
= (TRACEHANDLE
)0xdeadbeef;
400 return ERROR_SUCCESS
;
403 /******************************************************************************
404 * EtwRegisterTraceGuidsA (NTDLL.@)
406 ULONG WINAPI
EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress
,
407 void *RequestContext
, const GUID
*ControlGuid
, ULONG GuidCount
,
408 TRACE_GUID_REGISTRATION
*TraceGuidReg
, const char *MofImagePath
,
409 const char *MofResourceName
, TRACEHANDLE
*RegistrationHandle
)
411 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress
, RequestContext
,
412 debugstr_guid(ControlGuid
), GuidCount
, TraceGuidReg
, debugstr_a(MofImagePath
),
413 debugstr_a(MofResourceName
), RegistrationHandle
);
414 return ERROR_SUCCESS
;