Top Description Fields Constructors Methods
org.lwjgl.system.linux

public Class MMAN

extends Object
Class Inheritance
Imports
java.nio.*, org.lwjgl.system.*

Native bindings to <sys/mman.h>.

Field Summary

Modifier and TypeField and Description
public static final int
MAP_32BIT

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_ANON

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_ANONYMOUS

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_DENYWRITE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_EXECUTABLE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final long
MAP_FAILED

Return value of mmap in case of an error.

public static final int
MAP_FILE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_FIXED

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_FIXED_NOREPLACE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_GROWSDOWN

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_HUGE_1GB

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_HUGE_2MB

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
public static final int
public static final int
MAP_HUGETLB

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_LOCKED

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_NONBLOCK

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_NORESERVE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_POPULATE

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_PRIVATE

The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.

public static final int
MAP_SHARED

The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.

public static final int
MAP_SHARED_VALIDATE

The flags argument determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file.

public static final int
MAP_STACK

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_SYNC

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
MAP_UNINITIALIZED

Enum values:

  • MAP_32BIT - Put the mapping into the first 2 Gigabytes of the process address space.

    This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2 GB of memory, so as to improve context-switch performance on some early 64-bit processors. Modern x86-64 processors no longer have this performance problem, so use of this flag is not required on those systems. The MAP_32BIT flag is ignored when MAP_FIXED is set.

  • MAP_ANONYMOUS - The mapping is not backed by any file; its contents are initialized to zero.

    The fd argument is ignored; however, some implementations require fd to be -1 if MAP_ANONYMOUS (or MAP_ANON) is specified, and portable applications should ensure this. The offset argument should be zero. The use of MAP_ANONYMOUS in conjunction with MAP_SHARED is supported on Linux only since kernel 2.4.

  • MAP_ANON - Synonym for MAP_ANONYMOUS; provided for compatibility with other implementations.
  • MAP_DENYWRITE - This flag is ignored.

    (Long ago —Linux 2.0 and earlier— it signaled that attempts to write to the underlying file should fail with ETXTBSY. But this was a source of denial-of-service attacks.)

  • MAP_EXECUTABLE - This flag is ignored.
  • MAP_FILE - Compatibility flag. Ignored.
  • MAP_FIXED - Don't interpret addr as a hint: place the mapping at exactly that address.

    addr must be suitably aligned: for most architectures a multiple of the page size is sufficient; however, some architectures may impose additional restrictions. If the memory region specified by addr and length overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap will fail.

    Software that aspires to be portable should use the MAP_FIXED flag with care, keeping in mind that the exact layout of a process's memory mappings is allowed to change significantly between kernel versions, C library versions, and operating system releases. Carefully read the discussion of this flag in NOTES!

  • MAP_FIXED_NOREPLACE - This flag provides behavior that is similar to MAP_FIXED with respect to the addr enforcement, but differs in that MAP_FIXED_NOREPLACE never clobbers a preexisting mapped range.

    If the requested range would collide with an existing mapping, then this call fails with the error EEXIST. This flag can therefore be used as a way to atomically (with respect to other threads) attempt to map an address range: one thread will succeed; all others will report failure.

    Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE flag will typically (upon detecting a collision with a preexisting mapping) fall back to a "non-MAP_FIXED" type of behavior: they will return an address that is different from the requested address. Therefore, backward-compatible software should check the returned address against the requested address.

    (since Linux 4.17)

  • MAP_GROWSDOWN - This flag is used for stacks. It indicates to the kernel virtual memory system that the mapping should extend downward in memory.

    The return address is one page lower than the memory area that is actually created in the process's virtual address space. Touching an address in the "guard" page below the mapping will cause the mapping to grow by a page. This growth can be repeated until the mapping grows to within a page of the high end of the next lower mapping, at which point touching the "guard" page will result in a SIGSEGV signal.

  • MAP_HUGETLB - Allocate the mapping using "huge" pages.

    See the Linux kernel source file Documentation/admin-guide/mm/hugetlbpage.rst for further information, as well as NOTES, below.

    (since Linux 2.6.32)

  • MAP_HUGE_2MB - Used in conjunction with MAP_HUGETLB to select alternative hugetlb page sizes (respectively, 2 MB and 1 GB) on systems that support multiple hugetlb page sizes.

    More generally, the desired huge page size can be configured by encoding the base-2 logarithm of the desired page size in the six bits at the offset MAP_HUGE_SHIFT. (A value of zero in this bit field provides the default huge page size; the default huge page size can be discovered via the Hugepagesize field exposed by /proc/meminfo.) Thus, the above two constants are defined as:

    
    #define MAP_HUGE_2MB    (21 << MAP_HUGE_SHIFT)
    #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
public static final int
PROT_EXEC

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

public static final int
PROT_GROWSDOWN

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

public static final int
PROT_GROWSUP

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

public static final int
PROT_NONE

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

public static final int
PROT_READ

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

public static final int
PROT_WRITE

The prot argument describes the desired memory protection of the mapping (and must not conflict with the open mode of the file).

Constructor Summary

AccessConstructor and Description
protected
MMAN()

Method Summary

Modifier and TypeMethod and Description
public static native long

Returns:

on success, returns a pointer to the mapped area. On error, the value MAP_FAILED is returned, and errno is set to indicate the error.
mmap
(long addr, long length, int
describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). One or more of:
PROT_EXECPROT_READPROT_WRITEPROT_NONEPROT_GROWSDOWNPROT_GROWSUP
prot
,
int flags, int fd, long offset)

Creates a new mapping in the virtual address space of the calling process.

public static int

Returns:

on success, returns 0. On failure, it returns -1, and errno is set to indicate the error (probably to EINVAL).
munmap
(ByteBuffer addr)

Deletes the mappings for the specified address range, and causes further references to addresses within the range to generate invalid memory references.

public static native int
nmunmap(long addr, long length)

Unsafe version of: munmap

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait