folly/folly/portability/SysMman.h

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#ifndef _WIN32

#include <sys/mman.h>

// MAP_ANONYMOUS is named MAP_ANON on OSX/BSD.
#if defined(__APPLE__) || defined(__FreeBSD__)
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS
#endif
#endif

#else

#include <cstdint>

#include <sys/types.h>

using off64_t = int64_t;

#define MAP_ANONYMOUS
#define MAP_ANON
#define MAP_SHARED
#define MAP_PRIVATE
#define MAP_POPULATE
#define MAP_NORESERVE
#define MAP_FIXED

#define MAP_FAILED

#define PROT_NONE
#define PROT_READ
#define PROT_WRITE
#define PROT_EXEC

#define MADV_NORMAL
#define MADV_DONTNEED
#define MADV_SEQUENTIAL

extern "C" {
int madvise(const void* addr, size_t len, int advise);
int mlock(const void* addr, size_t len);
void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off);
void* mmap64(
    void* addr, size_t length, int prot, int flags, int fd, off64_t off);
int mprotect(void* addr, size_t size, int prot);
int munlock(const void* addr, size_t length);
int munmap(void* addr, size_t length);
}

#endif