ladybird/Kernel/API/POSIX/sys/mman.h
Daniel Bertalan 77f9272aaf Kernel+UE: Add MAP_FIXED_NOREPLACE mmap() flag
This feature was introduced in version 4.17 of the Linux kernel, and
while it's not specified by POSIX, I think it will be a nice addition to
our system.

MAP_FIXED_NOREPLACE provides a less error-prone alternative to
MAP_FIXED: while regular fixed mappings would cause any intersecting
ranges to be unmapped, MAP_FIXED_NOREPLACE returns EEXIST instead. This
ensures that we don't corrupt our process's address space if something
is already at the requested address.

Note that the more portable way to do this is to use regular
MAP_ANONYMOUS, and check afterwards whether the returned address matches
what we wanted. This, however, has a large performance impact on
programs like Wine which try to reserve large portions of the address
space at once, as the non-matching addresses have to be unmapped
separately.
2021-12-23 23:08:10 +01:00

55 lines
1.1 KiB
C

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/API/POSIX/sys/types.h>
#include <Kernel/API/POSIX/time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAP_FILE 0x00
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_STACK 0x40
#define MAP_NORESERVE 0x80
#define MAP_RANDOMIZED 0x100
#define MAP_PURGEABLE 0x200
#define MAP_FIXED_NOREPLACE 0x400
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define PROT_NONE 0x0
#define MAP_FAILED ((void*)-1)
#define MADV_NORMAL 0x0
#define MADV_SET_VOLATILE 0x1
#define MADV_SET_NONVOLATILE 0x2
#define MADV_DONTNEED 0x3
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html
#define POSIX_MADV_NORMAL MADV_NORMAL
#define POSIX_MADV_DONTNEED MADV_DONTNEED
// Unsupported posix_madvise() advise:
// POSIX_MADV_SEQUENTIAL
// POSIX_MADV_RANDOM
// POSIX_MADV_WILLNEED
#define MS_SYNC 1
#define MS_ASYNC 2
#define MS_INVALIDATE 4
#ifdef __cplusplus
}
#endif