mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
expose mmap size and offset option (#141)
* expose mmap size and offset option * fix panics
This commit is contained in:
@@ -1619,18 +1619,29 @@ pub fn mmapFile(
|
||||
const file_flags: u32 = if (@hasDecl(std.os.MAP, "FILE")) std.os.MAP.FILE else 0;
|
||||
|
||||
// Conforming applications must specify either MAP_PRIVATE or MAP_SHARED.
|
||||
var offset: usize = 0;
|
||||
var flags = file_flags;
|
||||
var map_size: ?usize = null;
|
||||
|
||||
if (args.nextEat()) |opts| {
|
||||
const sync = opts.get(ctx.ptr(), "sync") orelse JSC.JSValue.jsBoolean(false);
|
||||
const shared = opts.get(ctx.ptr(), "shared") orelse JSC.JSValue.jsBoolean(true);
|
||||
flags |= @as(u32, if (sync.toBoolean()) sync_flags else 0);
|
||||
flags |= @as(u32, if (shared.toBoolean()) std.os.MAP.SHARED else std.os.MAP.PRIVATE);
|
||||
|
||||
if (opts.get(ctx.ptr(), "size")) |value| {
|
||||
map_size = @intCast(usize, value.toInt64());
|
||||
}
|
||||
|
||||
if (opts.get(ctx.ptr(), "offset")) |value| {
|
||||
offset = @intCast(usize, value.toInt64());
|
||||
offset = std.mem.alignBackwardAnyAlign(offset, std.mem.page_size);
|
||||
}
|
||||
} else {
|
||||
flags |= std.os.MAP.SHARED;
|
||||
}
|
||||
|
||||
const map = switch (JSC.Node.Syscall.mmapFile(buf_z, flags)) {
|
||||
const map = switch (JSC.Node.Syscall.mmapFile(buf_z, flags, map_size, offset)) {
|
||||
.result => |map| map,
|
||||
|
||||
.err => |err| {
|
||||
|
||||
Reference in New Issue
Block a user