1919#include "libc/calls/syscall-nt.internal.h"
2020#include "libc/intrin/maps.h"
2121#include "libc/nt/memory.h"
22- #include "libc/nt/runtime.h"
2322#include "libc/runtime/runtime.h"
2423#include "libc/stdio/sysparam.h"
25- #include "libc/sysv/consts/auxv.h"
2624#include "libc/sysv/consts/map.h"
2725#include "libc/sysv/errfuns.h"
2826
@@ -36,28 +34,17 @@ textwindows int sys_msync_nt(char *addr, size_t size, int flags) {
3634
3735 int rc = 0 ;
3836 __maps_lock ();
39- struct Map * next , * map ;
37+ struct Map * map ;
4038 if (!(map = __maps_floor (addr )))
4139 map = __maps_first ();
42- for (; map && map -> addr <= addr + size ; map = next ) {
43- next = __maps_next (map );
44- if (!__maps_isalloc (map ))
45- continue ;
40+ for (; map && map -> addr <= addr + size ; map = __maps_next (map )) {
4641 if (map -> flags & MAP_ANONYMOUS )
47- continue ;
48- if (MAX (addr , map -> addr ) >= MIN (addr + size , map -> addr + map -> size ))
42+ continue ; // msync() is about coherency between file and memory
43+ char * beg = MAX (addr , map -> addr );
44+ char * end = MIN (addr + size , map -> addr + map -> size );
45+ if (beg >= end )
4946 continue ; // didn't overlap mapping
50-
51- // get true size of win32 allocation
52- size_t allocsize = map -> size ;
53- while (next && !__maps_isalloc (next ) &&
54- next -> addr + allocsize == next -> addr ) {
55- allocsize += next -> size ;
56- next = __maps_next (next );
57- }
58-
59- // perform the flush
60- if (!FlushViewOfFile (map -> addr , allocsize ))
47+ if (!FlushViewOfFile (beg , end - beg ))
6148 rc = -1 ;
6249 // TODO(jart): FlushFileBuffers too on g_fds handle if MS_SYNC?
6350 }
0 commit comments