mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
Only ftruncate shm_open'd file once, and add some error messages
This commit is contained in:
parent
e6fd0c62fd
commit
c5cdab1ff9
3 changed files with 22 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3961,6 +3961,7 @@ dependencies = [
|
||||||
"roc_build",
|
"roc_build",
|
||||||
"roc_builtins",
|
"roc_builtins",
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
|
"roc_error_macros",
|
||||||
"roc_gen_llvm",
|
"roc_gen_llvm",
|
||||||
"roc_intern",
|
"roc_intern",
|
||||||
"roc_load",
|
"roc_load",
|
||||||
|
|
|
@ -24,6 +24,7 @@ roc_types = {path = "../compiler/types"}
|
||||||
roc_gen_llvm = {path = "../compiler/gen_llvm"}
|
roc_gen_llvm = {path = "../compiler/gen_llvm"}
|
||||||
roc_region = { path = "../compiler/region" }
|
roc_region = { path = "../compiler/region" }
|
||||||
roc_build = { path = "../compiler/build" }
|
roc_build = { path = "../compiler/build" }
|
||||||
|
roc_error_macros = { path = "../error_macros" }
|
||||||
|
|
||||||
libloading = "0.7.1"
|
libloading = "0.7.1"
|
||||||
inkwell = { path = "../vendor/inkwell" }
|
inkwell = { path = "../vendor/inkwell" }
|
||||||
|
|
|
@ -5,6 +5,7 @@ use bumpalo::Bump;
|
||||||
use inkwell::context::Context;
|
use inkwell::context::Context;
|
||||||
use roc_build::link::llvm_module_to_dylib;
|
use roc_build::link::llvm_module_to_dylib;
|
||||||
use roc_collections::{MutSet, VecMap};
|
use roc_collections::{MutSet, VecMap};
|
||||||
|
use roc_error_macros::internal_error;
|
||||||
use roc_gen_llvm::{
|
use roc_gen_llvm::{
|
||||||
llvm::{build::LlvmBackendMode, externs::add_default_roc_externs},
|
llvm::{build::LlvmBackendMode, externs::add_default_roc_externs},
|
||||||
run_roc::RocCallResult,
|
run_roc::RocCallResult,
|
||||||
|
@ -52,18 +53,33 @@ impl<'a> ExpectMemory<'a> {
|
||||||
fn mmap_help(cstring: std::ffi::CString, shm_flags: i32) -> Self {
|
fn mmap_help(cstring: std::ffi::CString, shm_flags: i32) -> Self {
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
let shared_fd = libc::shm_open(cstring.as_ptr().cast(), shm_flags, 0o666);
|
let shared_fd = libc::shm_open(cstring.as_ptr().cast(), shm_flags, 0o666);
|
||||||
|
if shared_fd == -1 {
|
||||||
|
internal_error!("failed to shm_open fd");
|
||||||
|
}
|
||||||
|
|
||||||
libc::ftruncate(shared_fd, 0);
|
let mut stat: libc::stat = std::mem::zeroed();
|
||||||
libc::ftruncate(shared_fd, Self::SHM_SIZE as _);
|
if libc::fstat(shared_fd, &mut stat) == -1 {
|
||||||
|
internal_error!("failed to stat shared file, does it exist?");
|
||||||
|
}
|
||||||
|
if stat.st_size < Self::SHM_SIZE as _ {
|
||||||
|
if libc::ftruncate(shared_fd, Self::SHM_SIZE as _) == -1 {
|
||||||
|
internal_error!("failed to truncate shared file, are the permissions wrong?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
libc::mmap(
|
let ptr = libc::mmap(
|
||||||
std::ptr::null_mut(),
|
std::ptr::null_mut(),
|
||||||
Self::SHM_SIZE,
|
Self::SHM_SIZE,
|
||||||
libc::PROT_WRITE | libc::PROT_READ,
|
libc::PROT_WRITE | libc::PROT_READ,
|
||||||
libc::MAP_SHARED,
|
libc::MAP_SHARED,
|
||||||
shared_fd,
|
shared_fd,
|
||||||
0,
|
0,
|
||||||
)
|
);
|
||||||
|
if ptr as usize == usize::MAX {
|
||||||
|
// ptr = -1
|
||||||
|
roc_error_macros::internal_error!("failed to mmap shared pointer")
|
||||||
|
}
|
||||||
|
ptr
|
||||||
};
|
};
|
||||||
|
|
||||||
// puts in the initial header
|
// puts in the initial header
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue