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"
35 #if defined(__GNUC__) && defined(__i386__)
36 #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
37 #define POP_FPU(x) DO_FPU("fstpl",x)
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
) / 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
);