public static int getProcessID(Process process) { long id = getProcessHandle(process); if (id != 0) { HANDLE handle = new HANDLE(); handle.setPointer(Pointer.createConstant(id)); return Kernel32.INSTANCE.GetProcessId(handle); } return 0; }
public Pointer getHIcon(Pointer hWnd) { FuFlags fuFlags = new FuFlags(); fuFlags.setSMTO_NORMAL(); try { Pointer icon = SendMessageTimeoutA( hWnd, Messages.WM_GETICON, FType.ICON_SMALL, 0, fuFlags.getFlags(), 20); if (icon != null) return u32.CopyIcon(icon); } catch (Exception e) { } try { Pointer icon = SendMessageTimeoutA(hWnd, Messages.WM_GETICON, FType.ICON_BIG, 0, fuFlags.getFlags(), 20); if (icon != null) return u32.CopyIcon(icon); } catch (Exception e) { } try { Pointer icon = SendMessageTimeoutA( hWnd, Messages.WM_GETICON, FType.ICON_SMALL2, 0, fuFlags.getFlags(), 20); if (icon != null) return u32.CopyIcon(icon); } catch (Exception e) { } try { int hiconSM = GetClassLong(hWnd, GCFlags.GCL_HICONSM); if (hiconSM != 0) return u32.CopyIcon(Pointer.createConstant(hiconSM)); } catch (Exception e) { } try { int hicon = GetClassLong(hWnd, GCFlags.GCL_HICON); if (hicon != 0) return u32.CopyIcon(Pointer.createConstant(hicon)); } catch (Exception e) { } return null; }
public static int getWindowsProcessId(Process proc) throws Exception { if (proc.getClass().getName().equals("java.lang.Win32Process") || proc.getClass().getName().equals("java.lang.ProcessImpl")) { /* determine the pid on windows plattforms */ Field f = proc.getClass().getDeclaredField("handle"); f.setAccessible(true); long handl = f.getLong(proc); Kernel32 kernel = Kernel32.INSTANCE; WinNT.HANDLE handle = new WinNT.HANDLE(); handle.setPointer(Pointer.createConstant(handl)); return kernel.GetProcessId(handle); } return 0; }
private static int getProcessId(Process process) { int PID = 0; if (process.getClass().getName().equals("java.lang.Win32Process") || process.getClass().getName().equals("java.lang.ProcessImpl")) { try { Field f = process.getClass().getDeclaredField("handle"); f.setAccessible(true); long handl = f.getLong(process); Kernel kernel = Kernel.INSTANCE; W32API.HANDLE handle = new W32API.HANDLE(); handle.setPointer(Pointer.createConstant(handl)); PID = kernel.GetProcessId(handle); } catch (Throwable e) { Loggers.SERVER.error("PID PROBLEM " + e); } } return PID; }
/** * Get a window handle for a component identifier. * * @param componentId component identifier * @return native window handle */ private HWND getHWND(long componentId) { return new HWND(Pointer.createConstant(componentId)); }
public final WinDef.HWND longToHwnd(long input) { WinDef.HWND handle = new WinDef.HWND(); handle.setPointer(Pointer.createConstant(input)); return handle; }
public final WinDef.HMENU longToHmenu(long input) { WinDef.HMENU handle = new WinDef.HMENU(); handle.setPointer(Pointer.createConstant(input)); return handle; }
/** * Ported from Winbase.h (kernel32.dll/kernel services). Microsoft Windows SDK 6.0A. * * @author dblock[at]dblock.org */ public interface WinBase extends StdCallLibrary, WinDef, BaseTSD { /** Constant value representing an invalid HANDLE. */ HANDLE INVALID_HANDLE_VALUE = new HANDLE(Pointer.createConstant(Pointer.SIZE == 8 ? -1 : 0xFFFFFFFFL)); int WAIT_FAILED = 0xFFFFFFFF; int WAIT_OBJECT_0 = ((NTStatus.STATUS_WAIT_0) + 0); int WAIT_ABANDONED = ((NTStatus.STATUS_ABANDONED_WAIT_0) + 0); int WAIT_ABANDONED_0 = ((NTStatus.STATUS_ABANDONED_WAIT_0) + 0); /** Maximum computer name length. The value is 15 on Mac, 31 on everything else. */ int MAX_COMPUTERNAME_LENGTH = Platform.isMac() ? 15 : 31; /** * This logon type is intended for users who will be interactively using the computer, such as a * user being logged on by a terminal server, remote shell, or similar process. This logon type * has the additional expense of caching logon information for disconnected operations; therefore, * it is inappropriate for some client/server applications, such as a mail server. */ int LOGON32_LOGON_INTERACTIVE = 2; /** * This logon type is intended for high performance servers to authenticate plaintext passwords. * The LogonUser function does not cache credentials for this logon type. */ int LOGON32_LOGON_NETWORK = 3; /** * This logon type is intended for batch servers, where processes may be executing on behalf of a * user without their direct intervention. This type is also for higher performance servers that * process many plaintext authentication attempts at a time, such as mail or Web servers. The * LogonUser function does not cache credentials for this logon type. */ int LOGON32_LOGON_BATCH = 4; /** * Indicates a service-type logon. The account provided must have the service privilege enabled. */ int LOGON32_LOGON_SERVICE = 5; /** * This logon type is for GINA DLLs that log on users who will be interactively using the * computer. This logon type can generate a unique audit record that shows when the workstation * was unlocked. */ int LOGON32_LOGON_UNLOCK = 7; /** * This logon type preserves the name and password in the authentication package, which allows the * server to make connections to other network servers while impersonating the client. A server * can accept plaintext credentials from a client, call LogonUser, verify that the user can access * the system across the network, and still communicate with other servers. */ int LOGON32_LOGON_NETWORK_CLEARTEXT = 8; /** * This logon type allows the caller to clone its current token and specify new credentials for * outbound connections. The new logon session has the same local identifier but uses different * credentials for other network connections. This logon type is supported only by the * LOGON32_PROVIDER_WINNT50 logon provider. */ int LOGON32_LOGON_NEW_CREDENTIALS = 9; /** * Use the standard logon provider for the system. The default security provider is negotiate, * unless you pass NULL for the domain name and the user name is not in UPN format. In this case, * the default provider is NTLM. */ int LOGON32_PROVIDER_DEFAULT = 0; /** Use the Windows NT 3.5 logon provider. */ int LOGON32_PROVIDER_WINNT35 = 1; /** Use the NTLM logon provider. */ int LOGON32_PROVIDER_WINNT40 = 2; /** Use the negotiate logon provider. */ int LOGON32_PROVIDER_WINNT50 = 3; /** * If this flag is set, a child process created with the bInheritHandles parameter of * CreateProcess set to TRUE will inherit the object handle. */ int HANDLE_FLAG_INHERIT = 1; /** * If this flag is set, calling the {@link Kernel32#CloseHandle} function will not close the * object handle. */ int HANDLE_FLAG_PROTECT_FROM_CLOSE = 2; // STARTUPINFO flags int STARTF_USESHOWWINDOW = 0x001; int STARTF_USESIZE = 0x002; int STARTF_USEPOSITION = 0x004; int STARTF_USECOUNTCHARS = 0x008; int STARTF_USEFILLATTRIBUTE = 0x010; int STARTF_RUNFULLSCREEN = 0x020; int STARTF_FORCEONFEEDBACK = 0x040; int STARTF_FORCEOFFFEEDBACK = 0x080; int STARTF_USESTDHANDLES = 0x100; // Process Creation flags int DEBUG_PROCESS = 0x00000001; int DEBUG_ONLY_THIS_PROCESS = 0x00000002; int CREATE_SUSPENDED = 0x00000004; int DETACHED_PROCESS = 0x00000008; int CREATE_NEW_CONSOLE = 0x00000010; int CREATE_NEW_PROCESS_GROUP = 0x00000200; int CREATE_UNICODE_ENVIRONMENT = 0x00000400; int CREATE_SEPARATE_WOW_VDM = 0x00000800; int CREATE_SHARED_WOW_VDM = 0x00001000; int CREATE_FORCEDOS = 0x00002000; int INHERIT_PARENT_AFFINITY = 0x00010000; int CREATE_PROTECTED_PROCESS = 0x00040000; int EXTENDED_STARTUPINFO_PRESENT = 0x00080000; int CREATE_BREAKAWAY_FROM_JOB = 0x01000000; int CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000; int CREATE_DEFAULT_ERROR_MODE = 0x04000000; int CREATE_NO_WINDOW = 0x08000000; /* Invalid return values */ int INVALID_FILE_SIZE = 0xFFFFFFFF; int INVALID_SET_FILE_POINTER = 0xFFFFFFFF; int INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF; /** Return code for a process still active. */ int STILL_ACTIVE = WinNT.STATUS_PENDING; /** * The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals * since January 1, 1601 (UTC). Conversion code in this class Copyright 2002-2004 Apache Software * Foundation. * * @author Rainer Klute ([email protected]) for the Apache Software Foundation * (org.apache.poi.hpsf) */ public static class FILETIME extends Structure { public int dwLowDateTime; public int dwHighDateTime; public static class ByReference extends FILETIME implements Structure.ByReference { public ByReference() {} public ByReference(Pointer memory) { super(memory); } } public FILETIME(Date date) { long rawValue = dateToFileTime(date); dwHighDateTime = (int) (rawValue >> 32 & 0xffffffffL); dwLowDateTime = (int) (rawValue & 0xffffffffL); } public FILETIME() {} public FILETIME(Pointer memory) { super(memory); read(); } /** * The difference between the Windows epoch (1601-01-01 00:00:00) and the Unix epoch (1970-01-01 * 00:00:00) in milliseconds: 11644473600000L. (Use your favorite spreadsheet program to verify * the correctness of this value. By the way, did you notice that you can tell from the epochs * which operating system is the modern one? :-)) */ private static final long EPOCH_DIFF = 11644473600000L; /** * Converts a Windows FILETIME into a {@link Date}. The Windows FILETIME structure holds a date * and time associated with a file. The structure identifies a 64-bit integer specifying the * number of 100-nanosecond intervals which have passed since January 1, 1601. This 64-bit value * is split into the two double words stored in the structure. * * @param high The higher double word of the FILETIME structure. * @param low The lower double word of the FILETIME structure. * @return The Windows FILETIME as a {@link Date}. */ public static Date filetimeToDate(final int high, final int low) { final long filetime = (long) high << 32 | low & 0xffffffffL; final long ms_since_16010101 = filetime / (1000 * 10); final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF; return new Date(ms_since_19700101); } /** * Converts a {@link Date} into a filetime. * * @param date The date to be converted * @return The filetime * @see #filetimeToDate */ public static long dateToFileTime(final Date date) { final long ms_since_19700101 = date.getTime(); final long ms_since_16010101 = ms_since_19700101 + EPOCH_DIFF; return ms_since_16010101 * 1000 * 10; } public Date toDate() { return filetimeToDate(dwHighDateTime, dwLowDateTime); } public long toLong() { return toDate().getTime(); } public String toString() { return super.toString() + ": " + toDate().toString(); // $NON-NLS-1$ } } /* Local Memory Flags */ int LMEM_FIXED = 0x0000; int LMEM_MOVEABLE = 0x0002; int LMEM_NOCOMPACT = 0x0010; int LMEM_NODISCARD = 0x0020; int LMEM_ZEROINIT = 0x0040; int LMEM_MODIFY = 0x0080; int LMEM_DISCARDABLE = 0x0F00; int LMEM_VALID_FLAGS = 0x0F72; int LMEM_INVALID_HANDLE = 0x8000; int LHND = (LMEM_MOVEABLE | LMEM_ZEROINIT); int LPTR = (LMEM_FIXED | LMEM_ZEROINIT); /* Flags returned by LocalFlags (in addition to LMEM_DISCARDABLE) */ int LMEM_DISCARDED = 0x4000; int LMEM_LOCKCOUNT = 0x00FF; /** * Specifies a date and time, using individual members for the month, day, year, weekday, hour, * minute, second, and millisecond. The time is either in coordinated universal time (UTC) or * local time, depending on the function that is being called. * http://msdn.microsoft.com/en-us/library/ms724950(VS.85).aspx */ public static class SYSTEMTIME extends Structure { // The year. The valid values for this member are 1601 through 30827. public short wYear; // The month. The valid values for this member are 1 through 12. public short wMonth; // The day of the week. The valid values for this member are 0 through 6. public short wDayOfWeek; // The day of the month. The valid values for this member are 1 through 31. public short wDay; // The hour. The valid values for this member are 0 through 23. public short wHour; // The minute. The valid values for this member are 0 through 59. public short wMinute; // The second. The valid values for this member are 0 through 59. public short wSecond; // The millisecond. The valid values for this member are 0 through 999. public short wMilliseconds; } /** * The lpBuffer parameter is a pointer to a PVOID pointer, and that the nSize parameter specifies * the minimum number of TCHARs to allocate for an output message buffer. The function allocates a * buffer large enough to hold the formatted message, and places a pointer to the allocated buffer * at the address specified by lpBuffer. The caller should use the LocalFree function to free the * buffer when it is no longer needed. */ int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100; /** * Insert sequences in the message definition are to be ignored and passed through to the output * buffer unchanged. This flag is useful for fetching a message for later formatting. If this flag * is set, the Arguments parameter is ignored. */ int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200; /** * The lpSource parameter is a pointer to a null-terminated message definition. The message * definition may contain insert sequences, just as the message text in a message table resource * may. Cannot be used with FORMAT_MESSAGE_FROM_HMODULE or FORMAT_MESSAGE_FROM_SYSTEM. */ int FORMAT_MESSAGE_FROM_STRING = 0x00000400; /** * The lpSource parameter is a module handle containing the message-table resource(s) to search. * If this lpSource handle is NULL, the current process's application image file will be searched. * Cannot be used with FORMAT_MESSAGE_FROM_STRING. */ int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800; /** * The function should search the system message-table resource(s) for the requested message. If * this flag is specified with FORMAT_MESSAGE_FROM_HMODULE, the function searches the system * message table if the message is not found in the module specified by lpSource. Cannot be used * with FORMAT_MESSAGE_FROM_STRING. If this flag is specified, an application can pass the result * of the GetLastError function to retrieve the message text for a system-defined error. */ int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000; /** * The Arguments parameter is not a va_list structure, but is a pointer to an array of values that * represent the arguments. This flag cannot be used with 64-bit argument values. If you are using * 64-bit values, you must use the va_list structure. */ int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000; /** The drive type cannot be determined. */ int DRIVE_UNKNOWN = 0; /** The root path is invalid, for example, no volume is mounted at the path. */ int DRIVE_NO_ROOT_DIR = 1; /** * The drive is a type that has removable media, for example, a floppy drive or removable hard * disk. */ int DRIVE_REMOVABLE = 2; /** The drive is a type that cannot be removed, for example, a fixed hard drive. */ int DRIVE_FIXED = 3; /** The drive is a remote (network) drive. */ int DRIVE_REMOTE = 4; /** The drive is a CD-ROM drive. */ int DRIVE_CDROM = 5; /** The drive is a RAM disk. */ int DRIVE_RAMDISK = 6; /** * The OVERLAPPED structure contains information used in asynchronous (or overlapped) input and * output (I/O). */ public static class OVERLAPPED extends Structure { public ULONG_PTR Internal; public ULONG_PTR InternalHigh; public int Offset; public int OffsetHigh; public HANDLE hEvent; } int INFINITE = 0xFFFFFFFF; /** * Contains information about the current computer system. This includes the architecture and type * of the processor, the number of processors in the system, the page size, and other such * information. */ public static class SYSTEM_INFO extends Structure { /** Unnamed inner structure. */ public static class PI extends Structure { public static class ByReference extends PI implements Structure.ByReference {} /** * System's processor architecture. This value can be one of the following values: * * <p>PROCESSOR_ARCHITECTURE_UNKNOWN PROCESSOR_ARCHITECTURE_INTEL PROCESSOR_ARCHITECTURE_IA64 * PROCESSOR_ARCHITECTURE_AMD64 */ public WORD wProcessorArchitecture; /** Reserved for future use. */ public WORD wReserved; } /** Unnamed inner union. */ public static class UNION extends Union { public static class ByReference extends UNION implements Structure.ByReference {} /** * An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier. New * applications should use the wProcessorArchitecture branch of the union. Windows Me/98/95: * The system always sets this member to zero, the value defined for * PROCESSOR_ARCHITECTURE_INTEL. */ public DWORD dwOemID; /** Processor architecture (unnamed struct). */ public PI pi; } /** Processor architecture (unnamed union). */ public UNION processorArchitecture; /** Page size and the granularity of page protection and commitment. */ public DWORD dwPageSize; /** * Pointer to the lowest memory address accessible to applications and dynamic-link libraries * (DLLs). */ public Pointer lpMinimumApplicationAddress; /** Pointer to the highest memory address accessible to applications and DLLs. */ public Pointer lpMaximumApplicationAddress; /** * Mask representing the set of processors configured into the system. Bit 0 is processor 0; bit * 31 is processor 31. */ public DWORD_PTR dwActiveProcessorMask; /** Number of processors in the system. */ public DWORD dwNumberOfProcessors; /** * An obsolete member that is retained for compatibility with Windows NT 3.5 and Windows * Me/98/95. Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to * determine the type of processor. PROCESSOR_INTEL_386 PROCESSOR_INTEL_486 * PROCESSOR_INTEL_PENTIUM */ public DWORD dwProcessorType; /** Granularity for the starting address at which virtual memory can be allocated. */ public DWORD dwAllocationGranularity; /** * System's architecture-dependent processor level. It should be used only for display purposes. * To determine the feature set of a processor, use the IsProcessorFeaturePresent function. If * wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU * vendor. If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to * 1. */ public WORD wProcessorLevel; /** Architecture-dependent processor revision. */ public WORD wProcessorRevision; } /** * Contains information about the current state of both physical and virtual memory, including * extended memory. The GlobalMemoryStatusEx function stores information in this structure. */ public static class MEMORYSTATUSEX extends Structure { /** The size of the structure, in bytes. */ public DWORD dwLength; /** * A number between 0 and 100 that specifies the approximate percentage of physical memory that * is in use (0 indicates no memory use and 100 indicates full memory use). */ public DWORD dwMemoryLoad; /** The amount of actual physical memory, in bytes. */ public DWORDLONG ullTotalPhys; /** * The amount of physical memory currently available, in bytes. This is the amount of physical * memory that can be immediately reused without having to write its contents to disk first. It * is the sum of the size of the standby, free, and zero lists. */ public DWORDLONG ullAvailPhys; /** * The current committed memory limit for the system or the current process, whichever is * smaller, in bytes. */ public DWORDLONG ullTotalPageFile; /** * The maximum amount of memory the current process can commit, in bytes. This value is equal to * or smaller than the system-wide available commit value. */ public DWORDLONG ullAvailPageFile; /** * The size of the user-mode portion of the virtual address space of the calling process, in * bytes. */ public DWORDLONG ullTotalVirtual; /** * The amount of unreserved and uncommitted memory currently in the user-mode portion of the * virtual address space of the calling process, in bytes. */ public DWORDLONG ullAvailVirtual; /** Reserved. This value is always 0. */ public DWORDLONG ullAvailExtendedVirtual; public MEMORYSTATUSEX() { dwLength = new DWORD(size()); } }; /** * The SECURITY_ATTRIBUTES structure contains the security descriptor for an object and specifies * whether the handle retrieved by specifying this structure is inheritable. This structure * provides security settings for objects created by various functions, such as {@link * Kernel32#CreateFile}, {@link Kernel32#CreatePipe}, or {@link Advapi32#RegCreateKeyEx}. */ public static class SECURITY_ATTRIBUTES extends Structure { /** The size of the structure, in bytes. */ public DWORD dwLength; /** A pointer to a SECURITY_DESCRIPTOR structure that controls access to the object. */ public Pointer lpSecurityDescriptor; /** * A Boolean value that specifies whether the returned handle is inherited when a new process is * created */ public boolean bInheritHandle; public SECURITY_ATTRIBUTES() { dwLength = new DWORD(size()); } } /** * Specifies the window station, desktop, standard handles, and appearance of the main window for * a process at creation time. */ public static class STARTUPINFO extends Structure { /** The size of the structure, in bytes. */ public DWORD cb; /** Reserved; must be NULL. */ public String lpReserved; /** * The name of the desktop, or the name of both the desktop and window station for this process. * A backslash in the string indicates that the string includes both the desktop and window * station names. For more information, see Thread Connection to a Desktop. */ public String lpDesktop; /** * For console processes, this is the title displayed in the title bar if a new console window * is created. If NULL, the name of the executable file is used as the window title instead. * This parameter must be NULL for GUI or console processes that do not create a new console * window. */ public String lpTitle; /** * If dwFlags specifies STARTF_USEPOSITION, this member is the x offset of the upper left corner * of a window if a new window is created, in pixels. Otherwise, this member is ignored. * * <p>The offset is from the upper left corner of the screen. For GUI processes, the specified * position is used the first time the new process calls CreateWindow to create an overlapped * window if the x parameter of CreateWindow is CW_USEDEFAULT. */ public DWORD dwX; /** * If dwFlags specifies STARTF_USEPOSITION, this member is the y offset of the upper left corner * of a window if a new window is created, in pixels. Otherwise, this member is ignored. * * <p>The offset is from the upper left corner of the screen. For GUI processes, the specified * position is used the first time the new process calls CreateWindow to create an overlapped * window if the y parameter of CreateWindow is CW_USEDEFAULT. */ public DWORD dwY; /** * If dwFlags specifies STARTF_USESIZE, this member is the width of the window if a new window * is created, in pixels. Otherwise, this member is ignored. * * <p>For GUI processes, this is used only the first time the new process calls CreateWindow to * create an overlapped window if the nWidth parameter of CreateWindow is CW_USEDEFAULT. */ public DWORD dwXSize; /** * If dwFlags specifies STARTF_USESIZE, this member is the height of the window if a new window * is created, in pixels. Otherwise, this member is ignored. * * <p>For GUI processes, this is used only the first time the new process calls CreateWindow to * create an overlapped window if the nHeight parameter of CreateWindow is CW_USEDEFAULT. */ public DWORD dwYSize; /** * If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console * process, this member specifies the screen buffer width, in character columns. Otherwise, this * member is ignored. */ public DWORD dwXCountChars; /** * If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is created in a console * process, this member specifies the screen buffer height, in character rows. Otherwise, this * member is ignored. */ public DWORD dwYCountChars; /** * If dwFlags specifies STARTF_USEFILLATTRIBUTE, this member is the initial text and background * colors if a new console window is created in a console application. Otherwise, this member is * ignored. * * <p>This value can be any combination of the following values: FOREGROUND_BLUE, * FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, * BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values * produces red text on a white background: * * <p>FOREGROUND_RED| BACKGROUND_RED| BACKGROUND_GREEN| BACKGROUND_BLUE */ public DWORD dwFillAttribute; /** * A bit field that determines whether certain STARTUPINFO members are used when the process * creates a window. */ public int dwFlags; /** * If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of the values that can be * specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. * Otherwise, this member is ignored. * * <p>For GUI processes, the first time ShowWindow is called, its nCmdShow parameter is ignored * wShowWindow specifies the default value. In subsequent calls to ShowWindow, the wShowWindow * member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT. */ public WORD wShowWindow; /** Reserved for use by the C Run-time; must be zero. */ public WORD cbReserved2; /** Reserved for use by the C Run-time; must be NULL. */ public ByteByReference lpReserved2; /** * If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard input handle for the * process. If STARTF_USESTDHANDLES is not specified, the default for standard input is the * keyboard buffer. * * <p>If dwFlags specifies STARTF_USEHOTKEY, this member specifies a hotkey value that is sent * as the wParam parameter of a WM_SETHOTKEY message to the first eligible top-level window * created by the application that owns the process. If the window is created with the WS_POPUP * window style, it is not eligible unless the WS_EX_APPWINDOW extended window style is also * set. For more information, see CreateWindowEx. * * <p>Otherwise, this member is ignored. */ public HANDLE hStdInput; /** * If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard output handle for the * process. Otherwise, this member is ignored and the default for standard output is the console * window's buffer. */ public HANDLE hStdOutput; /** * If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard error handle for the * process. Otherwise, this member is ignored and the default for standard error is the console * window's buffer. */ public HANDLE hStdError; public STARTUPINFO() { cb = new DWORD(size()); } } /** * Contains information about a newly created process and its primary thread. It is used with the * CreateProcess, CreateProcessAsUser, CreateProcessWithLogonW, or CreateProcessWithTokenW * function. */ public static class PROCESS_INFORMATION extends Structure { /** * A handle to the newly created process. The handle is used to specify the process in all * functions that perform operations on the process object. */ public HANDLE hProcess; /** * A handle to the primary thread of the newly created process. The handle is used to specify * the thread in all functions that perform operations on the thread object. */ public HANDLE hThread; /** * A value that can be used to identify a process. The value is valid from the time the process * is created until all handles to the process are closed and the process object is freed; at * this point, the identifier may be reused. */ public DWORD dwProcessId; /** * A value that can be used to identify a thread. The value is valid from the time the thread is * created until all handles to the thread are closed and the thread object is freed; at this * point, the identifier may be reused. */ public DWORD dwThreadId; public static class ByReference extends PROCESS_INFORMATION implements Structure.ByReference { public ByReference() {} public ByReference(Pointer memory) { super(memory); } } public PROCESS_INFORMATION() {} public PROCESS_INFORMATION(Pointer memory) { super(memory); read(); } } /** * If the file is to be moved to a different volume, the function simulates the move by using the * CopyFile and DeleteFile functions. * * <p>This value cannot be used with MOVEFILE_DELAY_UNTIL_REBOOT. */ int MOVEFILE_COPY_ALLOWED = 0x2; /** Reserved for future use. */ int MOVEFILE_CREATE_HARDLINK = 0x10; /** * The system does not move the file until the operating system is restarted. The system moves the * file immediately after AUTOCHK is executed, but before creating any paging files. Consequently, * this parameter enables the function to delete paging files from previous startups. * * <p>This value can be used only if the process is in the context of a user who belongs to the * administrators group or the LocalSystem account. * * <p>This value cannot be used with MOVEFILE_COPY_ALLOWED. * * <p>Windows Server 2003 and Windows XP: For information about special situations where this * functionality can fail, and a suggested workaround solution, see Files are not exchanged when * Windows Server 2003 restarts if you use the MoveFileEx function to schedule a replacement for * some files in the Help and Support Knowledge Base. * * <p>Windows 2000: If you specify the MOVEFILE_DELAY_UNTIL_REBOOT flag for dwFlags, you cannot * also prepend the file name that is specified by lpExistingFileName with "\\?". */ int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4; /** * The function fails if the source file is a link source, but the file cannot be tracked after * the move. This situation can occur if the destination is a volume formatted with the FAT file * system. */ int MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20; /** * If a file named lpNewFileName exists, the function replaces its contents with the contents of * the lpExistingFileName file, provided that security requirements regarding access control lists * (ACLs) are met. For more information, see the Remarks section of this topic. * * <p>This value cannot be used if lpNewFileName or lpExistingFileName names a directory. */ int MOVEFILE_REPLACE_EXISTING = 0x1; /** * The function does not return until the file is actually moved on the disk. * * <p>Setting this value guarantees that a move performed as a copy and delete operation is * flushed to disk before the function returns. The flush occurs at the end of the copy operation. * * <p>This value has no effect if MOVEFILE_DELAY_UNTIL_REBOOT is set. */ int MOVEFILE_WRITE_THROUGH = 0x8; }
@SuppressWarnings("all") public class C { private static final String LIB = "c"; static { Native.register(LIB); } /* # define _SIGSET_NWORDS (1024 / (8 * sizeof (unsigned long int))) typedef struct { unsigned long int __val[_SIGSET_NWORDS]; } __sigset_t; */ public static final int _SIGSET_NWORDS = (1024 / (8 * NativeLong.SIZE)); public static class sigset_t extends Structure { public NativeLong[] __val = new NativeLong[_SIGSET_NWORDS]; protected List getFieldOrder() { return Arrays.asList("__val"); } public sigset_t() { super(); } public static class ByReference extends sigset_t implements Structure.ByReference {} public static class ByValue extends sigset_t implements Structure.ByValue {} } /* struct sched_param { int __sched_priority; }; */ public static class sched_param extends Structure { public int __sched_priority; protected List getFieldOrder() { return Arrays.asList("__sched_priority"); } public sched_param() { super(); } } /* //Structure describing the action to be taken when a signal arrives. struct sigaction { //Signal handler. #ifdef __USE_POSIX199309 union { //Used if SA_SIGINFO is not set. __sighandler_t sa_handler; //Used if SA_SIGINFO is set. void (*sa_sigaction) (int, siginfo_t *, void *); } __sigaction_handler; # define sa_handler __sigaction_handler.sa_handler # define sa_sigaction __sigaction_handler.sa_sigaction #else __sighandler_t sa_handler; #endif //Additional set of signals to be blocked. __sigset_t sa_mask; //Special flags. int sa_flags; //Restore handler. void (*sa_restorer) (void); }; */ public static class sigaction extends Structure { public static class __sigaction_handler extends Union { public sighandler_t /*sighandler_t*/ sa_handler; public sa_sigaction /*sa_sigaction*/ sa_sigaction; } public __sigaction_handler __sigaction_handler; public sigset_t sa_mask; public int sa_flags; public Pointer sa_restorer; protected List getFieldOrder() { return Arrays.asList("__sigaction_handler", "sa_mask", "sa_flags", "sa_restorer"); } public sigaction() { super(); } public sigaction(int sa_flags, sighandler_t sa_handler) { super(); sigemptyset(sa_mask.getPointer()); this.sa_flags = sa_flags; this.__sigaction_handler.sa_handler = sa_handler; this.__sigaction_handler.setType(sighandler_t.class); } public sigaction(int sa_flags, sa_sigaction sa_sigaction) { super(); sigemptyset(sa_mask.getPointer()); this.sa_flags = sa_flags | SA_SIGINFO; this.__sigaction_handler.sa_sigaction = sa_sigaction; this.__sigaction_handler.setType(sa_sigaction.class); } public static class ByReference extends sigaction implements Structure.ByReference { public ByReference() { super(); } public ByReference(int sa_flags, sighandler_t sa_handler) { super(sa_flags, sa_handler); } public ByReference(int sa_flags, sa_sigaction sa_sigaction) { super(sa_flags, sa_sigaction); } } public static class ByValue extends sigset_t implements Structure.ByValue {} } public static interface sighandler_t extends Callback { void handler(int signal); } public static interface sa_sigaction extends Callback { void action(int signum, siginfo_t info, Pointer context); } /* # define __SI_MAX_SIZE 128 # if __WORDSIZE == 64 # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 4) # else # define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3) # endif */ public static final int __SI_MAX_SIZE = 128; public static final int __SI_PAD_SIZE = Arch.getSystemArch().is64Bit() ? ((__SI_MAX_SIZE / (Integer.SIZE / Byte.SIZE)) - 4) : ((__SI_MAX_SIZE / (Integer.SIZE / Byte.SIZE)) - 3); // sigval // { // int sival_int; // void *sival_ptr; // } sigval_t; public static class sigval_t extends Union { public int sival_int; Pointer sival_ptr; } /* typedef struct { int si_signo; //Signal number. int si_errno; //If non-zero, an errno value associated with this signal, as defined in <errno.h>. int si_code; //Signal code. union { int _pad[__SI_PAD_SIZE]; // kill(). struct { __pid_t si_pid; // Sending process ID. __uid_t si_uid; // Real user ID of sending process. } _kill; // POSIX.1b timers. struct { int si_tid; // Timer ID. int si_overrun; // Overrun count. sigval_t si_sigval; // Signal value. } _timer; // POSIX.1b signals. struct { __pid_t si_pid; // Sending process ID. __uid_t si_uid; // Real user ID of sending process. sigval_t si_sigval; // Signal value. } _rt; // SIGCHLD. struct { __pid_t si_pid; // Which child. __uid_t si_uid; // Real user ID of sending process. int si_status; // Exit value or signal. __sigchld_clock_t si_utime; __sigchld_clock_t si_stime; } _sigchld; // SIGILL, SIGFPE, SIGSEGV, SIGBUS. struct { void *si_addr; // Faulting insn/memory ref. } _sigfault; // SIGPOLL. struct { long int si_band; // Band event for SIGPOLL. int si_fd; } _sigpoll; // SIGSYS. struct { void *_call_addr; // Calling user insn. int _syscall; // Triggering system call number. unsigned int _arch; // AUDIT_ARCH_* of syscall. } _sigsys; } _sifields; } siginfo_t __SI_ALIGNMENT; */ public static class siginfo_t extends Structure { public int si_signo; // Signal number. public int si_errno; // If non-zero, an errno value associated with this signal, as defined in // <errno.h>. public int si_code; // Signal code. public static class _sifields extends Union { public int[] _pad = new int[__SI_PAD_SIZE]; // kill(). // struct // { // __pid_t si_pid; // Sending process ID. // __uid_t si_uid; // Real user ID of sending process. // } _kill; public static class _kill extends Structure { public int si_pid; public short si_uid; protected List getFieldOrder() { return Arrays.asList("si_pid", "si_uid"); } } public _kill kill; // POSIX.1b timers. // struct // { // int si_tid; // Timer ID. // int si_overrun; // Overrun count. // sigval_t si_sigval; // Signal value. // } _timer; public static class _timer extends Structure { public int si_tid; public int si_overrun; public sigval_t si_sigval; protected List getFieldOrder() { return Arrays.asList("si_tid", "si_overrun", "si_sigval"); } } public _timer timer; // POSIX.1b signals. // struct // { // __pid_t si_pid; // Sending process ID. // __uid_t si_uid; // Real user ID of sending process. // sigval_t si_sigval; // Signal value. // } _rt; public static class _rt extends Structure { public int si_pid; public short si_uid; public sigval_t si_sigval; protected List getFieldOrder() { return Arrays.asList("si_pid", "si_uid", "si_sigval"); } } public _rt rt; // SIGCHLD. // struct // { // __pid_t si_pid; // Which child. // __uid_t si_uid; // Real user ID of sending process. // int si_status; // Exit value or signal. // __sigchld_clock_t si_utime; // __sigchld_clock_t si_stime; // } _sigchld; public static class _sigchld extends Structure { public int si_pid; public short si_uid; public int si_status; public long si_utime; public long si_stime; protected List getFieldOrder() { return Arrays.asList("si_pid", "si_uid", "si_status", "si_utime", "si_stime"); } } public _sigchld sig_chld; // SIGILL, SIGFPE, SIGSEGV, SIGBUS. // struct // { // void *si_addr; // Faulting insn/memory ref. // } _sigfault; public static class _sigfault extends Structure { public Pointer si_addr; protected List getFieldOrder() { return Arrays.asList("si_addr"); } } public _sigfault sig_fault; // SIGPOLL. // struct // { // long int si_band; // Band event for SIGPOLL. // int si_fd; // } _sigpoll; public static class _sigpoll extends Structure { public int si_band; public int si_fd; protected List getFieldOrder() { return Arrays.asList("si_band", "si_fd"); } } public _sigpoll sig_poll; // SIGSYS. // struct // { // void *_call_addr; // Calling user insn. // int _syscall; // Triggering system call number. // unsigned int _arch; // AUDIT_ARCH_* of syscall. // } _sigsys; public static class _sigsys extends Structure { public Pointer _call_addr; public int _syscall; public int _arch; protected List getFieldOrder() { return Arrays.asList("_call_addr", "_syscall", "_arch"); } } public _sigsys sig_sys; } public _sifields si_field; protected List getFieldOrder() { return Arrays.asList("si_signo", "si_errno", "si_code", "si_field"); } public siginfo_t() { super(); loadBySignal(); } public void loadBySignal() { loadBySignal(si_signo); } public void loadBySignal(int signum) { switch (signum) { case SIGCHLD: si_field.setType(_sifields._sigchld.class); break; case SIGKILL: case SIGTERM: si_field.setType(_sifields._kill.class); break; case SIGILL: case SIGFPE: case SIGSEGV: case SIGBUS: case SIGTRAP: si_field.setType(_sifields._sigfault.class); break; // case SIGIO: case SIGPOLL: si_field.setType(_sifields._sigpoll.class); break; } } public static class ByReference extends siginfo_t implements Structure.ByReference { public ByReference() { super(); } } public static class ByValue extends siginfo_t implements Structure.ByValue {} } /* struct signalfd_siginfo { uint32_t ssi_signo; int32_t ssi_errno; int32_t ssi_code; uint32_t ssi_pid; uint32_t ssi_uid; int32_t ssi_fd; uint32_t ssi_tid; uint32_t ssi_band; uint32_t ssi_overrun; uint32_t ssi_trapno; int32_t ssi_status; int32_t ssi_int; uint64_t ssi_ptr; uint64_t ssi_utime; uint64_t ssi_stime; uint64_t ssi_addr; uint8_t __pad[48]; }; */ public static class signalfd_siginfo extends Structure { public int ssi_signo; public int ssi_errno; public int ssi_code; public int ssi_pid; public int ssi_uid; public int ssi_fd; public int ssi_tid; public int ssi_band; public int ssi_overrun; public int ssi_trapno; public int ssi_status; public int ssi_int; public long ssi_ptr; public long ssi_utime; public long ssi_stime; public long ssi_addr; public byte[] __pad = new byte[48]; protected List getFieldOrder() { return Arrays.asList( "ssi_signo", "ssi_errno", "ssi_code", "ssi_pid", "ssi_uid", "ssi_fd", "ssi_tid", "ssi_band", "ssi_overrun", "ssi_trapno", "ssi_status", "ssi_int", "ssi_ptr", "ssi_utime", "ssi_stime", "ssi_addr", "__pad"); } public signalfd_siginfo() { super(); } } public static final int EPERM = 1 // Operation not permitted , ENOENT = 2 // No such file or directory , ESRCH = 3 // No such process , EINTR = 4 // Interrupted system call , EIO = 5 // I/O error , ENXIO = 6 // No such device or address , E2BIG = 7 // Arg list too long , ENOEXEC = 8 // Exec format error , EBADF = 9 // Bad file number , ECHILD = 10 // No child processes , EAGAIN = 11 // Try again , ENOMEM = 12 // Out of memory , EACCES = 13 // Permission denied , EFAULT = 14 // Bad address , ENOTBLK = 15 // Block device required , EBUSY = 16 // Device or resource busy , EEXIST = 17 // File exists , EXDEV = 18 // Cross-device link , ENODEV = 19 // No such device , ENOTDIR = 20 // Not a directory , EISDIR = 21 // Is a directory , EINVAL = 22 // Invalid argument , ENFILE = 23 // File table overflow , EMFILE = 24 // Too many open files , ENOTTY = 25 // Not a typewriter , ETXTBSY = 26 // Text file busy , EFBIG = 27 // File too large , ENOSPC = 28 // No space left on device , ESPIPE = 29 // Illegal seek , EROFS = 30 // Read-only file system , EMLINK = 31 // Too many links , EPIPE = 32 // Broken pipe , EDOM = 33 // Math argument out of domain of func , ERANGE = 34 // Math result not representable , EDEADLK = 35 // Resource deadlock would occur , ENAMETOOLONG = 36 // File name too long , ENOLCK = 37 // No record locks available , ENOSYS = 38 // Function not implemented , ENOTEMPTY = 39 // Directory not empty , ELOOP = 40 // Too many symbolic links encountered , ENOMSG = 42 // No message of desired type , EIDRM = 43 // Identifier removed , ECHRNG = 44 // Channel number out of range , EL2NSYNC = 45 // Level 2 not synchronized , EL3HLT = 46 // Level 3 halted , EL3RST = 47 // Level 3 reset , ELNRNG = 48 // Link number out of range , EUNATCH = 49 // Protocol driver not attached , ENOCSI = 50 // No CSI structure available , EL2HLT = 51 // Level 2 halted , EBADE = 52 // Invalid exchange , EBADR = 53 // Invalid request descriptor , EXFULL = 54 // Exchange full , ENOANO = 55 // No anode , EBADRQC = 56 // Invalid request code , EBADSLT = 57 // Invalid slot , EBFONT = 59 // Bad font file format , ENOSTR = 60 // Device not a stream , ENODATA = 61 // No data available , ETIME = 62 // Timer expired , ENOSR = 63 // Out of streams resources , ENONET = 64 // Machine is not on the network , ENOPKG = 65 // Package not installed , EREMOTE = 66 // Object is remote , ENOLINK = 67 // Link has been severed , EADV = 68 // Advertise error , ESRMNT = 69 // Srmount error , ECOMM = 70 // Communication error on send , EPROTO = 71 // Protocol error , EMULTIHOP = 72 // Multihop attempted , EDOTDOT = 73 // RFS specific error , EBADMSG = 74 // Not a data message , EOVERFLOW = 75 // Value too large for defined data type , ENOTUNIQ = 76 // Name not unique on network , EBADFD = 77 // File descriptor in bad state , EREMCHG = 78 // Remote address changed , ELIBACC = 79 // Can not access a needed shared library , ELIBBAD = 80 // Accessing a corrupted shared library , ELIBSCN = 81 // .lib section in a.out corrupted , ELIBMAX = 82 // Attempting to link in too many shared libraries , ELIBEXEC = 83 // Cannot exec a shared library directly , EILSEQ = 84 // Illegal byte sequence , ERESTART = 85 // Interrupted system call should be restarted , ESTRPIPE = 86 // Streams pipe error , EUSERS = 87 // Too many users , ENOTSOCK = 88 // Socket operation on non-socket , EDESTADDRREQ = 89 // Destination address required , EMSGSIZE = 90 // Message too long , EPROTOTYPE = 91 // Protocol wrong type for socket , ENOPROTOOPT = 92 // Protocol not available , EPROTONOSUPPORT = 93 // Protocol not supported , ESOCKTNOSUPPORT = 94 // Socket type not supported , EOPNOTSUPP = 95 // Operation not supported on transport endpoint , EPFNOSUPPORT = 96 // Protocol family not supported , EAFNOSUPPORT = 97 // Address family not supported by protocol , EADDRINUSE = 98 // Address already in use , EADDRNOTAVAIL = 99 // Cannot assign requested address , ENETDOWN = 100 // Network is down , ENETUNREACH = 101 // Network is unreachable , ENETRESET = 102 // Network dropped connection because of reset , ECONNABORTED = 103 // Software caused connection abort , ECONNRESET = 104 // Connection reset by peer , ENOBUFS = 105 // No buffer space available , EISCONN = 106 // Transport endpoint is already connected , ENOTCONN = 107 // Transport endpoint is not connected , ESHUTDOWN = 108 // Cannot send after transport endpoint shutdown , ETOOMANYREFS = 109 // Too many references: cannot splice , ETIMEDOUT = 110 // Connection timed out , ECONNREFUSED = 111 // Connection refused , EHOSTDOWN = 112 // Host is down , EHOSTUNREACH = 113 // No route to host , EALREADY = 114 // Operation already in progress , EINPROGRESS = 115 // Operation now in progress , ESTALE = 116 // Stale NFS file handle , EUCLEAN = 117 // Structure needs cleaning , ENOTNAM = 118 // Not a XENIX named type file , ENAVAIL = 119 // No XENIX semaphores available , EISNAM = 120 // Is a named type file , EREMOTEIO = 121 // Remote I/O error , EDQUOT = 122 // Quota exceeded , ENOMEDIUM = 123 // No medium found , EMEDIUMTYPE = 124 // Wrong medium type ; public static final int EWOULDBLOCK = EAGAIN // Operation would block , EDEADLOCK = EDEADLK; // /usr/include/x86_64-linux-gnu/sys/stat.h public static final int S_IRWXU = 0000700, S_IRUSR = 0000400, S_IWUSR = 0000200, S_IXUSR = 0000100, S_IRWXG = 0000070, S_IRGRP = 0000040, S_IWGRP = 0000020, S_IXGRP = 0000010, S_IRWXO = 0000007, S_IROTH = 0000004, S_IWOTH = 0000002, S_IXOTH = 0000001, S_ISUID = 0004000, S_ISGID = 0002000, S_ISVTX = 0001000; // /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h public static final int O_RDONLY = 0x0000, O_WRONLY = 0x0001, O_RDWR = 0x0002, O_ACCMODE = 0x0003, O_NONBLOCK = 0x0004, O_APPEND = 0x0008, O_SHLOCK = 0x0010, O_EXLOCK = 0x0020, O_ASYNC = 0x0040, O_FSYNC = 0x0080, O_CREAT = 0x0200, O_TRUNC = 0x0400, O_EXCL = 0x0800; // /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h public static final int F_GETFL = 3 /* get file status flags */, F_SETFL = 4 /* set file status flags */, F_NOCACHE = 48 /* Mac OS X specific flag, turns cache on/off */; // /usr/include/x86_64-linux-gnu/bits/eventfd.h public static final int EFD_SEMAPHORE = 00000001, EFD_CLOEXEC = 02000000, EFD_NONBLOCK = 00004000; // /usr/include/x86_64-linux-gnu/bits/signum.h public static final int SIGHUP = 1 /* Hangup (POSIX). */, SIGINT = 2 /* Interrupt (ANSI). */, SIGQUIT = 3 /* Quit (POSIX). */, SIGILL = 4 /* Illegal instruction (ANSI). */, SIGTRAP = 5 /* Trace trap (POSIX). */, SIGABRT = 6 /* Abort (ANSI). */, SIGIOT = 6 /* IOT trap (4.2 BSD). */, SIGBUS = 7 /* BUS error (4.2 BSD). */, SIGFPE = 8 /* Floating-point exception (ANSI). */, SIGKILL = 9 /* Kill, unblockable (POSIX). */, SIGUSR1 = 10 /* User-defined signal 1 (POSIX). */, SIGSEGV = 11 /* Segmentation violation (ANSI). */, SIGUSR2 = 12 /* User-defined signal 2 (POSIX). */, SIGPIPE = 13 /* Broken pipe (POSIX). */, SIGALRM = 14 /* Alarm clock (POSIX). */, SIGTERM = 15 /* Termination (ANSI). */, SIGSTKFLT = 16 /* Stack fault. */, SIGCHLD = 17 /* Child status has changed (POSIX). */, SIGCONT = 18 /* Continue (POSIX). */, SIGSTOP = 19 /* Stop, unblockable (POSIX). */, SIGTSTP = 20 /* Keyboard stop (POSIX). */, SIGTTIN = 21 /* Background read from tty (POSIX). */, SIGTTOU = 22 /* Background write to tty (POSIX). */, SIGURG = 23 /* Urgent condition on socket (4.2 BSD). */, SIGXCPU = 24 /* CPU limit exceeded (4.2 BSD). */, SIGXFSZ = 25 /* File size limit exceeded (4.2 BSD). */, SIGVTALRM = 26 /* Virtual alarm clock (4.2 BSD). */, SIGPROF = 27 /* Profiling alarm clock (4.2 BSD). */, SIGWINCH = 28 /* Window size change (4.3 BSD, Sun). */, SIGPOLL = 29 /* Pollable event occurred (System V). */, SIGIO = 29 /* I/O now possible (4.2 BSD). */, SIGPWR = 30 /* Power failure restart (System V). */, SIGSYS = 31 /* Bad system call. */, SIGUNUSED = 31; // /usr/include/x86_64-linux-gnu/bits/signalfd.h public static final int SFD_CLOEXEC = 02000000, SFD_NONBLOCK = 00004000; // /usr/include/x86_64-linux-gnu/bits/sigaction.h public static final int SIG_BLOCK = 0, SIG_UNBLOCK = 1, SIG_SETMASK = 2; // /usr/include/x86_64-linux-gnu/bits/signum.h public static final Pointer SIG_ERR = Pointer.createConstant(-1) /* Error return. */, SIG_DFL = Pointer.createConstant(0) /* Default action. */, SIG_IGN = Pointer.createConstant(1) /* Ignore signal. */; // /usr/include/x86_64-linux-gnu/bits/sigaction.h public static final int SA_NOCLDSTOP = 1 /* Don't send SIGCHLD when children stop. */, SA_NOCLDWAIT = 2 /* Don't create zombie on child death. */, SA_SIGINFO = 4 /* Invoke signal-catching function with three arguments instead of one. */, SA_ONSTACK = 0x08000000 /* Use signal stack by using `sa_restorer'. */, SA_RESTART = 0x10000000 /* Restart syscall on signal return. */, SA_NODEFER = 0x40000000 /* Don't automatically block the signal when its handler is being executed. */, SA_RESETHAND = 0x80000000 /* Reset to SIG_DFL on entry to handler. */, SA_INTERRUPT = 0x20000000 /* Historical no-op. */; // Some aliases for the SA_ constants. public static final int SA_NOMASK = SA_NODEFER, SA_ONESHOT = SA_RESETHAND, SA_STACK = SA_ONSTACK; // /usr/include/x86_64-linux-gnu/bits/waitflags.h public static final int WNOHANG = 1, WUNTRACED = 2, WSTOPPED = 2, WEXITED = 4, WCONTINUED = 8, WNOWAIT = 0x01000000, WNOTHREAD = 0x20000000, WALL = 0x40000000, WCLONE = 0x80000000; // Courtesy http://linux.die.net/include/bits/waitstatus.h public static int WEXITSTATUS(int status) { return (status & 0xff00) >> 8; } public static int WTERMSIG(int status) { return (status & 0x7f) >> 8; } public static boolean WIFEXITED(int status) { return WTERMSIG(status) == 0; } public static boolean WIFSIGNALED(int status) { return ((((status & 0x7f) + 1) >> 1) > 0); } public static boolean WIFSTOPPED(int status) { return (status & 0xff) == 0x7f; } public static boolean WIFCONTINUED(int status) { return status == 0xffff; } public static native int close(int fd); public static native int getpid(); public static native int kill(int pid, int sig); public static native int waitpid(int pid, IntByReference status, int options); public static native int pipe(int[] pipefd); public static native int read(int fd, ByteBuffer buffer, int count); public static native int write(int fd, ByteBuffer buffer, int count); public static native int fcntl(int fd, int command, long flags) throws LastErrorException; public static native int eventfd(int initval, int flags); public static native int eventfd_write(int fd, long value); public static native int eventfd_read(int fd, LongByReference value); public static native Pointer signal(int signum, Pointer handler); public static native sighandler_t signal(int signum, sighandler_t handler); public static native int sigemptyset(Pointer set); public static native int sigemptyset(sigset_t.ByReference set); public static native int sigfillset(sigset_t.ByReference set); public static native int sigaddset(sigset_t.ByReference set, int signum); public static native int sigdelset(sigset_t.ByReference set, int signum); public static native int sigismember(sigset_t.ByReference set, int signum); public static native int sigaction( int signum, sigaction.ByReference act, sigaction.ByReference oldact); public static native int sigprocmask( int how, sigset_t.ByReference set, sigset_t.ByReference oldset); public static native int signalfd(int fd, sigset_t.ByReference mask, int flags); }