]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm: Call msync with length = 0 on Cygwin
authorStefan Berger <stefanb@linux.ibm.com>
Tue, 5 Oct 2021 18:29:51 +0000 (14:29 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Tue, 5 Oct 2021 19:22:14 +0000 (15:22 -0400)
Cygwin internally uses the Windows API call FlushViewOfFile that
seems to not like to be called with an excessive number of bytes.
Instead, call it with length = 0 so that 'the file is flushed from
the base address to the end of the mapping' and then msync() succeeds.

Source:
https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-flushviewoffile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
src/swtpm/swtpm_nvstore_linear_file.c

index 42d6ca5b517d3851ee94b7b9a42eb361b65b316c..d5e81593769b099bfee6b5e848599c165361d0c3 100644 (file)
@@ -200,7 +200,12 @@ SWTPM_NVRAM_LinearFile_Flush(const char* uri SWTPM_ATTR_UNUSED,
     /* msync parameters must be page-aligned */
     uint32_t pagesize = sysconf(_SC_PAGESIZE);
     msync_offset = mmap_state.ptr + (offset & ~(pagesize - 1));
+#if defined(__CYGWIN__)
+    /* Cygwin uses Win API FlushViewOfFile, which we call with len = 0 */
+    msync_count = 0;
+#else
     msync_count = (count + (pagesize - 1)) & ~(pagesize - 1);
+#endif
 
     TPM_DEBUG("SWTPM_NVRAM_LinearFile_Flush: msync %d@0x%x\n",
               msync_count, msync_offset);