mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Allow even smaller memory limits.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user