Fully compatible and efficient POSIX library for Microsoft Windows
NT box (currently W2K-XP and probably later), like Interix. Windows NT generally allowed to
implement POSIX API, but all existing implementations are could divided into two parts:
-
Microsoft (posix.exe, psxss.exe, psxdll.dll not distributed since from W2K) and
extended Interix, but still single threaded, only console and not integrated with Win32.
-
From others developers, usually there are Win9X support too and implemented at the top of Win32
API so not fully compatible and efficient.
This is fully integrated with Win32, except SEH or any other installed subsystems and efficient and compatible library.
Now implemented:
-
Threads may be Round Robin scheduling with priorities from 1 to 15, or Microsoft realtime scheduling with priorities from 16 to 31.
- pthread_create
- pthread_create
- pthread_self
- pthread_equal
- pthread_exit
- pthread_join
- pthread_detach
- pthread_setschedparam
- pthread_getschedparam
- pthread_getconcurrency
- pthread_setconcurrency
- pthread_yield
- pthread_key_create
- pthread_key_delete
- pthread_setspecific
- pthread_getspecific
- pthread_cleanup_push is implemented throw SEH internal mechanisms, so work with __try/__finally/__except (if non POSIX signal mode) and try/catch if it is implemented throw SEH, that is in the most popular compilers.
- pthread_cleanup_push_defer_np - too
- pthread_cleanup_pop
- pthread_cleanup_pop_defer_np
- pthread_once
- pthread_setcancelstate
- pthread_setcanceltype
- pthread_cancel
- pthread_testcancel
- pthread_allocate_stack_np
- pthread_attr_init
- pthread_attr_setdetachstate
- pthread_attr_getdetachstate
- pthread_attr_setschedparam
- pthread_attr_getschedparam
- pthread_attr_setschedpolicy
- pthread_attr_getschedpolicy
- pthread_attr_setinheritsched
- pthread_attr_getinheritsched
- pthread_attr_setscope
- pthread_attr_getscope
- pthread_attr_setguardsize
- pthread_attr_getguardsize
- pthread_attr_setstackaddr
- pthread_attr_getstackaddr
- pthread_attr_setstacksize
- pthread_attr_getstacksize
- pthread_attr_setstack
- pthread_attr_getstack
-
Mutexes may be PTHREAD_MUTEX_ADAPTIVE_NP, PTHREAD_MUTEX_FAST_NP, PTHREAD_MUTEX_ERRORCHECK_NP, PTHREAD_MUTEX_RECURSIVE_NP, if defined Single Unix V2 things, then may be PTHREAD_MUTEX_NORMAL, PTHREAD_MUTEX_DEFAULT, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE.
Also support PTHREAD_PROCESS_SHARED (shared lock objects do not automatically released when process die), PTHREAD_PROCESS_PRIVATE.
Support timedwait for all types. Optimasing for using in SMP systems.
- pthread_mutex_init
- pthread_mutex_destroy
- pthread_mutex_lock
- pthread_mutex_timedlock
- pthread_mutex_trylock
- pthread_mutex_unlock
- pthread_mutexattr_init
- pthread_mutexattr_destroy
- pthread_mutexattr_gettype
- pthread_mutexattr_settype
- pthread_mutexattr_getpshared
- pthread_mutexattr_setpshared
- pthread_mutexattr_getkind_np
- pthread_mutexattr_setkind_np
-
Condvar, spin, rwlock, or barrier locks may be shared too. Spins is not busy waiting, because it is not efficient when use with threads with differ priorities. Using combined busy wait for the next acquiring to lock thread and no more acquires, and wait on wait object in the other ways.
Optimasing for using in SMP systems too.
- pthread_spin_init
- pthread_spin_destroy
- pthread_spin_lock
- pthread_spin_timedlock_np
- pthread_spin_unlock
- pthread_spin_trylock
- pthread_rwlock_init
- pthread_rwlock_destroy
- pthread_rwlock_wrlock
- pthread_rwlock_timedwrlock
- pthread_rwlock_trywrlock
- pthread_rwlock_rdlock
- pthread_rwlock_timedrdlock
- pthread_rwlock_tryrdlock
- pthread_rwlock_unlock
- pthread_barrier_init
- pthread_barrier_destroy
- pthread_barrier_wait
- pthread_barrierattr_init
- pthread_barrierattr_destroy
- pthread_barrierattr_getpshared
- pthread_barrierattr_setpshared
- pthread_cond_init
- pthread_cond_destroy
- pthread_cond_wait
- pthread_cond_timedwait
- pthread_cond_signal
- pthread_cond_broadcast
- pthread_condattr_init
- pthread_condattr_destroy
- pthread_condattr_getpshared
- pthread_condattr_setpshared
Interval timers may be ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF.
POSIX timers may use next cloks: CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID, CLOCK_THREAD_VIRTUAL_ID, additional flag is TIMER_ABSTIME,
with sigevent types: SIGEV_SIGNAL, SIGEV_NONE, SIGEV_THREAD.
- timer_create
- timer_delete
- timer_getoverrun
- timer_settime
- timer_gettime
-
Signals delivered not only when THREAD IN THE USER mode (usually in the other the same products that use suspend + get + modify + set context + resume thread scheme, I use normal kernel mode APC [delivers almost always] + setup callback), when in the kernel mode too. POSIX syscalls that can be interrupted are may be interrupted, others are always restarted. Signals don't delivered when thread suspended. Asynchronous signals are implemented throw special kernel mode APC (KeInsertQueueApc)
-
if previous mode was kernel and syscall is from this list:
-
NtWaitForMultipleObjects/ZwWaitForMultipleObjects (WaitForMultipleObjects, WaitForMultipleObjectsEx)
-
NtWaitForSingleObject/ZwWaitForSingleObject (WaitForSingleObject, WaitForSingleObjectEx)
-
NtDelayExecution/ZwDelayExecution (Sleep, SleepEx)
-
NtCreateFile/ZwCreateFile (CreateFile)
-
NtOpenFile/ZwOpenFile (OpenFile)
-
NtCreateNamedPipeFile/ZwCreateNamedPipeFile (CreateNamedPipe, ...)
-
NtCreateMailslotFile/ZwCreateMailslotFile (CreateMailslot)
-
NtReadFile/ZwReadFile (ReadFile, ReadFileEx except console; recv, WSARecv, recvfrom, WSARecvFrom)
-
NtReadFileScatter/ZwReadFileScatter (ReadFileScatter)
-
NtWriteFile/ZwWriteFile (WriteFile, WriteFileEx except console; send, WSASend, WSASendTo)
-
NtWriteFileGather/ZwWriteFileGather (WriteFileGather)
-
NtLockFile/ZwLockFile (LockFile, LockFileEx)
-
NtWaitLowEventPair/ZwWaitLowEventPair (subsystem)
-
NtWaitHighEventPair/ZwWaitHighEventPair (subsystem)
-
NtRequestWaitReplyPort/ZwRequestWaitReplyPort (subsystem, console)
then using user mode callback (KeUserModeCallback)
-
else if previous mode was user mode, then setup handler and context from saved in the kernel stack KTRAP_FRAME.
For working exceptions in POSIX manner driver modify some system vectors (working fine), so SEH hardware exceptions only for the POSIX processes in this case don't work (difference from Interix). To handle its use signal handlers instead. Call NtPsxSetPosixSignalMode to set task POSIX manner hardware exception processing. You can use any other Win32 API. Also some problems may occur when debugging signal handler and thread was in the kernel mode before signal arrived (for example windows debugger not responded later under XP :-( ).
- Up to 256 signals, including realtime extension.
- sigreturn
- sigreturn
- sigismember
- sigaddset
- sigdelset
- sighold
- sigrelse
- sigprocmask
- pthread_sigmask
- pthread_kill
- kill
- sigaction
- sysv_signal
- signal
- ssignal
- bsd_signal
- killpg
- raise
- gsignal
- pause
- _sigpause
- sigpause
- sigblock
- sigsetmask
- siggetmask
- sigsuspend
- sigpending
- sigwait
- sigwaitinfo
- sigtimedwait
- sigqueue
- siginterrupt
- sigvec
- sigignore
- sigstack
- sigaltstack
- sigset
- sys_siglist
- sig_number
- psignal
- strsignal
-
Scheduling may be Round Robin or Microsoft realtime. Priority and scheduling algorithm are setted for the all threads in the process.
- sched_setparam
- sched_getparam
- sched_setscheduler
- sched_getscheduler
- sched_yield
- sched_get_priority_max
- sched_get_priority_min
- sched_rr_get_interval
-
Mainly implemented as syscalls in the driver. They are exported like general NT syscall throw the 4s NT syscall table (KeAddSystemServiceTable), not throw IOCTL.
- NtPsxCreateThread
- NtPsxExitThread
- NtPsxJoinThread
- NtPsxDetachThread
- NtPsxThreadSetScheduler
- NtPsxThreadGetScheduler
- NtPsxThreadSetCancelState
- NtPsxThreadGetCancelState
- NtPsxThreadSetCancelType
- NtPsxThreadGetCancelType
- NtPsxCancelThread
- NtPsxThreadTestCancel
- NtPsxWaitThread
- NtPsxTimedWaitThread
- NtPsxUnWaitThread
- NtPsxKillThread
- NtPsxCreateCondVar
- NtPsxDestroyCondVar
- NtPsxWaitCondVar
- NtPsxTimedWaitCondVar
- NtPsxSignalCondVar
- NtPsxBroadCastCondVar
- NtPsxCreateWaitObj
- NtPsxDestroyWaitObj
- NtPsxWaitObject
- NtPsxTimedWaitObject
- NtPsxSignalWaitObj
- NtPsxKill
- NtPsxSignalMask
- NtPsxHoldSignal
- NtPsxSignalAction
- NtPsxPause
- NtPsxPending
- NtPsxWaitSignal
- NtPsxSignalVector
- NtPsxClock
- NtPsxGetClockResolution
- NtPsxGetKUTime
- NtPsxIntervalTimer
- NtPsxGet86Vector
- NtPsxGet86PageEntry
- NtPsxGet86VAD
- NtIx86Disassemble
- NtPsxSetScheduler
- NtPsxGetScheduler
- NtPsxCreateBarrier
- NtPsxDestroyBarrier
- NtPsxWaitBarrier
- NtPsxCreateWaitObjEx
- NtPsxDestroyWaitObjEx
- NtPsxGetWaitObjValue
- NtPsxThreadGetKUTime
-
Also implemented SMP heap (malloc, free, ...), some string functions (faster then from msvcrt.dll/ntdll.dll), X86 disassembler (tested only generic mode), XSI-conformant clock, alarm. Many of them implemented using undocumented functions and structures.
- RtHeapCreate
- RtHeapDestroy
- RtHeapAlloc
- RtHeapAllocDbg
- RtHeapFree
- RtHeapFreeDbg
- RtHeapReAlloc
- RtHeapReAllocDbg
- RtHeapCompact
- RtHeapUsableSize
- RtHeapUsableSizeDbg
- RtHeapWalk
- RtHeapUsageDump
- RtAllocEx
- RtAllocExDbg
- RtFreeEx
- RtFreeExDbg
- RtReAllocEx
- RtReAllocExDbg
- RtCompact
- RtUsableSizeEx
- RtUsableSizeExDbg
- RtUsageDump
- malloc
- malloc_dbg
- calloc
- calloc_dbg
- memalign
- memalign_dbg
- valloc
- valloc_dbg
- pvalloc
- pvalloc_dbg
- free
- cfree = free
- free_dbg
- realloc
- realloc_dbg
- malloc_trim
- malloc_usable_size
- malloc_usable_size_dbg
- memcpy
- memmove
- bcopy
- memccpy
- memset
- bzero
- memcmp
- bcmp
- memchr
- rawmemchr
- memrchr
- strlen
- strnlen
- strcmp
- strncmp
- strcpy
- strncpy
- strcat
- strncat
- strchr
- strrchr
- wmemcpy
- wmemmove
- wmemccpy
- wmemset
- wmemcmp
- wmemchr
- wrawmemchr
- wmemrchr
- wcslen
- wcsnlen
- wcscmp
- wcsncmp
- wcscpy
- wcsncpy
- wcsncat
- wcscat
- wcschr
- wcsrchr
- __rtassert
- __errnop
- __signgamp
- clock
- alarm
- __srandom_r
- srandom_r = __srandom_r
- __initstate_r
- initstate_r = __initstate_r
- __setstate_r
- setstate_r = __setstate_r
- __random_r
- random_r = __random_r
- __initstate
- initstate = __initstate
- __setstate
- setstate = __setstate
- __random
- random = __random
You may dounload project files from https://sourceforge.net/project/showfiles.php?group_id=53960&release_id=95767
To install unzip and run setup.exe, psxsys.sys must be in the same path and will be started from this place every time.