Mmap v 0.12 dev MAP..SHARED?

hello.

this v 0.11

const ptr = try std.os.mmap(
        null,
        20,
        std.os.PROT.READ | std.os.PROT.WRITE,
        std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE,
        file.handle,
        0,
    );
    de

v 0.12 .2755
std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE,

error : struct ‘os.linux.MAP__struct_3375’ has no member named ‘PRIVATE’

I tried with “MAP_TYPE” but I got the same error. I also tried std.posix.linux.MAP_TYPE and got the same result. Can you please help me?

std.os.linux.MAP changed from 0.11.0 to 0.12.0-dev, from u32 flags to struct MAP.
See mmap and MAP documentation.

version 0.12.0-dev.2063

std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE,

ok

v 0.12 .2755 not ok ???

Using 1 or 2 isn’t very readable. Which one corresponds to SHARED and PRIVATE?

These flags are in the first field of struct MAP, TYPE: MAP_TYPE

MAP{
    .TYPE = .SHARED_VALIDATE,
}

hello ;

not ok

These are enum fields, only one value is allowed.
Notice that Shared=1, Private=2 and Shared_Validate=3=1|2
You must replace:

std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE

with

.{ .TYPE = .SHARED_VALIDATE }
2 Likes

yes

oh thank you.

	const  ptr = std.os.mmap(
		null,
		file_size,
		std.os.PROT.READ | std.os.PROT.WRITE,
		// std.os.linux.MAP_TYPE.SHARED | std.os.linux.MAP_TYPE.PRIVATE,
		.{.TYPE =.SHARED_VALIDATE},
		ZCOM.handle,
		0
	) catch unreachable;
	defer std.os.munmap(ptr);

works, but only emulates SHARED it’s identical .{.TYPE =.SHARED}, not PRIVATE

before I could do SHARED | PRIVATE

You are mistaken. You were not getting both shared and private. From the man page:

This behavior is determined by including exactly one of the following values in flags:

Before, your code has undefined behavior. Now, it is a compile error. You are welcome :laughing:

3 Likes

en v 0.11 et v0.12 2063
I assure you that both worked. I could share with another job, and the file was unreadable.

std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE,


V 0.11
v0.12 .2063

std.os.linux.MAP.SHARED | std.os.linux.MAP.PRIVATE,

.{.TYPE =.SHARED_VALIDATE},

v0.12 2755

this IBM DOCS .

MAP_SHARED
When the MAP_SHARED flag is set, modifications to the mapped memory region will be visible to other processes that have mapped the same region using this flag. If the region is a mapped file region, modifications to the region will be written to the file.

You can specify only one of the MAP_SHARED or MAP_PRIVATE flags with the mmap subroutine. MAP_PRIVATE is the default setting when neither flag is specified unless you request SPEC1170 compliant behavior. In this case, you must choose either MAP_SHARED or MAP_PRIVATE.

MAP_PRIVATE
When the MAP_PRIVATE flag is specified, modifications to the mapped region by the calling process are not visible to other processes that have mapped the same region. If the region is a mapped file region, modifications to the region are not written to the file.

If this flag is specified, the initial write reference to an object page creates a private copy of that page and redirects the mapping to the copy. Until then, modifications to the page by processes that have mapped the same region with the MAP_SHARED flag are visible.

You can specify only one of the MAP_SHARED or MAP_PRIVATE flags with the mmap subroutine. MAP_PRIVATE is the default setting when neither flag is specified unless you request SPEC1170 compliant behavior. In this case, you must choose either MAP_SHARED or MAP_PRIVATE.

"To have merged the two was for the ideal I shared, and the file remained unreadable.

But IBM says it has to be one or the other… ."