void NaClSimpleServiceConnectionDtor(struct NaClRefCount *vself) {
  struct NaClSimpleServiceConnection *self =
      (struct NaClSimpleServiceConnection *) vself;

  NaClRefCountUnref((struct NaClRefCount *) self->server);
  NaClRefCountUnref((struct NaClRefCount *) self->connected_socket);

  NACL_VTBL(NaClRefCount, self) = &kNaClRefCountVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
Ejemplo n.º 2
0
int NaClReverseThreadIfCtor_protected(
    struct NaClReverseCountingThreadInterface   *self,
    void                                        *factory_data,
    NaClThreadIfStartFunction                   fn_ptr,
    void                                        *thread_data,
    size_t                                      thread_stack_size) {
  struct NaClReverseService *nrsp = (struct NaClReverseService *) factory_data;

  NaClLog(3, "Entered NaClReverseThreadIfCtor_protected\n");
  if (!NaClThreadInterfaceCtor_protected(
          (struct NaClThreadInterface *) self,
          NaClReverseThreadIfFactoryFn,
          NaClRefCountRef((struct NaClRefCount *) nrsp),
          fn_ptr,
          thread_data,
          thread_stack_size)) {
    NaClLog(4, "NaClThreadInterfaceCtor_protected failed\n");
    NaClRefCountUnref((struct NaClRefCount *) nrsp);
    return 0;
  }

  self->reverse_service = nrsp;
  (*NACL_VTBL(NaClReverseService, nrsp)->ThreadCountIncr)(nrsp);

  NACL_VTBL(NaClRefCount, self) =
      (struct NaClRefCountVtbl *) &kNaClReverseThreadInterfaceVtbl;

  NaClLog(3, "Leaving NaClAddrSpSquattingThreadIfCtor_protected\n");
  return 1;
}
Ejemplo n.º 3
0
void NaClRefCountSafeUnref(struct NaClRefCount *nrcp) {
  NaClLog(4, "NaClRefCountSafeUnref(0x%08"NACL_PRIxPTR").\n",
          (uintptr_t) nrcp);
  if (NULL == nrcp) {
    return;
  }
  NaClRefCountUnref(nrcp);
}
void NaClKernelServiceDtor(struct NaClRefCount *vself) {
  struct NaClKernelService *self = (struct NaClKernelService *) vself;

  NaClRefCountUnref((struct NaClRefCount *) self->runtime_host);

  NACL_VTBL(NaClRefCount, self) =
      (struct NaClRefCountVtbl *) &kNaClSimpleServiceVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
Ejemplo n.º 5
0
void NaClReverseThreadIfDtor(struct NaClRefCount *vself) {
  struct NaClReverseCountingThreadInterface *self =
      (struct NaClReverseCountingThreadInterface *) vself;

  NaClRefCountUnref((struct NaClRefCount *) self->reverse_service);
  self->reverse_service = NULL;
  NACL_VTBL(NaClRefCount, self) = &kNaClRefCountVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
void NaClReverseHostInterfaceDtor(struct NaClRefCount *vself) {
  struct NaClReverseHostInterface *self =
      (struct NaClReverseHostInterface *) vself;

  NaClRefCountUnref((struct NaClRefCount *) self->server);

  NACL_VTBL(NaClRefCount, self) = &kNaClRefCountVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
Ejemplo n.º 7
0
static void NaClManifestProxyDtor(struct NaClRefCount *vself) {
  struct NaClManifestProxy *self =
      (struct NaClManifestProxy *) vself;

  NaClRefCountUnref((struct NaClRefCount *) self->server);

  NACL_VTBL(NaClRefCount, self) =
      (struct NaClRefCountVtbl *) &kNaClSimpleServiceVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
Ejemplo n.º 8
0
void NaClDescQuotaDtor(struct NaClRefCount *vself) {
  struct NaClDescQuota *self = (struct NaClDescQuota *) vself;

  NaClRefCountSafeUnref((struct NaClRefCount *) self->quota_interface);
  NaClRefCountUnref((struct NaClRefCount *) self->desc);
  self->desc = NULL;
  NaClMutexDtor(&self->mu);

  NACL_VTBL(NaClDesc, self) = &kNaClDescVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself);
}
static void NaClDescPostMessageDtor(struct NaClRefCount *vself) {
  struct NaClDescPostMessage  *self = (struct NaClDescPostMessage *) vself;

  NaClLog(4, "Entered NaClDescPostMessageDtor\n");

  NaClRefCountUnref((struct NaClRefCount *) self->runtime_host);

  NACL_VTBL(NaClRefCount, vself) =
      (struct NaClRefCountVtbl const *) &kNaClDescVtbl;
  (*NACL_VTBL(NaClRefCount, vself)->Dtor)(vself);
  NaClLog(4, "Leaving NaClDescPostMessageDtor\n");
}
static void *AcceptThread(struct NaClThreadInterface *tif) {
  struct NaClSimpleService *server =
      (struct NaClSimpleService *) tif->thread_data;

  NaClLog(4, "Entered AcceptThread\n");
  while (0 == (*NACL_VTBL(NaClSimpleService, server)->
               AcceptAndSpawnHandler)(server)) {
    NaClLog(4, "AcceptThread: accepted, looping to next thread\n");
    continue;
  }
  NaClRefCountUnref(&server->base);
  return (void *) NULL;
}
Ejemplo n.º 11
0
void NaClReverseThreadIfExit(struct NaClThreadInterface   *vself,
                             void                         *exit_code) {
  struct NaClReverseCountingThreadInterface *self =
      (struct NaClReverseCountingThreadInterface *) vself;
  NaClLog(4,
          ("NaClReverseThreadIfExit: thread 0x%"NACL_PRIxPTR
           " is exiting\n"),
          (uintptr_t) vself);

  (*NACL_VTBL(NaClReverseService, self->reverse_service)->ThreadCountDecr)(
      self->reverse_service);

  NaClRefCountUnref((struct NaClRefCount *) self);
  NaClThreadExit((int)(uintptr_t) exit_code);
}
Ejemplo n.º 12
0
void NaClReverseServiceDtor(struct NaClRefCount *vself) {
  struct NaClReverseService *self = (struct NaClReverseService *) vself;

  if (0 != self->thread_count) {
    NaClLog(LOG_FATAL,
            "ReverseService dtor when thread count is nonzero\n");
  }
  self->thread_count = 0;
  NaClRefCountUnref((struct NaClRefCount *) self->iface);
  NaClCondVarDtor(&self->cv);
  NaClMutexDtor(&self->mu);

  NACL_VTBL(NaClRefCount, self) = (struct NaClRefCountVtbl *)
      &kNaClSimpleRevServiceVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)((struct NaClRefCount *) self);
}
int NaClSimpleServiceAcceptAndSpawnHandler(
    struct NaClSimpleService *self) {
  struct NaClSimpleServiceConnection  *conn = NULL;
  int                                 status;

  NaClLog(4, "Entered NaClSimpleServiceAcceptAndSpawnHandler\n");
  NaClLog(4,
          ("NaClSimpleServiceAcceptAndSpawnHandler:"
           " &conn is 0x%"NACL_PRIxPTR"\n"),
          (uintptr_t) &conn);
  status = (*NACL_VTBL(NaClSimpleService, self)->AcceptConnection)(
      self,
      &conn);
  NaClLog(4, "AcceptConnection vfn returned %d\n", status);
  if (0 != status) {
    goto abort;
  }
  NaClLog(4,
          "NaClSimpleServiceAcceptAndSpawnHandler: conn is 0x%"NACL_PRIxPTR"\n",
          (uintptr_t) conn);
  NaClLog(4, "NaClSimpleServiceAcceptAndSpawnHandler: spawning thread\n");

  CHECK(NULL == conn->thread);

  /* ownership of |conn| reference is passed to the thread */
  if (!NaClThreadInterfaceConstructAndStartThread(
          self->thread_factory_fn,
          self->thread_factory_data,
          RpcHandlerBase,
          conn,
          NACL_KERN_STACK_SIZE,
          &conn->thread)) {
    NaClLog(4, "NaClSimpleServiceAcceptAndSpawnHandler: no thread\n");
    NaClRefCountUnref((struct NaClRefCount *) conn);
    conn = NULL;
    conn->thread = NULL;
    status = -NACL_ABI_EAGAIN;
    goto abort;
  }
  status = 0;
abort:
  NaClLog(4,
          "Leaving NaClSimpleServiceAcceptAndSpawnHandler, status %d\n",
          status);
  return status;
}
int NaClSimpleServiceStartServiceThread(struct NaClSimpleService *server) {
  NaClLog(4, "NaClSimpleServiceStartServiceThread: spawning thread\n");
  CHECK(server->acceptor == NULL);

  if (!NaClThreadInterfaceConstructAndStartThread(
          server->thread_factory_fn,
          server->thread_factory_data,
          AcceptThread,
          NaClRefCountRef(&server->base),
          NACL_KERN_STACK_SIZE,
          &server->acceptor)) {
    NaClLog(4, "NaClSimpleServiceStartServiceThread: no thread\n");
    NaClRefCountUnref(&server->base);  /* undo ref in Ctor call arglist */
    return 0;
  }
  NaClLog(4, "NaClSimpleServiceStartServiceThread: success\n");
  return 1;
}
static void *RpcHandlerBase(struct NaClThreadInterface *tif) {
  struct NaClSimpleServiceConnection  *conn =
      (struct NaClSimpleServiceConnection *) tif->thread_data;

  NaClLog(4, "Entered RpcHandlerBase, invoking RpcHandler virtual fn\n");
  (*NACL_VTBL(NaClSimpleService, conn->server)->RpcHandler)(conn->server,
                                                            conn);
  NaClLog(4, "Leaving RpcHandlerBase\n");
  /*
   * The unref of conn may Dtor the currently running thread.  This is
   * okay, since this only removes the ability to use the thread
   * handle (in Windows) but does not otherwise affect the thread.  We
   * don't log afterwards, just in case the logging code (is later
   * modified to) use thread info.
   */
  NaClRefCountUnref((struct NaClRefCount *) conn);
  return (void *) NULL;
}
Ejemplo n.º 16
0
void NaClNameServiceDtor(struct NaClRefCount *vself) {
  struct NaClNameService      *self = (struct NaClNameService *) vself;

  struct NaClNameServiceEntry *p;
  struct NaClNameServiceEntry *next;

  for (p = self->head; NULL != p; p = next) {
    next = p->next;
    if (NULL != p->entry) {
      NaClRefCountUnref((struct NaClRefCount *) p->entry);
    } else {
      /*
       * Tell the factory fn that this particular use can be GC'd.
       */
      (void) (*p->factory)(p->state, p->name, 0, (struct NaClDesc **) NULL);
    }
    free(p);
  }
  NaClMutexDtor(&self->mu);
  NACL_VTBL(NaClRefCount, self) = (struct NaClRefCountVtbl *)
      &kNaClSimpleLtdServiceVtbl;
  (*NACL_VTBL(NaClRefCount, self)->Dtor)((struct NaClRefCount *) self);
}
Ejemplo n.º 17
0
void NaClDescSafeUnref(struct NaClDesc *ndp) {
  if (NULL != ndp) {
    NaClRefCountUnref(&ndp->base);
  }
}
Ejemplo n.º 18
0
void NaClDescUnref(struct NaClDesc *ndp) {
  NaClRefCountUnref(&ndp->base);
}