Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/kernel32/tests/fiber.c | 8 ++++++-- dlls/kernelbase/thread.c | 15 +-------------- dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/thread.c | 24 +++++++++++++++++++++++- include/winternl.h | 1 + 5 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/dlls/kernel32/tests/fiber.c b/dlls/kernel32/tests/fiber.c index b058dae7491..0304dcfcde0 100644 --- a/dlls/kernel32/tests/fiber.c +++ b/dlls/kernel32/tests/fiber.c @@ -38,7 +38,7 @@ static BOOL (WINAPI *pFlsFree)(DWORD); static PVOID (WINAPI *pFlsGetValue)(DWORD); static BOOL (WINAPI *pFlsSetValue)(DWORD,PVOID); static NTSTATUS (WINAPI *pRtlFlsAlloc)(PFLS_CALLBACK_FUNCTION,DWORD*); - +static NTSTATUS (WINAPI *pRtlFlsFree)(ULONG); static void *fibers[3]; static BYTE testparam = 185; static DWORD fls_index_to_set = FLS_OUT_OF_INDEXES; @@ -69,6 +69,7 @@ static VOID init_funcs(void)
#define X(f) p##f = (void*)GetProcAddress(hntdll, #f); X(RtlFlsAlloc); + X(RtlFlsFree); #undef X
} @@ -218,7 +219,10 @@ static void test_FiberLocalStorage(void) ok(count && (count <= 127 || (count > 4000 && count < 4096)), "Got unexpected count %u.\n", count);
for (i = 0; i < count; ++i) - pFlsFree(fls_indices[i]); + { + status = pRtlFlsFree(fls_indices[i]); + ok(!status, "Got unexpected status %#x.\n", status); + } } else { diff --git a/dlls/kernelbase/thread.c b/dlls/kernelbase/thread.c index bdc7502632b..2f304a06e9e 100644 --- a/dlls/kernelbase/thread.c +++ b/dlls/kernelbase/thread.c @@ -1082,20 +1082,7 @@ DWORD WINAPI DECLSPEC_HOTPATCH FlsAlloc( PFLS_CALLBACK_FUNCTION callback ) */ BOOL WINAPI DECLSPEC_HOTPATCH FlsFree( DWORD index ) { - BOOL ret; - - RtlAcquirePebLock(); - ret = RtlAreBitsSet( NtCurrentTeb()->Peb->FlsBitmap, index, 1 ); - if (ret) RtlClearBits( NtCurrentTeb()->Peb->FlsBitmap, index, 1 ); - if (ret) - { - /* FIXME: call Fls callback */ - /* FIXME: add equivalent of ThreadZeroTlsCell here */ - if (NtCurrentTeb()->FlsSlots) NtCurrentTeb()->FlsSlots[index] = 0; - } - else SetLastError( ERROR_INVALID_PARAMETER ); - RtlReleasePebLock(); - return ret; + return set_ntstatus( RtlFlsFree( index )); }
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index aac2af26f36..5cf7e31b01e 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -667,6 +667,7 @@ @ stdcall RtlFirstEntrySList(ptr) @ stdcall RtlFirstFreeAce(ptr ptr) @ stdcall RtlFlsAlloc(ptr ptr) +@ stdcall RtlFlsFree(long) @ stub RtlFlushPropertySet # @ stub RtlFlushSecureMemoryCache @ stdcall RtlFormatCurrentUserKeyPath(ptr) diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index f277a52dc06..bbec1f98728 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -256,7 +256,7 @@ TEB_ACTIVE_FRAME * WINAPI RtlGetFrame(void) /*********************************************************************** * RtlFlsAlloc (NTDLL.@) */ -NTSTATUS WINAPI DECLSPEC_HOTPATCH RtlFlsAlloc( PFLS_CALLBACK_FUNCTION callback, DWORD *ret_index ) +NTSTATUS WINAPI DECLSPEC_HOTPATCH RtlFlsAlloc( PFLS_CALLBACK_FUNCTION callback, ULONG *ret_index ) { PEB * const peb = NtCurrentTeb()->Peb; NTSTATUS status = STATUS_NO_MEMORY; @@ -289,3 +289,25 @@ NTSTATUS WINAPI DECLSPEC_HOTPATCH RtlFlsAlloc( PFLS_CALLBACK_FUNCTION callback, *ret_index = index; return status; } + + +/*********************************************************************** + * RtlFlsFree (NTDLL.@) + */ +NTSTATUS WINAPI DECLSPEC_HOTPATCH RtlFlsFree( ULONG index ) +{ + NTSTATUS status; + + RtlAcquirePebLock(); + if (RtlAreBitsSet( NtCurrentTeb()->Peb->FlsBitmap, index, 1 )) + { + RtlClearBits( NtCurrentTeb()->Peb->FlsBitmap, index, 1 ); + /* FIXME: call Fls callback */ + /* FIXME: add equivalent of ThreadZeroTlsCell here */ + if (NtCurrentTeb()->FlsSlots) NtCurrentTeb()->FlsSlots[index] = 0; + status = STATUS_SUCCESS; + } + else status = STATUS_INVALID_PARAMETER; + RtlReleasePebLock(); + return status; +} diff --git a/include/winternl.h b/include/winternl.h index ba9d9442590..117d34bbfdf 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -3372,6 +3372,7 @@ NTSYSAPI ULONG WINAPI RtlFindSetBitsAndClear(PRTL_BITMAP,ULONG,ULONG); NTSYSAPI ULONG WINAPI RtlFindSetRuns(PCRTL_BITMAP,PRTL_BITMAP_RUN,ULONG,BOOLEAN); NTSYSAPI BOOLEAN WINAPI RtlFirstFreeAce(PACL,PACE_HEADER *); NTSYSAPI NTSTATUS WINAPI RtlFlsAlloc(PFLS_CALLBACK_FUNCTION,ULONG *); +NTSYSAPI NTSTATUS WINAPI RtlFlsFree(ULONG); NTSYSAPI NTSTATUS WINAPI RtlFormatCurrentUserKeyPath(PUNICODE_STRING); NTSYSAPI NTSTATUS WINAPI RtlFormatMessage(LPCWSTR,ULONG,BOOLEAN,BOOLEAN,BOOLEAN,__ms_va_list *,LPWSTR,ULONG,ULONG*); NTSYSAPI NTSTATUS WINAPI RtlFormatMessageEx(LPCWSTR,ULONG,BOOLEAN,BOOLEAN,BOOLEAN,__ms_va_list *,LPWSTR,ULONG,ULONG*,ULONG);