public ImgSource(string aURI, CodeSourceProvider aProvider, CodeCollection aCollection, SIContent aImageContent) : base(aURI, aProvider) { iImageContent = aImageContent; // Make sure we receive any requests from the collection object for code. aCollection.IfaceInstructionConverter = this; aCollection.IsRelocatable = aImageContent.IsRelocationSupported; // XIP content should be read during priming. TTimeToRead timeToRead = TTimeToRead.EReadWhenPriming; if (aImageContent.IsRelocationSupported) { timeToRead = TTimeToRead.EReadWhenNeeded; } else { // If the image is fixed, then so is the collection base address aCollection.Relocate(aImageContent.RelocationAddress); } // Must add the collection *after* setting it's properties base.TimeToRead = timeToRead; base.Add(aCollection); }
public CodeCollection Activate(CodeSegDefinition aCodeSegment) { CodeCollection ret = null; // Find the corresponding Code seg CodeSourceAndCollection pair = SourceManager[aCodeSegment]; if (pair != null) { CodeCollection col = pair.Collection; if (col.IsFixed) { // Cannot activate a fixed Code segment - TODO: should this return "true", i.e. already activated? } else { bool safe = CheckSafeToActivate(aCodeSegment); if (safe) { // Deep copy the collection CodeCollection dupe = CodeCollection.NewCopy(iPlugin.ProvisioningManager.IdAllocator, col); // Set new process-specific relocated base address. This causes the underlying code to be // decompressed/read if not already done so. dupe.Relocate(aCodeSegment.Base); // At this point, the code owned by 'col' will have definitely been read (if available) // and that means col.IsCodeAvailable is probably true. However, dupe.IsCodeAvailable // is almost certainly false so we may need to copy the code over... if (dupe.IsCodeAvailable == false && col.IsCodeAvailable == true) { dupe.Code = col.Code; } System.Diagnostics.Debug.Assert(dupe.IsCodeAvailable == col.IsCodeAvailable); // Save so that we can unload it later pair = new CodeSourceAndCollection(pair, dupe); AddToActivationList(pair, aCodeSegment); // We managed to activate a binary, so return the collection ret = dupe; iPlugin.Trace("[C] ACTIVATE - {0}", aCodeSegment); } } } // return(ret); }