Reimplemented DXGrab with improvements; it no longer depends on
[wine] / dlls / ntdll / misc.c
1 /*
2  * Helper functions for ntdll
3  */
4 #include <time.h>
5 #include <math.h>
6
7 #include "config.h"
8
9 #include "debugtools.h"
10 #include "ntdll_misc.h"
11
12 DEFAULT_DEBUG_CHANNEL(ntdll);
13
14 #if defined(__GNUC__) && defined(__i386__)
15 #define DO_FPU(x,y) __asm__ __volatile__( x " %0;fwait" : "=m" (y) : )
16 #define POP_FPU(x) DO_FPU("fstpl",x)
17 #endif
18
19 void dump_ObjectAttributes (const OBJECT_ATTRIBUTES *oa)
20 {
21         if (oa)
22           TRACE("%p:(name=%s, attr=0x%08lx, hRoot=0x%08x, sd=%p) \n",
23             oa, debugstr_us(oa->ObjectName),
24             oa->Attributes, oa->RootDirectory, oa->SecurityDescriptor);
25 }
26
27 void dump_UnicodeString(const UNICODE_STRING *us, BOOLEAN showstring)
28 {
29         if (us)
30         {
31           if (showstring)
32             TRACE("%p %p(%s) (%u %u)\n", us, us->Buffer, debugstr_us(us), us->Length, us->MaximumLength);
33           else
34             TRACE("%p %p(<OUT>) (%u %u)\n", us, us->Buffer, us->Length, us->MaximumLength);
35         }
36 }
37
38 LPCSTR debugstr_as( const STRING *str )
39 {
40     if (!str) return "<null>";
41     return debugstr_an(str->Buffer, str->Length);
42 }
43
44 LPCSTR debugstr_us( const UNICODE_STRING *us )
45 {
46     if (!us) return "<null>";
47     return debugstr_wn(us->Buffer, us->Length);
48 }
49
50 /*********************************************************************
51  *                  _ftol   (NTDLL)
52  *
53  * VERSION
54  *      [GNUC && i386]
55  */
56 #if defined(__GNUC__) && defined(__i386__)
57 LONG __cdecl NTDLL__ftol(void)
58 {
59         /* don't just do DO_FPU("fistp",retval), because the rounding
60          * mode must also be set to "round towards zero"... */
61         double fl;
62         POP_FPU(fl);
63         return (LONG)fl;
64 }
65 #endif /* defined(__GNUC__) && defined(__i386__) */
66
67 /*********************************************************************
68  *                  _ftol   (NTDLL)
69  *
70  * FIXME
71  *      Should be register function
72  * VERSION
73  *      [!GNUC && i386]
74  */
75 #if !defined(__GNUC__) & defined(__i386__)
76 LONG __cdecl NTDLL__ftol(double fl)
77 {
78         FIXME("should be register function\n");
79         return (LONG)fl;
80 }
81 #endif /* !defined(__GNUC__) && defined(__i386__) */
82
83 /*********************************************************************
84  *                  _ftol   (NTDLL)
85  * VERSION
86  *      [!i386]
87  */
88 #ifndef __i386__
89 LONG __cdecl NTDLL__ftol(double fl)
90 {
91         return (LONG) fl;
92 }
93 #endif /* !defined(__i386__) */
94
95 /*********************************************************************
96  *                  _CIpow   (NTDLL)
97  * VERSION
98  *      [GNUC && i386]
99  */
100 #if defined(__GNUC__) && defined(__i386__)
101 double __cdecl NTDLL__CIpow(void)
102 {
103         double x,y;
104         POP_FPU(y);
105         POP_FPU(x);
106         return pow(x,y);
107 }
108 #endif /* defined(__GNUC__) && defined(__i386__) */
109
110
111 /*********************************************************************
112  *                  _CIpow   (NTDLL)
113  *
114  * FIXME
115  *      Should be register function
116  *
117  * VERSION
118  *      [!GNUC && i386]
119  */
120 #if !defined(__GNUC__) && defined(__i386__)
121 double __cdecl NTDLL__CIpow(double x,double y)
122 {
123         FIXME("should be register function\n");
124         return pow(x,y);
125 }
126 #endif /* !defined(__GNUC__) && defined(__i386__) */
127
128 /*********************************************************************
129  *                  _CIpow   (NTDLL)
130  * VERSION
131  *      [!i386]
132  */
133 #ifndef __i386__
134 double __cdecl NTDLL__CIpow(double x,double y)
135 {
136         return pow(x,y);
137 }
138 #endif /* !defined(__i386__) */
139
140