Пример #1
0
 public static int CreateAttachResponse(FlatBufferBuilder builder,
                                        int memory_file          = 0,
                                        int code_cache_file      = 0,
                                        uint code_cache_base     = 0,
                                        uint code_cache_size     = 0,
                                        int functions_file       = 0,
                                        int functions_trace_file = 0)
 {
     builder.StartObject(6);
     AttachResponse.AddFunctionsTraceFile(builder, functions_trace_file);
     AttachResponse.AddFunctionsFile(builder, functions_file);
     AttachResponse.AddCodeCacheSize(builder, code_cache_size);
     AttachResponse.AddCodeCacheBase(builder, code_cache_base);
     AttachResponse.AddCodeCacheFile(builder, code_cache_file);
     AttachResponse.AddMemoryFile(builder, memory_file);
     return(AttachResponse.EndAttachResponse(builder));
 }
Пример #2
0
    public async Task Attach(CancellationToken cancellationToken) {
      System.Diagnostics.Debug.Assert(CurrentState == State.Idle);

      SocketPermission permission = new SocketPermission(
                NetworkAccess.Connect,
                TransportType.Tcp,
                kServerHostname,
                kServerPort);
      permission.Demand();

      IPAddress ipAddress = new IPAddress(new byte[] { 127, 0, 0, 1 });
      IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, kServerPort);

      socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
                          ProtocolType.Tcp);
      socket.Blocking = false;
      socket.NoDelay = true;
      socket.ReceiveBufferSize = 1024 * 1024;
      socket.SendBufferSize = 1024 * 1024;
      socket.ReceiveTimeout = 0;
      socket.SendTimeout = 0;

      OnStateChanged(State.Attaching);

      while (true) {
        Task task = Task.Factory.FromAsync(socket.BeginConnect, socket.EndConnect, ipEndPoint, null);
        try {
          await task.WithCancellation(cancellationToken);
        } catch (OperationCanceledException) {
          socket.Close();
          socket = null;
          OnStateChanged(State.Idle);
          return;
        } catch (SocketException e) {
          if (e.SocketErrorCode == SocketError.ConnectionRefused) {
            // Not found - emulator may still be starting.
            System.Diagnostics.Debug.WriteLine("Connection refused; trying again...");
            continue;
          }
          OnStateChanged(State.Idle);
          return;
        }
        break;
      }

      // Start recv pump.
      Dispatch.Issue(() => ReceivePump());

      var fbb = BeginRequest();
      AttachRequest.StartAttachRequest(fbb);
      int requestDataOffset = AttachRequest.EndAttachRequest(fbb);
      var response = await CommitRequest(fbb, RequestData.AttachRequest, requestDataOffset);

      System.Diagnostics.Debug.Assert(response.ResponseDataType ==
                                      ResponseData.AttachResponse);
      var attachResponse = new AttachResponse();
      response.GetResponseData(attachResponse);

      // Open mmap to share memory.
      memoryHandle = FileMapping.OpenFileMapping(
          FileMapAccess.FILE_MAP_ALL_ACCESS, false, attachResponse.MemoryFile);
      if (memoryHandle.IsInvalid) {
        System.Diagnostics.Debug.Fail("Unable to open target memory");
        Detach();
        return;
      }

      // Open mmap to code cache.
      codeCacheHandle =
          FileMapping.OpenFileMapping(FileMapAccess.FILE_MAP_ALL_ACCESS, false,
                                      attachResponse.CodeCacheFile);
      if (codeCacheHandle.IsInvalid) {
        System.Diagnostics.Debug.Fail("Unable to open target code cache");
        Detach();
        return;
      }
      codeCachePtr = FileMapping.MapViewOfFileEx(
          codeCacheHandle, FileMapAccess.FILE_MAP_ALL_ACCESS, 0, 0,
          attachResponse.CodeCacheSize, attachResponse.CodeCacheBase);

      // Setup the memory system. This maps the emulator memory into our address
      // space.
      if (!Memory.InitializeMapping(memoryHandle)) {
        Detach();
        return;
      }

      OnStateChanged(State.Attached);
    }
Пример #3
0
 public static AttachResponse GetRootAsAttachResponse(ByteBuffer _bb, AttachResponse obj)
 {
     return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Пример #4
0
 public static AttachResponse GetRootAsAttachResponse(ByteBuffer _bb, AttachResponse obj)
 {
     return(obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }