public WaterboxHost(WaterboxOptions opt) { var nativeOpts = new MemoryLayoutTemplate { sbrk_size = Z.UU(opt.SbrkHeapSizeKB * 1024), sealed_size = Z.UU(opt.SealedHeapSizeKB * 1024), invis_size = Z.UU(opt.InvisibleHeapSizeKB * 1024), plain_size = Z.UU(opt.PlainHeapSizeKB * 1024), mmap_size = Z.UU(opt.MmapHeapSizeKB * 1024), }; var moduleName = opt.Filename; var path = Path.Combine(opt.Path, moduleName); var gzpath = path + ".gz"; byte[] data; if (File.Exists(gzpath)) { using var fs = new FileStream(gzpath, FileMode.Open, FileAccess.Read); data = Util.DecompressGzipFile(fs); } else { data = File.ReadAllBytes(path); } var retobj = new ReturnData(); NativeImpl.wbx_create_host(nativeOpts, opt.Filename, Reader(new MemoryStream(data, false)), IntPtr.Zero, retobj); _nativeHost = retobj.GetDataOrThrow(); }
protected T PreInit <T>(WaterboxOptions options) where T : LibWaterboxCore { options.Path ??= CoreComm.CoreFileProvider.DllPath(); _exe = new WaterboxHost(options); using (_exe.EnterExit()) { var ret = BizInvoker.GetInvoker <T>(_exe, _exe, CallingConventionAdapters.Waterbox); _core = ret; return(ret); } }
protected T PreInit <T>(WaterboxOptions options, IEnumerable <Delegate> allExtraDelegates = null) where T : LibWaterboxCore { options.Path ??= CoreComm.CoreFileProvider.DllPath(); _exe = new WaterboxHost(options); var delegates = new Delegate[] { _inputCallback }.AsEnumerable(); if (allExtraDelegates != null) { delegates = delegates.Concat(allExtraDelegates); } using (_exe.EnterExit()) { var ret = BizInvoker.GetInvoker <T>(_exe, _exe, CallingConventionAdapters.MakeWaterbox(delegates, _exe)); _core = ret; return(ret); } }
public WaterboxHost(WaterboxOptions opt) { _nextStart = opt.StartAddress; Initialize(_nextStart); using (this.EnterExit()) { _emu = new EmuLibc(this); _syscalls = new Syscalls(this); _imports = new PatchImportResolver( NotImplementedSyscalls.Instance, BizExvoker.GetExvoker(_emu, CallingConventionAdapters.Waterbox), BizExvoker.GetExvoker(_syscalls, CallingConventionAdapters.Waterbox) ); if (true) { var moduleName = opt.Filename; var path = Path.Combine(opt.Path, moduleName); var gzpath = path + ".gz"; byte[] data; if (File.Exists(gzpath)) { using var fs = new FileStream(gzpath, FileMode.Open, FileAccess.Read); data = Util.DecompressGzipFile(fs); } else { data = File.ReadAllBytes(path); } _module = new ElfLoader(moduleName, data, _nextStart, opt.SkipCoreConsistencyCheck, opt.SkipMemoryConsistencyCheck); ComputeNextStart(_module.Memory.Size); AddMemoryBlock(_module.Memory, moduleName); _savestateComponents.Add(_module); _disposeList.Add(_module); } ConnectAllImports(); // load all heaps _heap = CreateHeapHelper(opt.SbrkHeapSizeKB, "brk-heap", true); _sealedheap = CreateHeapHelper(opt.SealedHeapSizeKB, "sealed-heap", true); _invisibleheap = CreateHeapHelper(opt.InvisibleHeapSizeKB, "invisible-heap", false); _plainheap = CreateHeapHelper(opt.PlainHeapSizeKB, "plain-heap", true); if (opt.MmapHeapSizeKB != 0) { _mmapheap = new MapHeap(_nextStart, opt.MmapHeapSizeKB * 1024, "mmap-heap"); _mmapheap.Memory.Activate(); ComputeNextStart(opt.MmapHeapSizeKB * 1024); AddMemoryBlock(_mmapheap.Memory, "mmap-heap"); _savestateComponents.Add(_mmapheap); _disposeList.Add(_mmapheap); } System.Diagnostics.Debug.WriteLine($"About to enter unmanaged code for {opt.Filename}"); if (!OSTailoredCode.IsUnixHost && !System.Diagnostics.Debugger.IsAttached && Win32Imports.IsDebuggerPresent()) { // this means that GDB or another unconventional debugger is attached. // if that's the case, and it's observing this core, it probably wants a break System.Diagnostics.Debugger.Break(); } _module.RunNativeInit(); } }