diff --git a/CHANGES.md b/CHANGES.md index 768a6fcd21..e8c20e3ed3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Features * Use per-library String encoding settings (see [`Native.getDefaultStringEncoding()`](http://twall.github.com/jna/4.0.0/javadoc/com/sun/jna/Native#getDefaultStringEncoding()) and [`Structure.getStringEncoding()`](http://twall.github.com/jna/4.0.0/javadoc/com/sun/jna/Structure.html#getStringEncoding())) - [@twall](https://github.com/twall). * Added [memory dump for debugging](http://twall.github.com/jna/4.0.0/javadoc/com/sun/jna/Memory.html#dump())) - [@twall](https://github.com/twall). * Improve caching of Structure alignment, type mapping, and encoding information - [@twall](https://github.com/twall). +* [#225](https://github.com/twall/jna/pull/225): Added `platform.win32.Kernel32.GetLogicalProcessorInformation` and `platform.win32.Kernel32Util.getLogicalProcessorInformation` - [@trejkaz](https://github.com/trejkaz). Bug Fixes --------- 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 5d6da06b62..cd6f81084e 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java @@ -40,7 +40,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 @@ -77,11 +77,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, @@ -102,7 +102,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. @@ -112,7 +112,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 @@ -124,7 +124,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 @@ -138,7 +138,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). @@ -151,7 +151,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. @@ -160,7 +160,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. @@ -170,7 +170,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. */ @@ -179,7 +179,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(); @@ -187,14 +187,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. */ @@ -202,7 +202,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(); @@ -210,7 +210,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. @@ -224,7 +224,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. @@ -240,14 +240,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. */ @@ -255,14 +255,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. */ @@ -272,7 +272,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(); @@ -280,7 +280,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. */ @@ -289,7 +289,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 @@ -309,7 +309,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 @@ -352,7 +352,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 @@ -392,7 +392,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. @@ -431,30 +431,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. @@ -464,11 +464,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. @@ -476,13 +476,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. */ @@ -491,32 +491,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 @@ -527,7 +527,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. */ @@ -538,7 +538,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. @@ -559,11 +559,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, @@ -584,7 +584,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. @@ -596,7 +596,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 @@ -627,7 +627,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 @@ -653,7 +653,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. @@ -680,7 +680,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. @@ -704,7 +704,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 @@ -741,7 +741,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. @@ -774,7 +774,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. @@ -788,7 +788,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. @@ -837,7 +837,7 @@ public boolean ReadDirectoryChangesW(HANDLE directory, /** * Retrieves the short path form of the specified path. - * + * * @param lpszLongPath * The path string. * @param lpdzShortPath @@ -862,11 +862,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. @@ -875,11 +875,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, @@ -907,7 +907,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 @@ -937,7 +937,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. @@ -951,7 +951,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. @@ -964,7 +964,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. @@ -1001,7 +1001,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. @@ -1025,7 +1025,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. @@ -1038,7 +1038,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 @@ -1059,7 +1059,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. @@ -1079,7 +1079,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 @@ -1089,20 +1089,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. @@ -1110,7 +1110,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 @@ -1241,7 +1241,7 @@ boolean CreateProcessW(String lpApplicationName, char[] lpCommandLine, /** * This function returns a handle to an existing process object. - * + * * @param fdwAccess * Not supported; set to zero. * @param fInherit @@ -1257,7 +1257,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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 @@ -1269,7 +1269,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. */ @@ -1278,7 +1278,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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 @@ -1289,7 +1289,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. @@ -1304,7 +1304,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. @@ -1318,7 +1318,7 @@ boolean CreateProcessW(String lpApplicationName, char[] lpCommandLine, /** * The GetSystemInfo function returns information about the current system. - * + * * @param lpSystemInfo * Pointer to a SYSTEM_INFO structure that receives the * information. @@ -1330,7 +1330,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. @@ -1340,7 +1340,7 @@ boolean CreateProcessW(String lpApplicationName, char[] lpCommandLine, /** * The IsWow64Process function determines whether the specified process is * running under WOW64. - * + * * @param hProcess * Handle to a process. * @param Wow64Process @@ -1352,10 +1352,22 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. @@ -1368,17 +1380,17 @@ boolean CreateProcessW(String lpApplicationName, char[] 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 @@ -1386,7 +1398,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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 @@ -1394,7 +1406,7 @@ boolean CreateProcessW(String lpApplicationName, char[] 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. @@ -1407,7 +1419,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 @@ -1425,7 +1437,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 @@ -1436,7 +1448,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. */ @@ -1445,18 +1457,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. @@ -1466,7 +1478,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 @@ -1492,7 +1504,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 @@ -1525,7 +1537,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 @@ -1537,7 +1549,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. @@ -1560,7 +1572,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 @@ -1577,7 +1589,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 @@ -1588,7 +1600,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 @@ -1604,13 +1616,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 @@ -1618,27 +1630,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 @@ -1662,7 +1674,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 @@ -1676,9 +1688,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. */ @@ -1692,7 +1704,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 @@ -1702,7 +1714,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. */ @@ -1714,10 +1726,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 @@ -1725,19 +1737,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. @@ -1747,7 +1759,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. @@ -1768,7 +1780,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. @@ -1786,7 +1798,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. @@ -1794,7 +1806,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. @@ -1804,7 +1816,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 @@ -1828,7 +1840,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. */ @@ -1836,7 +1848,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 @@ -1867,7 +1879,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. @@ -1903,12 +1915,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 52d2da910f..64d22359cd 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java @@ -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; @@ -305,4 +306,33 @@ 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 err = Kernel32.INSTANCE.GetLastError(); + if (err != WinError.ERROR_INSUFFICIENT_BUFFER) + throw new Win32Exception(err); + } + else + { + 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/WinBase.java b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java index ddb2ce03af..a71318f4e3 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/WinBase.java @@ -429,7 +429,7 @@ public static class ByReference extends PI implements Structure.ByReference { protected List getFieldOrder() { return Arrays.asList(new String[] { "wProcessorArchitecture", "wReserved" }); - } + } } /** Unnamed inner union. */ 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 acb27cfb77..e57a161708 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER; +import com.sun.jna.platform.win32.WinNT.LOGICAL_PROCESSOR_RELATIONSHIP; /** * @author dblock[at]dblock[dot]org @@ -180,4 +181,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.length >= 1); // docs say so + for (WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION info : informationArray) { + assertTrue(info.processorMask.intValue() >= 0); + assertTrue(info.relationship >= LOGICAL_PROCESSOR_RELATIONSHIP.RelationProcessorCore && info.relationship <= LOGICAL_PROCESSOR_RELATIONSHIP.RelationAll); + } + } }