internal static void Finalize() { if (useAddressTranslation) { VMManager.Finalize(); } }
private bool Delete() { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); ApplicationDbContext db = new ApplicationDbContext(); var name = Request.GetQueryNameValuePairs(); int id = Int32.Parse(name.ElementAt(0).Key); var cloudService = db.QuickCreates.Where(l => l.ID == id).FirstOrDefault(); try { string res = vmm.DeleteQCV(cloudService.ServiceName); } catch (Exception e) { // string message = e.InnerException.ToString(); db.QuickCreates.Remove(cloudService); db.SaveChanges(); } if (cloudService != null) { db.QuickCreates.Remove(cloudService); db.SaveChanges(); } return(true); }
public async Task <JsonResult> Getimages() { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); var swr = new StringWriter(); imageList = await vmm.GetAzureVMImages(); List <string> imageListRest = new List <string>(); //imageList.TryGetValue("") //imageListRest.Add(; //imageListRest.Add(imageList[185]); //imageListRest.Add(imageList[186]); //imageListRest.Add(imageList[187]); var imgLst = new List <SelectListItem>(); foreach (KeyValuePair <string, string> entry in imageList) { imgLst.Add(new SelectListItem { Value = entry.Key, Text = entry.Value }); } TempData["OS"] = imgLst; return(Json(new { Status = 0, MessageTitle = "Success" })); }
internal static UIntPtr KernelMapPhysicalMemory(PhysicalAddress physStart, UIntPtr numBytes) { if (useAddressTranslation) { UIntPtr permaLoc = VMManager.TranslatePhysicalRange(physStart, numBytes); if (permaLoc != UIntPtr.Zero) { // This location has a permanent mapping return(permaLoc); } else { // This location must be mapped on the fly return(VMManager.MapPhysicalMemory(KernelRangeWrapper, Process.kernelProcess, physStart, numBytes)); } } else { // identity map without paging return(unchecked ((UIntPtr)physStart.Value)); } }
private static bool GetDmaPhysicalAddress(UIntPtr virtualAddr, out UIntPtr physAddr, out UIntPtr physRemaining) { UIntPtr alignedAddr = MemoryManager.PageAlign(virtualAddr); #if PAGING PhysicalAddress phys = VMManager.GetPageMapping(alignedAddr); if (phys != PhysicalAddress.Null) { physAddr = (UIntPtr)phys.Value + (virtualAddr - alignedAddr); physRemaining = MemoryManager.PagePad(physAddr + 1) - physAddr; return(true); } #else if (virtualAddr != UIntPtr.Zero) { physAddr = virtualAddr; physRemaining = MemoryManager.PagePad(physAddr + 1) - physAddr; return(true); } #endif // PAGING physAddr = UIntPtr.Zero; physRemaining = UIntPtr.Zero; return(false); }
internal static UIntPtr UserMapPhysicalMemory(PhysicalAddress physStart, UIntPtr numBytes) { return(useAddressTranslation ? VMManager.MapPhysicalMemory(ProtectionDomain.CurrentDomain.UserRange, Thread.CurrentProcess, physStart, numBytes) : unchecked ((UIntPtr)physStart.Value)); }
async void checkLabEndTime_Elapsed(object sender, ElapsedEventArgs e) { try { if (conn.State != ConnectionState.Open) { conn.ConnectionString = ConnectionString; conn.Open(); } } catch (Exception ex) { // Log.Write(EventKind.Critical, Log.FormatExceptionInfo(ex), null); //Log exception message } SqlCommand closeLabs = new SqlCommand("Select * from Labs where ((datediff(minute, end_time, getdate())) = 0) ", conn); SqlDataReader closeLabsReader = closeLabs.ExecuteReader(); if (closeLabsReader != null) { try { while (closeLabsReader.Read()) { string labName = closeLabsReader.GetString(1); int labID = closeLabsReader.GetInt32(0); SqlCommand VMList = new SqlCommand("Select * from LabVMs where Lab_ID = " + labID, conn); SqlDataReader VMListReader = VMList.ExecuteReader(); while (VMListReader.Read()) { SqlCommand updateLabsStatus = new SqlCommand("update labs set status='Deleting' where id = " + labID, conn); updateLabsStatus.ExecuteNonQuery(); string serviceName = VMListReader.GetString(1); SqlCommand closeParticipantList = new SqlCommand("Delete from LabParticipants where LabID = " + labID, conn); SqlDataReader closeParticipantReader = closeParticipantList.ExecuteReader(); SqlCommand closeLabConfigOb = new SqlCommand("Delete from LabConfigurations where LabID = " + labID, conn); SqlDataReader closeLabConfigReader = closeLabConfigOb.ExecuteReader(); SqlCommand deleteVMPath = new SqlCommand("Delete from LabVMs where Lab_ID = " + labID, conn); deleteVMPath.ExecuteNonQuery(); SqlCommand deleteLabsStatus = new SqlCommand("Delete from Labs where id = " + labID, conn); deleteLabsStatus.ExecuteNonQuery(); VMManager vmm = new VMManager(SubscriptionID, CertThumbPrint); string status = await vmm.DeleteQCVM(serviceName).ConfigureAwait(continueOnCapturedContext: false); } } } catch (Exception exc) { //Log Exception // Log.Write(EventKind.Critical, Log.FormatExceptionInfo(exc), null); } } }
internal static void UserUnmapPhysicalMemory(UIntPtr startAddr, UIntPtr limitAddr) { if (useAddressTranslation) { VMManager.UnmapPhysicalMemory(ProtectionDomain.CurrentDomain.UserRange, Thread.CurrentProcess, startAddr, limitAddr); } }
// // Unmap the page at the provided virtual address and release its // underlying physical page // internal static void UnmapAndReleasePage(UIntPtr virtualAddr) { DebugStub.Assert(VMManager.IsPageMapped(virtualAddr), "Trying to unmap an unmapped page"); PhysicalAddress phys = VMManager.UnmapPage(virtualAddr); DebugStub.Assert(phys != PhysicalAddress.Null); PhysicalPages.FreePage(phys); }
private unsafe UIntPtr FreeInternal(UIntPtr startPage, UIntPtr numPages) { DebugStub.Assert(MemoryManager.IsPageAligned(startPage)); DebugStub.Assert(startPage >= dataStart); UIntPtr blockLimit = startPage + MemoryManager.BytesFromPages(numPages); DebugStub.Assert(blockLimit <= rangeLimit); DebugStub.Assert(nextAlloc >= blockLimit); bool iflag = Lock(); try { // Mark the pages free within our lock so we can rely on // blocks being uniformly marked free in here SetRange(startPage, blockLimit, MemoryManager.PageFree); // Reduce fragmentation: lower the nextAlloc pointer if // we have freed the top end of memory. if (nextAlloc == blockLimit) { nextAlloc = startPage; // // NOTE: this chooses to use the page table // information, which is currently usermode-accessible // in the case of a user-mode range. Keep in mind that // the information may be corrupt! // // Further optimization: drop nextAlloc more // if the memory below us is free, too. uint * pageTable = PageTable; UIntPtr stepPage = nextAlloc; uint val; do { nextAlloc = stepPage; stepPage -= MemoryManager.PageSize; uint dsc = pageTable[(uint)PageFromAddr(stepPage)]; val = dsc & MemoryManager.SystemPageMask; }while ((val == MemoryManager.PageFree) && (!VMManager.IsPageMapped(stepPage))); // sanity } freedCount++; freedBytes += (ulong)MemoryManager.BytesFromPages(numPages); } finally { Unlock(iflag); } return(MemoryManager.BytesFromPages(numPages)); }
// Use this for initialization void Start() { scriptMoneyManager = GetComponent <MoneyManager>(); scriptVMManager = GameObject.Find("VMmain").GetComponent <VMManager>(); scriptMoneyManager.ChangeMoney(100); gameFlag = false; titleFlag = true; level = 0; LevelUp(); DrawTime(); }
async public Task <bool> GenerateVMConfig(QuickCreate model) { VMManager vmm = GetVMM(); if (await vmm.IsServiceNameAvailable(model.Name).ConfigureAwait(continueOnCapturedContext: false) == false) { return(false); } bool isVmImage = false; string ImageName = ""; string ImagePath = ""; XDocument vm = vmm.NewAzureVMConfig(model.Name, model.Machine_Size, model.OS, GetOSDiskMediaLocation(model.OSLabel), true, isVmImage, ImageName, ImagePath); if (!isVmImage) { vm = vmm.NewWindowsProvisioningConfig(vm, model.Name, pwd); vm = vmm.NewNetworkConfigurationSet(vm); vm = vmm.AddNewInputEndpoint(vm, "web", "TCP", 80, 80); vm = vmm.AddNewInputEndpoint(vm, "rdp", "TCP", 3389, 3389); } var builder = new StringBuilder(); var settings = new XmlWriterSettings() { Indent = true }; using (var writer = XmlWriter.Create(builder, settings)) { vm.WriteTo(writer); } String requestID_cloudService = await vmm.NewAzureCloudService(model.ServiceName, "West US", String.Empty).ConfigureAwait(continueOnCapturedContext: false); OperationResult result = await vmm.PollGetOperationStatus(requestID_cloudService, 5, 120).ConfigureAwait(continueOnCapturedContext: false); String requestID_createDeployment; if (result.Status == OperationStatus.Succeeded) { // VM creation takes too long so we'll check it later requestID_createDeployment = await vmm.NewAzureVMDeployment(model.ServiceName, model.Name, String.Empty, vm, null, isVmImage).ConfigureAwait(continueOnCapturedContext: false); OperationResult resultvm = await vmm.PollGetOperationStatus(requestID_createDeployment, 5, 120).ConfigureAwait(continueOnCapturedContext: false); } else { requestID_createDeployment = ""; } return(true); }
async public Task <JsonResult> DeleteQCVM(int id) { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); ApplicationDbContext db = new ApplicationDbContext(); var cloudService = db.QuickCreates.Where(l => l.ID == id).FirstOrDefault(); await vmm.DeleteQCVM(cloudService.ServiceName); db.QuickCreates.Remove(cloudService); db.SaveChanges(); return(Json(new { Status = 0 })); }
public async Task <string> GetVMLabel(string imgName) { string Label; VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); imageList = await vmm.GetAzureVMImages(); imageList.TryGetValue(imgName, out Label); label = Label; return(label); }
///////////////////////////////////// // PUBLIC STATIC METHODS ///////////////////////////////////// internal static void Initialize() { tableLock = new SmartSpinlock(SpinLock.Types.ProtectionDomainTable); PdTable = new ProtectionDomain[maxPDs]; PdIndexGenerator = 1; // Create the default protection domain AddressSpace defaultSpace = VMManager.GetBootstrapSpace(); PdTable[0] = new ProtectionDomain(defaultSpace, "Default", true); }
// // Get a new physical page and map it to the provided virtual address // private static bool CommitAndMapNewPage(UIntPtr virtualAddr, ProtectionDomain inDomain) { DebugStub.Assert(IsPageAligned(virtualAddr)); PhysicalAddress newPage = PhysicalPages.AllocPage(); if (newPage == PhysicalAddress.Null) { // Failed. return(false); } VMManager.MapPage(newPage, virtualAddr, inDomain); return(true); }
internal static unsafe void PostGCInitialize() { if (useAddressTranslation) { VMManager.PostGCInitialize(); // Create the wrapper for the kernel range. The fixed // statement is safe since KernelRange is a static // struct. fixed(VirtualMemoryRange_struct *pKernelRange = &KernelRange) { KernelRangeWrapper = new VirtualMemoryRange(pKernelRange, ProtectionDomain.DefaultDomain); } } }
private IEnumerable <SelectListItem> Getimages() { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); var swr = new StringWriter(); imageList = vmm.GetAzureVMImages().Result; List <string> imageListRest = new List <string>(); var imgLst = new List <SelectListItem>(); foreach (KeyValuePair <string, string> entry in imageList) { imgLst.Add(new SelectListItem { Value = entry.Key, Text = entry.Value }); } return(imgLst); }
internal static void KernelUnmapPhysicalMemory(UIntPtr startAddr, UIntPtr limitAddr) { if (useAddressTranslation) { if (VMManager.IsPermaMapped(startAddr, limitAddr)) { return; // nothing to do } else { VMManager.UnmapPhysicalMemory(KernelRangeWrapper, Process.kernelProcess, startAddr, limitAddr); } } // else do nothing }
async private Task <bool> CreateVM(string serviceName, string vmName, string password, string Machine_Size, string OS) { VMManager vmm = new VMManager(SubscriptionID, CertThumbPrint); if (await vmm.IsServiceNameAvailable(serviceName).ConfigureAwait(continueOnCapturedContext: false) == false) { return(false); } XDocument vm = vmm.NewAzureVMConfig(vmName, Machine_Size, OS, GetOSDiskMediaLocation(vmName), true); vm = vmm.NewWindowsProvisioningConfig(vm, vmName, password); vm = vmm.NewNetworkConfigurationSet(vm); vm = vmm.AddNewInputEndpoint(vm, "web", "TCP", 80, 80); vm = vmm.AddNewInputEndpoint(vm, "rdp", "TCP", 3389, 3389); var builder = new StringBuilder(); var settings = new XmlWriterSettings() { Indent = true }; using (var writer = XmlWriter.Create(builder, settings)) { vm.WriteTo(writer); } String requestID_cloudService = await vmm.NewAzureCloudService(serviceName, "West US", String.Empty).ConfigureAwait(continueOnCapturedContext: false); OperationResult result = await vmm.PollGetOperationStatus(requestID_cloudService, 5, 120).ConfigureAwait(continueOnCapturedContext: false);; String requestID_createDeployment; if (result.Status == OperationStatus.Succeeded) { // VM creation takes too long so we'll check it later requestID_createDeployment = await vmm.NewAzureVMDeployment(serviceName, vmName, String.Empty, vm, null).ConfigureAwait(continueOnCapturedContext: false); } else { requestID_createDeployment = ""; } return(true); }
async public Task <JsonResult> CaptureQCVM(int id, string ImageName) { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); ApplicationDbContext db = new ApplicationDbContext(); var cloudService = db.QuickCreates.Where(l => l.ID == id).FirstOrDefault(); await vmm.ShutDownVM(cloudService.ServiceName, cloudService.Name); VirtualMachineCaptureVMImageParameters param = new VirtualMachineCaptureVMImageParameters(); param.VMImageLabel = "NewVmImage"; param.VMImageName = "NewVmImage"; param.OSState = "Specialized"; System.Threading.CancellationToken token = new System.Threading.CancellationToken(false); await vmm.CaptureVM(cloudService.ServiceName, cloudService.Name, param.VMImageName); await vmm.RebootVM(cloudService.ServiceName, cloudService.Name); return(Json(new { Status = 0 })); }
public JsonResult GetVmSizes() { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); var swr = new StringWriter(); imageList = vmm.GetAzureVMSizes().Result; List <string> imageListRest = new List <string>(); var imgLst = new List <SelectListItem>(); foreach (KeyValuePair <string, string> entry in imageList) { imgLst.Add(new SelectListItem { Value = entry.Key, Text = entry.Value }); } TempData["Size"] = imgLst; return(Json(new { Status = 0, MessageTitle = "Success" })); }
async private Task <String> GetVMImageDiskLocation(string imageName) { XNamespace ns = "http://schemas.microsoft.com/windowsazure"; VMManager vmm = GetVMM(); string imageLocation = string.Empty; XDocument xml = await vmm.GetUserVMImages(); var images = xml.Root.Descendants(ns + "VMImage").Where(i => i.Element(ns + "Category").Value == "User"); foreach (var image in images) { string imgName = image.Element(ns + "Name").Value; if (imageName == imgName) { imageLocation = image.Element(ns + "OSDiskConfiguration").Element(ns + "MediaLink").Value; } } return(imageLocation); }
public async Task <JsonResult> GetVMStatus(string ServiceName, string VMName, string id) { VMManager vmm = GetVMM(); string instanceStatus = string.Empty; string powerState = string.Empty; XDocument vmXML = await vmm.GetAzureVM(ServiceName, VMName); var statusm = vmXML.Root.Descendants(vmm.ns + "RoleInstanceList"); foreach (var status in statusm) { instanceStatus = status.Element(vmm.ns + "RoleInstance").Element(vmm.ns + "InstanceStatus").Value; powerState = status.Element(vmm.ns + "RoleInstance").Element(vmm.ns + "PowerState").Value; } return(Json(new { Status = 0, InstanceStatus = instanceStatus, PowerState = powerState, VMName = VMName, ServiceName = ServiceName, id = id })); }
public async Task <ActionResult> Index() { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); imageList = await vmm.GetAzureVMImages(); List <string> imageListRest = new List <string>(); //imageListRest.Add(imageList[184]); //imageListRest.Add(imageList[185]); //imageListRest.Add(imageList[186]); //imageListRest.Add(imageList[187]); var imgLst = new List <SelectListItem>(); foreach (KeyValuePair <string, string> entry in imageList) { imgLst.Add(new SelectListItem { Value = entry.Key, Text = entry.Value }); } TempData["OS"] = imgLst; return(View()); }
public JsonResult DeleteQCVM(int id) { VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]); ApplicationDbContext db = new ApplicationDbContext(); var cloudService = db.QuickCreates.Where(l => l.ID == id).FirstOrDefault(); try { string res = vmm.DeleteQCVM(cloudService.ServiceName).Result; } catch (Exception e) { // string message = e.InnerException.ToString(); db.QuickCreates.Remove(cloudService); db.SaveChanges(); } if (cloudService != null) { db.QuickCreates.Remove(cloudService); db.SaveChanges(); } return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); // return Json(new { Status = 0 }); }
///////////////////////////////////// // PUBLIC METHODS ///////////////////////////////////// // // The range of memory turned over to a VirtualMemoryRange structure // must not have *any* mapped pages in it to start out with // // A VirtualMemoryRange can build a pagetable that *describes* // more memory than it *manages* (this supports some kernel GC // oddities). In that case, pages out-of-range are marked // as PageType.Unknown. Obviously, allocation requests are never // satisfied with out-of-bounds data. // internal unsafe VirtualMemoryRange_struct( UIntPtr baseAddr, UIntPtr limitAddr, UIntPtr descrBaseAddr, UIntPtr descrLimitAddr, ProtectionDomain inDomain) { DebugStub.Assert(MemoryManager.IsPageAligned(baseAddr)); DebugStub.Assert(MemoryManager.IsPageAligned(limitAddr)); DebugStub.Assert(MemoryManager.IsPageAligned(descrBaseAddr)); DebugStub.Assert(MemoryManager.IsPageAligned(descrLimitAddr)); // The descriptive range can't be smaller than the managed range DebugStub.Assert(descrLimitAddr >= limitAddr); DebugStub.Assert(descrBaseAddr <= baseAddr); descrBase = descrBaseAddr; descrLimit = descrLimitAddr; rangeBase = baseAddr; rangeLimit = limitAddr; rangeLock = new SpinLock(SpinLock.Types.VirtualMemoryRange); describedPages = MemoryManager.PagesFromBytes(descrLimit - descrBase); // Figure out how many pages we need for a page description table UIntPtr pageTableSize = MemoryManager.PagePad(describedPages * sizeof(uint)); dataStart = baseAddr + pageTableSize; nextAlloc = dataStart; // Commit and prepare the page table pageTable = (uint *)baseAddr; bool success = MemoryManager.CommitAndMapRange( baseAddr, baseAddr + pageTableSize, inDomain); if (!success) { Kernel.Panic("Couldn't get pages to create a new VirtualMemoryRange page table"); } allocatedBytes = 0; allocatedCount = 0; freedBytes = 0; freedCount = 0; // Describe the pages outside our range as Unknown if (descrBase < rangeBase) { SetRange(descrBase, rangeBase, MemoryManager.PageUnknown); } if (descrLimit > rangeLimit) { SetRange(rangeLimit, descrLimit, MemoryManager.PageUnknown); } // The page-table pages themselves are in use by the System SetRange((UIntPtr)pageTable, (UIntPtr)pageTable + pageTableSize, MemoryManager.KernelPageNonGC); // Describe pages in-range as Free SetRange(dataStart, rangeLimit, MemoryManager.PageFree); #if DEBUG // Check that our data range is pristine for (UIntPtr stepAddr = dataStart; stepAddr < rangeLimit; stepAddr += MemoryManager.PageSize) { DebugStub.Assert(!VMManager.IsPageMapped(stepAddr)); } #endif }
private ProtectionDomain(string name, bool isKernelDomain) : this(VMManager.CreateNewAddressSpace(), name, isKernelDomain) { }
///////////////////////////////////// // PUBLIC METHODS ///////////////////////////////////// internal static void Initialize() { DebugStub.WriteLine("Initializing memory subsystem..."); // Only allow paging in HALs which support running in Ring 0 // but always force paging in the HIP builds for compatibility #if !PAGING useAddressTranslation = UseAddressTranslationInCmdLine(); #else useAddressTranslation = true; #endif if (useAddressTranslation) { DebugStub.WriteLine("Using address translation...\n"); Platform p = Platform.ThePlatform; // Set up the hardware-pages table and reserve a range for // I/O memory IOMemoryBaseAddr = PhysicalPages.Initialize(Platform.IO_MEMORY_SIZE); // Set up the I/O memory heap KernelIOMemoryHeap = new PhysicalHeap((UIntPtr)IOMemoryBaseAddr.Value, (UIntPtr)(IOMemoryBaseAddr.Value + Platform.IO_MEMORY_SIZE)); // Set up virtual memory. ** This enables paging ** ! VMManager.Initialize(); // Set up the kernel's memory ranges. // // The kernel's general-purpose range is special because // it *describes* low memory as well as the GC range proper // so the kernel's GC doesn't get confused by pointers to // static data in the kernel image. KernelRange = new VirtualMemoryRange_struct( VMManager.KernelHeapBase, VMManager.KernelHeapLimit, UIntPtr.Zero, VMManager.KernelHeapLimit, null); // no concurrent access to page descriptors yet // Mark the kernel's special areas. First, record the kernel memory. if (p.KernelDllSize != 0) { UIntPtr kernelDllLimit = p.KernelDllBase + p.KernelDllSize; KernelRange.SetRange(p.KernelDllBase, kernelDllLimit, MemoryManager.KernelPageNonGC); } // Record the boot allocated kernel memory. if (p.BootAllocatedMemorySize != 0) { UIntPtr bootAllocatedMemoryLimit = p.BootAllocatedMemory + p.BootAllocatedMemorySize; KernelRange.SetRange(p.BootAllocatedMemory, bootAllocatedMemoryLimit, MemoryManager.KernelPageNonGC); } // Set stack page for CPU 0 KernelRange.SetRange(Platform.BootCpu.KernelStackLimit, (Platform.BootCpu.KernelStackBegin - Platform.BootCpu.KernelStackLimit), MemoryManager.KernelPageStack); DebugStub.WriteLine("MemoryManager initialized with {0} physical pages still free", __arglist(PhysicalPages.GetFreePageCount())); KernelRange.Dump("Initialized"); isInitialized = true; } else { FlatPages.Initialize(); DebugStub.WriteLine("KernelBaseAddr: {0:x8} KernelLimitAddr {1:x8}", __arglist(KernelBaseAddr, KernelBaseAddr + BytesFromPages(KernelPageCount))); } }