WINNT POSIX
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) 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 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 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
-
Asynchronous signals are implemented throw special kernel mode APC (KeInsertQueueApc), so delivered almost always.
All syscall in the 'KeWaitForSingleObject/KeWaitForMultipleObjects' are always interrupted, when asynchronous signal arrived and wait mode is UserMode and current irql is less then APC_LEVEL.
For working exceptions in POSIX manner driver modify some system vectors (working fine).
- 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
-
Write on copy fork.
- fork
- __pthread_atfork_enable_initialize_np
- __pthread_atfork_disable_initialize_np
- __pthread_atfork_mark_dll_for_reinitialize_np
-
Mainly implemented as syscalls in the driver. They are exported like general NT syscall throw the 4s NT syscall table (KeAddSystemServiceTable), not throw IOCTL.
-
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
- towlower
- towupper
- wcscasecmp
- _wcsicmp = wcscasecmp
- wcsncasecmp
- _wcsnicmp = wcsncasecmp
- __wchar_ctypes
- iswalnum
- iswalpha
- iswcntrl
- iswdigit
- iswlower
- iswgraph
- iswprint
- iswpunct
- iswspace
- iswupper
- iswxdigit
- iswblank
- iswascii
- __iswalnum_l = iswalnum
- __iswalpha_l = iswalpha
- __iswcntrl_l = iswcntrl
- __iswdigit_l = iswdigit
- __iswlower_l = iswlower
- __iswgraph_l = iswgraph
- __iswprint_l = iswprint
- __iswpunct_l = iswpunct
- __iswspace_l = iswspace
- __iswupper_l = iswupper
- __iswxdigit_l = iswxdigit
- __iswblank_l = iswblank
- __wctype_l = wctype
- __iswctype_l = iswctype
- __towlower_l = towlower
- __towupper_l = towupper
- __wctrans_l = wctrans
- __towctrans_l = towctrans
- __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
Driver is untested with PAE extension. To build driver to PAE system add _X86PAE_ to project define list. Driver and dll are self modified binaries so they require being checked 'Generate debug info' in the link tab to prevent some functions deleting by a linker. I will glad to every report about project to avi@risp.ru.
You may dounload project files from https://sourceforge.net/project/showfiles.php?group_id=53960&release_id=95767
BUILD:
- Add define '_FAST_SYSCALL' to build dll using 'sysenter/sysexit'.
- Remove define '_FAST_SYSCALL' to build dll using 'int 2E'.
INSTALL TREE:
- psxdll
- new
- psxdll2.dll - contain default signal handling for non posix processes and injected in every process
- psxdll.dll - with syscalls implemented throw 'sysenter/sysexit'
- psxdll.pdb
- old
- psxdll2.dll - too, but with syscalls implemented throw 'int 2E'
- psxdll.dll - with syscalls implemented throw 'int 2E'
- psxdll.pdb
- psxsys.inf
- psxsys.pdb
- psxsys.sys
INSTALL STEPS for Windows 2K:
- Run 'Add/Remove Hardware Wizard' from control panel.
- Click 'Next'.
- Choose 'Add/Troubleshoot a device', then click 'Next'.
- Choose 'Add new device', then click 'Next'.
- Choose 'No, I want to select the hardware from list', then click 'Next'.
- Choose 'Other devices', then click 'Next'.
- Press 'Have Disk', click 'Next'.
- Enter files location, click 'OK'.
- You can see 'POSIX port for Windows NT box' in the 'Models' list, click 'Next'.
- Press 'Next' and 'Finish'.
- Restart system.
UNINSTALL STEPS:
- Run 'Add/Remove Hardware Wizard' from control panel.
- Click 'Next'.
- Choose 'Uninstall/Unplug a device', then click 'Next'.
- Choose 'Uninstall a device', then click 'Next'.
- Choose 'POSIX port for Windows NT box' from devices list, then click 'Next'.
- Choose 'Yes, I want to uninstall this device', click 'Next'.
- Press 'Finish'.
INSTALL STEPS for Windows XP:
- Run 'Add Hardware' from control panel.
- Click 'Next'.
- Choose 'Yes, I already connected the hardware, then click 'Next'.
- Choose 'Add a new hardware device', then click 'Next'.
- Choose 'Install the hardware that I manually select from a list(Advanced)', then click 'Next'.
- Choose 'Show all devices', then click 'Next'.
- Press 'Have Disk', click 'Next'.
- Enter files location, click 'OK'.
- You can see 'POSIX port for Windows NT box' in the 'Models' list, click 'Next'.
- Press 'Next' and 'Finish'.
- Restart system.
UNINSTALL STEPS:
- Run 'System' from control panel.
- Choose 'Hardware' tab.
- Choose 'Device manager', then click 'Next'.
- Delete 'Unknown device', from IEEE 1394 Bus host controllers.