mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 18:51:46 +00:00
39 lines
985 B
C++
39 lines
985 B
C++
#include "TracyMmap.hpp"
|
|
|
|
#if defined _MSC_VER || defined __MINGW32__ || defined __CYGWIN__
|
|
# include <io.h>
|
|
# include <windows.h>
|
|
|
|
void* mmap( void* addr, size_t length, int prot, int flags, int fd, off_t offset )
|
|
{
|
|
HANDLE hnd;
|
|
void* map = nullptr;
|
|
|
|
switch( prot )
|
|
{
|
|
case PROT_READ:
|
|
if( hnd = CreateFileMapping( HANDLE( _get_osfhandle( fd ) ), nullptr, PAGE_READONLY, 0, 0, nullptr ) )
|
|
{
|
|
map = MapViewOfFile( hnd, FILE_MAP_READ, 0, 0, length );
|
|
CloseHandle( hnd );
|
|
}
|
|
break;
|
|
case PROT_WRITE:
|
|
if( hnd = CreateFileMapping( HANDLE( _get_osfhandle( fd ) ), nullptr, PAGE_READWRITE, 0, 0, nullptr ) )
|
|
{
|
|
map = MapViewOfFile( hnd, FILE_MAP_WRITE, 0, 0, length );
|
|
CloseHandle( hnd );
|
|
}
|
|
break;
|
|
}
|
|
|
|
return map ? (char*)map + offset : (void*)-1;
|
|
}
|
|
|
|
int munmap( void* addr, size_t length )
|
|
{
|
|
return UnmapViewOfFile( addr ) != 0 ? 0 : -1;
|
|
}
|
|
|
|
#endif
|