mfplat: Make functionality of GetMediaTypeHandler more clear.
[wine.git] / dlls / ntdll / misc.c
blobc29a1c26c26764e38730ebeb7001b40596cbea33
1 /*
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
22 #include "config.h"
24 #include <time.h>
25 #include <math.h>
26 #ifdef HAVE_SYS_UTSNAME_H
27 #include <sys/utsname.h>
28 #endif
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "wine/library.h"
33 #include "wine/debug.h"
34 #include "ntdll_misc.h"
35 #include "wmistr.h"
36 #include "evntrace.h"
37 #include "evntprov.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;
80 if (!init_done)
82 uname( &buf );
83 init_done = TRUE;
85 if (sysname) *sysname = buf.sysname;
86 if (release) *release = buf.release;
87 #else
88 if (sysname) *sysname = "";
89 if (release) *release = "";
90 #endif
93 /*********************************************************************
94 * abs (NTDLL.@)
96 int CDECL NTDLL_abs( int i )
98 return abs( i );
101 /*********************************************************************
102 * labs (NTDLL.@)
104 LONG CDECL NTDLL_labs( LONG i )
106 return labs( i );
109 /*********************************************************************
110 * atan (NTDLL.@)
112 double CDECL NTDLL_atan( double d )
114 return atan( d );
117 /*********************************************************************
118 * ceil (NTDLL.@)
120 double CDECL NTDLL_ceil( double d )
122 return ceil( d );
125 /*********************************************************************
126 * cos (NTDLL.@)
128 double CDECL NTDLL_cos( double d )
130 return cos( d );
133 /*********************************************************************
134 * fabs (NTDLL.@)
136 double CDECL NTDLL_fabs( double d )
138 return fabs( d );
141 /*********************************************************************
142 * floor (NTDLL.@)
144 double CDECL NTDLL_floor( double d )
146 return floor( d );
149 /*********************************************************************
150 * log (NTDLL.@)
152 double CDECL NTDLL_log( double d )
154 return log( d );
157 /*********************************************************************
158 * pow (NTDLL.@)
160 double CDECL NTDLL_pow( double x, double y )
162 return pow( x, y );
165 /*********************************************************************
166 * sin (NTDLL.@)
168 double CDECL NTDLL_sin( double d )
170 return sin( d );
173 /*********************************************************************
174 * sqrt (NTDLL.@)
176 double CDECL NTDLL_sqrt( double d )
178 return sqrt( d );
181 /*********************************************************************
182 * tan (NTDLL.@)
184 double CDECL NTDLL_tan( double d )
186 return tan( 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 /*********************************************************************
198 * _CIcos (NTDLL.@)
200 double CDECL NTDLL__CIcos(void)
202 FPU_DOUBLE(x);
203 return NTDLL_cos(x);
206 /*********************************************************************
207 * _CIlog (NTDLL.@)
209 double CDECL NTDLL__CIlog(void)
211 FPU_DOUBLE(x);
212 return NTDLL_log(x);
215 /*********************************************************************
216 * _CIpow (NTDLL.@)
218 double CDECL NTDLL__CIpow(void)
220 FPU_DOUBLES(x,y);
221 return NTDLL_pow(x,y);
224 /*********************************************************************
225 * _CIsin (NTDLL.@)
227 double CDECL NTDLL__CIsin(void)
229 FPU_DOUBLE(x);
230 return NTDLL_sin(x);
233 /*********************************************************************
234 * _CIsqrt (NTDLL.@)
236 double CDECL NTDLL__CIsqrt(void)
238 FPU_DOUBLE(x);
239 return NTDLL_sqrt(x);
242 /*********************************************************************
243 * _ftol (NTDLL.@)
245 LONGLONG CDECL NTDLL__ftol(void)
247 FPU_DOUBLE(x);
248 return (LONGLONG)x;
251 #endif /* defined(__GNUC__) && defined(__i386__) */
253 static void
254 NTDLL_mergesort( void *arr, void *barr, size_t elemsize, int(__cdecl *compar)(const void *, const void *),
255 size_t left, size_t right )
257 if(right>left) {
258 size_t i, j, k, m;
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);
267 i++;
268 } else {
269 memcpy(X(barr,k), X(arr, j), elemsize);
270 j++;
273 if (i<=m)
274 memcpy(X(barr,k), X(arr,i), (m-i+1)*elemsize);
275 else
276 memcpy(X(barr,k), X(arr,j), (right-j+1)*elemsize);
278 memcpy(X(arr, left), X(barr, left), (right-left+1)*elemsize);
280 #undef X
283 /*********************************************************************
284 * qsort (NTDLL.@)
286 void __cdecl NTDLL_qsort( void *base, size_t nmemb, size_t size,
287 int(__cdecl *compar)(const void *, const void *) )
289 void *secondarr;
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 /*********************************************************************
297 * bsearch (NTDLL.@)
299 void * __cdecl
300 NTDLL_bsearch( const void *key, const void *base, size_t nmemb,
301 size_t size, int (__cdecl *compar)(const void *, const void *) )
303 ssize_t min = 0;
304 ssize_t max = nmemb - 1;
306 while (min <= max)
308 ssize_t cursor = min + (max - min) / 2;
309 int ret = compar(key,(const char *)base+(cursor*size));
310 if (!ret)
311 return (char*)base+(cursor*size);
312 if (ret < 0)
313 max = cursor - 1;
314 else
315 min = cursor + 1;
317 return NULL;
321 /*********************************************************************
322 * _lfind (NTDLL.@)
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;
329 for (i=0;i<n;i++)
330 if (!compar(key,(char*)base+(size*i)))
331 return (char*)base+(size*i);
332 return NULL;
335 /******************************************************************************
336 * WinSqmEndSession (NTDLL.@)
338 NTSTATUS WINAPI WinSqmEndSession(HANDLE session)
340 FIXME("(%p): stub\n", session);
341 return STATUS_NOT_IMPLEMENTED;
344 /*********************************************************************
345 * WinSqmIncrementDWORD (NTDLL.@)
347 void WINAPI WinSqmIncrementDWORD(DWORD unk1, DWORD unk2, DWORD unk3)
349 FIXME("(%d, %d, %d): stub\n", unk1, unk2, unk3);
352 /*********************************************************************
353 * WinSqmIsOptedIn (NTDLL.@)
355 BOOL WINAPI WinSqmIsOptedIn(void)
357 FIXME("(): stub\n");
358 return FALSE;
361 /******************************************************************************
362 * WinSqmStartSession (NTDLL.@)
364 HANDLE WINAPI WinSqmStartSession(GUID *sessionguid, DWORD sessionid, DWORD unknown1)
366 FIXME("(%p, 0x%x, 0x%x): stub\n", sessionguid, sessionid, unknown1);
367 return INVALID_HANDLE_VALUE;
370 /***********************************************************************
371 * WinSqmSetDWORD (NTDLL.@)
373 void WINAPI WinSqmSetDWORD(HANDLE session, DWORD datapoint_id, DWORD datapoint_value)
375 FIXME("(%p, %d, %d): stub\n", session, datapoint_id, datapoint_value);
378 /******************************************************************************
379 * EtwEventActivityIdControl (NTDLL.@)
381 ULONG WINAPI EtwEventActivityIdControl(ULONG code, GUID *guid)
383 static int once;
385 if (!once++) FIXME("0x%x, %p: stub\n", code, guid);
386 return ERROR_SUCCESS;
389 /******************************************************************************
390 * EtwEventProviderEnabled (NTDLL.@)
392 BOOLEAN WINAPI EtwEventProviderEnabled( REGHANDLE handle, UCHAR level, ULONGLONG keyword )
394 FIXME("%s, %u, %s: stub\n", wine_dbgstr_longlong(handle), level, wine_dbgstr_longlong(keyword));
395 return FALSE;
398 /******************************************************************************
399 * EtwEventRegister (NTDLL.@)
401 ULONG WINAPI EtwEventRegister( LPCGUID provider, PENABLECALLBACK callback, PVOID context,
402 PREGHANDLE handle )
404 FIXME("(%s, %p, %p, %p) stub.\n", debugstr_guid(provider), callback, context, handle);
406 if (!handle) return ERROR_INVALID_PARAMETER;
408 *handle = 0xdeadbeef;
409 return ERROR_SUCCESS;
412 /******************************************************************************
413 * EtwEventUnregister (NTDLL.@)
415 ULONG WINAPI EtwEventUnregister( REGHANDLE handle )
417 FIXME("(%s) stub.\n", wine_dbgstr_longlong(handle));
418 return ERROR_SUCCESS;
421 /*********************************************************************
422 * EtwEventSetInformation (NTDLL.@)
424 ULONG WINAPI EtwEventSetInformation( REGHANDLE handle, EVENT_INFO_CLASS class, void *info,
425 ULONG length )
427 FIXME("(%s, %u, %p, %u) stub\n", wine_dbgstr_longlong(handle), class, info, length);
428 return ERROR_SUCCESS;
431 /******************************************************************************
432 * EtwEventWriteString (NTDLL.@)
434 ULONG WINAPI EtwEventWriteString( REGHANDLE handle, UCHAR level, ULONGLONG keyword, PCWSTR string )
436 FIXME("%s, %u, %s, %s: stub\n", wine_dbgstr_longlong(handle), level,
437 wine_dbgstr_longlong(keyword), debugstr_w(string));
438 return ERROR_SUCCESS;
441 /******************************************************************************
442 * EtwEventWriteTransfer (NTDLL.@)
444 ULONG WINAPI EtwEventWriteTransfer( REGHANDLE handle, PCEVENT_DESCRIPTOR descriptor, LPCGUID activity,
445 LPCGUID related, ULONG count, PEVENT_DATA_DESCRIPTOR data )
447 FIXME("%s, %p, %s, %s, %u, %p: stub\n", wine_dbgstr_longlong(handle), descriptor,
448 debugstr_guid(activity), debugstr_guid(related), count, data);
449 return ERROR_SUCCESS;
452 /******************************************************************************
453 * EtwRegisterTraceGuidsW (NTDLL.@)
455 * Register an event trace provider and the event trace classes that it uses
456 * to generate events.
458 * PARAMS
459 * RequestAddress [I] ControlCallback function
460 * RequestContext [I] Optional provider-defined context
461 * ControlGuid [I] GUID of the registering provider
462 * GuidCount [I] Number of elements in the TraceGuidReg array
463 * TraceGuidReg [I/O] Array of TRACE_GUID_REGISTRATION structures
464 * MofImagePath [I] not supported, set to NULL
465 * MofResourceName [I] not supported, set to NULL
466 * RegistrationHandle [O] Provider's registration handle
468 * RETURNS
469 * Success: ERROR_SUCCESS
470 * Failure: System error code
472 ULONG WINAPI EtwRegisterTraceGuidsW( WMIDPREQUEST RequestAddress,
473 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
474 TRACE_GUID_REGISTRATION *TraceGuidReg, const WCHAR *MofImagePath,
475 const WCHAR *MofResourceName, TRACEHANDLE *RegistrationHandle )
477 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
478 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_w(MofImagePath),
479 debugstr_w(MofResourceName), RegistrationHandle);
481 if (TraceGuidReg)
483 ULONG i;
484 for (i = 0; i < GuidCount; i++)
486 FIXME(" register trace class %s\n", debugstr_guid(TraceGuidReg[i].Guid));
487 TraceGuidReg[i].RegHandle = (HANDLE)0xdeadbeef;
490 *RegistrationHandle = (TRACEHANDLE)0xdeadbeef;
491 return ERROR_SUCCESS;
494 /******************************************************************************
495 * EtwRegisterTraceGuidsA (NTDLL.@)
497 ULONG WINAPI EtwRegisterTraceGuidsA( WMIDPREQUEST RequestAddress,
498 void *RequestContext, const GUID *ControlGuid, ULONG GuidCount,
499 TRACE_GUID_REGISTRATION *TraceGuidReg, const char *MofImagePath,
500 const char *MofResourceName, TRACEHANDLE *RegistrationHandle )
502 FIXME("(%p, %p, %s, %u, %p, %s, %s, %p): stub\n", RequestAddress, RequestContext,
503 debugstr_guid(ControlGuid), GuidCount, TraceGuidReg, debugstr_a(MofImagePath),
504 debugstr_a(MofResourceName), RegistrationHandle);
505 return ERROR_SUCCESS;
508 /******************************************************************************
509 * EtwUnregisterTraceGuids (NTDLL.@)
511 ULONG WINAPI EtwUnregisterTraceGuids( TRACEHANDLE RegistrationHandle )
513 if (!RegistrationHandle)
514 return ERROR_INVALID_PARAMETER;
516 FIXME("%s: stub\n", wine_dbgstr_longlong(RegistrationHandle));
517 return ERROR_SUCCESS;
520 /******************************************************************************
521 * EtwEventEnabled (NTDLL.@)
523 BOOLEAN WINAPI EtwEventEnabled( REGHANDLE handle, const EVENT_DESCRIPTOR *descriptor )
525 FIXME("(%s, %p): stub\n", wine_dbgstr_longlong(handle), descriptor);
526 return FALSE;
529 /******************************************************************************
530 * EtwEventWrite (NTDLL.@)
532 ULONG WINAPI EtwEventWrite( REGHANDLE handle, const EVENT_DESCRIPTOR *descriptor, ULONG count,
533 EVENT_DATA_DESCRIPTOR *data )
535 FIXME("(%s, %p, %u, %p): stub\n", wine_dbgstr_longlong(handle), descriptor, count, data);
536 return ERROR_SUCCESS;
539 /******************************************************************************
540 * EtwGetTraceEnableFlags (NTDLL.@)
542 ULONG WINAPI EtwGetTraceEnableFlags( TRACEHANDLE handle )
544 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle));
545 return 0;
548 /******************************************************************************
549 * EtwGetTraceEnableLevel (NTDLL.@)
551 UCHAR WINAPI EtwGetTraceEnableLevel( TRACEHANDLE handle )
553 FIXME("(%s) stub\n", wine_dbgstr_longlong(handle));
554 return TRACE_LEVEL_VERBOSE;
557 /******************************************************************************
558 * EtwGetTraceLoggerHandle (NTDLL.@)
560 TRACEHANDLE WINAPI EtwGetTraceLoggerHandle( PVOID buf )
562 FIXME("(%p) stub\n", buf);
563 return INVALID_PROCESSTRACE_HANDLE;
566 /******************************************************************************
567 * EtwLogTraceEvent (NTDLL.@)
569 ULONG WINAPI EtwLogTraceEvent( TRACEHANDLE SessionHandle, PEVENT_TRACE_HEADER EventTrace )
571 FIXME("%s %p\n", wine_dbgstr_longlong(SessionHandle), EventTrace);
572 return ERROR_CALL_NOT_IMPLEMENTED;
575 /******************************************************************************
576 * EtwTraceMessageVa (NTDLL.@)
578 ULONG WINAPI EtwTraceMessageVa( TRACEHANDLE handle, ULONG flags, LPGUID guid, USHORT number,
579 __ms_va_list args )
581 FIXME("(%s %x %s %d) : stub\n", wine_dbgstr_longlong(handle), flags, debugstr_guid(guid), number);
582 return ERROR_SUCCESS;
585 /******************************************************************************
586 * EtwTraceMessage (NTDLL.@)
588 ULONG WINAPIV EtwTraceMessage( TRACEHANDLE handle, ULONG flags, LPGUID guid, USHORT number, ... )
590 __ms_va_list valist;
591 ULONG ret;
593 __ms_va_start( valist, number );
594 ret = EtwTraceMessageVa( handle, flags, guid, number, valist );
595 __ms_va_end( valist );
596 return ret;
599 NTSTATUS WINAPI NtCreateLowBoxToken(HANDLE *token_handle, HANDLE existing_token_handle, ACCESS_MASK desired_access,
600 OBJECT_ATTRIBUTES *object_attributes, SID *package_sid, ULONG capability_count,
601 SID_AND_ATTRIBUTES *capabilities, ULONG handle_count, HANDLE *handle)
603 FIXME("(%p, %p, %x, %p, %p, %u, %p, %u, %p): stub\n", token_handle, existing_token_handle, desired_access,
604 object_attributes, package_sid, capability_count, capabilities, handle_count, handle);
606 /* We need to return a NULL handle since later it will be passed to CloseHandle and that must not fail */
607 *token_handle = NULL;
608 return STATUS_SUCCESS;
611 /*********************************************************************
612 * ApiSetQueryApiSetPresence (NTDLL.@)
614 BOOL WINAPI ApiSetQueryApiSetPresence(const UNICODE_STRING *namespace, BOOLEAN *present)
616 FIXME("(%s, %p) stub!\n", debugstr_us(namespace), present);
618 if(present)
619 *present = TRUE;
620 return TRUE;