示例#1
0
        // connect all of the .wbxsyscall stuff
        public void ConnectSyscalls(IImportResolver syscalls)
        {
            Memory.Protect(Memory.Start, Memory.Size, MemoryBlock.Protection.RW);

            var tmp     = new IntPtr[1];
            var ptrSize = (ulong)IntPtr.Size;

            foreach (var s in _importSymbols)
            {
                if (s.Size == ptrSize)
                {
                    var p = syscalls.GetProcAddrOrThrow(s.Name);
                    tmp[0] = p;
                    Marshal.Copy(tmp, 0, Z.US(s.Value), 1);
                }
                else
                {
                    if (s.Size % ptrSize != 0)
                    {
                        // They're supposed to be arrays of pointers, so uhhh yeah?
                        throw new InvalidOperationException($"Symbol {s.Name} has unexpected size");
                    }
                    var count = (int)(s.Size / ptrSize);
                    for (var i = 0; i < count; i++)
                    {
                        var p = syscalls.GetProcAddrOrThrow($"{s.Name}[{i}]");
                        tmp[0] = p;
                        Marshal.Copy(tmp, 0, Z.US(s.Value + ((ulong)i * ptrSize)), 1);
                    }
                }
            }

            Protect();
        }
 public IntPtr GetArrivalFunctionPointer(IntPtr p, ParameterInfo pp, object lifetime)
 {
     lock (_sync)
     {
         var index = FindFreeIndex();
         var count = VerifyDelegateSignature(pp);
         WriteThunk(ThunkDll.GetProcAddrOrThrow($"arrive{count}"), p, index);
         SetLifetime(index, lifetime);
         return(GetThunkAddress(index));
     }
 }
示例#3
0
 public LinkInterop(NeoGeoPort core, BlockingCollection <LinkRequest> push, BlockingCollection <LinkResult> pull)
 {
     _core     = core;
     _push     = push;
     _pull     = pull;
     _exporter = BizExvoker.GetExvoker(this, CallingConventionAdapters.Waterbox);
     _readcb   = _exporter.GetProcAddrOrThrow("CommsReadCallback");
     _pollcb   = _exporter.GetProcAddrOrThrow("CommsPollCallback");
     _writecb  = _exporter.GetProcAddrOrThrow("CommsWriteCallback");
     ConnectPointers();
 }
示例#4
0
        public void ConnectImports(string moduleName, IImportResolver module)
        {
            // this is called once internally when bootstrapping, and externally
            // when we need to restore a savestate from another run.  so imports might or might not be sealed

            if (_everythingSealed && _imports != null)
            {
                Memory.Protect(_imports.Start, _imports.Size, MemoryBlockBase.Protection.RW);
            }

            Dictionary <string, IntPtr> imports;

            if (ImportsByModule.TryGetValue(moduleName, out imports))
            {
                foreach (var kvp in imports)
                {
                    var valueArray = new IntPtr[] { module.GetProcAddrOrThrow(kvp.Key) };
                    Marshal.Copy(valueArray, 0, kvp.Value, 1);
                }
            }

            if (_everythingSealed && _imports != null)
            {
                Memory.Protect(_imports.Start, _imports.Size, _imports.Prot);
            }
        }