Simplify memory manager code

This commit is contained in:
Justine Tunney 2024-12-28 17:08:18 -08:00
parent 379cd77078
commit aca4214ff6
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
11 changed files with 442 additions and 325 deletions

View file

@ -26,27 +26,24 @@
#include "libc/sysv/errfuns.h"
textwindows int sys_msync_nt(char *addr, size_t size, int flags) {
size = (size + __pagesize - 1) & -__pagesize;
int pagesz = __pagesize;
size = (size + pagesz - 1) & -pagesz;
if ((uintptr_t)addr & (pagesz - 1))
if ((uintptr_t)addr & (__pagesize - 1))
return einval();
if (__maps_held())
return edeadlk();
int rc = 0;
if (__maps_lock()) {
rc = edeadlk();
} else {
struct Map *map, *floor;
floor = __maps_floor(addr);
for (map = floor; map && map->addr <= addr + size; map = __maps_next(map)) {
char *beg = MAX(addr, map->addr);
char *end = MIN(addr + size, map->addr + map->size);
if (beg < end)
if (!FlushViewOfFile(beg, end - beg))
rc = -1;
// TODO(jart): FlushFileBuffers too on g_fds handle if MS_SYNC?
}
__maps_lock();
struct Map *map, *floor;
floor = __maps_floor(addr);
for (map = floor; map && map->addr <= addr + size; map = __maps_next(map)) {
char *beg = MAX(addr, map->addr);
char *end = MIN(addr + size, map->addr + map->size);
if (beg < end)
if (!FlushViewOfFile(beg, end - beg))
rc = -1;
// TODO(jart): FlushFileBuffers too on g_fds handle if MS_SYNC?
}
__maps_unlock();