IHostSecurityManager::SetSecurityContext Method

Sets the security context of the currently executing thread.

HRESULT SetSecurityContext (
    [in]  EContextType eContextType,
    [out] IHostSecurityContext** ppSecurityContext
);

Parameters

  • eContextType
    [in] One of the EContextType values, indicating what type of context the common language runtime (CLR) is placing on the host.

  • ppSecurityContext
    [out] A pointer to the address of a new IHostSecurityContext object.

Return Value

HRESULT

Description

S_OK

SetSecurityContext returned successfully.

HOST_E_CLRNOTAVAILABLE

The CLR has not been loaded into a process, or the CLR is in a state in which it cannot run managed code or process the call successfully.

HOST_E_TIMEOUT

The call timed out.

HOST_E_NOT_OWNER

The caller does not own the lock.

HOST_E_ABANDONED

An event was canceled while a blocked thread or fiber was waiting on it.

E_FAIL

An unknown catastrophic failure occurred. When a method returns E_FAIL, the CLR is no longer usable within the process. Subsequent calls to hosting methods return HOST_E_CLRNOTAVAILABLE.

Remarks

The CLR calls SetSecurityContext in several scenarios. Before it executes class and module constructors and finalizers, the CLR calls SetSecurityContext to protect the host from execution failures. It then resets the security context to its original state after execution of the constructor or finalizer, by using another call to SetSecurityContext. A similar pattern occurs with I/O completion. If the host implements IHostIoCompletionManager, the CLR calls SetSecurityContext after the host calls ICLRIoCompletionManager::OnComplete.

At asynchronous points in worker threads, the CLR calls SetSecurityContext within ThreadPool..::.QueueUserWorkItem or within IHostThreadPoolManager::QueueUserWorkItem, depending on whether the host or the CLR is implementing the thread pool.

Requirements

Platforms: Windows 2000, Windows XP, Windows Server 2003 family

Header: MSCorEE.idl

Library: Included as a resource in MSCorEE.dll

.NET Framework Version: 2.0

See Also

Concepts

EContextType Enumeration

ICLRIoCompletionManager Interface

IHostIoCompletionManager Interface

IHostSecurityContext Interface

IHostSecurityManager Interface

IHostThreadPoolManager Interface

Reference

System.Threading..::.ThreadPool