Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 58 additions and 28 deletions.
  1. +58 −28 mmstats/_mmap.py
View
86 mmstats/_mmap.py
@@ -4,6 +4,7 @@
libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c'))
import mmap as stdlib_mmap
import os
+import sys
from . import libgettid
@@ -39,35 +40,64 @@ def init_mmap(path=DEFAULT_PATH, filename=DEFAULT_FILENAME, size=PAGESIZE):
return (fd, full_path, size, m_ptr)
-# Linux consts from /usr/include/bits/mman.h
-MS_ASYNC = 1
-MS_SYNC = 4
-
-
-libc.mmap.restype = ctypes.c_void_p
-libc.mmap.argtypes = [
- ctypes.c_void_p, # address
- ctypes.c_size_t, # size of mapping
- ctypes.c_int, # protection
- ctypes.c_int, # flags
- ctypes.c_int, # fd
- ctypes.c_int, # offset (needs to be off_t type?)
-]
-
-
-def mmap(size, fd):
- m_ptr = libc.mmap(None,
- size,
- stdlib_mmap.PROT_READ | stdlib_mmap.PROT_WRITE,
- stdlib_mmap.MAP_SHARED,
- fd,
- 0
+if sys.platform == 'win32':
+ """
+ LPVOID WINAPI MapViewOfFile(
+ __in HANDLE hFileMappingObject,
+ __in DWORD dwDesiredAccess,
+ __in DWORD dwFileOffsetHigh,
+ __in DWORD dwFileOffsetLow,
+ __in SIZE_T dwNumberOfBytesToMap
+ );
+ """
+ # I don't think the C lib is the right place to look for this function
+ libc.MapViewOfFile.restype = ctypes.c_void_p
+ libc.MapViewOfFile.argtypes = [
+ ctypes.wintypes.HANDLE, # hFileMappObject
+ ctypes.wintypes.DWORD, # dwDesiredAccess
+ ctypes.wintypes.DWORD, # dwFielOffsetHigh
+ ctypes.wintypes.DWORD, # dwFielOffsetlow
+ ctypes.c_size_t, # dwNumberOfBytesToMap
+ ]
+
+ def mmap(size, fd):
+ m_ptr = libc.MapViewOfFile(
+ fd,
+ ctypes.wintypes.FILE_MAP_ALL_ACCESS, #TODO ACCESS
+ 0, #FIXME High order offset?!
+ 0, #FIXME Low order offset?!
+ size
)
- if m_ptr == -1:
- # Error
- e = ctypes.get_errno()
- raise OSError(e, errno.errorcode[e])
- return m_ptr
+ return m_ptr
+
+else:
+ # Linux consts from /usr/include/bits/mman.h
+ MS_ASYNC = 1
+ MS_SYNC = 4
+
+ libc.mmap.restype = ctypes.c_void_p
+ libc.mmap.argtypes = [
+ ctypes.c_void_p, # address
+ ctypes.c_size_t, # size of mapping
+ ctypes.c_int, # protection
+ ctypes.c_int, # flags
+ ctypes.c_int, # fd
+ ctypes.c_int, # offset (needs to be off_t type?)
+ ]
+
+ def mmap(size, fd):
+ m_ptr = libc.mmap(None,
+ size,
+ stdlib_mmap.PROT_READ | stdlib_mmap.PROT_WRITE,
+ stdlib_mmap.MAP_SHARED,
+ fd,
+ 0
+ )
+ if m_ptr == -1:
+ # Error
+ e = ctypes.get_errno()
+ raise OSError(e, errno.errorcode[e])
+ return m_ptr
libc.msync.restype = ctypes.c_int

No commit comments for this range

Something went wrong with that request. Please try again.