Commit 598c5816 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Don't allocate FLS index 0.

parent 93920c38
...@@ -230,7 +230,7 @@ DWORD WINAPI FlsAlloc( PFLS_CALLBACK_FUNCTION callback ) ...@@ -230,7 +230,7 @@ DWORD WINAPI FlsAlloc( PFLS_CALLBACK_FUNCTION callback )
} }
else else
{ {
index = RtlFindClearBitsAndSet( peb->FlsBitmap, 1, 0 ); index = RtlFindClearBitsAndSet( peb->FlsBitmap, 1, 1 );
if (index != ~0U) if (index != ~0U)
{ {
if (!NtCurrentTeb()->FlsSlots && if (!NtCurrentTeb()->FlsSlots &&
...@@ -279,7 +279,7 @@ BOOL WINAPI FlsFree( DWORD index ) ...@@ -279,7 +279,7 @@ BOOL WINAPI FlsFree( DWORD index )
*/ */
PVOID WINAPI FlsGetValue( DWORD index ) PVOID WINAPI FlsGetValue( DWORD index )
{ {
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->FlsBitmapBits) || !NtCurrentTeb()->FlsSlots) if (!index || index >= 8 * sizeof(NtCurrentTeb()->Peb->FlsBitmapBits) || !NtCurrentTeb()->FlsSlots)
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return NULL; return NULL;
...@@ -293,7 +293,7 @@ PVOID WINAPI FlsGetValue( DWORD index ) ...@@ -293,7 +293,7 @@ PVOID WINAPI FlsGetValue( DWORD index )
*/ */
BOOL WINAPI FlsSetValue( DWORD index, PVOID data ) BOOL WINAPI FlsSetValue( DWORD index, PVOID data )
{ {
if (index >= 8 * sizeof(NtCurrentTeb()->Peb->FlsBitmapBits)) if (!index || index >= 8 * sizeof(NtCurrentTeb()->Peb->FlsBitmapBits))
{ {
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
......
...@@ -2768,7 +2768,7 @@ DWORD WINAPI TlsAlloc( void ) ...@@ -2768,7 +2768,7 @@ DWORD WINAPI TlsAlloc( void )
PEB * const peb = NtCurrentTeb()->Peb; PEB * const peb = NtCurrentTeb()->Peb;
RtlAcquirePebLock(); RtlAcquirePebLock();
index = RtlFindClearBitsAndSet( peb->TlsBitmap, 1, 0 ); index = RtlFindClearBitsAndSet( peb->TlsBitmap, 1, 1 );
if (index != ~0U) NtCurrentTeb()->TlsSlots[index] = 0; /* clear the value */ if (index != ~0U) NtCurrentTeb()->TlsSlots[index] = 0; /* clear the value */
else else
{ {
......
...@@ -181,6 +181,35 @@ static void test_FiberLocalStorage(PFLS_CALLBACK_FUNCTION cbfunc) ...@@ -181,6 +181,35 @@ static void test_FiberLocalStorage(PFLS_CALLBACK_FUNCTION cbfunc)
ok(ret, "FlsFree failed\n"); ok(ret, "FlsFree failed\n");
if (cbfunc) if (cbfunc)
todo_wine ok(cbCount == 1, "Wrong callback count: %d\n", cbCount); todo_wine ok(cbCount == 1, "Wrong callback count: %d\n", cbCount);
/* test index 0 */
SetLastError( 0xdeadbeef );
val = pFlsGetValue( 0 );
ok( !val, "fls index 0 set to %p\n", val );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "setting fls index wrong error %u\n", GetLastError() );
SetLastError( 0xdeadbeef );
ret = pFlsSetValue( 0, (void *)0xdeadbeef );
ok( !ret, "setting fls index 0 succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "setting fls index wrong error %u\n", GetLastError() );
SetLastError( 0xdeadbeef );
val = pFlsGetValue( 0 );
ok( !val, "fls index 0 wrong value %p\n", val );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "setting fls index wrong error %u\n", GetLastError() );
fls = pFlsAlloc( NULL );
ok( fls != FLS_OUT_OF_INDEXES, "FlsAlloc failed\n" );
ok( fls != 0, "fls index 0 allocated\n" );
val = pFlsGetValue( fls );
ok( !val, "fls index %u wrong value %p\n", fls, val );
ret = pFlsSetValue( fls, (void *)0xdeadbeef );
ok( ret, "setting fls index %u failed\n", fls );
val = pFlsGetValue( fls );
ok( val == (void *)0xdeadbeef, "fls index %u wrong value %p\n", fls, val );
pFlsFree( fls );
ret = pFlsSetValue( fls, (void *)0xdeadbabe );
ok( ret, "setting fls index %u failed\n", fls );
val = pFlsGetValue( fls );
ok( val == (void *)0xdeadbabe, "fls index %u wrong value %p\n", fls, val );
} }
START_TEST(fiber) START_TEST(fiber)
......
...@@ -257,6 +257,7 @@ HANDLE thread_init(void) ...@@ -257,6 +257,7 @@ HANDLE thread_init(void)
sizeof(peb->TlsExpansionBitmapBits) * 8 ); sizeof(peb->TlsExpansionBitmapBits) * 8 );
RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 ); RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 );
RtlSetBits( peb->TlsBitmap, 0, 1 ); /* TLS index 0 is reserved and should be initialized to NULL. */ RtlSetBits( peb->TlsBitmap, 0, 1 ); /* TLS index 0 is reserved and should be initialized to NULL. */
RtlSetBits( peb->FlsBitmap, 0, 1 );
InitializeListHead( &peb->FlsListHead ); InitializeListHead( &peb->FlsListHead );
InitializeListHead( &ldr.InLoadOrderModuleList ); InitializeListHead( &ldr.InLoadOrderModuleList );
InitializeListHead( &ldr.InMemoryOrderModuleList ); InitializeListHead( &ldr.InMemoryOrderModuleList );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment