Added an unknown VxD error code.
[wine] / win32 / newfns.c
1 /*
2  * Win32 miscellaneous functions
3  *
4  * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
5  */
6
7 /* Misc. new functions - they should be moved into appropriate files
8 at a later date. */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/time.h>
13 #include <unistd.h>
14 #include "windef.h"
15 #include "winerror.h"
16 #include "heap.h"
17 #include "debugtools.h"
18
19 DEFAULT_DEBUG_CHANNEL(win32);
20 DECLARE_DEBUG_CHANNEL(debug);
21
22
23 static BOOL     QUERYPERF_Initialized           = 0;
24 #if defined(__i386__) && defined(__GNUC__)
25 static BOOL     QUERYPERF_RDTSC_Use             = 0;
26 static LONGLONG QUERYPERF_RDTSC_Frequency       = 0;
27 #endif
28
29 static void QUERYPERF_Init(void)
30 {
31 #if defined(__i386__) && defined(__GNUC__)
32     /* We are running on i386 and compiling on GCC.
33      * Do a runtime check to see if we have the rdtsc instruction available
34      */
35     FILE                *fp;
36     char                line[256], *s, *value;
37     double              cpuMHz;
38
39     TRACE("()\n");
40     
41     if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE ))
42     {
43         /* rdtsc is available.  However, in order to use it
44          * we also need to be able to get the processor's
45          * speed.  Currently we do this by reading /proc/cpuinfo
46          * which makes it Linux-specific.
47          */
48
49         TRACE("rdtsc available\n");
50
51         fp = fopen( "/proc/cpuinfo", "r" );
52         if (fp)
53         {
54             while(fgets( line, sizeof(line), fp ))
55             {
56                 /* NOTE: the ':' is the only character we can rely on */
57                 if (!(value = strchr( line, ':' )))
58                     continue;
59
60                 /* terminate the valuename */
61                 *value++ = '\0';
62                 /* skip any leading spaces */
63                 while (*value == ' ') value++;
64                 if ((s = strchr( value, '\n' )))
65                     *s = '\0';
66
67                 if (!strncasecmp( line, "cpu MHz", strlen( "cpu MHz" ) ))
68                 {
69                     if (sscanf( value, "%lf", &cpuMHz ) == 1)
70                     {
71                         QUERYPERF_RDTSC_Frequency = (LONGLONG)(cpuMHz * 1000000.0);
72                         QUERYPERF_RDTSC_Use = TRUE;
73                         TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency);
74                         break;
75                     }
76                 }
77             }
78             fclose(fp);
79         }
80     }
81 #endif
82     QUERYPERF_Initialized = TRUE;
83 }
84
85                     
86 /****************************************************************************
87  *              QueryPerformanceCounter (KERNEL32.564)
88  */
89 BOOL WINAPI QueryPerformanceCounter(PLARGE_INTEGER counter)
90 {
91     struct timeval tv;
92
93     if (!QUERYPERF_Initialized)
94         QUERYPERF_Init();
95
96 #if defined(__i386__) && defined(__GNUC__)
97     if (QUERYPERF_RDTSC_Use)
98     {
99         /* i586 optimized version */
100         __asm__ __volatile__ ( "rdtsc"
101                                : "=a" (counter->s.LowPart), "=d" (counter->s.HighPart) );
102         return TRUE;
103     }
104     /* fall back to generic routine (ie, for i386, i486) */
105 #endif
106
107     /* generic routine */
108     gettimeofday( &tv, NULL );
109     counter->QuadPart = (LONGLONG)tv.tv_usec + (LONGLONG)tv.tv_sec * 1000000LL;
110     return TRUE;
111 }
112
113 /****************************************************************************
114  *              QueryPerformanceFrequency (KERNEL32.565)
115  */
116 BOOL WINAPI QueryPerformanceFrequency(PLARGE_INTEGER frequency)
117 {
118     if (!QUERYPERF_Initialized)
119         QUERYPERF_Init();
120
121 #if defined(__i386__) && defined(__GNUC__)
122     if (QUERYPERF_RDTSC_Use)
123     {
124         frequency->QuadPart = QUERYPERF_RDTSC_Frequency;
125         return TRUE;
126     }
127 #endif
128     
129     frequency->s.LowPart        = 1000000;
130     frequency->s.HighPart       = 0;
131     return TRUE;
132 }
133
134 /****************************************************************************
135  *              FlushInstructionCache (KERNEL32.261)
136  */
137 BOOL WINAPI FlushInstructionCache(DWORD x,DWORD y,DWORD z) {
138         FIXME_(debug)("(0x%08lx,0x%08lx,0x%08lx): stub\n",x,y,z);
139         return TRUE;
140 }
141
142 /***********************************************************************
143  *           GetSystemPowerStatus      (KERNEL32.@)
144  */
145 BOOL WINAPI GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr)
146 {
147     return FALSE;   /* no power management support */
148 }
149
150
151 /***********************************************************************
152  *           SetSystemPowerState      (KERNEL32.@)
153  */
154 BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate,
155                                   BOOL force_flag)
156 {
157     /* suspend_or_hibernate flag: w95 does not support
158        this feature anyway */
159
160     for ( ;0; )
161     {
162         if ( force_flag )
163         {
164         }
165         else
166         {
167         }
168     }
169     return TRUE;
170 }
171
172
173 /******************************************************************************
174  * CreateMailslotA [KERNEL32.164]
175  */
176 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
177                                    DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa)
178 {
179     FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName),
180           nMaxMessageSize, lReadTimeout, sa);
181     return 1;
182 }
183
184
185 /******************************************************************************
186  * CreateMailslotW [KERNEL32.165]  Creates a mailslot with specified name
187  * 
188  * PARAMS
189  *    lpName          [I] Pointer to string for mailslot name
190  *    nMaxMessageSize [I] Maximum message size
191  *    lReadTimeout    [I] Milliseconds before read time-out
192  *    sa              [I] Pointer to security structure
193  *
194  * RETURNS
195  *    Success: Handle to mailslot
196  *    Failure: INVALID_HANDLE_VALUE
197  */
198 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
199                                    DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
200 {
201     FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName), 
202           nMaxMessageSize, lReadTimeout, sa);
203     return 1;
204 }
205
206
207 /******************************************************************************
208  * GetMailslotInfo [KERNEL32.347]  Retrieves info about specified mailslot
209  *
210  * PARAMS
211  *    hMailslot        [I] Mailslot handle
212  *    lpMaxMessageSize [O] Address of maximum message size
213  *    lpNextSize       [O] Address of size of next message
214  *    lpMessageCount   [O] Address of number of messages
215  *    lpReadTimeout    [O] Address of read time-out
216  * 
217  * RETURNS
218  *    Success: TRUE
219  *    Failure: FALSE
220  */
221 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
222                                LPDWORD lpNextSize, LPDWORD lpMessageCount,
223                                LPDWORD lpReadTimeout )
224 {
225     FIXME("(%04x): stub\n",hMailslot);
226     if (lpMaxMessageSize) *lpMaxMessageSize = (DWORD)NULL;
227     if (lpNextSize) *lpNextSize = (DWORD)NULL;
228     if (lpMessageCount) *lpMessageCount = (DWORD)NULL;
229     if (lpReadTimeout) *lpReadTimeout = (DWORD)NULL;
230     return TRUE;
231 }
232
233
234 /******************************************************************************
235  * GetCompressedFileSizeA [KERNEL32.291]
236  *
237  * NOTES
238  *    This should call the W function below
239  */
240 DWORD WINAPI GetCompressedFileSizeA(
241     LPCSTR lpFileName,
242     LPDWORD lpFileSizeHigh)
243 {
244     FIXME("(...): stub\n");
245     return 0xffffffff;
246 }
247
248
249 /******************************************************************************
250  * GetCompressedFileSizeW [KERNEL32.292]  
251  * 
252  * RETURNS
253  *    Success: Low-order doubleword of number of bytes
254  *    Failure: 0xffffffff
255  */
256 DWORD WINAPI GetCompressedFileSizeW(
257     LPCWSTR lpFileName,     /* [in]  Pointer to name of file */
258     LPDWORD lpFileSizeHigh) /* [out] Receives high-order doubleword of size */
259 {
260     FIXME("(%s,%p): stub\n",debugstr_w(lpFileName),lpFileSizeHigh);
261     return 0xffffffff;
262 }
263
264
265 /******************************************************************************
266  * SetComputerNameA [KERNEL32.621]  
267  */
268 BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName )
269 {
270     LPWSTR lpComputerNameW = HEAP_strdupAtoW(GetProcessHeap(),0,lpComputerName);
271     BOOL ret = SetComputerNameW(lpComputerNameW);
272     HeapFree(GetProcessHeap(),0,lpComputerNameW);
273     return ret;
274 }
275
276
277 /******************************************************************************
278  * SetComputerNameW [KERNEL32.622]
279  *
280  * PARAMS
281  *    lpComputerName [I] Address of new computer name
282  * 
283  * RETURNS STD
284  */
285 BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName )
286 {
287     FIXME("(%s): stub\n", debugstr_w(lpComputerName));
288     return TRUE;
289 }
290
291 /******************************************************************************
292  *              CreateIoCompletionPort (KERNEL32.@)
293  */
294 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle,
295 HANDLE hExistingCompletionPort, DWORD dwCompletionKey,
296 DWORD dwNumberOfConcurrentThreads)
297 {
298     FIXME("(%04x, %04x, %08lx, %08lx): stub.\n", hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
299     return (HANDLE)NULL;
300 }