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

Unified Diff: src/minsfi/trusted/entry.c

Issue 539683002: MinSFI: Add loader (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Created 6 years, 3 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/minsfi/trusted/entry.c
diff --git a/src/minsfi/trusted/entry.c b/src/minsfi/trusted/entry.c
new file mode 100644
index 0000000000000000000000000000000000000000..d78b9bd2ffeccc3d38a8d01a5f08388dbdc31c51
--- /dev/null
+++ b/src/minsfi/trusted/entry.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2014 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "native_client/src/include/minsfi.h"
+#include "native_client/src/include/minsfi_priv.h"
+
+/*
+ * Fixed offset of the data segment. This must be kept in sync with the
+ * AllocateDataSegment compiler pass.
+ */
+#define DATASEG_OFFSET 0x10000
+
+/* Globals exported by the sandbox, aka the manifest. */
+extern uint32_t __sfi_pointer_size;
+extern const char __sfi_data_segment[];
+extern uint32_t __sfi_data_segment_size;
+
+/* Entry point of the sandbox */
+extern int _start_minsfi(void);
+
+/*
+ * This is the global memory base variable used by the SFI sandboxing. It is
+ * a 64-bit unsigned integer on both 32-bit and 64-bit platforms.
+ */
+uint64_t __sfi_memory_base = 0;
jvoung (off chromium) 2014/09/05 00:31:59 Could add some emphasis that this is exported, but
dbrazdil 2014/09/05 19:41:37 Done.
+
+static inline void get_manifest(manifest *sb) {
+ sb->ptr_size = __sfi_pointer_size;
+ sb->dataseg_offset = DATASEG_OFFSET;
+ sb->dataseg_size = __sfi_data_segment_size;
+ sb->dataseg_template = __sfi_data_segment;
+}
+
+int minsfi_exec(void) {
+ if (__sfi_memory_base == 0) {
+ char *base;
+ manifest sb;
+
+ get_manifest(&sb);
+ base = init_sandbox(&sb);
+ if (base == NULL)
+ return EXIT_FAILURE;
+
+ __sfi_memory_base = (uint64_t) ((uintptr_t) base);
+ }
+
+ return _start_minsfi();
+}
+
+bool minsfi_destroy(void) {
+ manifest sb;
+
+ if (__sfi_memory_base == 0)
+ return true;
+
+ get_manifest(&sb);
+ return destroy_sandbox((char*) ((uintptr_t) __sfi_memory_base), &sb);
jvoung (off chromium) 2014/09/05 00:31:59 Should this modify __sfi_memory_base back to 0 bef
dbrazdil 2014/09/05 19:41:37 Done. Added tests which check that the base has be
+}

Powered by Google App Engine
This is Rietveld 408576698