Allow even smaller memory limits.

This commit is contained in:
Christoffer Lerno
2025-07-18 10:54:03 +02:00
parent 34bded30eb
commit adb3df05c6
3 changed files with 5 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2021-2022 Christoffer Lerno. All rights reserved.
// Copyright (c) 2021-2025 Christoffer Lerno. All rights reserved.
// Use of this source code is governed by the MIT license
// a copy of which can be found in the LICENSE_STDLIB file.
module std::io;

View File

@@ -21,6 +21,7 @@
- `env::AUTHORS` and `env::AUTHOR_EMAILS` added.
- Suppress codegen of panic printing with when panic messages are set to "off".
- Implicit linking of libc math when libc math functions are used.
- Allow even smaller memory limits.
### Fixes
- mkdir/rmdir would not work properly with substring paths on non-windows platforms.

View File

@@ -28,20 +28,20 @@ static inline void mmap_init(Vmem *vmem, size_t size)
}
#elif PLATFORM_POSIX
void* ptr = NULL;
size_t min_size = size / 32;
size_t min_size = size / 128;
if (min_size < 1) min_size = size;
while (size >= min_size)
{
ptr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
// It worked?
if (ptr != MAP_FAILED && ptr) break;
if (ptr != MAP_FAILED) break;
// Did it fail in a non-retriable way?
if (errno != ENOMEM && errno != EOVERFLOW && errno != EAGAIN) break;
// Try a smaller size
size /= 2;
}
// Check if we ended on a failure.
if ((ptr == MAP_FAILED) || !ptr)
if (ptr == MAP_FAILED)
{
FATAL_ERROR("Failed to map a virtual memory block.");
}