public override Object GetRealObject(StreamingContext context) { DBG.Info(DBG.SC, "SCM: GetRealObject()"); if (!IsMarshaledObject) { DBG.Info(DBG.SC, "SCM: GetRealObject() returning objref!"); return(this); } else { if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(_rt)) { Object otp = base.GetRealObject(context); // We need to notify the object that there is a managed reference. ((ServicedComponent)otp).DoSetCOMIUnknown(IntPtr.Zero); return(otp); } else { if (_rp == null) { _rp = _um.GetRealProxy(); } DBG.Assert(_rp != null, "GetRealObject on a marshaller with no proxy!"); return(_rp.GetTransparentProxy()); } } }
internal ServicedComponentMarshaler(MarshalByRefObject o, Type requestedType) : base(o, requestedType) { DBG.Assert(RemotingServices.IsTransparentProxy(o), "IsTransparentProxy failed"); _rp = RemotingServices.GetRealProxy(o); _rt = requestedType; }
public static void AddObject(IntPtr key, Object val) { _rwlock.AcquireWriterLock(Timeout.Infinite); try { WeakReference wf = _table[key] as WeakReference; if (wf == null) { DBG.Info(DBG.SC, "LookupTable.AddObject(): Adding new entry for " + key); // We didn't find an entry, we need to add a new one: wf = new WeakReference(val, false); _table.Add(key, wf); } else { DBG.Info(DBG.SC, "LookupTable.AddObject(): Reusing entry for " + key); // We found an entry, it better be the same or null: DBG.Assert(wf.Target == null || wf.Target == val, "different live TP found in table"); if (wf.Target == null) { wf.Target = val; } } } finally { _rwlock.ReleaseWriterLock(); } }
/// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.ServicedComponent"]/*' /> public ServicedComponent() { ServicedComponentProxy pxy = RemotingServices.GetRealProxy(this) as ServicedComponentProxy; DBG.Assert(pxy != null, "RealProxy() is null during constructor!"); pxy.SuppressFinalizeServer(); Type thisType = this.GetType(); _denyRemoteDispatch = ServicedComponentInfo.AreMethodsSecure(thisType); // Get the methodinfo for finalize... // REVIEW: Do we have to do anything special to make sure we // get the one furthest down the chain? bool bFoundInCache = false; _finalize = _finalizeCache.Get(thisType, out bFoundInCache) as MethodInfo; if (bFoundInCache == false) { _finalize = GetDeclaredFinalizer(thisType); _finalizeCache.Put(thisType, _finalize); } _calledDispose = false; }
// TODO: @cleanup: Move to ServicedComponentProxy private static void ReconnectForPooling(ServicedComponentProxy scp) { Type serverType = scp.GetProxiedType(); bool fIsJitActivated = scp.IsJitActivated; bool fIsTypePooled = scp.IsObjectPooled; bool fAreMethodsSecure = scp.AreMethodsSecure; ProxyTearoff tearoff = null; DBG.Assert(fIsTypePooled == true, "CS.ReconnectForPooling called on a non-pooled proxy!"); DBG.Info(DBG.SC, "CS.ReconnectForPooling (type is pooled) " + serverType); ServicedComponent server = scp.DisconnectForPooling(ref tearoff); // now setup a new SCP that we can add to the pool // with the current server object and the CCW ServicedComponentProxy newscp = new ServicedComponentProxy(serverType, fIsJitActivated, fIsTypePooled, fAreMethodsSecure, false); DBG.Info(DBG.SC, "CS.ReconnectForPooling (calling newscp.ConnectForPooling)"); newscp.ConnectForPooling(scp, server, tearoff, false); // switch the CCW from oldtp to new tp DBG.Info(DBG.SC, "CS.ReconnectForPooling (SwitchingWrappers)"); EnterpriseServicesHelper.SwitchWrappers(scp, newscp); // Strengthen the CCW: The only reference now held is // the reference from the pool. if (tearoff != null) { Marshal.ChangeWrapperHandleStrength(tearoff, false); } Marshal.ChangeWrapperHandleStrength(newscp.GetTransparentProxy(), false); }
public void ConfigureDefaults(Object a, Object key) { DBG.Assert(!(Platform.IsLessThan(Platform.W2K)), "Configuring interfaces on non-w2k platform!"); if (!Platform.IsLessThan(Platform.W2K)) { bool setQdefault = true; ICatalogObject obj = (ICatalogObject)key; // If this type (a) has been touched by the parent component, // we don't want to set this value... if (_cache[_type] != null) { Object co = _cache[_type]; if (co is Hashtable && ((Hashtable)co)[a] != null) { DBG.Info(DBG.Registration, "*** not setting queue defaults!"); setQdefault = false; } } if (setQdefault) { obj.SetValue("QueuingEnabled", false); } } }
// TODO: Move to ServicedComponent static method public static void DeactivateObject(Object otp, bool disposing) { RealProxy rp = RemotingServices.GetRealProxy(otp); ServicedComponentProxy scp = rp as ServicedComponentProxy; DBG.Assert(scp != null, "CS.DeactivateObject called on a non-ServicedComponentProxy"); if (!scp.IsProxyDeactivated) { DBG.Assert(scp.HomeToken == Thunk.Proxy.GetCurrentContextToken(), "Deactivate called from wrong context"); if (scp.IsObjectPooled) { DBG.Info(DBG.SC, "CS.DeactivateObject calling ReconnectForPooling"); ReconnectForPooling(scp); } // this would wack the real server also so do this last DBG.Info(DBG.SC, "CS.DeactivateObject calling scp.DeactivateProxy"); scp.DeactivateProxy(disposing); } DBG.Assert(scp.IsProxyDeactivated, "scp not deactive"); }
public ComObjRef(SerializationInfo info, StreamingContext ctx) { byte[] buffer = null; IntPtr pUnk = IntPtr.Zero; SerializationInfoEnumerator e = info.GetEnumerator(); while (e.MoveNext()) { if (e.Name.Equals("buffer")) { buffer = (byte[])e.Value; } } DBG.Assert(buffer != null, "Buffer in ComObjRef is null!"); try { pUnk = Thunk.Proxy.UnmarshalObject(buffer); _realobj = Marshal.GetObjectForIUnknown(pUnk); } finally { if (pUnk != IntPtr.Zero) { Marshal.Release(pUnk); } } if (_realobj == null) { throw new NotSupportedException(); } }
public override RealProxy CreateProxy(ObjRef objRef, Type serverType, Object serverObject, Context serverContext) { DBG.Assert(serverType != null, "server type is null in CreateProxy"); // // If this guy isn't one of our objrefs, then we should use remoting. Otherwise, // go ahead and call GetRealObject on it. // if (objRef == null) { return(base.CreateProxy(objRef, serverType, serverObject, serverContext)); } if ((objRef is FastRSCPObjRef) || ((objRef is ServicedComponentMarshaler) && (!objRef.IsFromThisProcess() || ServicedComponentInfo.IsTypeEventSource(serverType)))) { DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating custom CreateProxy"); Object otp = objRef.GetRealObject(new StreamingContext(StreamingContextStates.Remoting)); return(RemotingServices.GetRealProxy(otp)); } else { DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating standard CreateProxy"); return(base.CreateProxy(objRef, serverType, serverObject, serverContext)); } }
void IObjPool.PutEndTx(Object p) { DBG.Assert(p != null, "ComExposedPool: EndTx delivered a null object!"); // Release, cause this guy's not in the pool any longer. DBG.Info(DBG.Pool, "Returing object on tx end!"); _cb(p); ReleaseToken(); }
internal static String GetString(String key) { InitResourceManager(); String s = _resmgr.GetString(key, null); DBG.Assert(s != null, "The resource \"" + key + "\" could not be found.", "Please check to make sure that the resource name is spelled correctly, and that such a resource exists in resources.txt"); return(s); }
internal void Add(IntPtr ikey, Object value) { DBG.Assert((int)ikey != 0, "Adding entry with key 0"); DBG.Assert((int)ikey != -1, "Adding entry with key -1"); int i = BinarySearch(ikey); DBG.Assert(!(i >= 0), " Duplicated entry being added to Deactivated list"); Insert(~i, ikey, value); }
public void ConfigureDefaults(Object a, Object key) { DBG.Assert(!(Platform.IsLessThan(Platform.W2K)), "Configuring methods on non-w2k platform!"); if (!Platform.IsLessThan(Platform.W2K)) { ICatalogObject obj = (ICatalogObject)key; obj.SetValue("AutoComplete", false); } }
// copied from ServicedComponentMarshaler above directly // IF YOU MAK ANY CHANGES TO THIS, KEEP THE OTHER COPY IN SYNC public override void GetObjectData(SerializationInfo info, StreamingContext context) { DBG.Info(DBG.SC, "FSCM: GetObjectData"); ComponentServices.InitializeRemotingChannels(); if (info == null) { throw new ArgumentNullException("info"); } // Check to see if this is a remoting channel, if so, then we // should use the standard objref marshal (cause we're going over SOAP // or another remoting channel). object oClientIsClr = CallContext.GetData("__ClientIsClr"); DBG.Info(DBG.SC, "FSCM: GetObjectData: oClientIsClr = " + oClientIsClr); bool bUseStandardObjRef = (oClientIsClr == null)?false:(bool)oClientIsClr; if (bUseStandardObjRef) { RemoteServicedComponentProxy rscp = _rp as RemoteServicedComponentProxy; if (rscp != null) { DBG.Info(DBG.SC, "FSCM: GetObjectData: intermediary objref"); ObjRef std = RemotingServices.Marshal((MarshalByRefObject)(rscp.RemotingIntermediary.GetTransparentProxy()), null, null); std.GetObjectData(info, context); } else { DBG.Info(DBG.SC, "FSCM: GetObjectData: Using standard objref"); base.GetObjectData(info, context); } } else { DBG.Info(DBG.SC, "FSCM: GetObjectData: Using custom objref"); base.GetObjectData(info, context); //*** base.GetObjectData sets the type to be itself // now wack the type to be us info.SetType(typeof(ServicedComponentMarshaler)); DBG.Assert(_rp != null, "_rp is null"); info.AddValue("servertype", _rp.GetProxiedType()); byte[] dcomBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)_rp.GetTransparentProxy()); DBG.Assert(dcomBuffer != null, "dcomBuffer is null"); if (dcomBuffer != null) { info.AddValue("dcomInfo", dcomBuffer); } } }
public override Object GetRealObject(StreamingContext context) { DBG.Info(DBG.SC, "FSCM: GetRealObject"); DBG.Assert(_pUnk != IntPtr.Zero, "pUnk is zero!"); DBG.Assert(_serverType != null, "_serverType is null!"); RealProxy rp = new RemoteServicedComponentProxy(_serverType, _pUnk, false); _rp = rp; return((MarshalByRefObject)rp.GetTransparentProxy()); }
internal static Exception GetExceptionForHR(int hr) { try { Marshal.ThrowExceptionForHR(hr); } catch (Exception e) { return(e); } // This should never get hit, as ThrowExceptionForHR should // always throw. DBG.Assert(false, "ThrowExceptionForHR failed to throw."); return(null); }
private void FixupMethodSecurityForInterface(ICatalogCollection coll, Type InterfaceType) { ICatalogObject obj = null; // Look through the interfaces in ifcColl, and find specific interface. Guid iid = Marshal.GenerateGuidForType(InterfaceType); int count = coll.Count(); for (int i = 0; i < count; i++) { ICatalogObject test = (ICatalogObject)(coll.Item(i)); if (new Guid((String)(test.Key())) == iid) { obj = test; break; } } DBG.Assert(obj != null, "Could not find interface " + InterfaceType + " in catalog!"); if (obj != null) { SecurityRoleAttribute attr = new SecurityRoleAttribute("Marshaler", false); attr.Description = Resource.FormatString("Reg_MarshalerDesc"); IConfigurationAttribute confattr = attr as IConfigurationAttribute; DBG.Assert(confattr != null, "SecurityRoleAttribute does not support IConfigurationAttribute!"); // Now, set up the cache to configure this interface: _cache["CurrentTarget"] = "Interface"; _cache["InterfaceCollection"] = coll; _cache["Interface"] = obj; _cache["InterfaceType"] = InterfaceType; // First step, Ensure that the role is here: if (confattr.Apply(_cache)) { coll.SaveChanges(); } // Now, fix up the real roles: if (confattr.AfterSaveChanges(_cache)) { coll.SaveChanges(); } } }
internal static void Tick(String name) { long _count2; bool r = Util.QueryPerformanceCounter(out _count2); DBG.Assert(r, "Hardware does not support perf counter!"); if (_count != 0) { double delta = ((double)(_count2 - _count)) / ((double)_freq); DBG.Info(DBG.Perf, "PERF: " + name + ": " + delta + " s"); } else { DBG.Info(DBG.Perf, "PERF: " + name + ": First sample."); } _count = _count2; }
// Map an interface catalog object (key) to a runtime type (ifc) public Object FindObject(ICatalogCollection coll, Object key) { ICatalogObject ifcObj = (ICatalogObject)key; Type ifc = null; ifc = FindInterfaceByID(ifcObj, _type, _ifcs); if (ifc == null) { ifc = FindInterfaceByName(ifcObj, _type, _ifcs); } DBG.Assert(ifc != null, "Unable to find requested interface: \n" + "\t" + (String)(ifcObj.Name()) + "\n" + "\t" + (String)(ifcObj.Key())); return(ifc); }
internal RemoteServicedComponentProxy(Type serverType, IntPtr pUnk, bool fAttachServer) : base(serverType) { DBG.Info(DBG.SC, "RSCP: type = " + serverType); DBG.Assert(serverType != null, "server type is null"); _fUseIntfDispatch = (ServicedComponentInfo.IsTypeEventSource(serverType) || ServicedComponentInfo.AreMethodsSecure(serverType)); DBG.Info(DBG.SC, "RSCP: using interface dispatch = " + _fUseIntfDispatch); if (pUnk != IntPtr.Zero) { _pUnk = pUnk; _server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk); if (fAttachServer) { AttachServer((MarshalByRefObject)_server); _fAttachedServer = true; } } }
public Object FindObject(ICatalogCollection coll, Object key) { ICatalogObject methObj = (ICatalogObject)key; int slot = (int)(methObj.GetValue("Index")); ComMemberType mtype = ComMemberType.Method; MemberInfo info = Marshal.GetMethodInfoForComSlot(_type, slot, ref mtype); DBG.Assert(info != null, "Failed to find method info for COM slot!"); // Now we have the member info, look through the interface // mapping for this guy: if (info is PropertyInfo) { if (mtype == ComMemberType.PropSet) { info = ((PropertyInfo)info).GetSetMethod(); } else if (mtype == ComMemberType.PropGet) { info = ((PropertyInfo)info).GetGetMethod(); } else { DBG.Assert(false, "Illegal ComMemberType returned"); } } if (_map.InterfaceMethods != null) { for (int i = 0; i < _map.InterfaceMethods.Length; i++) { if (_map.InterfaceMethods[i] == info) { return(_map.TargetMethods[i]); } } DBG.Assert(false, "Had interface mapping, but found no method."); } return(info); }
/// <include file='doc\RegistrationWrappers.uex' path='docs/doc[@for="RegistrationHelperTx.UninstallAssemblyFromConfig"]/*' /> public void UninstallAssemblyFromConfig([MarshalAs(UnmanagedType.IUnknown)] ref RegistrationConfig regConfig, Object sync) { bool succeed = false; try { DBG.Assert(ContextUtil.IsInTransaction, "Running in transactional helper w/o transaction will deadlock!"); RegistrationDriver helper = new RegistrationDriver(); helper.UninstallAssembly(regConfig, sync); ContextUtil.SetComplete(); succeed = true; } finally { if (!succeed) { DBG.Info(DBG.Registration, "Uninstall failed."); ContextUtil.SetAbort(); } } }
bool IConfigurationAttribute.AfterSaveChanges(Hashtable cache) { String target = (String)(cache["CurrentTarget"]); // Now that the component itself is configured, we go and add // roles to the sub-collection. (This ensures that all the // component logic that hits sub-collections gets run first. if (target == "Component") { Platform.Assert(Platform.MTS, "SecurityRoleAttribute"); // Pull out the RolesForComponent collection, add the name of // the desired role to that collection. AddRoleFor("Component", cache); } else if (target == "Method") { Platform.Assert(Platform.W2K, "SecurityRoleAttribute"); // Pull out the RolesForMethod collection, add the name of // the desired role to that collection. AddRoleFor("Method", cache); } else if (target == "Interface") { AddRoleFor("Interface", cache); } else if (target == "Application") { // We don't actually need to do anything for application, // as we have already verified that the role exists. } else { // We got called on a target we don't know about, which // shouldn't ever happen. DBG.Assert(false, "Invalid target for RoleAttribute"); } return(true); }
// helper to implement RemoteDispatch methods private String RemoteDispatchHelper(String s, out bool failed) { if (_denyRemoteDispatch) { throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } IMessage reqMsg = ComponentServices.ConvertToMessage(s, this); // Check to see if the method is marked as secure on the // server side: If so, we need to kick it back to the caller, // cause they called us incorrectly. Also verify the method // is not private, internal, or static. CheckMethodAccess(reqMsg); RealProxy rp = RemotingServices.GetRealProxy(this); DBG.Assert(rp != null, "Null RP in Invoke helper"); IMessage retMsg = rp.Invoke(reqMsg); // Check for failures: IMethodReturnMessage mrm = retMsg as IMethodReturnMessage; if (mrm != null && mrm.Exception != null) { failed = true; } else { failed = false; } String sret = ComponentServices.ConvertToString(retMsg); return(sret); }
internal static Object GetFeatureData(PlatformFeature feature) { Object value = FindFeatureData(feature); if (value != null) { return(value); } switch (feature) { case PlatformFeature.SWC: value = Thunk.SWCThunk.IsSWCSupported(); break; default: DBG.Assert(false, "Unknown feature"); return(null); } SetFeatureData(feature, value); return(value); }
static Perf() { bool r = Util.QueryPerformanceFrequency(out _freq); DBG.Assert(r, "Hardware does not support perf counter!"); }
void IObjPool.Shutdown() { DBG.Assert(false, "ComExposedPool: This shouldn't be called"); throw new NotSupportedException(); }
// Implement Invoke public override IMessage Invoke(IMessage reqMsg) { AssertValid(); IMessage retMsg = null; // CHECK FOR CTOR if (reqMsg is IConstructionCallMessage) { DBG.Info(DBG.SC, "RSCP: Short circuiting constructor call."); if (((IConstructionCallMessage)reqMsg).ArgCount > 0) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments")); } // WE don't need dispatch the constructor message, the default .ctor is called // by CoCI // Create the return message MarshalByRefObject retObj = (MarshalByRefObject)GetTransparentProxy(); return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, retObj)); } // NON CTOR MESSAGE MethodBase mb = ((IMethodMessage)reqMsg).MethodBase; MemberInfo m = (MemberInfo)mb; DBG.Assert(m != null, "member info should not be null"); if (mb == _getTypeMethod) { DBG.Info(DBG.SC, "RSCP: Hijacking call to GetType"); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(ProxiedType, null, 0, mcm.LogicalCallContext, mcm)); } if (mb == _getHashCodeMethod) { int hashCode = this.GetHashCode(); DBG.Info(DBG.SC, "RSCP: Hijacking call to GetHashCode, returning " + hashCode); IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; return(new ReturnMessage(hashCode, null, 0, mcm.LogicalCallContext, mcm)); } DBG.Info(DBG.SC, "RSCP: Delivering call to " + mb.Name); // convert to class member info MemberInfo clsMemInfo = ReflectionCache.ConvertToClassMI(ProxiedType, m); DBG.Assert(!clsMemInfo.ReflectedType.IsInterface, "Failed to convert interface member info to class member info"); // dispatch the call #if _DEBUG if (clsMemInfo != m) { DBG.Info(DBG.SC, "RSCP: converted interface to class call: " + clsMemInfo.Name); } #endif try { int iMethodInfo; // check for rolebased security if (_fUseIntfDispatch || (((iMethodInfo = ServicedComponentInfo.MICachedLookup(clsMemInfo)) & ServicedComponentInfo.MI_HASSPECIALATTRIBUTES) != 0) || ((iMethodInfo & ServicedComponentInfo.MI_EXECUTEMESSAGEVALID) != 0) ) { // role based security implies we dispatch through an interface MemberInfo intfMemInfo = ReflectionCache.ConvertToInterfaceMI(m); if (intfMemInfo == null) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping")); } //retMsg = EnterpriseServicesHelper.DispatchRemoteCall(reqMsg, intfMemInfo, _server); MethodCallMessageWrapperEx msgex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)intfMemInfo); retMsg = RemotingServices.ExecuteMessage((MarshalByRefObject)_server, (IMethodCallMessage)msgex); } else { // check for AutoDone bool fAutoDone = (iMethodInfo & ServicedComponentInfo.MI_AUTODONE) != 0; String s = ComponentServices.ConvertToString(reqMsg); IRemoteDispatch iremDisp = (IRemoteDispatch)_server; String sret; if (fAutoDone) { sret = iremDisp.RemoteDispatchAutoDone(s); } else { sret = iremDisp.RemoteDispatchNotAutoDone(s); } retMsg = ComponentServices.ConvertToReturnMessage(sret, reqMsg); } } catch (COMException e) { if (!(e.ErrorCode == Util.CONTEXT_E_ABORTED || e.ErrorCode == Util.CONTEXT_E_ABORTING)) { throw; } if (IsDisposeRequest(reqMsg)) { IMethodCallMessage mcm = reqMsg as IMethodCallMessage; retMsg = new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm); } else { throw; } } // if disposing, we need to release this side of the world. if (IsDisposeRequest(reqMsg)) { Dispose(true); } return(retMsg); }
/// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.IManagedObject.GetObjectIdentity"]/*' /> /// <internalonly/> void IManagedObject.GetObjectIdentity(ref String s, ref int AppDomainID, ref int ccw) { DBG.Assert(false, "IManagedObject.GetObjectIdentity should never be called."); throw new NotSupportedException("IManagedObject.GetObjectIdentity"); }
// Some dummy empty methods for IManagedObject. // These should never be called, this is just here to ensure that // IManagedObject gets stuck in the type library. /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.IManagedObject.GetSerializedBuffer"]/*' /> /// <internalonly/> void IManagedObject.GetSerializedBuffer(ref String s) { DBG.Assert(false, "IManagedObject.GetSerializedBuffer should never be called."); throw new NotSupportedException("IManagedObject.GetSerializedBuffer"); }