From 136653a6445677a323a9f98f1f7e45526802cb6b Mon Sep 17 00:00:00 2001 From: Trejkaz Date: Wed, 1 May 2013 13:24:31 +1000 Subject: [PATCH] GetLogicalProcessorInformation and associated structs --- .../com/sun/jna/platform/win32/Kernel32.java | 280 ++++++++-------- .../sun/jna/platform/win32/Kernel32Util.java | 90 ++++-- .../src/com/sun/jna/platform/win32/WinNT.java | 304 +++++++++++++++--- .../jna/platform/win32/Kernel32UtilTest.java | 48 +-- 4 files changed, 498 insertions(+), 224 deletions(-) diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java index b65b5c7ad6..4f52bc1073 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java @@ -41,7 +41,7 @@ public interface Kernel32 extends WinNT { * resource based on a message identifier and a language identifier. The * function copies the formatted message text to an output buffer, * processing any embedded insert sequences if requested. - * + * * @param dwFlags * Formatting options, and how to interpret the lpSource * parameter. The low-order byte of dwFlags specifies how the @@ -78,11 +78,11 @@ int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId, * Reads data from the specified file or input/output (I/O) device. Reads * occur at the position specified by the file pointer if supported by the * device. - * + * * This function is designed for both synchronous and asynchronous * operations. For a similar function designed solely for asynchronous * operation, see ReadFileEx - * + * * @param hFile * A handle to the device (for example, a file, file stream, * physical disk, volume, console buffer, tape drive, socket, @@ -103,7 +103,7 @@ int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId, * the function fails, or is completing asynchronously, the return * value is zero (FALSE). To get extended error information, call * the GetLastError function. - * + * * Note The GetLastError code ERROR_IO_PENDING is not a failure; it * designates the read operation is pending completion * asynchronously. For more information, see Remarks. @@ -113,7 +113,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * Frees the specified local memory object and invalidates its handle. - * + * * @param hLocal * A handle to the local memory object. * @return If the function succeeds, the return value is NULL. If the @@ -125,7 +125,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * Frees the specified global memory object and invalidates its handle. - * + * * @param hGlobal * A handle to the global memory object. * @return If the function succeeds, the return value is NULL If the @@ -139,7 +139,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, * The GetModuleHandle function retrieves a module handle for the specified * module if the file has been mapped into the address space of the calling * process. - * + * * @param name * Pointer to a null-terminated string that contains the name of * the module (either a .dll or .exe file). @@ -152,7 +152,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetSystemTime function retrieves the current system date and time. * The system time is expressed in Coordinated Universal Time (UTC). - * + * * @param lpSystemTime * Pointer to a SYSTEMTIME structure to receive the current * system date and time. @@ -161,7 +161,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * Retrieves the current local date and time. - * + * * @param lpSystemTime * A pointer to a SYSTEMTIME structure to receive the current * local date and time. @@ -171,7 +171,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetTickCount function retrieves the number of milliseconds that have * elapsed since the system was started, up to 49.7 days. - * + * * @return Number of milliseconds that have elapsed since the system was * started. */ @@ -180,7 +180,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetCurrentThreadId function retrieves the thread identifier of the * calling thread. - * + * * @return The return value is the thread identifier of the calling thread. */ int GetCurrentThreadId(); @@ -188,14 +188,14 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetCurrentThread function retrieves a pseudo handle for the current * thread. - * + * * @return The return value is a pseudo handle for the current thread. */ HANDLE GetCurrentThread(); /** * This function returns the process identifier of the calling process. - * + * * @return The return value is the process identifier of the calling * process. */ @@ -203,7 +203,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * This function returns a pseudohandle for the current process. - * + * * @return The return value is a pseudohandle to the current process. */ HANDLE GetCurrentProcess(); @@ -211,7 +211,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetProcessId function retrieves the process identifier of the * specified process. - * + * * @param process * Handle to the process. The handle must have the * PROCESS_QUERY_INFORMATION access right. @@ -225,7 +225,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetProcessVersion function retrieves the major and minor version * numbers of the system on which the specified process expects to run. - * + * * @param processId * Process identifier of the process of interest. A value of zero * specifies the calling process. @@ -241,14 +241,14 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * Retrieves the termination status of the specified process. - * + * * @param hProcess * A handle to the process. * @param lpExitCode * A pointer to a variable to receive the process termination * status. * @return If the function succeeds, the return value is nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -256,14 +256,14 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * Terminates the specified process and all of its threads. - * + * * @param hProcess * A handle to the process to be terminated. * @param uExitCode * The exit code to be used by the process and threads terminated * as a result of this call. * @return If the function succeeds, the return value is nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -273,7 +273,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, * The GetLastError function retrieves the calling thread's last-error code * value. The last-error code is maintained on a per-thread basis. Multiple * threads do not overwrite each other's last-error code. - * + * * @return The return value is the calling thread's last-error code value. */ int GetLastError(); @@ -281,7 +281,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The SetLastError function sets the last-error code for the calling * thread. - * + * * @param dwErrCode * Last-error code for the thread. */ @@ -290,7 +290,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, /** * The GetDriveType function determines whether a disk drive is a removable, * fixed, CD-ROM, RAM disk, or network drive. - * + * * @param lpRootPathName * Pointer to a null-terminated string that specifies the root * directory of the disk to return information about. A trailing @@ -310,7 +310,7 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead, * resource based on a message identifier and a language identifier. The * function copies the formatted message text to an output buffer, * processing any embedded insert sequences if requested. - * + * * @param dwFlags * Formatting options, and how to interpret the lpSource * parameter. The low-order byte of dwFlags specifies how the @@ -353,7 +353,7 @@ int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId, * resource based on a message identifier and a language identifier. The * function copies the formatted message text to an output buffer, * processing any embedded insert sequences if requested. - * + * * @param dwFlags * Formatting options, and how to interpret the lpSource * parameter. The low-order byte of dwFlags specifies how the @@ -393,7 +393,7 @@ int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId, * physical disk, volume, console buffer, tape drive, communications * resource, mailslot, or named pipe. The function returns a handle that can * be used to access an object. - * + * * @param lpFileName * A pointer to a null-terminated string that specifies the name * of an object to create or open. @@ -432,30 +432,30 @@ HANDLE CreateFile(String lpFileName, int dwDesiredAccess, int dwShareMode, /** * Copies an existing file to a new file. - * + * * @param lpExistingFileName * The name of an existing file. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. * For more information, see Naming a File. - * + * * If lpExistingFileName does not exist, CopyFile fails, and * GetLastError returns ERROR_FILE_NOT_FOUND. - * + * * @param lpNewFileName * The name of the new file. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. * For more information, see Naming a File. - * + * * @param bFailIfExists * If this parameter is TRUE and the new file specified by * lpNewFileName already exists, the function fails. If this * parameter is FALSE and the new file already exists, the * function overwrites the existing file and succeeds. - * + * * @return If the function succeeds, the return value is nonzero. If the * function fails, the return value is zero. To get extended error * information, call GetLastError. @@ -465,11 +465,11 @@ boolean CopyFile(String lpExistingFileName, String lpNewFileName, /** * Moves an existing file or a directory, including its children. - * + * * @param lpExistingFileName * The current name of the file or directory on the local * computer. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. * For more information, see Naming a File. @@ -477,13 +477,13 @@ boolean CopyFile(String lpExistingFileName, String lpNewFileName, * The new name for the file or directory. The new name must not * already exist. A new file may be on a different file system or * drive. A new directory must be on the same drive. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. * For more information, see Naming a File. * @return true, if successful If the function succeeds, the return value is * nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -492,32 +492,32 @@ boolean CopyFile(String lpExistingFileName, String lpNewFileName, /** * Moves an existing file or directory, including its children, with various * move options. - * + * * @param lpExistingFileName * The current name of the file or directory on the local * computer. - * + * * If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT, the file * cannot exist on a remote share, because delayed operations are * performed before the network is available. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. * For more information, see Naming a File - * + * * Windows 2000: If you prepend the file name with "\\?\", you * cannot also specify the MOVEFILE_DELAY_UNTIL_REBOOT flag for * dwFlags. * @param lpNewFileName * The new name of the file or directory on the local computer. - * + * * When moving a file, the destination can be on a different file * system or volume. If the destination is on another drive, you * must set the MOVEFILE_COPY_ALLOWED flag in dwFlags. - * + * * When moving a directory, the destination must be on the same * drive. - * + * * If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and * lpNewFileName is NULL, MoveFileEx registers the * lpExistingFileName file to be deleted when the system @@ -528,7 +528,7 @@ boolean CopyFile(String lpExistingFileName, String lpNewFileName, * This parameter can be one or more of the following values. * @return true, if successful If the function succeeds, the return value is * nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -539,7 +539,7 @@ boolean MoveFileEx(String lpExistingFileName, String lpNewFileName, * The CreateDirectory function creates a new directory. If the underlying * file system supports security on files and directories, the function * applies a specified security descriptor to the new directory. - * + * * @param lpPathName * Pointer to a null-terminated string that specifies the path of * the directory to be created. @@ -560,11 +560,11 @@ boolean CreateDirectory(String lpPathName, * Reads data from the specified file or input/output (I/O) device. Reads * occur at the position specified by the file pointer if supported by the * device. - * + * * This function is designed for both synchronous and asynchronous * operations. For a similar function designed solely for asynchronous * operation, see ReadFileEx - * + * * @param hFile * A handle to the device (for example, a file, file stream, * physical disk, volume, console buffer, tape drive, socket, @@ -585,7 +585,7 @@ boolean CreateDirectory(String lpPathName, * the function fails, or is completing asynchronously, the return * value is zero (FALSE). To get extended error information, call * the GetLastError function. - * + * * Note The GetLastError code ERROR_IO_PENDING is not a failure; it * designates the read operation is pending completion * asynchronously. For more information, see Remarks. @@ -597,7 +597,7 @@ boolean ReadFile(HANDLE hFile, Pointer lpBuffer, int nNumberOfBytesToRead, * Creates an input/output (I/O) completion port and associates it with a * specified file handle, or creates an I/O completion port that is not yet * associated with a file handle, allowing association at a later time. - * + * * @param FileHandle * An open file handle or INVALID_HANDLE_VALUE. * @param ExistingCompletionPort @@ -628,7 +628,7 @@ HANDLE CreateIoCompletionPort(HANDLE FileHandle, * completion port. If there is no completion packet queued, the function * waits for a pending I/O operation associated with the completion port to * complete. - * + * * @param CompletionPort * A handle to the completion port. * @param lpNumberOfBytes @@ -654,7 +654,7 @@ boolean GetQueuedCompletionStatus(HANDLE CompletionPort, /** * Posts an I/O completion packet to an I/O completion port. - * + * * @param CompletionPort * A handle to an I/O completion port to which the I/O completion * packet is to be posted. @@ -681,7 +681,7 @@ boolean PostQueuedCompletionStatus(HANDLE CompletionPort, * interval elapses. To enter an alertable wait state, use the * WaitForSingleObjectEx function. To wait for multiple objects, use the * WaitForMultipleObjects. - * + * * @param hHandle * A handle to the object. For a list of the object types whose * handles can be specified, see the following Remarks section. @@ -705,7 +705,7 @@ boolean PostQueuedCompletionStatus(HANDLE CompletionPort, * Waits until one or all of the specified objects are in the signaled state * or the time-out interval elapses. To enter an alertable wait state, use * the WaitForMultipleObjectsEx function. - * + * * @param nCount * The number of object handles in the array pointed to by * lpHandles. The maximum number of object handles is @@ -742,7 +742,7 @@ int WaitForMultipleObjects(int nCount, HANDLE[] hHandle, boolean bWaitAll, /** * The DuplicateHandle function duplicates an object handle. - * + * * @param hSourceProcessHandle * Handle to the process with the handle to duplicate. The handle * must have the PROCESS_DUP_HANDLE access right. @@ -775,7 +775,7 @@ boolean DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, /** * The CloseHandle function closes an open object handle. - * + * * @param hObject * Handle to an open object. This parameter can be a pseudo * handle or INVALID_HANDLE_VALUE. @@ -789,7 +789,7 @@ boolean DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, * Retrieves information that describes the changes within the specified * directory. The function does not report changes to the specified * directory itself. Note: there's no ReadDirectoryChangesA. - * + * * @param directory * A handle to the directory to be monitored. This directory must * be opened with the FILE_LIST_DIRECTORY access right. @@ -838,7 +838,7 @@ public boolean ReadDirectoryChangesW(HANDLE directory, /** * Retrieves the short path form of the specified path. - * + * * @param lpszLongPath * The path string. * @param lpdzShortPath @@ -863,11 +863,11 @@ int GetShortPathName(String lpszLongPath, char[] lpdzShortPath, * The LocalAlloc function allocates the specified number of bytes from the * heap. Windows memory management does not provide a separate local heap * and global heap. - * - * @param type + * + * @param uFlags * Memory allocation attributes. The default is the LMEM_FIXED * value. - * @param cbInput + * @param uBytes * Number of bytes to allocate. If this parameter is zero and the * uFlags parameter specifies LMEM_MOVEABLE, the function returns * a handle to a memory object that is marked as discarded. @@ -876,11 +876,11 @@ int GetShortPathName(String lpszLongPath, char[] lpdzShortPath, * value is NULL. To get extended error information, call * GetLastError. */ - Pointer LocalAlloc(int type, int cbInput); + Pointer LocalAlloc(int /* UINT */ uFlags, int /* SIZE_T */ uBytes); /** * Writes data to the specified file or input/output (I/O) device. - * + * * @param hFile * A handle to the file or I/O device (for example, a file, file * stream, physical disk, volume, console buffer, tape drive, @@ -908,7 +908,7 @@ boolean WriteFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToWrite, /** * Creates or opens a named or unnamed event object. - * + * * @param lpEventAttributes * A pointer to a SECURITY_ATTRIBUTES structure. If this * parameter is NULL, the handle cannot be inherited by child @@ -938,7 +938,7 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes, /** * Sets the specified event object to the signaled state. - * + * * @param hEvent * A handle to the event object. The CreateEvent or OpenEvent * function returns this handle. @@ -952,7 +952,7 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes, * Sets the specified event object to the signaled state and then resets it * to the nonsignaled state after releasing the appropriate number of * waiting threads. - * + * * @param hEvent * A handle to the event object. The CreateEvent or OpenEvent * function returns this handle. @@ -965,7 +965,7 @@ HANDLE CreateEvent(WinBase.SECURITY_ATTRIBUTES lpEventAttributes, /** * Creates or opens a named or unnamed file mapping object for a specified * file. - * + * * @param hFile * A handle to the file from which to create a file mapping * object. @@ -1002,7 +1002,7 @@ HANDLE CreateFileMapping(HANDLE hFile, /** * Maps a view of a file mapping into the address space of a calling * process. - * + * * @param hFileMappingObject * A handle to a file mapping object. The CreateFileMapping and * OpenFileMapping functions return this handle. @@ -1026,7 +1026,7 @@ Pointer MapViewOfFile(HANDLE hFileMappingObject, int dwDesiredAccess, /** * Unmaps a mapped view of a file from the calling process's address space. - * + * * @param lpBaseAddress * A pointer to the base address of the mapped view of a file * that is to be unmapped. @@ -1039,7 +1039,7 @@ Pointer MapViewOfFile(HANDLE hFileMappingObject, int dwDesiredAccess, /** * Retrieves only the NetBIOS name of the local computer. - * + * * @param buffer * A pointer to a buffer that receives the computer name or the * cluster virtual server name. The buffer size should be large @@ -1060,7 +1060,7 @@ Pointer MapViewOfFile(HANDLE hFileMappingObject, int dwDesiredAccess, /** * The OpenThread function opens an existing thread object. - * + * * @param dwDesiredAccess * Access to the thread object. This access right is checked * against any security descriptor for the thread. @@ -1080,7 +1080,7 @@ HANDLE OpenThread(int dwDesiredAccess, boolean bInheritHandle, /** * Creates a new process and its primary thread. The new process runs in the * security context of the calling process. - * + * * @param lpApplicationName * The name of the module to be executed. * @param lpCommandLine @@ -1090,20 +1090,20 @@ HANDLE OpenThread(int dwDesiredAccess, boolean bInheritHandle, * whether the returned handle to the new process object can be * inherited by child processes. If lpProcessAttributes is NULL, * the handle cannot be inherited. - * + * * @param lpThreadAttributes * A pointer to a SECURITY_ATTRIBUTES structure that determines * whether the returned handle to the new thread object can be * inherited by child processes. If lpThreadAttributes is NULL, * the handle cannot be inherited. - * + * * @param bInheritHandles * If this parameter TRUE, each inheritable handle in the calling * process is inherited by the new process. If the parameter is * FALSE, the handles are not inherited. Note that inherited * handles have the same value and access rights as the original * handles. - * + * * @param dwCreationFlags * The flags that control the priority class and the creation of * the process. @@ -1111,7 +1111,7 @@ HANDLE OpenThread(int dwDesiredAccess, boolean bInheritHandle, * A pointer to the environment block for the new process. If * this parameter is NULL, the new process uses the environment * of the calling process. - * + * * @param lpCurrentDirectory * The full path to the current directory for the process. * @param lpStartupInfo @@ -1131,7 +1131,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * This function returns a handle to an existing process object. - * + * * @param fdwAccess * Not supported; set to zero. * @param fInherit @@ -1147,7 +1147,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The GetTempPath function retrieves the path of the directory designated * for temporary files. - * + * * @param nBufferLength * Size of the string buffer identified by lpBuffer, in TCHARs. * @param buffer @@ -1159,7 +1159,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, * terminating null character. If the return value is greater than * nBufferLength, the return value is the length, in TCHARs, of the * buffer required to hold the path. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -1168,7 +1168,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The GetVersion function returns the current version number of the * operating system. - * + * * @return If the function succeeds, the return value includes the major and * minor version numbers of the operating system in the low order * word, and information about the operating system platform in the @@ -1179,7 +1179,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The GetVersionEx function obtains extended information about the version * of the operating system that is currently running. - * + * * @param lpVersionInfo * Pointer to an OSVERSIONINFO data structure that the function * fills with operating system version information. @@ -1194,7 +1194,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The GetVersionEx function obtains extended information about the version * of the operating system that is currently running. - * + * * @param lpVersionInfo * Pointer to an OSVERSIONINFOEX data structure that the function * fills with operating system version information. @@ -1208,7 +1208,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The GetSystemInfo function returns information about the current system. - * + * * @param lpSystemInfo * Pointer to a SYSTEM_INFO structure that receives the * information. @@ -1220,7 +1220,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, * system to an application running under WOW64. If the function is called * from a 64-bit application, it is equivalent to the GetSystemInfo * function. - * + * * @param lpSystemInfo * Pointer to a SYSTEM_INFO structure that receives the * information. @@ -1230,7 +1230,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * The IsWow64Process function determines whether the specified process is * running under WOW64. - * + * * @param hProcess * Handle to a process. * @param Wow64Process @@ -1242,10 +1242,22 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, */ boolean IsWow64Process(HANDLE hProcess, IntByReference Wow64Process); + /** + * Retrieves information about logical processors and related hardware. + * + * @param buffer a buffer which receives an array of {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION} structures. + * @param returnLength on input, specifies the length of the buffer in bytes. On output, receives the number of + * bytes actually returned, or if {@link #GetLastError()} returned + * {@link WinError#ERROR_INSUFFICIENT_BUFFER}, the number of bytes wanted for the call to work. + * @return {@code true} on success, {@code false} on failure. To get extended error information, call + * {@link #GetLastError()}. + */ + boolean GetLogicalProcessorInformation(Pointer buffer, DWORDbyReference returnLength); + /** * Retrieves information about the system's current usage of both physical * and virtual memory. - * + * * @param lpBuffer * A pointer to a MEMORYSTATUSEX structure that receives * information about current memory availability. @@ -1258,17 +1270,17 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, /** * Retrieves the date and time that a file or directory was created, last * accessed, and last modified. - * + * * @param hFile * A handle to the file or directory for which dates and times * are to be retrieved. The handle must have been created using * the CreateFile function with the GENERIC_READ access right. - * + * * @param lpCreationTime * A pointer to a FILETIME structure to receive the date and time * the file or directory was created. This parameter can be NULL * if the application does not require this information. - * + * * @param lpLastAccessTime * A pointer to a FILETIME structure to receive the date and time * the file or directory was last accessed. The last access time @@ -1276,7 +1288,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, * read from, or, in the case of executable files, run. This * parameter can be NULL if the application does not require this * information. - * + * * @param lpLastWriteTime * A pointer to a FILETIME structure to receive the date and time * the file or directory was last written to, truncated, or @@ -1284,7 +1296,7 @@ boolean CreateProcess(String lpApplicationName, String lpCommandLine, * This date and time is not updated when file attributes or * security descriptors are changed. This parameter can be NULL * if the application does not require this information. - * + * * @return If the function succeeds, the return value is nonzero. If the * function fails, the return value is zero. To get extended error * information, call GetLastError. @@ -1297,7 +1309,7 @@ boolean GetFileTime(HANDLE hFile, /** * Sets the date and time that the specified file or directory was created, * last accessed, or last modified. - * + * * @param hFile * A handle to the file or directory. The handle must have been * created using the CreateFile function with the @@ -1315,7 +1327,7 @@ boolean GetFileTime(HANDLE hFile, * written to, read from, or (in the case of executable files) * run. This parameter can be NULL if the application does not * need to change this information. - * + * * To preserve the existing last access time for a file even * after accessing a file, call SetFileTime immediately after * opening the file handle with this parameter's FILETIME @@ -1326,7 +1338,7 @@ boolean GetFileTime(HANDLE hFile, * parameter can be NULL if the application does not need to * change this information. * @return If the function succeeds, the return value is nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -1335,18 +1347,18 @@ int SetFileTime(HANDLE hFile, WinBase.FILETIME lpCreationTime, /** * Sets the attributes for a file or directory. - * + * * @param lpFileName * The name of the file whose attributes are to be set. - * + * * The name is limited to MAX_PATH characters. To extend this * limit to 32,767 wide characters, prepend "\\?\" to the path. - * + * * @param dwFileAttributes * The file attributes to set for the file. This parameter can be * one or more values, combined using the bitwise-OR operator. * However, all other values override FILE_ATTRIBUTE_NORMAL. - * + * * @return If the function succeeds, the return value is nonzero. If the * function fails, the return value is zero. To get extended error * information, call GetLastError. @@ -1356,7 +1368,7 @@ int SetFileTime(HANDLE hFile, WinBase.FILETIME lpCreationTime, /** * The GetLogicalDriveStrings function fills a buffer with strings that * specify valid drives in the system. - * + * * @param nBufferLength * Maximum size of the buffer pointed to by lpBuffer, in TCHARs. * This size does not include the terminating null character. If @@ -1382,7 +1394,7 @@ int SetFileTime(HANDLE hFile, WinBase.FILETIME lpCreationTime, * space that is available on a disk volume, which is the total amount of * space, the total amount of free space, and the total amount of free space * available to the user that is associated with the calling thread. - * + * * @param lpDirectoryName * A pointer to a null-terminated string that specifies a * directory on a disk. If this parameter is NULL, the function @@ -1415,7 +1427,7 @@ boolean GetDiskFreeSpaceEx(String lpDirectoryName, /** * Deletes an existing file. - * + * * @param filename * The name of the file to be deleted. * @return If the function succeeds, the return value is nonzero. If the @@ -1427,7 +1439,7 @@ boolean GetDiskFreeSpaceEx(String lpDirectoryName, /** * Creates an anonymous pipe, and returns handles to the read and write ends * of the pipe. - * + * * @param hReadPipe * A pointer to a variable that receives the read handle for the * pipe. @@ -1450,7 +1462,7 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, /** * Sets certain properties of an object handle. - * + * * @param hObject * A handle to an object whose information is to be set. * @param dwMask @@ -1467,7 +1479,7 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, /** * Retrieves file system attributes for a specified file or directory. - * + * * @param lpFileName * The name of the file or directory. Prepend \\?\ to the path * for names up to 32,767 wide characters @@ -1478,7 +1490,7 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, /** * Retrieves the file type of the specified file. - * + * * @param hFile * A handle to the file. * @return FILE_TYPE_UNKNOWN if the function fails, or if the type is @@ -1494,13 +1506,13 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, /** * Sends a control code directly to a specified device driver, causing the * corresponding device to perform the corresponding operation. - * + * * @param hDevice * A handle to the device on which the operation is to be * performed. The device is typically a volume, directory, file, * or stream. To retrieve a device handle, use the CreateFile * function. For more information, see Remarks. - * + * * @param dwIoControlCode * The control code for the operation. This value identifies the * specific operation to be performed and the type of device on @@ -1508,27 +1520,27 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, * Remarks. The documentation for each control code provides * usage details for the lpInBuffer, nInBufferSize, lpOutBuffer, * and nOutBufferSize parameters. - * + * * @param lpInBuffer * A pointer to the input buffer that contains the data required * to perform the operation. The format of this data depends on * the value of the dwIoControlCode parameter. This parameter can * be NULL if dwIoControlCode specifies an operation that does * not require input data. - * + * * @param nInBufferSize * The size of the input buffer, in bytes. - * + * * @param lpOutBuffer * A pointer to the output buffer that is to receive the data * returned by the operation. The format of this data depends on * the value of the dwIoControlCode parameter. This parameter can * be NULL if dwIoControlCode specifies an operation that does * not return data. - * + * * @param nOutBufferSize * The size of the output buffer, in bytes. - * + * * @param lpBytesReturned * A pointer to a variable that receives the size of the data * stored in the output buffer, in bytes. If the output buffer is @@ -1552,7 +1564,7 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, * is associated with an I/O completion port, you can retrieve * the number of bytes returned by calling * GetQueuedCompletionStatus. - * + * * @param lpOverlapped * A pointer to an OVERLAPPED structure. If hDevice was opened * without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is @@ -1566,9 +1578,9 @@ public boolean CreatePipe(HANDLEByReference hReadPipe, * operation has been completed. Otherwise, the function does not * return until the operation has been completed or an error * occurs. - * + * * @return If the function succeeds, the return value is nonzero. - * + * * If the function fails, the return value is zero. To get extended * error information, call GetLastError. */ @@ -1582,7 +1594,7 @@ boolean DeviceIoControl(HANDLE hDevice, int dwIoControlCode, * disk volume, which is the total amount of space, the total amount of free * space, and the total amount of free space available to the user that is * associated with the calling thread. - * + * * @param lpDirectoryName * the lp directory name * @param lpFreeBytesAvailable @@ -1592,7 +1604,7 @@ boolean DeviceIoControl(HANDLE hDevice, int dwIoControlCode, * @param lpTotalNumberOfFreeBytes * the lp total number of free bytes * @return If the function succeeds, the return value is nonzero. - * + * * If the function fails, the return value is zero (0). To get * extended error information, call GetLastError. */ @@ -1604,10 +1616,10 @@ boolean GetDiskFreeSpaceEx(String lpDirectoryName, /** * Takes a snapshot of the specified processes, as well as the heaps, * modules, and threads used by these processes. - * + * * @param dwFlags * The portions of the system to be included in the snapshot. - * + * * @param th32ProcessID * The process identifier of the process to be included in the * snapshot. This parameter can be zero to indicate the current @@ -1615,19 +1627,19 @@ boolean GetDiskFreeSpaceEx(String lpDirectoryName, * TH32CS_SNAPMODULE, TH32CS_SNAPMODULE32, or TH32CS_SNAPALL * value is specified. Otherwise, it is ignored and all processes * are included in the snapshot. - * + * * If the specified process is the Idle process or one of the * CSRSS processes, this function fails and the last error code * is ERROR_ACCESS_DENIED because their access restrictions * prevent user-level code from opening them. - * + * * If the specified process is a 64-bit process and the caller is * a 32-bit process, this function fails and the last error code * is ERROR_PARTIAL_COPY (299). - * + * * @return If the function succeeds, it returns an open handle to the * specified snapshot. - * + * * If the function fails, it returns INVALID_HANDLE_VALUE. To get * extended error information, call GetLastError. Possible error * codes include ERROR_BAD_LENGTH. @@ -1637,7 +1649,7 @@ boolean GetDiskFreeSpaceEx(String lpDirectoryName, /** * Retrieves information about the first process encountered in a system * snapshot. - * + * * @param hSnapshot * A handle to the snapshot returned from a previous call to the * CreateToolhelp32Snapshot function. @@ -1658,7 +1670,7 @@ boolean Process32First(HANDLE hSnapshot, /** * Retrieves information about the next process recorded in a system * snapshot. - * + * * @param hSnapshot * A handle to the snapshot returned from a previous call to the * CreateToolhelp32Snapshot function. @@ -1676,7 +1688,7 @@ boolean Process32Next(HANDLE hSnapshot, /** * The SetEnvironmentVariable function sets the contents of the specified * environment variable for the current process. - * + * * @param lpName * Pointer to a string containing the name of the environment * variable to set. @@ -1684,7 +1696,7 @@ boolean Process32Next(HANDLE hSnapshot, * Pointer to a string containing the value to set it to. if this * value is NULL, the variable is deleted from the current * process' environment. - * + * * @return If the function succeeds, the return value is non-zero. If the * function fails, the return value is zero. To get extended error * information, call GetLastError. @@ -1694,7 +1706,7 @@ boolean Process32Next(HANDLE hSnapshot, /** * Retrieves the contents of the specified variable from the environment * block of the calling process. - * + * * @param lpName * The name of the environment variable. * @param lpBuffer @@ -1718,7 +1730,7 @@ boolean Process32Next(HANDLE hSnapshot, /** * Returns the locale identifier for the system locale. - * + * * @return Returns the locale identifier for the system default locale, * identified by LOCALE_SYSTEM_DEFAULT. */ @@ -1726,7 +1738,7 @@ boolean Process32Next(HANDLE hSnapshot, /** * Returns the locale identifier for the user default locale. - * + * * @return Returns the locale identifier for the user default locale, * represented as LOCALE_USER_DEFAULT. If the user default locale is * a custom locale, this function always returns @@ -1757,7 +1769,7 @@ boolean Process32Next(HANDLE hSnapshot, /** * Retrieves a string from the specified section in an initialization file. - * + * * @param lpAppName * The name of the section containing the key name. If this parameter is {@code null}, the {@link #GetPrivateProfileString} function copies all * section names in the file to the supplied buffer. @@ -1793,12 +1805,12 @@ boolean Process32Next(HANDLE hSnapshot, *

*/ DWORD GetPrivateProfileString(String lpAppName, String lpKeyName, String lpDefault, char[] lpReturnedString, DWORD nSize, String lpFileName); - + /** * Copies a string into the specified section of an initialization file. - * + * * If the file was created using Unicode characters, the function writes Unicode characters to the file. Otherwise, the function writes ANSI characters. - * + * * @param lpAppName * The name of the section to which the string will be copied. If the section does not exist, it is created. The name of the section is * case-independent; the string can be any combination of uppercase and lowercase letters. diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java index 9a93575fb2..2185f90897 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java @@ -1,14 +1,14 @@ /* Copyright (c) 2010, 2013 Daniel Doubrovkine, Markus Karg, All Rights Reserved - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * Lesser General Public License for more details. */ package com.sun.jna.platform.win32; @@ -18,6 +18,7 @@ import java.util.List; import com.sun.jna.LastErrorException; +import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.platform.win32.WinNT.HANDLEByReference; @@ -31,10 +32,10 @@ * @author markus[at]headcrashing[dot]eu */ public abstract class Kernel32Util implements WinDef { - + /** * Get current computer NetBIOS name. - * @return + * @return * Netbios name. */ public static String getComputerName() { @@ -45,7 +46,7 @@ public static String getComputerName() { } return Native.toString(buffer); } - + /** * Format a message from an HRESULT. * @param code @@ -54,24 +55,24 @@ public static String getComputerName() { * Formatted message. */ public static String formatMessageFromHR(HRESULT code) { - PointerByReference buffer = new PointerByReference(); + PointerByReference buffer = new PointerByReference(); if (0 == Kernel32.INSTANCE.FormatMessage( WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER - | WinBase.FORMAT_MESSAGE_FROM_SYSTEM - | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS, + | WinBase.FORMAT_MESSAGE_FROM_SYSTEM + | WinBase.FORMAT_MESSAGE_IGNORE_INSERTS, null, - code.intValue(), + code.intValue(), 0, // TODO: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) - buffer, - 0, + buffer, + 0, null)) { throw new LastErrorException(Kernel32.INSTANCE.GetLastError()); - } + } String s = buffer.getValue().getString(0, ! Boolean.getBoolean("w32.ascii")); Kernel32.INSTANCE.LocalFree(buffer.getValue()); - return s.trim(); + return s.trim(); } - + /** * Format a system message from an error code. * @param code @@ -82,7 +83,7 @@ public static String formatMessageFromHR(HRESULT code) { public static String formatMessageFromLastErrorCode(int code) { return formatMessageFromHR(W32Errors.HRESULT_FROM_WIN32(code)); } - + /** * Return the path designated for temporary files. * @return @@ -90,19 +91,19 @@ public static String formatMessageFromLastErrorCode(int code) { */ public static String getTempPath() { DWORD nBufferLength = new DWORD(WinDef.MAX_PATH); - char[] buffer = new char[nBufferLength.intValue()]; + char[] buffer = new char[nBufferLength.intValue()]; if (Kernel32.INSTANCE.GetTempPath(nBufferLength, buffer).intValue() == 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } return Native.toString(buffer); } - + public static void deleteFile(String filename) { if (! Kernel32.INSTANCE.DeleteFile(filename)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } } - + /** * Returns valid drives in the system. * @return @@ -113,14 +114,14 @@ public static String[] getLogicalDriveStrings() { if (dwSize.intValue() <= 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } - + char buf[] = new char[dwSize.intValue()]; dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf); if (dwSize.intValue() <= 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } - List drives = new ArrayList(); + List drives = new ArrayList(); String drive = ""; // the buffer is double-null-terminated for(int i = 0; i < buf.length - 1; i++) { @@ -132,8 +133,8 @@ public static String[] getLogicalDriveStrings() { } } return drives.toArray(new String[0]); - } - + } + /** * Retrieves file system attributes for a specified file or directory. * @param fileName @@ -202,12 +203,12 @@ public static int getFileType(String fileName) throws FileNotFoundException { public static int getDriveType(String rootName) { return Kernel32.INSTANCE.GetDriveType(rootName); } - + /** * Get the value of an environment variable. * @param name * Name of the environment variable. - * @return + * @return * Value of an environment variable. */ public static String getEnvironmentVariable(String name) { @@ -248,7 +249,7 @@ public static final int getPrivateProfileInt(final String appName, final String /** * Retrieves a string from the specified section in an initialization file. - * + * * @param lpAppName * The name of the section containing the key name. If this parameter is {@code null}, the {@link Kernel32#GetPrivateProfileString} function copies all * section names in the file to the supplied buffer. @@ -288,4 +289,41 @@ public static final void writePrivateProfileString(final String appName, final S if (!Kernel32.INSTANCE.WritePrivateProfileString(appName, keyName, string, fileName)) throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } + + /** + * Convenience method to get the processor information. Takes care of auto-growing the array. + * + * @return the array of processor information. + */ + public static final WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] getLogicalProcessorInformation() + { + int sizePerStruct = new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION().size(); + WinDef.DWORDbyReference bufferSize = new WinDef.DWORDbyReference(new WinDef.DWORD(sizePerStruct)); + Memory memory; + while (true) + { + memory = new Memory(bufferSize.getValue().intValue()); + if (!Kernel32.INSTANCE.GetLogicalProcessorInformation(memory, bufferSize)) + { + int lastError = Kernel32.INSTANCE.GetLastError(); + if (Kernel32.INSTANCE.GetLastError() == WinError.ERROR_INSUFFICIENT_BUFFER) + { + // Back around - will reallocate a buffer with the new size we were told to use. + } + else + { + throw new LastErrorException(lastError); + } + } + else + { + // Success exit. + break; + } + } + + WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION firstInformation = new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION(memory); + int returnedStructCount = bufferSize.getValue().intValue() / sizePerStruct; + return (WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]) firstInformation.toArray(new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[returnedStructCount]); + } } diff --git a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java index 4469b38af8..fe4b812c67 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinNT.java @@ -1,14 +1,14 @@ /* Copyright (c) 2007 Timothy Wall, All Rights Reserved - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * Lesser General Public License for more details. */ package com.sun.jna.platform.win32; @@ -30,7 +30,7 @@ * by NT, but exposed through the Win32 API. Ported from WinNT.h Microsoft * Windows SDK 6.0A. Avoid including any NIO Buffer mappings here; put them in a * DLL-derived interface (e.g. kernel32, user32, etc) instead. - * + * * @author dblock[at]dblock.org */ @SuppressWarnings("serial") @@ -251,7 +251,7 @@ public static class LUID_AND_ATTRIBUTES extends Structure { protected List getFieldOrder() { return Arrays.asList(new String[] { "Luid", "Attributes" }); } - + public LUID_AND_ATTRIBUTES() { } @@ -266,11 +266,11 @@ public LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes) { * and its attributes. SIDs are used to uniquely identify users or groups. */ public static class SID_AND_ATTRIBUTES extends Structure { - + protected List getFieldOrder() { return Arrays.asList(new String[] { "Sid", "Attributes" }); } - + public SID_AND_ATTRIBUTES() { super(); } @@ -296,11 +296,11 @@ public SID_AND_ATTRIBUTES(Pointer memory) { * (SID) that will be applied to newly created objects. */ public static class TOKEN_OWNER extends Structure { - + protected List getFieldOrder() { return Arrays.asList(new String[] { "Owner" }); } - + public TOKEN_OWNER() { super(); } @@ -324,9 +324,9 @@ public TOKEN_OWNER(Pointer memory) { public static class PSID extends Structure { public static class ByReference extends PSID implements Structure.ByReference { } - - protected List getFieldOrder() { - return Arrays.asList(new String[] { "sid" }); + + protected List getFieldOrder() { + return Arrays.asList(new String[] { "sid" }); } public PSID() { @@ -386,11 +386,11 @@ public PSID getValue() { * token. */ public static class TOKEN_USER extends Structure { - + protected List getFieldOrder() { return Arrays.asList(new String[] { "User" }); } - + public TOKEN_USER() { super(); } @@ -417,11 +417,11 @@ public TOKEN_USER(int size) { * identifiers (SIDs) in an access token. */ public static class TOKEN_GROUPS extends Structure { - + protected List getFieldOrder() { return Arrays.asList(new String[] { "GroupCount", "Group0" }); } - + public TOKEN_GROUPS() { super(); } @@ -465,7 +465,7 @@ public static class TOKEN_PRIVILEGES extends Structure { * contains the LUID and attributes of a privilege. */ public LUID_AND_ATTRIBUTES Privileges[]; - + protected List getFieldOrder() { return Arrays.asList(new String[] { "PrivilegeCount", "Privileges" }); } @@ -679,7 +679,7 @@ public abstract class SID_NAME_USE { /** * The FILE_NOTIFY_INFORMATION structure describes the changes found by the * ReadDirectoryChangesW function. - * + * * This structure is non-trivial since it is a pattern stamped into a large * block of result memory rather than something that stands alone or is used * for input. @@ -690,7 +690,7 @@ public static class FILE_NOTIFY_INFORMATION extends Structure { public int FileNameLength; // filename is not nul-terminated, so we can't use a String/WString public char[] FileName = new char[1]; - + protected List getFieldOrder() { return Arrays.asList(new String[] { "NextEntryOffset", "Action", "FileNameLength", "FileName" }); } @@ -946,7 +946,7 @@ public FILE_NOTIFY_INFORMATION next() { int REG_FULL_RESOURCE_DESCRIPTOR = 9; /** - * + * */ int REG_RESOURCE_REQUIREMENTS_LIST = 10; @@ -994,14 +994,14 @@ public static class UNION extends Union { } public UNION u; - + protected List getFieldOrder() { return Arrays.asList(new String[] { "u" }); } /** * Low DWORD. - * + * * @return DWORD. */ public DWORD getLow() { @@ -1010,7 +1010,7 @@ public DWORD getLow() { /** * High DWORD. - * + * * @return DWORD. */ public DWORD getHigh() { @@ -1019,7 +1019,7 @@ public DWORD getHigh() { /** * 64-bit value. - * + * * @return 64-bit value. */ public long getValue() { @@ -1435,72 +1435,72 @@ public abstract class WELL_KNOWN_SID_TYPE { public static final int WinBuiltinTerminalServerLicenseServersSid = 60; /** - * + * */ public static final int WinBuiltinDCOMUsersSid = 61; /** - * + * */ public static final int WinBuiltinIUsersSid = 62; /** - * + * */ public static final int WinIUserSid = 63; /** - * + * */ public static final int WinBuiltinCryptoOperatorsSid = 64; /** - * + * */ public static final int WinUntrustedLabelSid = 65; /** - * + * */ public static final int WinLowLabelSid = 66; /** - * + * */ public static final int WinMediumLabelSid = 67; /** - * + * */ public static final int WinHighLabelSid = 68; /** - * + * */ public static final int WinSystemLabelSid = 69; /** - * + * */ public static final int WinWriteRestrictedCodeSid = 70; /** - * + * */ public static final int WinCreatorOwnerRightsSid = 71; /** - * + * */ public static final int WinCacheablePrincipalsGroupSid = 72; /** - * + * */ public static final int WinNonCacheablePrincipalsGroupSid = 73; /** - * + * */ public static final int WinEnterpriseReadonlyControllersSid = 74; @@ -1572,7 +1572,7 @@ public static class OSVERSIONINFO extends Structure { protected List getFieldOrder() { return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion" }); } - + public OSVERSIONINFO() { szCSDVersion = new char[128]; dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO) @@ -1657,7 +1657,7 @@ public static class OSVERSIONINFOEX extends Structure { protected List getFieldOrder() { return Arrays.asList(new String[] { "dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion", "wServicePackMajor", "wServicePackMinor", "wSuiteMask", "wProductType", "wReserved"}); } - + public OSVERSIONINFOEX() { szCSDVersion = new char[128]; dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX) @@ -1862,7 +1862,7 @@ public static class EVENTLOGRECORD extends Structure { protected List getFieldOrder() { return Arrays.asList(new String[] { "Length", "Reserved", "RecordNumber", "TimeGenerated", "TimeWritten", "EventID", "EventType", "NumStrings", "EventCategory", "ReservedFlags", "ClosingRecordNumber", "StringOffset", "UserSidLength", "UserSidOffset", "DataLength", "DataOffset"}); } - + public EVENTLOGRECORD() { } @@ -1960,18 +1960,18 @@ public SECURITY_DESCRIPTOR(Pointer memory) { } public byte[] data; - + protected List getFieldOrder() { return Arrays.asList(new String[] { "data" }); } } public static class ACL extends Structure { - + protected List getFieldOrder() { return Arrays.asList(new String[] { "AclRevision", "Sbz1", "AclSize", "AceCount", "Sbz2" }); } - + public ACL() { } @@ -2030,7 +2030,7 @@ public static class ByReference extends SECURITY_DESCRIPTOR_RELATIVE protected List getFieldOrder() { return Arrays.asList(new String[] { "Revision", "Sbz1", "Control", "Owner", "Group", "Sacl", "Dacl" }); } - + private ACL DACL; public SECURITY_DESCRIPTOR_RELATIVE() { @@ -2070,7 +2070,7 @@ public ACEStructure() { } public ACEStructure(Pointer p) { super(p); } - + protected List getFieldOrder() { return Arrays.asList(new String[] { "AceType", "AceFlags", "AceSize" }); } @@ -2172,4 +2172,216 @@ interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback { void callback(int errorCode, int nBytesTransferred, WinBase.OVERLAPPED overlapped); } + + /** + * Describes the relationship between the specified processor set. This structure is used with the + * {@link Kernel32#GetLogicalProcessorInformation} function. + */ + public static class SYSTEM_LOGICAL_PROCESSOR_INFORMATION extends Structure { + /** + * The processor mask identifying the processors described by this structure. A processor mask is a bit + * vector in which each set bit represents an active processor in the relationship. + */ + public ULONG_PTR processorMask; + + /** + * The relationship between the processors identified by the value of the {@link #processorMask} member. + * This member can be one of + * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache}, + * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode}, + * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCore} or + * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationPackage}. + * + * @see LOGICAL_PROCESSOR_RELATIONSHIP + */ + public int /* LOGICAL_PROCESSOR_RELATIONSHIP */ relationship; + + /** + * A union of fields which differs depending on {@link #relationship}. + */ + public AnonymousUnionPayload payload; + + public SYSTEM_LOGICAL_PROCESSOR_INFORMATION() { + super(ALIGN_MSVC); + } + + public SYSTEM_LOGICAL_PROCESSOR_INFORMATION(Pointer memory) { + super(memory, ALIGN_MSVC); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "processorMask", "relationship", "payload" }); + } + + public static class AnonymousUnionPayload extends Union { + /** + * Contains valid data only if {@link #relationship} is {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCore}. + */ + public AnonymousStructProcessorCore processorCore; + + /** + * Contains valid data only if {@link #relationship} is {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationNumaNode}. + */ + public AnonymousStructNumaNode numaNode; + + /** + *

Identifies the characteristics of a particular cache. There is one record returned for each cache + * reported. Some or all caches may not be reported, depending on how caches are identified. Therefore, + * do not assume the absence of any particular caches. Caches are not necessarily shared among + * logical processors.

+ * + *

Contains valid data only if {@link #relationship} is + * {@link LOGICAL_PROCESSOR_RELATIONSHIP#RelationCache}.

+ * + *

This member was not supported until Windows Server 2003 SP1 / Windows XP Professional x64.

+ */ + public CACHE_DESCRIPTOR cache; + + /** + * Reserved. Do not use. + */ + public ULONGLONG[] reserved = new ULONGLONG[2]; + } + + public static class AnonymousStructProcessorCore extends Structure { + /** + *

If the value of this mmeber is {@code 1}, the logical processors identified by the value of the + * {@link #processorMask} member share functional units, as in Hyperthreading or SMT. Otherwise, the + * identified logical processors do not share functional units.

+ * + *

Note: Prior to Windows Vista, this member is also {@code 1} for cores that share a physical + * package.

+ */ + public BYTE flags; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "flags" }); + } + } + + public static class AnonymousStructNumaNode extends Structure { + /** + * Identifies the NUMA node. Valid values are {@code 0} to the highest NUMA node number inclusive. + * A non-NUMA multiprocessor system will report that all processors belong to one NUMA node. + */ + public DWORD nodeNumber; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "nodeNumber" }); + } + } + } + + /** + * Represents the relationship between the processor set identified in the corresponding + * {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION} or {@link SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX} structure. + */ + public static abstract class LOGICAL_PROCESSOR_RELATIONSHIP { + /** + * The specified logical processors share a single processor core. + */ + public static final int RelationProcessorCore = 0; + + /** + * The specified logical processors are part of the same NUMA node. + */ + public static final int RelationNumaNode = 1; + + /** + *

The specified logical processors share a cache.

+ * + *

Not supported until Windows Server 2003 SP1 / Windows XP Professional x64.

+ */ + public static final int RelationCache = 2; + + /** + *

The specified logical processors share a physical package (a single package socketed or soldered onto a + * motherboard may contain multiple processor cores or threads, each of which is treated as a separate + * processor by the operating system.)

+ * + *

Not supported until Windows Server 2003 SP1 / Windows XP Professional x64.

+ */ + public static final int RelationProcessorPackage = 3; + + /** + *

The specified logical processors share a single processor group.

+ * + *

Not supported until Windows Server 2008 R2.

+ */ + public static final int RelationGroup = 4; + + /** + *

On input, retrieves information about all possible relation types. This value is not used on output.

+ * + *

Not supported until Windows Server 2008 R2.

+ */ + public static final int RelationAll = 0xFFFF; + } + + /** + * Describes the cache attributes. + */ + public static class CACHE_DESCRIPTOR extends Structure { + /** + * The cache level. This member can be 1, 2 or 3, corresponding to L1, L2 or L3 cache, respectively (other + * values may be supported in the future.) + */ + public BYTE level; + + /** + * The cache associativity. If this member is {@link #CACHE_FULLY_ASSOCIATIVE}, the cache is fully + * associative. + */ + public BYTE associativity; + + /** + * The cache line size, in bytes. + */ + public WORD lineSize; + + /** + * The cache size, in bytes. + */ + public DWORD size; + + /** + * The cache type. + * + * @see PROCESSOR_CACHE_TYPE + */ + public int /* PROCESSOR_CACHE_TYPE */ type; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "level", "associativity", "lineSize", "size", "type" }); + } + } + + /** + * Represents the type of processor cache identifier in the corresponding {@link CACHE_DESCRIPTOR} structure. + */ + public static abstract class PROCESSOR_CACHE_TYPE { + /** + * The cache is unified. + */ + public static int CacheUnified = 0; + + /** + * The cache is for processor instructions. + */ + public static int CacheInstruction = 1; + + /** + * The cache is for data. + */ + public static int CacheData = 2; + + /** + * The cache is for traces. + */ + public static int CacheTrace = 3; + } } diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java index eb540e431d..9736811134 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java @@ -1,16 +1,16 @@ /* Copyright (c) 2010, 2013 Daniel Doubrovkine, Markus Karg, All Rights Reserved - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * Lesser General Public License for more details. */ -package com.sun.jna.platform.win32; +package com.sun.jna.platform.win32; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -20,6 +20,9 @@ import java.io.IOException; import java.io.PrintWriter; +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.Kernel32Util; +import com.sun.jna.platform.win32.WinNT; import junit.framework.TestCase; import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER; @@ -29,7 +32,7 @@ * @author markus[at]headcrashing[dot]eu */ public class Kernel32UtilTest extends TestCase { - + public static void main(String[] args) throws Exception { System.out.println("Computer name: " + Kernel32Util.getComputerName()); System.out.println("Temp path: " + Kernel32Util.getTempPath()); @@ -38,12 +41,12 @@ public static void main(String[] args) throws Exception { String[] logicalDrives = Kernel32Util.getLogicalDriveStrings(); for(String logicalDrive : logicalDrives) { // drive type - System.out.println(" " + logicalDrive + " (" + System.out.println(" " + logicalDrive + " (" + Kernel32.INSTANCE.GetDriveType(logicalDrive) + ")"); // free space - LARGE_INTEGER.ByReference lpFreeBytesAvailable = new LARGE_INTEGER.ByReference(); - LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new LARGE_INTEGER.ByReference(); - LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new LARGE_INTEGER.ByReference(); + LARGE_INTEGER.ByReference lpFreeBytesAvailable = new LARGE_INTEGER.ByReference(); + LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new LARGE_INTEGER.ByReference(); + LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new LARGE_INTEGER.ByReference(); if (Kernel32.INSTANCE.GetDiskFreeSpaceEx(logicalDrive, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes)) { System.out.println(" Total: " + formatBytes(lpTotalNumberOfBytes.getValue())); System.out.println(" Free: " + formatBytes(lpTotalNumberOfFreeBytes.getValue())); @@ -85,25 +88,25 @@ private static String formatBytes(long bytes) { return String.format("%d bytes", bytes); } } - + public void testGetComputerName() { assertTrue(Kernel32Util.getComputerName().length() > 0); } - + public void testFormatMessageFromLastErrorCode() { assertEquals("The remote server has been paused or is in the process of being started.", - Kernel32Util.formatMessageFromLastErrorCode(W32Errors.ERROR_SHARING_PAUSED)); + Kernel32Util.formatMessageFromLastErrorCode(W32Errors.ERROR_SHARING_PAUSED)); } public void testFormatMessageFromHR() { assertEquals("The operation completed successfully.", Kernel32Util.formatMessageFromHR(W32Errors.S_OK)); } - + public void testGetTempPath() { assertTrue(Kernel32Util.getTempPath().length() > 0); } - + public void testGetLogicalDriveStrings() { String[] logicalDrives = Kernel32Util.getLogicalDriveStrings(); assertTrue(logicalDrives.length > 0); @@ -111,14 +114,14 @@ public void testGetLogicalDriveStrings() { assertTrue(logicalDrive.length() > 0); } } - + public void testDeleteFile() throws IOException { String filename = Kernel32Util.getTempPath() + "\\FileDoesNotExist.jna"; File f = new File(filename); f.createNewFile(); Kernel32Util.deleteFile(filename); } - + public void testGetFileAttributes() throws IOException { String filename = Kernel32Util.getTempPath(); int fileAttributes = Kernel32Util.getFileAttributes(filename); @@ -129,7 +132,7 @@ public void testGetFileAttributes() throws IOException { tempFile.delete(); assertEquals(0, fileAttributes2 & WinNT.FILE_ATTRIBUTE_DIRECTORY); } - + public void testGetEnvironmentVariable() { assertEquals(null, Kernel32Util.getEnvironmentVariable("jna-getenvironment-test")); Kernel32.INSTANCE.SetEnvironmentVariable("jna-getenvironment-test", "42"); @@ -172,7 +175,7 @@ public final void testWritePrivateProfileString() throws IOException { Kernel32Util.writePrivateProfileString("Section", "existingKey", "DEF", tmp.getCanonicalPath()); Kernel32Util.writePrivateProfileString("Section", "addedKey", "GHI", tmp.getCanonicalPath()); Kernel32Util.writePrivateProfileString("Section", "removedKey", null, tmp.getCanonicalPath()); - + final BufferedReader reader = new BufferedReader(new FileReader(tmp)); assertEquals(reader.readLine(), "[Section]"); assertTrue(reader.readLine().matches("existingKey\\s*=\\s*DEF")); @@ -180,4 +183,13 @@ public final void testWritePrivateProfileString() throws IOException { assertEquals(reader.readLine(), null); reader.close(); } + + public final void testGetLogicalProcessorInformation() { + WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION informationArray = Kernel32Util.getLogicalProcessorInformation(); + assertTrue(informationArray >= 1); // docs say so + for (WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION information : informationArray) { + //TODO: What can we check? Java itself has no way to get physical processor info (if it did, + // I wouldn't be writing in JNA support for it.) + } + } }