1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // +build linux,amd64 linux,arm64 linux,ppc64le
6
7 #include <errno.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <sys/mman.h>
11
12 #include "libcgo.h"
13
14 uintptr_t
15 x_cgo_mmap(void *addr, uintptr_t length, int32_t prot, int32_t flags, int32_t fd, uint32_t offset) {
16 void *p;
17
18 _cgo_tsan_acquire();
19 p = mmap(addr, length, prot, flags, fd, offset);
20 _cgo_tsan_release();
21 if (p == MAP_FAILED) {
22 /* This is what the Go code expects on failure. */
23 return (uintptr_t)errno;
24 }
25 return (uintptr_t)p;
26 }
27
28 void
29 x_cgo_munmap(void *addr, uintptr_t length) {
30 int r;
31
32 _cgo_tsan_acquire();
33 r = munmap(addr, length);
34 _cgo_tsan_release();
35 if (r < 0) {
36 /* The Go runtime is not prepared for munmap to fail. */
37 abort();
38 }
39 }
40
View as plain text