...

Text file src/runtime/cgo/gcc_mmap.c

Documentation: runtime/cgo

     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//go:build (linux && (amd64 || arm64 || loong64 || ppc64le)) || (freebsd && amd64)
     6
     7#include <errno.h>
     8#include <stdint.h>
     9#include <stdlib.h>
    10#include <sys/mman.h>
    11
    12#include "libcgo.h"
    13
    14uintptr_t
    15x_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
    28void
    29x_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}

View as plain text