internal static string GetSiteNameFromId(uint siteId) { if ((siteId == 1) && (s_defaultSiteName != null)) { return(s_defaultSiteName); } IntPtr zero = IntPtr.Zero; int cchSiteName = 0; string str = null; try { str = ((UnsafeIISMethods.MgdGetSiteNameFromId(IntPtr.Zero, siteId, out zero, out cchSiteName) == 0) && (zero != IntPtr.Zero)) ? StringUtil.StringFromWCharPtr(zero, cchSiteName) : string.Empty; } finally { if (zero != IntPtr.Zero) { Marshal.FreeBSTR(zero); } } if (siteId == 1) { s_defaultSiteName = str; } return(str); }
bool IServerConfig.GetUncUser(IApplicationHost appHost, VirtualPath path, out string username, out string password) { bool flag = false; username = null; password = null; IntPtr zero = IntPtr.Zero; int cchUserName = 0; IntPtr bstrPassword = IntPtr.Zero; int cchPassword = 0; try { if (UnsafeIISMethods.MgdGetVrPathCreds(IntPtr.Zero, appHost.GetSiteName(), path.VirtualPathString, out zero, out cchUserName, out bstrPassword, out cchPassword) == 0) { username = (cchUserName > 0) ? StringUtil.StringFromWCharPtr(zero, cchUserName) : null; password = (cchPassword > 0) ? StringUtil.StringFromWCharPtr(bstrPassword, cchPassword) : null; flag = !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password); } } finally { if (zero != IntPtr.Zero) { Marshal.FreeBSTR(zero); } if (bstrPassword != IntPtr.Zero) { Marshal.FreeBSTR(bstrPassword); } } return(flag); }
internal static string GetSiteNameFromId(uint siteId) { if (siteId == DEFAULT_SITE_ID_UINT && s_defaultSiteName != null) { return(s_defaultSiteName); } IntPtr pBstr = IntPtr.Zero; int cBstr = 0; string siteName = null; try { int result = UnsafeIISMethods.MgdGetSiteNameFromId(IntPtr.Zero, siteId, out pBstr, out cBstr); siteName = (result == 0 && pBstr != IntPtr.Zero) ? StringUtil.StringFromWCharPtr(pBstr, cBstr) : String.Empty; } finally { if (pBstr != IntPtr.Zero) { Marshal.FreeBSTR(pBstr); } } if (siteId == DEFAULT_SITE_ID_UINT) { s_defaultSiteName = siteName; } return(siteName); }
internal static void TraceEnableCheck(EtwTraceConfigType configType, IntPtr p) { // Don't activate if webengine.dll isn't loaded if (!HttpRuntime.IsEngineLoaded) { return; } switch (configType) { case EtwTraceConfigType.IIS7_INTEGRATED: bool f; UnsafeIISMethods.MgdEtwGetTraceConfig(p /*pRequestContext*/, out f, out _traceFlags, out _traceLevel); break; case EtwTraceConfigType.IIS7_ISAPI: int[] contentInfo = new int[3]; UnsafeNativeMethods.EcbGetTraceFlags(p /*pECB*/, contentInfo); _traceFlags = contentInfo[0]; _traceLevel = contentInfo[1]; break; case EtwTraceConfigType.DOWNLEVEL: UnsafeNativeMethods.GetEtwValues(out _traceLevel, out _traceFlags); break; default: break; } }
public StopListeningWaitHandle() { // This handle is process-wide and not ref counted, so no need to wrap inside a SafeHandle IntPtr eventHandle = UnsafeIISMethods.MgdGetStopListeningEventHandle(); // Per documentation for RegisterWaitForSingleObject, we need to duplicate handles // before asynchronously waiting on them. SafeWaitHandle safeWaitHandle; bool succeeded = DuplicateHandle( hSourceProcessHandle: _processHandle, hSourceHandle: eventHandle, hTargetProcessHandle: _processHandle, lpTargetHandle: out safeWaitHandle, dwDesiredAccess: 0, bInheritHandle: false, dwOptions: 2 /* DUPLICATE_SAME_ACCESS */); if (!succeeded) { int hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } this.SafeWaitHandle = safeWaitHandle; }
private static void DependencyRemovedCallback(string key, object value, CacheItemRemovedReason reason) { DependencyCacheEntry entry = value as DependencyCacheEntry; if (entry.KernelCacheEntryKey != null) { if (HttpRuntime.UseIntegratedPipeline) { UnsafeIISMethods.MgdFlushKernelCache(entry.KernelCacheEntryKey); } else { System.Web.UnsafeNativeMethods.InvalidateKernelCache(entry.KernelCacheEntryKey); } } if ((reason == CacheItemRemovedReason.DependencyChanged) && (entry.OutputCacheEntryKey != null)) { try { RemoveFromProvider(entry.OutputCacheEntryKey, entry.ProviderName); } catch (Exception exception) { HandleErrorWithoutContext(exception); } } }
private VirtualPath GetAppPathForPathWorker(string siteID, VirtualPath path) { string str; uint result = 0; if (!uint.TryParse(siteID, out result)) { return(VirtualPath.RootVirtualPath); } IntPtr zero = IntPtr.Zero; int cchPath = 0; try { str = ((UnsafeIISMethods.MgdGetAppPathForPath(IntPtr.Zero, result, path.VirtualPathString, out zero, out cchPath) == 0) && (cchPath > 0)) ? StringUtil.StringFromWCharPtr(zero, cchPath) : null; } finally { if (zero != IntPtr.Zero) { Marshal.FreeBSTR(zero); } } if (str == null) { return(VirtualPath.RootVirtualPath); } return(VirtualPath.Create(str)); }
internal static void TraceEnableCheck(EtwTraceConfigType configType, IntPtr p) { if (HttpRuntime.IsEngineLoaded) { switch (configType) { case EtwTraceConfigType.DOWNLEVEL: UnsafeNativeMethods.GetEtwValues(out _traceLevel, out _traceFlags); return; case EtwTraceConfigType.IIS7_ISAPI: { int[] contentInfo = new int[3]; UnsafeNativeMethods.EcbGetTraceFlags(p, contentInfo); _traceFlags = contentInfo[0]; _traceLevel = contentInfo[1]; return; } case EtwTraceConfigType.IIS7_INTEGRATED: bool flag; UnsafeIISMethods.MgdEtwGetTraceConfig(p, out flag, out _traceFlags, out _traceLevel); return; } } }
// only used by providers private static void DependencyRemovedCallback(string key, object value, CacheItemRemovedReason reason) { Debug.Trace("OutputCache", "DependencyRemovedCallback: reason=" + reason + ", key=" + key); DependencyCacheEntry dce = value as DependencyCacheEntry; if (dce.KernelCacheEntryKey != null) { // invalidate kernel cache entry if (HttpRuntime.UseIntegratedPipeline) { UnsafeIISMethods.MgdFlushKernelCache(dce.KernelCacheEntryKey); } else { UnsafeNativeMethods.InvalidateKernelCache(dce.KernelCacheEntryKey); } } if (reason == CacheItemRemovedReason.DependencyChanged) { if (dce.OutputCacheEntryKey != null) { try { OutputCache.RemoveFromProvider(dce.OutputCacheEntryKey, dce.ProviderName); } catch (Exception e) { HandleErrorWithoutContext(e); } } } }
// only used by internal cache private static void EntryRemovedCallback(string key, object value, CacheItemRemovedReason reason) { Debug.Trace("OutputCache", "EntryRemovedCallback: reason=" + reason + ", key=" + key); DecrementCount(); PerfCounters.DecrementCounter(AppPerfCounter.OUTPUT_CACHE_ENTRIES); PerfCounters.IncrementCounter(AppPerfCounter.OUTPUT_CACHE_TURNOVER_RATE); CachedRawResponse cachedRawResponse = value as CachedRawResponse; if (cachedRawResponse != null) { String kernelCacheUrl = cachedRawResponse._kernelCacheUrl; // if it is kernel cached, the url will be non-null. // if the entry was re-inserted, don't remove kernel entry since it will be updated if (kernelCacheUrl != null && HttpRuntime.CacheInternal.Get(key) == null) { // invalidate kernel cache entry if (HttpRuntime.UseIntegratedPipeline) { UnsafeIISMethods.MgdFlushKernelCache(kernelCacheUrl); } else { UnsafeNativeMethods.InvalidateKernelCache(kernelCacheUrl); } } } }
VirtualPath GetAppPathForPathWorker(string siteID, VirtualPath path) { Debug.Trace("MapPath", "ProcHostMP.GetAppPathForPath(" + siteID + ", " + path.VirtualPathString + ")\n"); uint siteValue = 0; if (!UInt32.TryParse(siteID, out siteValue)) { return(VirtualPath.RootVirtualPath); } IntPtr pBstr = IntPtr.Zero; int cBstr = 0; string appPath; try { int result = UnsafeIISMethods.MgdGetAppPathForPath(IntPtr.Zero, siteValue, path.VirtualPathString, out pBstr, out cBstr); appPath = (result == 0 && cBstr > 0) ? StringUtil.StringFromWCharPtr(pBstr, cBstr) : null; } finally { if (pBstr != IntPtr.Zero) { Marshal.FreeBSTR(pBstr); } } return((appPath != null) ? VirtualPath.Create(appPath) : VirtualPath.RootVirtualPath); }
internal ProcessHostMapPath(IProcessHostSupportFunctions functions) { // if the functions are null and we're // not in a worker process, init the mgdeng config system if (null == functions) { ProcessHostConfigUtils.InitStandaloneConfig(); } // we need to explicit create a COM proxy in this app domain // so we don't go back to the default domain or have lifetime issues if (null != functions) { _functions = Misc.CreateLocalSupportFunctions(functions); } // proactive set the config functions for // webengine in case this is a TCP init path if (null != _functions) { IntPtr configSystem = _functions.GetNativeConfigurationSystem(); Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem"); if (IntPtr.Zero != configSystem) { // won't fail if valid pointer // no cleanup needed, we don't own instance UnsafeIISMethods.MgdSetNativeConfiguration(configSystem); } } }
ProcessHostServerConfig() { if (null == HostingEnvironment.SupportFunctions) { ProcessHostConfigUtils.InitStandaloneConfig(); } else { IProcessHostSupportFunctions fns = HostingEnvironment.SupportFunctions; if (null != fns) { IntPtr configSystem = fns.GetNativeConfigurationSystem(); Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem"); if (IntPtr.Zero != configSystem) { // won't fail if valid pointer // no cleanup needed, we don't own instance UnsafeIISMethods.MgdSetNativeConfiguration(configSystem); } } } _siteNameForCurrentApplication = HostingEnvironment.SiteNameNoDemand; if (_siteNameForCurrentApplication == null) { _siteNameForCurrentApplication = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT); } }
internal NativeConfigWrapper() { int num = UnsafeIISMethods.MgdInitNativeConfig(); if (num < 0) { ProcessHostConfigUtils.s_InitedExternalConfig = 0; throw new InvalidOperationException(System.Web.SR.GetString("Cant_Init_Native_Config", new object[] { num.ToString("X8", CultureInfo.InvariantCulture) })); } }
internal NativeConfigWrapper() { int result = UnsafeIISMethods.MgdInitNativeConfig(); if (result < 0) { s_InitedExternalConfig = 0; throw new InvalidOperationException(SR.GetString(SR.Cant_Init_Native_Config, result.ToString("X8", CultureInfo.InvariantCulture))); } }
long IServerConfig.GetW3WPMemoryLimitInKB() { long limit = 0L; if (UnsafeIISMethods.MgdGetMemoryLimitKB(out limit) < 0) { return(0L); } return(limit); }
private void Dispose(bool disposing) { if (this._nativeConfig != IntPtr.Zero) { IntPtr pConfigSystem = Interlocked.Exchange(ref this._nativeConfig, IntPtr.Zero); if (pConfigSystem != IntPtr.Zero) { Misc.ThrowIfFailedHr(UnsafeIISMethods.MgdReleaseNativeConfigSystem(pConfigSystem)); } } }
static HttpResponseUnmanagedBufferElement() { if (HttpRuntime.UseIntegratedPipeline) { s_Pool = UnsafeIISMethods.MgdGetBufferPool(BufferingParams.INTEGRATED_MODE_BUFFER_SIZE); } else { s_Pool = UnsafeNativeMethods.BufferPoolGetPool(0x7c00, 0x40); } }
void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID) { Debug.Trace("MapPath", "ProcHostMP.ResolveSiteArgument(" + siteArgument + ")\n"); if (String.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT))) { siteName = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT); siteID = ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING; } else { siteName = String.Empty; siteID = String.Empty; string resolvedName = null; if (IISMapPath.IsSiteId(siteArgument)) { uint id; if (UInt32.TryParse(siteArgument, out id)) { resolvedName = ProcessHostConfigUtils.GetSiteNameFromId(id); } } // try to resolve the string else { uint id = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument); if (id != 0) { siteID = id.ToString(CultureInfo.InvariantCulture); siteName = siteArgument; return; } } if (!String.IsNullOrEmpty(resolvedName)) { siteName = resolvedName; siteID = siteArgument; } else { siteName = siteArgument; siteID = String.Empty; } } Debug.Assert(!String.IsNullOrEmpty(siteName), "!String.IsNullOrEmpty(siteName), siteArg=" + siteArgument); }
internal TlsTokenBindingHandle(IntPtr mgdContext) { int hr = UnsafeIISMethods.MgdGetTlsTokenBindingIdentifiers( mgdContext, ref handle, out _providedTokenBlob, out _providedTokenBlobSize, out _referredTokenBlob, out _referredtokenBlobSize); Misc.ThrowIfFailedHr(hr); }
internal NativeConfig(string version) { if (version == null) { throw new ArgumentNullException("version"); } int hresult = 0; using (new IISVersionHelper(version)) { hresult = UnsafeIISMethods.MgdCreateNativeConfigSystem(out _nativeConfig); } Misc.ThrowIfFailedHr(hresult); }
public void ProcessRequest() { Task <AspNetWebSocket> webSocketTask = ProcessRequestImplAsync(); // If 'webSocketTask' contains a non-null Result, this is our last chance to ensure that we // have completed all pending IO. Otherwise we run the risk of iiswsock.dll making a reverse // p/invoke call into our managed layer and touching objects that have already been GCed. Task abortTask = webSocketTask.ContinueWith(task => (task.Result != null) ? ((AspNetWebSocket)task.Result).AbortAsync() : (Task)null, TaskContinuationOptions.ExecuteSynchronously).Unwrap(); // Once all pending IOs are complete, we can progress the IIS state machine and finish the request. // Execute synchronously since it's very short-running (posts to the native ThreadPool). abortTask.ContinueWith(_ => UnsafeIISMethods.MgdPostCompletion(_root.WorkerRequest.RequestContext, RequestNotificationStatus.Continue), TaskContinuationOptions.ExecuteSynchronously); }
long IServerConfig.GetW3WPMemoryLimitInKB() { long limit = 0; int result = UnsafeIISMethods.MgdGetMemoryLimitKB(out limit); if (result < 0) { return(0); } return(limit); }
protected override void PopulateMappings() { IntPtr mimeMapCollection = IntPtr.Zero; try { int result; int mimeMapCount; // Read the collection result = UnsafeIISMethods.MgdGetMimeMapCollection(IntPtr.Zero, _applicationContext, out mimeMapCollection, out mimeMapCount); Marshal.ThrowExceptionForHR(result); for (int i = 0; i < mimeMapCount; i++) { IntPtr bstrFileExtension = IntPtr.Zero; IntPtr bstrMimeType = IntPtr.Zero; try { int cBstrFileExtension; int cBstrMimeType; // Read an individual element from the collection result = UnsafeIISMethods.MgdGetNextMimeMap(mimeMapCollection, (uint)i, out bstrFileExtension, out cBstrFileExtension, out bstrMimeType, out cBstrMimeType); Marshal.ThrowExceptionForHR(result); string fileExtension = (cBstrFileExtension > 0) ? StringUtil.StringFromWCharPtr(bstrFileExtension, cBstrFileExtension) : null; string mimeType = (cBstrMimeType > 0) ? StringUtil.StringFromWCharPtr(bstrMimeType, cBstrMimeType) : null; AddMapping(fileExtension, mimeType); } finally { // It's our responsibility to release these strings when we're done if (bstrFileExtension != IntPtr.Zero) { Marshal.FreeBSTR(bstrFileExtension); } if (bstrMimeType != IntPtr.Zero) { Marshal.FreeBSTR(bstrMimeType); } } } } finally { // It's our responsibility to release the collection when we're done if (mimeMapCollection != IntPtr.Zero) { Marshal.Release(mimeMapCollection); } } }
void Dispose(bool disposing) { if (disposing) { // release managed resources } // release native resources if (_nativeConfig != IntPtr.Zero) { IntPtr pConfigSystem = Interlocked.Exchange(ref _nativeConfig, IntPtr.Zero); if (pConfigSystem != IntPtr.Zero) { int hresult = UnsafeIISMethods.MgdReleaseNativeConfigSystem(pConfigSystem); Misc.ThrowIfFailedHr(hresult); } } }
internal string GetSiteNameFromId(uint siteID) { IntPtr pBstr = IntPtr.Zero; int cBstr = 0; string siteName = null; try { int result = UnsafeIISMethods.MgdGetSiteNameFromId(_nativeConfig, siteID, out pBstr, out cBstr); siteName = (result == 0 && pBstr != IntPtr.Zero) ? StringUtil.StringFromWCharPtr(pBstr, cBstr) : String.Empty; } finally { if (pBstr != IntPtr.Zero) { Marshal.FreeBSTR(pBstr); } } return(siteName); }
internal HttpResponseUnmanagedBufferElement() { if (HttpRuntime.UseIntegratedPipeline) { this._data = UnsafeIISMethods.MgdGetBuffer(s_Pool); base._size = BufferingParams.INTEGRATED_MODE_BUFFER_SIZE; } else { this._data = UnsafeNativeMethods.BufferPoolGetBuffer(s_Pool); base._size = 0x7c00; } if (this._data == IntPtr.Zero) { throw new OutOfMemoryException(); } base._free = base._size; base._recycle = true; }
private void ForceRecycle() { IntPtr pBuffer = Interlocked.Exchange(ref this._data, IntPtr.Zero); if (pBuffer != IntPtr.Zero) { base._free = 0; base._recycle = false; if (HttpRuntime.UseIntegratedPipeline) { UnsafeIISMethods.MgdReturnBuffer(pBuffer); } else { UnsafeNativeMethods.BufferPoolReleaseBuffer(pBuffer); } GC.SuppressFinalize(this); } }
internal string GetSiteNameFromId(uint siteID) { IntPtr zero = IntPtr.Zero; int cchSiteName = 0; string str = null; try { str = ((UnsafeIISMethods.MgdGetSiteNameFromId(this._nativeConfig, siteID, out zero, out cchSiteName) == 0) && (zero != IntPtr.Zero)) ? StringUtil.StringFromWCharPtr(zero, cchSiteName) : string.Empty; } finally { if (zero != IntPtr.Zero) { Marshal.FreeBSTR(zero); } } return(str); }
void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID) { if ((string.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, "1")) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(1))) { siteName = ProcessHostConfigUtils.GetSiteNameFromId(1); siteID = "1"; } else { siteName = string.Empty; siteID = string.Empty; string siteNameFromId = null; if (IISMapPath.IsSiteId(siteArgument)) { uint num; if (uint.TryParse(siteArgument, out num)) { siteNameFromId = ProcessHostConfigUtils.GetSiteNameFromId(num); } } else { uint num2 = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument); if (num2 != 0) { siteID = num2.ToString(CultureInfo.InvariantCulture); siteName = siteArgument; return; } } if (!string.IsNullOrEmpty(siteNameFromId)) { siteName = siteNameFromId; siteID = siteArgument; } else { siteName = siteArgument; siteID = string.Empty; } } }