diff --git a/dll/ntdll/CMakeLists.txt b/dll/ntdll/CMakeLists.txt index 6ad60fd8404..09e077cb4e6 100644 --- a/dll/ntdll/CMakeLists.txt +++ b/dll/ntdll/CMakeLists.txt @@ -1,4 +1,6 @@ +add_subdirectory(nt_0600) + spec2def(ntdll.dll def/ntdll.spec ADD_IMPORTLIB) add_definitions( diff --git a/dll/win32/ntdll_vista/CMakeLists.txt b/dll/ntdll/nt_0600/CMakeLists.txt similarity index 74% rename from dll/win32/ntdll_vista/CMakeLists.txt rename to dll/ntdll/nt_0600/CMakeLists.txt index d0edd56c6c0..061502ac7f1 100644 --- a/dll/win32/ntdll_vista/CMakeLists.txt +++ b/dll/ntdll/nt_0600/CMakeLists.txt @@ -1,20 +1,22 @@ -remove_definitions(-D_WIN32_WINNT=0x502 -DWINVER=0x502) -add_definitions(-D_WIN32_WINNT=0x600 -DWINVER=0x600 - -D__NTDLL__ - -D_NTOSKRNL_ - -D_NTSYSTEM_) - spec2def(ntdll_vista.dll ntdll_vista.spec ADD_IMPORTLIB) +add_definitions( + -D__NTDLL__ + -D_NTOSKRNL_ + -DCRTDLL) + +include_directories( + BEFORE include + ${REACTOS_SOURCE_DIR}/sdk/include/reactos/subsys) + list(APPEND SOURCE DllMain.c - condvar.c - srw.c ${CMAKE_CURRENT_BINARY_DIR}/ntdll_vista.def) add_library(ntdll_vista MODULE ${SOURCE}) set_module_type(ntdll_vista win32dll ENTRYPOINT DllMain 12) +target_link_libraries(ntdll_vista rtl_vista) if(ARCH STREQUAL "arm") target_link_libraries(ntdll_vista chkstk) endif() diff --git a/dll/win32/ntdll_vista/DllMain.c b/dll/ntdll/nt_0600/DllMain.c similarity index 100% rename from dll/win32/ntdll_vista/DllMain.c rename to dll/ntdll/nt_0600/DllMain.c diff --git a/dll/win32/ntdll_vista/ntdll_vista.spec b/dll/ntdll/nt_0600/ntdll_vista.spec similarity index 70% rename from dll/win32/ntdll_vista/ntdll_vista.spec rename to dll/ntdll/nt_0600/ntdll_vista.spec index 2bcde610d01..1a3098dde3f 100644 --- a/dll/win32/ntdll_vista/ntdll_vista.spec +++ b/dll/ntdll/nt_0600/ntdll_vista.spec @@ -8,3 +8,7 @@ @ stdcall RtlReleaseSRWLockShared(ptr) @ stdcall RtlAcquireSRWLockExclusive(ptr) @ stdcall RtlReleaseSRWLockExclusive(ptr) +@ stdcall RtlRunOnceInitialize(ptr) +@ stdcall RtlRunOnceBeginInitialize(ptr long ptr) +@ stdcall RtlRunOnceComplete(ptr long ptr) +@ stdcall RtlRunOnceExecuteOnce(ptr ptr ptr ptr) diff --git a/dll/win32/CMakeLists.txt b/dll/win32/CMakeLists.txt index 66a82d2d3b9..01e6dee240e 100644 --- a/dll/win32/CMakeLists.txt +++ b/dll/win32/CMakeLists.txt @@ -140,7 +140,6 @@ add_subdirectory(netid) add_subdirectory(netmsg) add_subdirectory(newdev) add_subdirectory(npptools) -add_subdirectory(ntdll_vista) add_subdirectory(ntdsapi) add_subdirectory(ntlanman) add_subdirectory(ntmarta) diff --git a/dll/win32/kernel32_vista/CMakeLists.txt b/dll/win32/kernel32_vista/CMakeLists.txt index 068297a4a03..915346689a1 100644 --- a/dll/win32/kernel32_vista/CMakeLists.txt +++ b/dll/win32/kernel32_vista/CMakeLists.txt @@ -15,7 +15,7 @@ list(APPEND SOURCE add_library(kernel32_vista MODULE ${SOURCE}) set_module_type(kernel32_vista win32dll ENTRYPOINT DllMain 12) -add_importlibs(kernel32_vista kernel32 ntdll) +add_importlibs(kernel32_vista kernel32 ntdll_vista ntdll) add_delay_importlibs(kernel32_vista ntdll_vista) add_dependencies(kernel32_vista psdk) add_cd_file(TARGET kernel32_vista DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/kernel32_vista/InitOnceExecuteOnce.c b/dll/win32/kernel32_vista/InitOnceExecuteOnce.c index b9073fd0fd3..1ef59160aef 100644 --- a/dll/win32/kernel32_vista/InitOnceExecuteOnce.c +++ b/dll/win32/kernel32_vista/InitOnceExecuteOnce.c @@ -5,107 +5,8 @@ #include #include -/* Taken from Wine ntdll/sync.c */ - -HANDLE keyed_event = NULL; - -static DWORD WINAPI RtlRunOnceBeginInitialize( RTL_RUN_ONCE *once, ULONG flags, void **context ) -{ - if (flags & RTL_RUN_ONCE_CHECK_ONLY) - { - ULONG_PTR val = (ULONG_PTR)once->Ptr; - - if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; - if ((val & 3) != 2) return STATUS_UNSUCCESSFUL; - if (context) *context = (void *)(val & ~3); - return STATUS_SUCCESS; - } - - for (;;) - { - ULONG_PTR next, val = (ULONG_PTR)once->Ptr; - - switch (val & 3) - { - case 0: /* first time */ - if (!interlocked_cmpxchg_ptr( &once->Ptr, - (flags & RTL_RUN_ONCE_ASYNC) ? (void *)3 : (void *)1, 0 )) - return STATUS_PENDING; - break; - - case 1: /* in progress, wait */ - if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; - next = val & ~3; - if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1), - (void *)val ) == (void *)val) - NtWaitForKeyedEvent( keyed_event, &next, FALSE, NULL ); - break; - - case 2: /* done */ - if (context) *context = (void *)(val & ~3); - return STATUS_SUCCESS; - - case 3: /* in progress, async */ - if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER; - return STATUS_PENDING; - } - } -} - -static DWORD WINAPI RtlpRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context ) -{ - if ((ULONG_PTR)context & 3) return STATUS_INVALID_PARAMETER; - - if (flags & RTL_RUN_ONCE_INIT_FAILED) - { - if (context) return STATUS_INVALID_PARAMETER; - if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; - } - else context = (void *)((ULONG_PTR)context | 2); - - for (;;) - { - ULONG_PTR val = (ULONG_PTR)once->Ptr; - - switch (val & 3) - { - case 1: /* in progress */ - if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break; - val &= ~3; - while (val) - { - ULONG_PTR next = *(ULONG_PTR *)val; - NtReleaseKeyedEvent( keyed_event, (void *)val, FALSE, NULL ); - val = next; - } - return STATUS_SUCCESS; - - case 3: /* in progress, async */ - if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER; - if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break; - return STATUS_SUCCESS; - - default: - return STATUS_UNSUCCESSFUL; - } - } -} - -static DWORD WINAPI RtlpRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, - void *param, void **context ) -{ - DWORD ret = RtlRunOnceBeginInitialize( once, 0, context ); - - if (ret != STATUS_PENDING) return ret; - - if (!func( once, param, context )) - { - RtlpRunOnceComplete( once, RTL_RUN_ONCE_INIT_FAILED, NULL ); - return STATUS_UNSUCCESSFUL; - } - - return RtlpRunOnceComplete( once, 0, context ? *context : NULL ); -} +DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, + void *param, void **context ); /* Taken from Wine kernel32/sync.c */ @@ -114,5 +15,5 @@ static DWORD WINAPI RtlpRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_IN */ BOOL NTAPI InitOnceExecuteOnce( INIT_ONCE *once, PINIT_ONCE_FN func, void *param, void **context ) { - return !RtlpRunOnceExecuteOnce( once, (PRTL_RUN_ONCE_INIT_FN)func, param, context ); + return !RtlRunOnceExecuteOnce( once, (PRTL_RUN_ONCE_INIT_FN)func, param, context ); } diff --git a/sdk/lib/rtl/CMakeLists.txt b/sdk/lib/rtl/CMakeLists.txt index 573e4c08026..65bf915b45d 100644 --- a/sdk/lib/rtl/CMakeLists.txt +++ b/sdk/lib/rtl/CMakeLists.txt @@ -114,3 +114,13 @@ add_asm_files(rtl_asm ${ASM_SOURCE}) add_library(rtl ${SOURCE} ${rtl_asm}) add_pch(rtl rtl.h SOURCE) add_dependencies(rtl psdk asm) + +list(APPEND SOURCE_VISTA + condvar.c + runonce.c + srw.c +) + +add_library(rtl_vista ${SOURCE_VISTA}) +add_pch(rtl rtl_vista.h SOURCE_VISTA) +add_dependencies(rtl_vista psdk) diff --git a/dll/win32/ntdll_vista/condvar.c b/sdk/lib/rtl/condvar.c similarity index 100% rename from dll/win32/ntdll_vista/condvar.c rename to sdk/lib/rtl/condvar.c diff --git a/dll/win32/ntdll_vista/rtl_vista.h b/sdk/lib/rtl/rtl_vista.h similarity index 90% rename from dll/win32/ntdll_vista/rtl_vista.h rename to sdk/lib/rtl/rtl_vista.h index 9f96f15b50d..ef887b77681 100644 --- a/dll/win32/ntdll_vista/rtl_vista.h +++ b/sdk/lib/rtl/rtl_vista.h @@ -6,8 +6,13 @@ * PROGRAMMER: Alex Ionescu */ -#ifndef RTL_H -#define RTL_H +#ifndef RTL_VISTA_H +#define RTL_VISTA_H + +#undef _WIN32_WINNT +#undef WINVER +#define _WIN32_WINNT 0x600 +#define WINVER 0x600 /* We're a core NT DLL, we don't import syscalls */ #define _INC_SWPRINTF_INL_ @@ -54,4 +59,4 @@ #define InterlockedBitTestAndSet64 _interlockedbittestandset64 #endif -#endif /* RTL_H */ +#endif /* RTL_VISTA_H */ diff --git a/sdk/lib/rtl/runonce.c b/sdk/lib/rtl/runonce.c new file mode 100644 index 00000000000..10401287983 --- /dev/null +++ b/sdk/lib/rtl/runonce.c @@ -0,0 +1,121 @@ + +/* Taken from Wine ntdll/sync.c */ + +#include "rtl_vista.h" +#include +#include + +/****************************************************************** + * RtlRunOnceInitialize (NTDLL.@) + */ +void WINAPI RtlRunOnceInitialize( RTL_RUN_ONCE *once ) +{ + once->Ptr = NULL; +} + +/****************************************************************** + * RtlRunOnceBeginInitialize (NTDLL.@) + */ +DWORD WINAPI RtlRunOnceBeginInitialize( RTL_RUN_ONCE *once, ULONG flags, void **context ) +{ + if (flags & RTL_RUN_ONCE_CHECK_ONLY) + { + ULONG_PTR val = (ULONG_PTR)once->Ptr; + + if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; + if ((val & 3) != 2) return STATUS_UNSUCCESSFUL; + if (context) *context = (void *)(val & ~3); + return STATUS_SUCCESS; + } + + for (;;) + { + ULONG_PTR next, val = (ULONG_PTR)once->Ptr; + + switch (val & 3) + { + case 0: /* first time */ + if (!interlocked_cmpxchg_ptr( &once->Ptr, + (flags & RTL_RUN_ONCE_ASYNC) ? (void *)3 : (void *)1, 0 )) + return STATUS_PENDING; + break; + + case 1: /* in progress, wait */ + if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; + next = val & ~3; + if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1), + (void *)val ) == (void *)val) + NtWaitForKeyedEvent( 0, &next, FALSE, NULL ); + break; + + case 2: /* done */ + if (context) *context = (void *)(val & ~3); + return STATUS_SUCCESS; + + case 3: /* in progress, async */ + if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER; + return STATUS_PENDING; + } + } +} + +/****************************************************************** + * RtlRunOnceComplete (NTDLL.@) + */ +DWORD WINAPI RtlRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context ) +{ + if ((ULONG_PTR)context & 3) return STATUS_INVALID_PARAMETER; + + if (flags & RTL_RUN_ONCE_INIT_FAILED) + { + if (context) return STATUS_INVALID_PARAMETER; + if (flags & RTL_RUN_ONCE_ASYNC) return STATUS_INVALID_PARAMETER; + } + else context = (void *)((ULONG_PTR)context | 2); + + for (;;) + { + ULONG_PTR val = (ULONG_PTR)once->Ptr; + + switch (val & 3) + { + case 1: /* in progress */ + if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break; + val &= ~3; + while (val) + { + ULONG_PTR next = *(ULONG_PTR *)val; + NtReleaseKeyedEvent( 0, (void *)val, FALSE, NULL ); + val = next; + } + return STATUS_SUCCESS; + + case 3: /* in progress, async */ + if (!(flags & RTL_RUN_ONCE_ASYNC)) return STATUS_INVALID_PARAMETER; + if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break; + return STATUS_SUCCESS; + + default: + return STATUS_UNSUCCESSFUL; + } + } +} + +/****************************************************************** + * RtlRunOnceExecuteOnce (NTDLL.@) + */ +DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, + void *param, void **context ) +{ + DWORD ret = RtlRunOnceBeginInitialize( once, 0, context ); + + if (ret != STATUS_PENDING) return ret; + + if (!func( once, param, context )) + { + RtlRunOnceComplete( once, RTL_RUN_ONCE_INIT_FAILED, NULL ); + return STATUS_UNSUCCESSFUL; + } + + return RtlRunOnceComplete( once, 0, context ? *context : NULL ); +} diff --git a/dll/win32/ntdll_vista/srw.c b/sdk/lib/rtl/srw.c similarity index 100% rename from dll/win32/ntdll_vista/srw.c rename to sdk/lib/rtl/srw.c