static ssize_t ImcSendmsg(NaClSrpcMessageDesc desc,
                          const NaClSrpcMessageHeader* header,
                          int flags) {
  nacl_abi_ssize_t retval = imc_sendmsg(desc, header, flags);
  if (-1 == retval) {
    return -errno;
  }
  return retval;
}
示例#2
0
文件: mojo_irt.c 项目: freiling/mojo
static void DoMojoCall(uint32_t params[], nacl_abi_size_t num_params) {
  struct NaClAbiNaClImcMsgIoVec iov[1] = {
    {params, num_params}
  };
  struct NaClAbiNaClImcMsgHdr msgh = {iov, 1, NULL, 0};
  // Note: return value unchecked.  We're relying on the result parameter being
  // unmodified - if the syscall fails, the Mojo function will return whatever
  // the result parameter was initialized to before this function was called.
  imc_sendmsg(NACL_MOJO_DESC, &msgh, 0);
}
void domain1(void) {
  char *message = "hello";
  struct NaClImcMsgIoVec iov = { message, strlen(message) };
  struct NaClImcMsgHdr msg = { &iov, 1, NULL, 0, 0 };
  int sent;

  printf("In domain 1: Sending message, \"%s\"\n", message);
  sent = imc_sendmsg(SEND_DESC, &msg, 0);
  assert(sent >= 0);
}
示例#4
0
int send_message(int sock_fd, char *data, size_t data_size,
                 int *fds, int fds_size) {
  struct NaClAbiNaClImcMsgIoVec iov;
  struct NaClAbiNaClImcMsgHdr msg;
  iov.base = data;
  iov.length = data_size;
  msg.iov = &iov;
  msg.iov_length = 1;
  msg.descv = fds;
  msg.desc_length = fds_size;
  return imc_sendmsg(sock_fd, &msg, 0);
}
/*
 * Send a bad response (a request, actually).
 */
static void SendBadResponse(int d) {
  struct NaClImcMsgHdr header;
  struct NaClImcMsgIoVec iovec[1];
  /* Construct the IO vector to have one data payload. */
  iovec[0].base = (char*) kRequestHeader;
  iovec[0].length = sizeof(kRequestHeader);
  /* Set the header to have the IO vector and no descriptors. */
  header.iov = iovec;
  header.iov_length = sizeof(iovec) / sizeof(iovec[0]);
  header.descv = NULL;
  header.desc_length = 0;
  /* Send the message. */
  imc_sendmsg(d, &header, 0);
}
/*
 * sends a string w/ at most one descriptor.
 */
void send_imc_msg(int         channel,
                  char const  *msg,
                  int         desc) {
  struct NaClAbiNaClImcMsgHdr msg_hdr;
  struct NaClAbiNaClImcMsgIoVec iov;
  int                     nbytes;
  int                     rv;

  msg_hdr.iov = &iov;
  msg_hdr.iov_length = 1;
  msg_hdr.descv = &desc;
  msg_hdr.desc_length = -1 != desc;
  iov.base = (char *) msg;
  iov.length = nbytes = strlen(msg);
  if (nbytes != (rv = imc_sendmsg(channel, &msg_hdr, 0))) {
    fprintf(stderr, "imc_sendmsg returned %d, expected %d\n", rv, nbytes);
    fprintf(stderr, "errno %d\n", errno);
    exit(1);
  }
}
/*
 * __NaClSrpcImcFlush send the contents of a write buffer over the IMC
 * channel. It returns 1 if successful, or 0 otherwise.
 */
int __NaClSrpcImcFlush(NaClSrpcImcBuffer* buffer, NaClSrpcChannel* channel) {
  ssize_t        retval;
  buffer->iovec[0].length = buffer->next_byte;
#ifdef __native_client__
  retval = imc_sendmsg(channel->imc_handle, &buffer->header, 0);
#else
  retval = NaClImcSendTypedMessage(channel->imc_handle,
                                   &buffer->header,
                                   0);
#endif
  NACL_SRPC_IMC_HEADER_DESC_LENGTH(*buffer) = 0;
  buffer->next_desc = 0;
  buffer->next_byte = 0;
  if ((size_t) retval != buffer->iovec[0].length) {
    dprintf((SIDE "SRPC: FLUSH: send error.\n"));
    return 0;
  }
  dprintf((SIDE "SRPC: FLUSH: complete send.\n"));
  return 1;
}