summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/isolate.rs12
-rw-r--r--src/main.rs2
-rw-r--r--src/snapshot.cc18
-rw-r--r--src/snapshot.rs18
4 files changed, 29 insertions, 21 deletions
diff --git a/src/isolate.rs b/src/isolate.rs
index c02f4d6ce..abc5ded4d 100644
--- a/src/isolate.rs
+++ b/src/isolate.rs
@@ -400,8 +400,12 @@ mod tests {
let argv = vec![String::from("./deno"), String::from("hello.js")];
let (flags, rest_argv, _) = flags::set_flags(argv).unwrap();
// TODO Don't use deno_snapshot for these tests.
- let mut isolate =
- Isolate::new(snapshot::deno_snapshot(), flags, rest_argv, dispatch_sync);
+ let mut isolate = Isolate::new(
+ unsafe { snapshot::deno_snapshot.clone() },
+ flags,
+ rest_argv,
+ dispatch_sync,
+ );
tokio_util::init(|| {
isolate
.execute(
@@ -443,7 +447,7 @@ mod tests {
let (flags, rest_argv, _) = flags::set_flags(argv).unwrap();
// TODO Don't use deno_snapshot for these tests.
let mut isolate = Isolate::new(
- snapshot::deno_snapshot(),
+ unsafe { snapshot::deno_snapshot.clone() },
flags,
rest_argv,
metrics_dispatch_sync,
@@ -484,7 +488,7 @@ mod tests {
let (flags, rest_argv, _) = flags::set_flags(argv).unwrap();
// TODO Don't use deno_snapshot for these tests.
let mut isolate = Isolate::new(
- snapshot::deno_snapshot(),
+ unsafe { snapshot::deno_snapshot.clone() },
flags,
rest_argv,
metrics_dispatch_async,
diff --git a/src/main.rs b/src/main.rs
index b05a41642..4595f7160 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -96,7 +96,7 @@ fn main() {
});
let mut isolate = isolate::Isolate::new(
- snapshot::deno_snapshot(),
+ unsafe { snapshot::deno_snapshot.clone() },
flags,
rest_argv,
ops::dispatch,
diff --git a/src/snapshot.cc b/src/snapshot.cc
new file mode 100644
index 000000000..b0945d319
--- /dev/null
+++ b/src/snapshot.cc
@@ -0,0 +1,18 @@
+// Copyright 2018 the Deno authors. All rights reserved. MIT license.
+
+#include "deno.h"
+
+extern "C" {
+
+extern const char snapshot_start asm("snapshot_start");
+extern const char snapshot_end asm("snapshot_end");
+asm(".data\n"
+ "snapshot_start: .incbin \"gen/snapshot_deno.bin\"\n"
+ "snapshot_end:\n"
+ ".globl snapshot_start;\n"
+ ".globl snapshot_end;");
+extern const deno_buf deno_snapshot = {
+ nullptr, 0, reinterpret_cast<uint8_t*>(const_cast<char*>(&snapshot_start)),
+ static_cast<size_t>(&snapshot_end - &snapshot_start)};
+
+}
diff --git a/src/snapshot.rs b/src/snapshot.rs
index fcb41f6c8..52c8df47d 100644
--- a/src/snapshot.rs
+++ b/src/snapshot.rs
@@ -1,19 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
use libdeno::deno_buf;
-use std;
-
-pub fn deno_snapshot() -> deno_buf {
- let data =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin"));
- let ptr = data.as_ptr();
- // TODO The transmute is not necessary here. deno_buf specifies mutable
- // pointers when it doesn't necessarally need mutable. So maybe the deno_buf
- // type should be broken into a mutable and non-mutable version?
- let ptr_mut = unsafe { std::mem::transmute::<*const u8, *mut u8>(ptr) };
- deno_buf {
- alloc_ptr: std::ptr::null_mut(),
- alloc_len: 0,
- data_ptr: ptr_mut,
- data_len: data.len(),
- }
+extern "C" {
+ pub static deno_snapshot: deno_buf;
}