Add mmap() wrapper.

This commit is contained in:
Bartosz Taudul 2020-02-12 19:22:46 +01:00
parent fa1747bdb2
commit cc805b7b74
10 changed files with 101 additions and 0 deletions

View File

@ -134,6 +134,7 @@
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyPrint.cpp" /> <ClCompile Include="..\..\..\server\TracyPrint.cpp" />
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" /> <ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" /> <ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
@ -181,8 +182,10 @@
<ClInclude Include="..\..\..\common\tracy_sema.h" /> <ClInclude Include="..\..\..\common\tracy_sema.h" />
<ClInclude Include="..\..\..\server\TracyCharUtil.hpp" /> <ClInclude Include="..\..\..\server\TracyCharUtil.hpp" />
<ClInclude Include="..\..\..\server\TracyEvent.hpp" /> <ClInclude Include="..\..\..\server\TracyEvent.hpp" />
<ClInclude Include="..\..\..\server\TracyFileRead.hpp" />
<ClInclude Include="..\..\..\server\TracyFileWrite.hpp" /> <ClInclude Include="..\..\..\server\TracyFileWrite.hpp" />
<ClInclude Include="..\..\..\server\TracyMemory.hpp" /> <ClInclude Include="..\..\..\server\TracyMemory.hpp" />
<ClInclude Include="..\..\..\server\TracyMmap.hpp" />
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" /> <ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
<ClInclude Include="..\..\..\server\TracyPrint.hpp" /> <ClInclude Include="..\..\..\server\TracyPrint.hpp" />
<ClInclude Include="..\..\..\server\TracySlab.hpp" /> <ClInclude Include="..\..\..\server\TracySlab.hpp" />

View File

@ -123,6 +123,9 @@
<ClCompile Include="..\..\..\zstd\zstdmt_compress.c"> <ClCompile Include="..\..\..\zstd\zstdmt_compress.c">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
<Filter>server</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp"> <ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -284,5 +287,11 @@
<ClInclude Include="..\..\..\zstd\zstdmt_compress.h"> <ClInclude Include="..\..\..\zstd\zstdmt_compress.h">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\server\TracyFileRead.hpp">
<Filter>server</Filter>
</ClInclude>
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
<Filter>server</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -134,6 +134,7 @@
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" /> <ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" /> <ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
<ClCompile Include="..\..\..\server\TracyWorker.cpp" /> <ClCompile Include="..\..\..\server\TracyWorker.cpp" />
@ -179,8 +180,10 @@
<ClInclude Include="..\..\..\common\tracy_sema.h" /> <ClInclude Include="..\..\..\common\tracy_sema.h" />
<ClInclude Include="..\..\..\server\TracyCharUtil.hpp" /> <ClInclude Include="..\..\..\server\TracyCharUtil.hpp" />
<ClInclude Include="..\..\..\server\TracyEvent.hpp" /> <ClInclude Include="..\..\..\server\TracyEvent.hpp" />
<ClInclude Include="..\..\..\server\TracyFileRead.hpp" />
<ClInclude Include="..\..\..\server\TracyFileWrite.hpp" /> <ClInclude Include="..\..\..\server\TracyFileWrite.hpp" />
<ClInclude Include="..\..\..\server\TracyMemory.hpp" /> <ClInclude Include="..\..\..\server\TracyMemory.hpp" />
<ClInclude Include="..\..\..\server\TracyMmap.hpp" />
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" /> <ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
<ClInclude Include="..\..\..\server\TracySlab.hpp" /> <ClInclude Include="..\..\..\server\TracySlab.hpp" />
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" /> <ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />

View File

@ -117,6 +117,9 @@
<ClCompile Include="..\..\..\zstd\zstdmt_compress.c"> <ClCompile Include="..\..\..\zstd\zstdmt_compress.c">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
<Filter>server</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp"> <ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -272,5 +275,11 @@
<ClInclude Include="..\..\..\zstd\zstdmt_compress.h"> <ClInclude Include="..\..\..\zstd\zstdmt_compress.h">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\server\TracyFileRead.hpp">
<Filter>server</Filter>
</ClInclude>
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
<Filter>server</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -114,6 +114,7 @@
<ClCompile Include="..\..\..\nfd\nfd_win.cpp" /> <ClCompile Include="..\..\..\nfd\nfd_win.cpp" />
<ClCompile Include="..\..\..\server\TracyBadVersion.cpp" /> <ClCompile Include="..\..\..\server\TracyBadVersion.cpp" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyPrint.cpp" /> <ClCompile Include="..\..\..\server\TracyPrint.cpp" />
<ClCompile Include="..\..\..\server\TracyStorage.cpp" /> <ClCompile Include="..\..\..\server\TracyStorage.cpp" />
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" /> <ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
@ -193,6 +194,7 @@
<ClInclude Include="..\..\..\server\TracyFileWrite.hpp" /> <ClInclude Include="..\..\..\server\TracyFileWrite.hpp" />
<ClInclude Include="..\..\..\server\TracyImGui.hpp" /> <ClInclude Include="..\..\..\server\TracyImGui.hpp" />
<ClInclude Include="..\..\..\server\TracyMemory.hpp" /> <ClInclude Include="..\..\..\server\TracyMemory.hpp" />
<ClInclude Include="..\..\..\server\TracyMmap.hpp" />
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" /> <ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
<ClInclude Include="..\..\..\server\TracyPrint.hpp" /> <ClInclude Include="..\..\..\server\TracyPrint.hpp" />
<ClInclude Include="..\..\..\server\TracyShortPtr.hpp" /> <ClInclude Include="..\..\..\server\TracyShortPtr.hpp" />

View File

@ -189,6 +189,9 @@
<ClCompile Include="..\..\..\zstd\zstdmt_compress.c"> <ClCompile Include="..\..\..\zstd\zstdmt_compress.c">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
<Filter>server</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp"> <ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -473,6 +476,9 @@
<ClInclude Include="..\..\..\zstd\zstdmt_compress.h"> <ClInclude Include="..\..\..\zstd\zstdmt_compress.h">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
<Filter>server</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Natvis Include="DebugVis.natvis" /> <Natvis Include="DebugVis.natvis" />

38
server/TracyMmap.cpp Normal file
View File

@ -0,0 +1,38 @@
#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

19
server/TracyMmap.hpp Normal file
View File

@ -0,0 +1,19 @@
#ifndef __TRACYMMAP_HPP__
#define __TRACYMMAP_HPP__
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __CYGWIN__
# include <sys/mman.h>
#else
# include <string.h>
# include <sys/types.h>
# define PROT_READ 1
# define PROT_WRITE 2
# define MAP_SHARED 0
void* mmap( void* addr, size_t length, int prot, int flags, int fd, off_t offset );
int munmap( void* addr, size_t length );
#endif
#endif

View File

@ -134,6 +134,7 @@
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" /> <ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
<ClCompile Include="..\..\..\server\TracyMemory.cpp" /> <ClCompile Include="..\..\..\server\TracyMemory.cpp" />
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
<ClCompile Include="..\..\..\server\TracyPrint.cpp" /> <ClCompile Include="..\..\..\server\TracyPrint.cpp" />
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" /> <ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" /> <ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
@ -180,8 +181,10 @@
<ClInclude Include="..\..\..\common\tracy_sema.h" /> <ClInclude Include="..\..\..\common\tracy_sema.h" />
<ClInclude Include="..\..\..\server\TracyCharUtil.hpp" /> <ClInclude Include="..\..\..\server\TracyCharUtil.hpp" />
<ClInclude Include="..\..\..\server\TracyEvent.hpp" /> <ClInclude Include="..\..\..\server\TracyEvent.hpp" />
<ClInclude Include="..\..\..\server\TracyFileRead.hpp" />
<ClInclude Include="..\..\..\server\TracyFileWrite.hpp" /> <ClInclude Include="..\..\..\server\TracyFileWrite.hpp" />
<ClInclude Include="..\..\..\server\TracyMemory.hpp" /> <ClInclude Include="..\..\..\server\TracyMemory.hpp" />
<ClInclude Include="..\..\..\server\TracyMmap.hpp" />
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" /> <ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
<ClInclude Include="..\..\..\server\TracyPrint.hpp" /> <ClInclude Include="..\..\..\server\TracyPrint.hpp" />
<ClInclude Include="..\..\..\server\TracySlab.hpp" /> <ClInclude Include="..\..\..\server\TracySlab.hpp" />

View File

@ -120,6 +120,9 @@
<ClCompile Include="..\..\..\zstd\zstdmt_compress.c"> <ClCompile Include="..\..\..\zstd\zstdmt_compress.c">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
<Filter>server</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\common\tracy_lz4.hpp"> <ClInclude Include="..\..\..\common\tracy_lz4.hpp">
@ -278,5 +281,11 @@
<ClInclude Include="..\..\..\zstd\zstdmt_compress.h"> <ClInclude Include="..\..\..\zstd\zstdmt_compress.h">
<Filter>zstd</Filter> <Filter>zstd</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\..\server\TracyFileRead.hpp">
<Filter>server</Filter>
</ClInclude>
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
<Filter>server</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>