3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/thread/tls.c
6 * PURPOSE: Thread functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * Tls functions are modified from WINE
13 /* INCLUDES ******************************************************************/
15 #include <ddk/ntddk.h>
16 #include <ntdll/rtl.h>
18 #include <kernel32/thread.h>
19 #include <kernel32/error.h>
22 #include <kernel32/kernel32.h>
25 /* FUNCTIONS *****************************************************************/
33 Index = RtlFindClearBitsAndSet (NtCurrentPeb()->TlsBitmap, 1, 0);
34 if (Index == (ULONG)-1)
36 SetLastErrorByStatus(STATUS_NO_MEMORY);
40 NtCurrentTeb()->TlsSlots[Index] = 0;
48 TlsFree(DWORD dwTlsIndex)
50 if (dwTlsIndex >= TLS_MINIMUM_AVAILABLE)
52 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
57 if (RtlAreBitsSet(NtCurrentPeb()->TlsBitmap, dwTlsIndex, 1))
60 * clear the tls cells (slots) in all threads
61 * of the current process
63 NtSetInformationThread(NtCurrentThread(),
67 RtlClearBits(NtCurrentPeb()->TlsBitmap,
77 TlsGetValue(DWORD dwTlsIndex)
79 if (dwTlsIndex >= TLS_MINIMUM_AVAILABLE)
81 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
84 return(NtCurrentTeb()->TlsSlots[dwTlsIndex]);
88 TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
90 if (dwTlsIndex >= TLS_MINIMUM_AVAILABLE)
92 SetLastErrorByStatus(STATUS_INVALID_PARAMETER);
95 NtCurrentTeb()->TlsSlots[dwTlsIndex] = lpTlsValue;