# Mmap v 0.12 dev MAP..SHARED?

**URL:** <https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269>\
**Category:** Help\
**Tags:** memory-management\
**Created:** [February 15, 2024, 10:32pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269 "2024-02-15T22:32:13Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 15, 2024, 10:32pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/1 "2024-02-15T22:32:14Z")

</div>

hello.

this v 0.11

```zig
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?

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [February 15, 2024, 10:42pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/2 "2024-02-15T22:42:40Z")

</div>

`std.os.linux.MAP` changed from 0.11.0 to 0.12.0-dev, from u32 flags to struct MAP.  
See [mmap](https://ziglang.org/documentation/master/std/#A;std:os.linux.mmap) and [MAP](https://ziglang.org/documentation/master/std/#A;std:posix.linux.MAP) documentation.

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 15, 2024, 10:48pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/3 "2024-02-15T22:48:59Z")

</div>

version 0.12.0-dev.2063

```zig
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?

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [February 15, 2024, 11:21pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/4 "2024-02-15T23:21:37Z")

</div>

These flags are in the first field of struct MAP, TYPE: [MAP\_TYPE](https://ziglang.org/documentation/master/std/#A;std:posix.linux.MAP_TYPE)

```zig
MAP{
    .TYPE = .SHARED_VALIDATE,
}

```

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 15, 2024, 11:38pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/5 "2024-02-15T23:38:47Z")

</div>

hello ;

> [@JPL](#):
>
> `std.os.linux.MAP_TYPE.SHARED | std.os.linux.MAP_TYPE.PRIVATE,`

not ok

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [February 15, 2024, 11:45pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/6 "2024-02-15T23:45:55Z")

</div>

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

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

```

with

```zig
.{ .TYPE = .SHARED_VALIDATE }

```

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 15, 2024, 11:52pm UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/7 "2024-02-15T23:52:08Z")

</div>

> [@dimdin](#):
>
> `.{ .TYPE = .SHARED_VALIDATE }`

yes

oh thank you.

```zig
	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);

```

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 16, 2024, 12:20am UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/8 "2024-02-16T00:20:10Z")

</div>

> [@JPL](#):
>
> `.{.TYPE =.SHARED_VALIDATE},`

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

before I could do SHARED | PRIVATE

---

<div class="post-metadata">

**Author:** ![andrewrk](https://ziggit.dev/user_avatar/ziggit.dev/andrewrk/32/7011_2.png) [@andrewrk](https://ziggit.dev/u/andrewrk)\
**Post date:** [February 16, 2024, 12:24am UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/9 "2024-02-16T00:24:21Z")

</div>

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 😆

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 16, 2024, 12:42am UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/10 "2024-02-16T00:42:39Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 16, 2024, 1:25am UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/11 "2024-02-16T01:25:03Z")

</div>

![shared_private](https://ziggit.dev/uploads/default/original/2X/f/f3f61aaf62f9fd8c7659c6651336faa4f30f236e.png)  
V 0.11  
v0.12 .2063

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

```

 ![sshared_validate](https://ziggit.dev/uploads/default/original/2X/a/a7b2970a50a32fe1f40edbb8e0243171c0e5e5b0.png)

```zig
.{.TYPE =.SHARED_VALIDATE},

```

v0.12 2755

---

<div class="post-metadata">

**Author:** ![JPL](https://ziggit.dev/letter_avatar_proxy/v4/letter/j/a9adbd/32.png) [@JPL](https://ziggit.dev/u/JPL)\
**Post date:** [February 16, 2024, 1:48am UTC](https://ziggit.dev/t/mmap-v-0-12-dev-map-shared/3269/12 "2024-02-16T01:48:35Z")

</div>

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… ."
