#include "native_client/src/include/portability_string.h"
#include "native_client/src/include/nacl_macros.h"
+#include "native_client/src/public/desc_metadata_types.h"
+#include "native_client/src/public/nacl_app.h"
+#include "native_client/src/public/secure_service.h"
+
#include "native_client/src/shared/gio/gio.h"
#include "native_client/src/shared/platform/nacl_check.h"
#include "native_client/src/shared/platform/nacl_exit.h"
#include "native_client/src/trusted/desc/nacl_desc_imc.h"
#include "native_client/src/trusted/desc/nacl_desc_io.h"
#include "native_client/src/trusted/desc/nrd_xfer.h"
+#include "native_client/src/trusted/desc_cacheability/desc_cacheability.h"
#include "native_client/src/trusted/fault_injection/fault_injection.h"
#include "native_client/src/trusted/fault_injection/test_injection.h"
#include "native_client/src/trusted/gio/gio_nacl_desc.h"
#include "native_client/src/trusted/simple_service/nacl_simple_rservice.h"
#include "native_client/src/trusted/simple_service/nacl_simple_service.h"
#include "native_client/src/trusted/threading/nacl_thread_interface.h"
+#include "native_client/src/trusted/validator/validation_cache.h"
static int IsEnvironmentVariableSet(char const *env_name) {
return NULL != getenv(env_name);
struct NaClSyscallTableEntry *table) {
struct NaClDescEffectorLdr *effp;
+ /* Zero-initialize in case we miss any fields below. */
+ memset(nap, 0, sizeof(*nap));
+
/* The validation cache will be injected later, if it exists. */
nap->validation_cache = NULL;
return NaClAppWithSyscallTableCtor(nap, nacl_syscall);
}
+struct NaClApp *NaClAppCreate(void) {
+ struct NaClApp *nap = malloc(sizeof(struct NaClApp));
+ if (nap == NULL)
+ NaClLog(LOG_FATAL, "Failed to allocate NaClApp\n");
+ if (!NaClAppCtor(nap))
+ NaClLog(LOG_FATAL, "NaClAppCtor() failed\n");
+ return nap;
+}
+
/*
* unaligned little-endian load. precondition: nbytes should never be
* more than 8.
NaClLog(2, "num_syscalls = %d (0x%x)\n", num_syscalls, num_syscalls);
-#if defined(NACL_TARGET_ARM_THUMB2_MODE)
- CHECK(0 != ((nap->user_entry_pt | nap->initial_entry_pt) & 0x1));
- /*
- * Thumb trampolines start 2 bytes before the aligned syscall address used
- * by ordinary ARM. We initialize this by adding 0xe to the start address
- * of each trampoline. Because the last start address would actually start
- * into user code above, this allows one fewer trampolines than in ARM.
- */
- for (i = 0, addr = nap->mem_start + NACL_SYSCALL_START_ADDR + 0xe;
- i < num_syscalls - 1;
- ++i, addr += NACL_SYSCALL_BLOCK_SIZE) {
- NaClPatchOneTrampoline(nap, addr);
- }
-#else
for (i = 0, addr = nap->mem_start + NACL_SYSCALL_START_ADDR;
i < num_syscalls;
++i, addr += NACL_SYSCALL_BLOCK_SIZE) {
NaClPatchOneTrampoline(nap, addr);
}
-#endif
#if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64
NaClPatchOneTrampolineCall(nap->get_tls_fast_path1_addr,
nap->mem_start + NACL_SYSCALL_START_ADDR
NaClXMutexUnlock(&nap->mu);
}
-struct NaClDesc *NaClGetDescMu(struct NaClApp *nap,
- int d) {
+struct NaClDesc *NaClAppGetDescMu(struct NaClApp *nap,
+ int d) {
struct NaClDesc *result;
result = (struct NaClDesc *) DynArrayGet(&nap->desc_tbl, d);
return result;
}
-void NaClSetDescMu(struct NaClApp *nap,
- int d,
- struct NaClDesc *ndp) {
+void NaClAppSetDescMu(struct NaClApp *nap,
+ int d,
+ struct NaClDesc *ndp) {
struct NaClDesc *result;
result = (struct NaClDesc *) DynArrayGet(&nap->desc_tbl, d);
if (!DynArraySet(&nap->desc_tbl, d, ndp)) {
NaClLog(LOG_FATAL,
- "NaClSetDesc: could not set descriptor %d to 0x%08"
+ "NaClAppSetDesc: could not set descriptor %d to 0x%08"
NACL_PRIxPTR"\n",
d,
(uintptr_t) ndp);
}
}
-int32_t NaClSetAvailMu(struct NaClApp *nap,
- struct NaClDesc *ndp) {
+int32_t NaClAppSetDescAvailMu(struct NaClApp *nap,
+ struct NaClDesc *ndp) {
size_t pos;
pos = DynArrayFirstAvail(&nap->desc_tbl);
if (pos > INT32_MAX) {
NaClLog(LOG_FATAL,
- ("NaClSetAvailMu: DynArrayFirstAvail returned a value"
+ ("NaClAppSetDescAvailMu: DynArrayFirstAvail returned a value"
" that is greather than 2**31-1.\n"));
}
- NaClSetDescMu(nap, (int) pos, ndp);
+ NaClAppSetDescMu(nap, (int) pos, ndp);
return (int32_t) pos;
}
-struct NaClDesc *NaClGetDesc(struct NaClApp *nap,
- int d) {
+struct NaClDesc *NaClAppGetDesc(struct NaClApp *nap,
+ int d) {
struct NaClDesc *res;
NaClFastMutexLock(&nap->desc_mu);
- res = NaClGetDescMu(nap, d);
+ res = NaClAppGetDescMu(nap, d);
NaClFastMutexUnlock(&nap->desc_mu);
return res;
}
-void NaClSetDesc(struct NaClApp *nap,
- int d,
- struct NaClDesc *ndp) {
+void NaClAppSetDesc(struct NaClApp *nap,
+ int d,
+ struct NaClDesc *ndp) {
NaClFastMutexLock(&nap->desc_mu);
- NaClSetDescMu(nap, d, ndp);
+ NaClAppSetDescMu(nap, d, ndp);
NaClFastMutexUnlock(&nap->desc_mu);
}
-int32_t NaClSetAvail(struct NaClApp *nap,
- struct NaClDesc *ndp) {
+int32_t NaClAppSetDescAvail(struct NaClApp *nap,
+ struct NaClDesc *ndp) {
int32_t pos;
NaClFastMutexLock(&nap->desc_mu);
- pos = NaClSetAvailMu(nap, ndp);
+ pos = NaClAppSetDescAvailMu(nap, ndp);
NaClFastMutexUnlock(&nap->desc_mu);
return pos;
if (NULL == dp) {
NaClLog(LOG_FATAL, "NaClAddHostDescriptor: NaClDescIoDescMake failed\n");
}
- NaClSetDesc(nap, nacl_desc, (struct NaClDesc *) dp);
+ NaClAppSetDesc(nap, nacl_desc, (struct NaClDesc *) dp);
}
void NaClAddImcHandle(struct NaClApp *nap,
NaClLog(LOG_FATAL, ("NaClAddImcHandle: cannot construct"
" IMC descriptor object\n"));
}
- NaClSetDesc(nap, nacl_desc, (struct NaClDesc *) dp);
+ NaClAppSetDesc(nap, nacl_desc, (struct NaClDesc *) dp);
}
if (NULL != ndp) {
NaClLog(4, "Setting descriptor %d\n", (int) ix);
- NaClSetDesc(nap, (int) ix, ndp);
+ NaClAppSetDesc(nap, (int) ix, ndp);
} else if (NACL_RESOURCE_PHASE_START == nap->resource_phase) {
/*
* Environment not set or redirect failed -- handle default inheritance.
"addr at 0x%08"NACL_PRIxPTR"\n",
(uintptr_t) pair[0],
(uintptr_t) pair[1]);
- NaClSetDesc(nap, NACL_SERVICE_PORT_DESCRIPTOR, pair[0]);
- NaClSetDesc(nap, NACL_SERVICE_ADDRESS_DESCRIPTOR, pair[1]);
+ NaClAppSetDesc(nap, NACL_SERVICE_PORT_DESCRIPTOR, pair[0]);
+ NaClAppSetDesc(nap, NACL_SERVICE_ADDRESS_DESCRIPTOR, pair[1]);
NaClDescSafeUnref(nap->service_port);
NaClLog(4, "Leaving NaClSecureCommandChannel\n");
}
+
void NaClAppLoadModule(struct NaClApp *nap,
struct NaClDesc *nexe,
void (*load_cb)(void *instance_data,
NaClXMutexLock(&nap->mu);
/*
- * Check / Mark the nexe binary as OK to attempt memory mapping.
- *
- * TODO(bsy): change needed to get NaClFileToken and resolve to file
- * path information, set NaClRichFileInfo, and stash via
- * NaClSetFileOriginInfo, then set NACL_DESC_FLAGS_MMAP_EXEC_OK.
+ * Check and possibly mark the nexe binary as OK to attempt memory
+ * mapping. We first clear the safe-for-mmap flag -- if we do not
+ * trust the renderer to really send us a safe-to-mmap descriptor
+ * and have to query the validation cache, then we also do not want
+ * to trust the metadata flag value that originated from the
+ * renderer.
*/
+ NaClDescMarkUnsafeForMmap(nexe);
+ NaClReplaceDescIfValidationCacheAssertsMappable(&nexe,
+ nap->validation_cache);
status = NACL_FI_VAL("load_module", NaClErrorCode,
NaClAppLoadFile(nexe, nap));