2 * Win32 miscellaneous functions
4 * Copyright 1995 Thomas Sandford (tdgsandf@prds-grn.demon.co.uk)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* Misc. new functions - they should be moved into appropriate files
25 #include "wine/port.h"
29 #ifdef HAVE_SYS_TIME_H
30 # include <sys/time.h>
36 #define NONAMELESSUNION
37 #define NONAMELESSSTRUCT
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(win32
);
45 WINE_DECLARE_DEBUG_CHANNEL(debug
);
48 static BOOL QUERYPERF_Initialized
= 0;
49 #if defined(__i386__) && defined(__GNUC__)
50 static BOOL QUERYPERF_RDTSC_Use
= 0;
51 static LONGLONG QUERYPERF_RDTSC_Frequency
= 0;
54 static void QUERYPERF_Init(void)
56 #if defined(__i386__) && defined(__GNUC__)
57 /* We are running on i386 and compiling on GCC.
58 * Do a runtime check to see if we have the rdtsc instruction available
61 char line
[256], *s
, *value
;
66 if (IsProcessorFeaturePresent( PF_RDTSC_INSTRUCTION_AVAILABLE
))
68 /* rdtsc is available. However, in order to use it
69 * we also need to be able to get the processor's
70 * speed. Currently we do this by reading /proc/cpuinfo
71 * which makes it Linux-specific.
74 TRACE("rdtsc available\n");
76 fp
= fopen( "/proc/cpuinfo", "r" );
79 while(fgets( line
, sizeof(line
), fp
))
81 /* NOTE: the ':' is the only character we can rely on */
82 if (!(value
= strchr( line
, ':' )))
85 /* terminate the valuename */
87 /* skip any leading spaces */
88 while (*value
== ' ') value
++;
89 if ((s
= strchr( value
, '\n' )))
92 if (!strncasecmp( line
, "cpu MHz", strlen( "cpu MHz" ) ))
94 if (sscanf( value
, "%lf", &cpuMHz
) == 1)
96 QUERYPERF_RDTSC_Frequency
= (LONGLONG
)(cpuMHz
* 1000000.0);
97 QUERYPERF_RDTSC_Use
= TRUE
;
98 TRACE("using frequency: %lldHz\n", QUERYPERF_RDTSC_Frequency
);
107 QUERYPERF_Initialized
= TRUE
;
111 /****************************************************************************
112 * QueryPerformanceCounter (KERNEL32.@)
114 BOOL WINAPI
QueryPerformanceCounter(PLARGE_INTEGER counter
)
118 if (!QUERYPERF_Initialized
)
121 #if defined(__i386__) && defined(__GNUC__)
122 if (QUERYPERF_RDTSC_Use
)
124 /* i586 optimized version */
125 __asm__
__volatile__ ( "rdtsc"
126 : "=a" (counter
->s
.LowPart
), "=d" (counter
->s
.HighPart
) );
129 /* fall back to generic routine (ie, for i386, i486) */
132 /* generic routine */
133 gettimeofday( &tv
, NULL
);
134 counter
->QuadPart
= (LONGLONG
)tv
.tv_usec
+ (LONGLONG
)tv
.tv_sec
* 1000000;
138 /****************************************************************************
139 * QueryPerformanceFrequency (KERNEL32.@)
141 BOOL WINAPI
QueryPerformanceFrequency(PLARGE_INTEGER frequency
)
143 if (!QUERYPERF_Initialized
)
146 #if defined(__i386__) && defined(__GNUC__)
147 if (QUERYPERF_RDTSC_Use
)
149 frequency
->QuadPart
= QUERYPERF_RDTSC_Frequency
;
154 frequency
->s
.LowPart
= 1000000;
155 frequency
->s
.HighPart
= 0;
159 /****************************************************************************
160 * FlushInstructionCache (KERNEL32.@)
162 BOOL WINAPI
FlushInstructionCache(HANDLE hProcess
, LPCVOID lpBaseAddress
, SIZE_T dwSize
)
164 if (GetVersion() & 0x80000000) return TRUE
; /* not NT, always TRUE */
165 FIXME_(debug
)("(0x%08lx,%p,0x%08lx): stub\n",(DWORD
)hProcess
, lpBaseAddress
, dwSize
);
169 /***********************************************************************
170 * GetSystemPowerStatus (KERNEL32.@)
172 BOOL WINAPI
GetSystemPowerStatus(LPSYSTEM_POWER_STATUS sps_ptr
)
174 return FALSE
; /* no power management support */
178 /***********************************************************************
179 * SetSystemPowerState (KERNEL32.@)
181 BOOL WINAPI
SetSystemPowerState(BOOL suspend_or_hibernate
,
184 /* suspend_or_hibernate flag: w95 does not support
185 this feature anyway */
200 /******************************************************************************
201 * CreateMailslotA [KERNEL32.@]
203 HANDLE WINAPI
CreateMailslotA( LPCSTR lpName
, DWORD nMaxMessageSize
,
204 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
206 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_a(lpName
),
207 nMaxMessageSize
, lReadTimeout
, sa
);
212 /******************************************************************************
213 * CreateMailslotW [KERNEL32.@] Creates a mailslot with specified name
216 * lpName [I] Pointer to string for mailslot name
217 * nMaxMessageSize [I] Maximum message size
218 * lReadTimeout [I] Milliseconds before read time-out
219 * sa [I] Pointer to security structure
222 * Success: Handle to mailslot
223 * Failure: INVALID_HANDLE_VALUE
225 HANDLE WINAPI
CreateMailslotW( LPCWSTR lpName
, DWORD nMaxMessageSize
,
226 DWORD lReadTimeout
, LPSECURITY_ATTRIBUTES sa
)
228 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName
),
229 nMaxMessageSize
, lReadTimeout
, sa
);
234 /******************************************************************************
235 * GetMailslotInfo [KERNEL32.@] Retrieves info about specified mailslot
238 * hMailslot [I] Mailslot handle
239 * lpMaxMessageSize [O] Address of maximum message size
240 * lpNextSize [O] Address of size of next message
241 * lpMessageCount [O] Address of number of messages
242 * lpReadTimeout [O] Address of read time-out
248 BOOL WINAPI
GetMailslotInfo( HANDLE hMailslot
, LPDWORD lpMaxMessageSize
,
249 LPDWORD lpNextSize
, LPDWORD lpMessageCount
,
250 LPDWORD lpReadTimeout
)
252 FIXME("(%p): stub\n",hMailslot
);
253 if (lpMaxMessageSize
) *lpMaxMessageSize
= (DWORD
)NULL
;
254 if (lpNextSize
) *lpNextSize
= (DWORD
)NULL
;
255 if (lpMessageCount
) *lpMessageCount
= (DWORD
)NULL
;
256 if (lpReadTimeout
) *lpReadTimeout
= (DWORD
)NULL
;
261 /******************************************************************************
262 * GetCompressedFileSizeA [KERNEL32.@]
265 * This should call the W function below
267 DWORD WINAPI
GetCompressedFileSizeA(
269 LPDWORD lpFileSizeHigh
)
271 FIXME("(...): stub\n");
276 /******************************************************************************
277 * GetCompressedFileSizeW [KERNEL32.@]
280 * Success: Low-order doubleword of number of bytes
281 * Failure: 0xffffffff
283 DWORD WINAPI
GetCompressedFileSizeW(
284 LPCWSTR lpFileName
, /* [in] Pointer to name of file */
285 LPDWORD lpFileSizeHigh
) /* [out] Receives high-order doubleword of size */
287 FIXME("(%s,%p): stub\n",debugstr_w(lpFileName
),lpFileSizeHigh
);
292 /******************************************************************************
293 * CreateIoCompletionPort (KERNEL32.@)
295 HANDLE WINAPI
CreateIoCompletionPort(HANDLE hFileHandle
,
296 HANDLE hExistingCompletionPort
, DWORD dwCompletionKey
,
297 DWORD dwNumberOfConcurrentThreads
)
299 FIXME("(%p, %p, %08lx, %08lx): stub.\n", hFileHandle
, hExistingCompletionPort
, dwCompletionKey
, dwNumberOfConcurrentThreads
);
303 /******************************************************************************
304 * GetQueuedCompletionStatus (KERNEL32.@)
306 BOOL WINAPI
GetQueuedCompletionStatus(
307 HANDLE CompletionPort
, LPDWORD lpNumberOfBytesTransferred
,
308 LPDWORD lpCompletionKey
, LPOVERLAPPED
*lpOverlapped
, DWORD dwMilliseconds
310 FIXME("(%p,%p,%p,%p,%ld), stub!\n",CompletionPort
,lpNumberOfBytesTransferred
,lpCompletionKey
,lpOverlapped
,dwMilliseconds
);
311 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
315 /******************************************************************************
316 * GetDevicePowerState (KERNEL32.@)
318 BOOL WINAPI
GetDevicePowerState(HANDLE hDevice
, BOOL
* pfOn
)
320 FIXME("(hDevice %p pfOn %p): stub\n", hDevice
, pfOn
);
321 return TRUE
; /* no information */
324 /***********************************************************************
327 BOOL WINAPI
Beep( DWORD dwFreq
, DWORD dwDur
)
329 static const char beep
= '\a';
330 /* dwFreq and dwDur are ignored by Win95 */
331 if (isatty(2)) write( 2, &beep
, 1 );