Example #1
0
/*++
Function:
  TlsGetValue

See MSDN doc.
--*/
LPVOID
PALAPI
TlsGetValue(
    IN DWORD dwTlsIndex)
{
    THREAD *thread;
    PERF_ENTRY(TlsGetValue);
    ENTRY("TlsGetValue()\n");
    if (dwTlsIndex == (DWORD) -1 || dwTlsIndex >= TLS_SLOT_SIZE)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return 0;
    }

    thread = PROCGetCurrentThreadObject();
    if (thread == NULL)
    {
        ASSERT("Unable to access the current thread\n");
        SetLastError(ERROR_INVALID_DATA);
        return 0;
    }

    /* From MSDN : "The TlsGetValue function calls SetLastError to clear a
       thread's last error when it succeeds." */
    thread->lastError = NO_ERROR;

    LOGEXIT("TlsGetValue \n" );
    PERF_EXIT(TlsGetValue);
    return thread->tlsSlots[dwTlsIndex];
}
Example #2
0
/*++
Function:
  TlsSetValue

See MSDN doc.
--*/
BOOL
PALAPI
TlsSetValue(
    IN DWORD dwTlsIndex,
    IN LPVOID lpTlsValue)
{
    THREAD *thread;
    BOOL bRet = FALSE;
    PERF_ENTRY(TlsSetValue);
    ENTRY("TlsSetValue(dwTlsIndex=%u, lpTlsValue=%p)\n", dwTlsIndex, lpTlsValue);

    if (dwTlsIndex == (DWORD) -1 || dwTlsIndex >= TLS_SLOT_SIZE)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        goto EXIT;
    }

    thread = PROCGetCurrentThreadObject();
    if (thread == NULL)
    {
        ASSERT("Unable to access the current thread\n");
        goto EXIT;
    }

    thread->tlsSlots[dwTlsIndex] = lpTlsValue;
    bRet = TRUE;
EXIT:
    LOGEXIT("TlsSetValue returns BOOL %d\n", bRet);
    PERF_EXIT(TlsSetValue);
    return bRet;
}
Example #3
0
/*++
Function:
    TlsInternalGetValue

    Do the work of TlsGetValue, but without calling SetLastError(NO_ERROR)
    This is so that PAL functions can call it without changing LastError

Parameters :
    DWORD dwTlsIndex : TLS index to query
    LPVOID *pValue : pointer where the requested value will be placed

Return value :
    TRUE if function succeeds, FALSE otherwise.

--*/
BOOL TlsInternalGetValue(DWORD dwTlsIndex, LPVOID *pValue)
{
    THREAD *thread;

    if (dwTlsIndex == (DWORD) -1 || dwTlsIndex >= TLS_SLOT_SIZE)
    {
        ASSERT("Invalid index (%d)\n", dwTlsIndex);
        return FALSE;
    }

    thread = PROCGetCurrentThreadObject();
    if (thread == NULL)
    {
        ASSERT("Unable to access the current thread\n");
        return FALSE;
    }

    *pValue = thread->tlsSlots[dwTlsIndex];
    return TRUE;
}
Example #4
0
/*++
Function:
  SetLastError

SetLastError

The SetLastError function sets the last-error code for the calling thread.

Parameters

dwErrCode
       [in] Specifies the last-error code for the thread.

Return Values

This function does not return a value.

--*/
VOID
PALAPI
SetLastError(
         IN DWORD dwErrCode)
{
    THREAD * thread;
  
    ENTRY("SetLastError (dwErrCode=%u)\n", dwErrCode);

    thread = PROCGetCurrentThreadObject();
    if (thread == NULL)
    {
        StartupLastError = dwErrCode;
        goto done;
    }

    thread->lastError = dwErrCode;

done:
    LOGEXIT("SetLastError returns\n");
}
Example #5
0
/*++
Function:
  GetLastError

GetLastError

The GetLastError function retrieves the calling thread's last-error
code value. The last-error code is maintained on a per-thread
basis. Multiple threads do not overwrite each other's last-error code.

Parameters

This function has no parameters.

Return Values

The return value is the calling thread's last-error code
value. Functions set this value by calling the SetLastError
function. The Return Value section of each reference page notes the
conditions under which the function sets the last-error code.

--*/
DWORD
PALAPI
GetLastError(
         VOID)
{
    DWORD retval;
    THREAD * thread;

    ENTRY("GetLastError ()\n");
    thread = PROCGetCurrentThreadObject();
    if (thread == NULL)
    {
	retval = StartupLastError;
        goto done;
    }

    retval = thread->lastError;

done:
    LOGEXIT("GetLastError returns %d\n",retval);
    return retval;
}