Commit 8bab33e3 by Nicolas Capens Committed by Nicolas Capens

Remove named anonymous mmap for GL/VK allocations

The use of named anonymous file mappings was only meant for the allocation of executable memory by the Reactor JIT. Bug: b/174801963 Change-Id: Ifae13c7ed5cdbb7d940cea750d3f061d08e9f442 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50889 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent bae138de
...@@ -53,37 +53,19 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -53,37 +53,19 @@ void *allocateRaw(size_t bytes, size_t alignment)
{ {
ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment. ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment.
#if defined(LINUX_ENABLE_NAMED_MMAP) unsigned char *block = new unsigned char[bytes + sizeof(Allocation) + alignment];
if(alignment < sizeof(void*)) unsigned char *aligned = nullptr;
{
return malloc(bytes);
}
else
{
void *allocation;
int result = posix_memalign(&allocation, alignment, bytes);
if(result != 0)
{
errno = result;
allocation = nullptr;
}
return allocation;
}
#else
unsigned char *block = new unsigned char[bytes + sizeof(Allocation) + alignment];
unsigned char *aligned = nullptr;
if(block) if(block)
{ {
aligned = (unsigned char*)((uintptr_t)(block + sizeof(Allocation) + alignment - 1) & -(intptr_t)alignment); aligned = (unsigned char*)((uintptr_t)(block + sizeof(Allocation) + alignment - 1) & -(intptr_t)alignment);
Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation)); Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation));
// allocation->bytes = bytes; // allocation->bytes = bytes;
allocation->block = block; allocation->block = block;
} }
return aligned; return aligned;
#endif
} }
} // anonymous namespace } // anonymous namespace
...@@ -119,17 +101,13 @@ void *allocate(size_t bytes, size_t alignment) ...@@ -119,17 +101,13 @@ void *allocate(size_t bytes, size_t alignment)
void deallocate(void *memory) void deallocate(void *memory)
{ {
#if defined(LINUX_ENABLE_NAMED_MMAP) if(memory)
free(memory); {
#else unsigned char *aligned = (unsigned char*)memory;
if(memory) Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation));
{
unsigned char *aligned = (unsigned char*)memory;
Allocation *allocation = (Allocation*)(aligned - sizeof(Allocation));
delete[] allocation->block; delete[] allocation->block;
} }
#endif
} }
void clear(uint16_t *memory, uint16_t element, size_t count) void clear(uint16_t *memory, uint16_t element, size_t count)
......
...@@ -54,23 +54,6 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -54,23 +54,6 @@ void *allocateRaw(size_t bytes, size_t alignment)
{ {
ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment. ASSERT((alignment & (alignment - 1)) == 0); // Power of 2 alignment.
#if defined(LINUX_ENABLE_NAMED_MMAP)
if(alignment < sizeof(void *))
{
return malloc(bytes);
}
else
{
void *allocation;
int result = posix_memalign(&allocation, alignment, bytes);
if(result != 0)
{
errno = result;
allocation = nullptr;
}
return allocation;
}
#else
unsigned char *block = (unsigned char *)malloc(bytes + sizeof(Allocation) + alignment); unsigned char *block = (unsigned char *)malloc(bytes + sizeof(Allocation) + alignment);
unsigned char *aligned = nullptr; unsigned char *aligned = nullptr;
...@@ -84,7 +67,6 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -84,7 +67,6 @@ void *allocateRaw(size_t bytes, size_t alignment)
} }
return aligned; return aligned;
#endif
} }
} // anonymous namespace } // anonymous namespace
...@@ -118,9 +100,6 @@ void *allocate(size_t bytes, size_t alignment) ...@@ -118,9 +100,6 @@ void *allocate(size_t bytes, size_t alignment)
void deallocate(void *memory) void deallocate(void *memory)
{ {
#if defined(LINUX_ENABLE_NAMED_MMAP)
free(memory);
#else
if(memory) if(memory)
{ {
unsigned char *aligned = (unsigned char *)memory; unsigned char *aligned = (unsigned char *)memory;
...@@ -128,7 +107,6 @@ void deallocate(void *memory) ...@@ -128,7 +107,6 @@ void deallocate(void *memory)
free(allocation->block); free(allocation->block);
} }
#endif
} }
void clear(uint16_t *memory, uint16_t element, size_t count) void clear(uint16_t *memory, uint16_t element, size_t count)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment