Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: src/native_client/src/trusted/service_runtime/sel_ldr.c

Issue 2659002: Remove thread refcount and remove NaClAppDtor() (Closed)
Patch Set: Fix Gyp build Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/native_client/src/trusted/service_runtime/sel_ldr.c
diff --git a/src/native_client/src/trusted/service_runtime/sel_ldr.c b/src/native_client/src/trusted/service_runtime/sel_ldr.c
index 1bc46bbc0707a5997ac0cfc182fe95b8b5f6c672..bbb0a2d03a3ab11eb7c40e339ba77a8562a549aa 100644
--- a/src/native_client/src/trusted/service_runtime/sel_ldr.c
+++ b/src/native_client/src/trusted/service_runtime/sel_ldr.c
@@ -45,7 +45,6 @@ int NaClAppCtor(struct NaClApp *nap) {
nap->stack_size = NACL_DEFAULT_STACK_MAX;
nap->mem_start = 0;
- nap->guard_pages_initialized = 0;
nap->static_text_end = 0;
nap->dynamic_text_start = 0;
nap->dynamic_text_end = 0;
@@ -142,117 +141,6 @@ cleanup_none:
return 0;
}
-void NaClAppDtor(struct NaClApp *nap) {
- size_t i;
- struct NaClDesc *ndp;
- struct NaClAppThread *natp;
-
-#if NACL_WINDOWS && !defined(NACL_STANDALONE)
- NaClHandlePassLdrDtor();
-#endif
-
- NaClLog(2,
- ("NaClAppDtor: there are %d threads alive;"
- " thread table size %"NACL_PRIuS"\n"),
- nap->num_threads,
- nap->threads.num_entries);
- for (i = 0; i < nap->threads.num_entries; ++i) {
- int refcount;
- enum NaClThreadState state;
-
- NaClLog(2, "Checking thread %"NACL_PRIuS"\n", i);
- if (NULL == (natp = NaClGetThreadMu(nap, (int) i))) {
- continue;
- }
- NaClLog(2, "Extracting state for thread %"NACL_PRIuS"\n", i);
- NaClXMutexLock(&natp->mu);
- state = natp->state;
- NaClLog(2, "state %d\n", state);
- NaClXMutexUnlock(&natp->mu);
-
- NaClRemoveThreadMu(nap, (int) i);
- refcount = NaClAppThreadDecRef(natp);
-
- if (state != NACL_APP_THREAD_DEAD) {
- NaClLog(LOG_WARNING,
- ("NaClAppDtor: thread %"NACL_PRIuS" still running when NaCl app"
- " is being destroyed?!?\n"),
- i);
- }
- if (refcount != 0) {
- NaClLog(LOG_WARNING,
- ("NaClAppDtor: thread %"NACL_PRIuS" refcount not 0 when NaCl app"
- " is being destroyed?!?\n"),
- i);
- }
- }
-
- NaClLog(4, "There are %"NACL_PRIuS" descriptor entries\n",
- nap->desc_tbl.num_entries);
-
- for (i = 0; i < nap->desc_tbl.num_entries; ++i) {
- ndp = (struct NaClDesc *) DynArrayGet(&nap->desc_tbl, i);
- NaClDescSafeUnref(ndp);
- }
-
- NaClLog(4,
- "Deallocating synchronization variables for"
- " desc, thread, work_queue\n");
-
- NaClMutexDtor(&nap->desc_mu);
- NaClMutexDtor(&nap->threads_mu);
- NaClCondVarDtor(&nap->threads_cv);
- NaClSyncQueueDtor(&nap->work_queue);
-
- NaClLog(4, "Freeing NaCl module origin\n");
-
- free(nap->origin);
- nap->origin = (char *) NULL;
-
- NaClLog(4, "Freeing text_shm\n");
-
- NaClMutexDtor(&nap->dynamic_load_mutex);
- NaClDescSafeUnref(nap->text_shm);
- nap->text_shm = NULL;
-
- NaClLog(4, "Freeing service_port\n");
-
- NaClDescSafeUnref(nap->service_port);
- nap->service_port = NULL;
-
- NaClLog(4, "Freeing service_address\n");
-
- NaClDescSafeUnref(nap->service_address);
- nap->service_address = NULL;
-
- NaClLog(4, "Freeing secure channel\n");
-
- NaClDescSafeUnref(nap->secure_channel);
- nap->secure_channel = NULL;
-
- NaClLog(4, "Freeing synchronization variables for the NaClApp\n");
-
- NaClCondVarDtor(&nap->cv);
- NaClMutexDtor(&nap->mu);
-
- NaClLog(4, "Freeing memory\n");
-
- NaClAppFreeAllMemory(nap);
-
- NaClLog(4, "Freeing vmmap\n");
-
- NaClVmmapDtor(&nap->mem_map);
-
- NaClLog(4, "Freeing desc_tbl, threads\n");
-
- DynArrayDtor(&nap->desc_tbl);
- DynArrayDtor(&nap->threads);
-
- NaClLog(4, "NaClAppDtor: Done\n");
-
- return;
-}
-
size_t NaClAlignPad(size_t val, size_t align) {
/* align is always a power of 2, but we do not depend on it */
if (!align) {
@@ -1149,102 +1037,6 @@ void NaClDumpServiceAddressTo(struct NaClApp *nap,
}
}
-struct NaClFreeState {
- struct NaClApp *nap;
- struct NaClDescEffector *effp;
- uintptr_t partial;
- size_t pbytes;
-};
-
-static void NaClAppFreeWalker(void *state,
- struct NaClVmmapEntry *entry) {
- struct NaClFreeState *p = (struct NaClFreeState *) state;
- uintptr_t sysaddr;
- size_t nbytes;
-
- NaClLog(3,
- ("NaClAppFreeWalker: p->partial = 0x%08"NACL_PRIxPTR","
- " p->pbytes = 0x%08"NACL_PRIxS"\n"),
- p->partial, p->pbytes);
- NaClLog(3,
- (" entry->page_num = 0x%"NACL_PRIxPTR", entry->npages = 0x%"
- NACL_PRIxS","
- " entry->nmop = 0x%08"NACL_PRIxPTR"\n"),
- entry->page_num, entry->npages, (uintptr_t) entry->nmop);
- sysaddr = NaClUserToSysAddrNullOkay(p->nap,
- entry->page_num << NACL_PAGESHIFT);
- nbytes = entry->npages << NACL_PAGESHIFT;
- if (NULL == entry->nmop) {
- if (0 != p->pbytes) {
- /* partial exists, accumulate and try to free */
- if (p->partial + p->pbytes != sysaddr) {
- NaClLog(LOG_FATAL,
- ("Partial allocation pages not contiguous?!?"
- " Partial start 0x%08"NACL_PRIxPTR", length 0x%"NACL_PRIxS";"
- " next start 0x%08"NACL_PRIxPTR"\n"),
- p->partial, p->pbytes, sysaddr);
- }
- p->pbytes += nbytes;
- if (NaClRoundHostAllocPage(p->pbytes) == p->pbytes) {
- NaCl_page_free((void *) p->partial, p->pbytes);
- p->partial = 0;
- p->pbytes = 0;
- } else {
- NaClLog(3, "Partial accummulated 0x%08"NACL_PRIxPTR", 0x%"
- NACL_PRIxS"\n",
- p->partial, p->pbytes);
- }
- } else {
- /* free if we can; else accumulate */
- if (NaClRoundHostAllocPage(nbytes) == nbytes) {
- NaCl_page_free((void *) sysaddr, nbytes);
- } else {
- p->partial = sysaddr;
- p->pbytes = nbytes;
- }
- }
- } else {
- uintptr_t user_address = entry->page_num << NACL_PAGESHIFT;
- if (NaClRoundAllocPage(user_address) != user_address) {
- NaClLog(LOG_FATAL,
- ("descriptor backed memory does not start"
- " at allocation boundary, addr: 0x%08"NACL_PRIxPTR"\n"),
- user_address);
- }
- if (NaClRoundHostAllocPage(nbytes) != nbytes) {
- NaClLog(LOG_FATAL,
- ("descriptor backed memory size not allocation granularity:"
- " 0x%"NACL_PRIxS"\n"),
- nbytes);
- }
- if (0 != (*entry->nmop->ndp->vtbl->UnmapUnsafe)(entry->nmop->ndp,
- p->effp,
- (void *) sysaddr,
- nbytes)) {
- NaClLog(LOG_FATAL,
- "NaClAppFreeWalker could not unmap memory\n");
- }
- }
-}
-
-void NaClAppFreeAllMemory(struct NaClApp *nap) {
- struct NaClFreeState state;
- struct NaClDescEffectorCleanup eff;
-
- NaClLog(4, "NaClAppFreeAllMemory: invoking TeardownMprotectGuards\n");
- NaClTeardownMprotectGuards(nap);
- NaClLog(4, "NaClAppFreeAllMemory: TeardownMprotectGuards done\n");
-
- state.nap = nap;
- state.effp = (struct NaClDescEffector *) &eff;
- state.partial = 0;
- state.pbytes = 0;
-
- NaClDescEffectorCleanupCtor(&eff);
- NaClVmmapVisit(&nap->mem_map, NaClAppFreeWalker, &state);
- (*eff.base.vtbl->Dtor)(&eff.base);
-}
-
#ifdef __GNUC__

Powered by Google App Engine
This is Rietveld 408576698