mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
make the mmapped buffer configurable
This commit is contained in:
parent
64c2d8d87e
commit
40d7e94a17
5 changed files with 37 additions and 30 deletions
|
@ -8,6 +8,8 @@ use roc_build::link::{LinkType, LinkingStrategy};
|
|||
use roc_collections::VecMap;
|
||||
use roc_error_macros::{internal_error, user_error};
|
||||
use roc_gen_llvm::llvm::build::LlvmBackendMode;
|
||||
use roc_gen_llvm::run_roc::RocCallResult;
|
||||
use roc_gen_llvm::run_roc_dylib;
|
||||
use roc_load::{Expectations, LoadingProblem, Threading};
|
||||
use roc_module::symbol::{Interns, ModuleId};
|
||||
use roc_mono::ir::OptLevel;
|
||||
|
@ -360,26 +362,6 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
|||
}
|
||||
});
|
||||
|
||||
unsafe {
|
||||
let name = "/roc_expect_buffer"; // IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
let cstring = CString::new(name).unwrap();
|
||||
let shared_fd =
|
||||
libc::shm_open(cstring.as_ptr().cast(), libc::O_RDWR | libc::O_CREAT, 0o666);
|
||||
|
||||
libc::ftruncate(shared_fd, SHM_SIZE);
|
||||
|
||||
let _shared_ptr = libc::mmap(
|
||||
std::ptr::null_mut(),
|
||||
4096,
|
||||
libc::PROT_WRITE,
|
||||
libc::MAP_SHARED,
|
||||
shared_fd,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
// let target_valgrind = matches.is_present(FLAG_VALGRIND);
|
||||
|
||||
let arena = &arena;
|
||||
let target = &triple;
|
||||
let opt_level = opt_level;
|
||||
|
@ -414,30 +396,42 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let name = "/roc_expect_buffer"; // IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
let cstring = CString::new(name).unwrap();
|
||||
|
||||
let arena = &bumpalo::Bump::new();
|
||||
let interns = arena.alloc(interns);
|
||||
|
||||
let mut writer = std::io::stdout();
|
||||
|
||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
let name = "/roc_expect_buffex";
|
||||
let cstring = CString::new(name).unwrap();
|
||||
|
||||
let shared_ptr = unsafe {
|
||||
let shared_fd = libc::shm_open(cstring.as_ptr().cast(), libc::O_RDWR, 0o666);
|
||||
|
||||
libc::ftruncate(shared_fd, SHM_SIZE);
|
||||
|
||||
libc::mmap(
|
||||
let ptr = libc::mmap(
|
||||
std::ptr::null_mut(),
|
||||
SHM_SIZE as usize,
|
||||
libc::PROT_READ | libc::PROT_WRITE,
|
||||
libc::MAP_SHARED,
|
||||
shared_fd,
|
||||
0,
|
||||
)
|
||||
.cast()
|
||||
);
|
||||
|
||||
if ptr as isize == -1 {
|
||||
internal_error!("could not set up the expect shared memory region")
|
||||
}
|
||||
|
||||
ptr.cast()
|
||||
};
|
||||
|
||||
// communicate the mmapped name to zig/roc
|
||||
let set_mmapped_file = run_roc_dylib!(lib, "set_mmapped_file", (*const i8, usize), ());
|
||||
let mut result = RocCallResult::default();
|
||||
unsafe { set_mmapped_file((cstring.as_ptr(), name.len() + 1), &mut result) };
|
||||
std::mem::forget(cstring);
|
||||
|
||||
let (failed, passed) = roc_repl_expect::run::run_expects(
|
||||
&mut writer,
|
||||
arena,
|
||||
|
@ -1019,7 +1013,7 @@ unsafe fn roc_run_native_debug(
|
|||
|
||||
roc_dev_expect(
|
||||
&mut std::io::stdout(),
|
||||
&arena,
|
||||
arena,
|
||||
&mut expectations,
|
||||
interns,
|
||||
shared_memory_ptr,
|
||||
|
|
|
@ -13,8 +13,18 @@ const O_CREAT: c_int = 64;
|
|||
pub const PROT_WRITE: c_int = 2;
|
||||
pub const MAP_SHARED: c_int = 0x0001;
|
||||
|
||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
var MMAPPED_FILE: []const u8 = "/roc_expect_buffer";
|
||||
|
||||
pub fn setMmappedFile(ptr: [*]u8, length: usize) callconv(.C) usize {
|
||||
MMAPPED_FILE = ptr[0..length];
|
||||
|
||||
// the rust side expects that a pointer is returned
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn expectFailedStart() callconv(.C) [*]u8 {
|
||||
const name = "/roc_expect_buffer"; // IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
const name = MMAPPED_FILE;
|
||||
|
||||
const shared_fd = shm_open(@ptrCast(*const i8, name), O_RDWR | O_CREAT, 0o666);
|
||||
|
||||
|
|
|
@ -169,6 +169,9 @@ comptime {
|
|||
if (builtin.target.cpu.arch != .wasm32) {
|
||||
exportUtilsFn(expect.expectFailedStart, "expect_failed_start");
|
||||
exportUtilsFn(expect.expectFailedFinalize, "expect_failed_finalize");
|
||||
|
||||
// sets the buffer used for expect failures
|
||||
@export(expect.setMmappedFile, .{ .name = "set_mmapped_file", .linkage = .Strong });
|
||||
}
|
||||
|
||||
if (builtin.target.cpu.arch == .aarch64) {
|
||||
|
|
|
@ -47,7 +47,7 @@ impl<T: Sized> From<RocCallResult<T>> for Result<T, String> {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! run_roc_dylib {
|
||||
($lib:expr, $main_fn_name:expr, $argument_type:ty, $return_type:ty, $errors:expr) => {{
|
||||
($lib:expr, $main_fn_name:expr, $argument_type:ty, $return_type:ty) => {{
|
||||
use inkwell::context::Context;
|
||||
use roc_builtins::bitcode;
|
||||
use roc_gen_llvm::run_roc::RocCallResult;
|
||||
|
|
|
@ -62,7 +62,7 @@ fn roc_function<'a, 'b>(
|
|||
|
||||
assert!(errors.is_empty(), "Encountered errors:\n{}", errors);
|
||||
|
||||
run_roc_dylib!(arena.alloc(lib), main_fn_name, &Input, Output, errors)
|
||||
run_roc_dylib!(arena.alloc(lib), main_fn_name, &Input, Output)
|
||||
}
|
||||
|
||||
fn create_input_list() -> RocList<i64> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue