Index: lib/profile/WindowsMMap.c =================================================================== --- lib/profile/WindowsMMap.c +++ lib/profile/WindowsMMap.c @@ -120,9 +120,33 @@ } COMPILER_RT_VISIBILITY -int flock(int fd, int operation) -{ - return -1; /* Not supported. */ +int flock(int fd, int operation) { + HANDLE handle = (HANDLE)_get_osfhandle(fd); + if (handle == INVALID_HANDLE_VALUE) + return -1; + + switch (operation) { + case LOCK_EX: { + OVERLAPPED overlapped = { 0 }; + if (!LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, MAXDWORD, MAXDWORD, + &overlapped)) + return -1; + + break; + } + + case LOCK_UN: { + if (!UnlockFile(handle, 0, 0, MAXDWORD, MAXDWORD)) + return -1; + + break; + } + + default: + return -1; /* Not supported. */ + } + + return 0; } #undef DWORD_HI