Delete unused functionality.
Core SwiftShader should no longer be able to allocate executable
memory. That responsibility now falls entirely on Reactor.
Bug b/115344057
Bug swiftshader:16
Change-Id: If5dad25e52e661331ef0555b2d9de743cbfd3173
Reviewed-on: https://swiftshader-review.googlesource.com/c/21369
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Common/Memory.cpp b/src/Common/Memory.cpp
index 45fef40..f44fc9e 100644
--- a/src/Common/Memory.cpp
+++ b/src/Common/Memory.cpp
@@ -78,54 +78,6 @@
return aligned;
#endif
}
-
-#if defined(LINUX_ENABLE_NAMED_MMAP)
-// Create a file descriptor for anonymous memory with the given
-// name. Returns -1 on failure.
-// TODO: remove once libc wrapper exists.
-int memfd_create(const char* name, unsigned int flags)
-{
- #if __aarch64__
- #define __NR_memfd_create 279
- #elif __arm__
- #define __NR_memfd_create 279
- #elif __powerpc64__
- #define __NR_memfd_create 360
- #elif __i386__
- #define __NR_memfd_create 356
- #elif __x86_64__
- #define __NR_memfd_create 319
- #endif /* __NR_memfd_create__ */
- #ifdef __NR_memfd_create
- // In the event of no system call this returns -1 with errno set
- // as ENOSYS.
- return syscall(__NR_memfd_create, name, flags);
- #else
- return -1;
- #endif
-}
-
-// Returns a file descriptor for use with an anonymous mmap, if
-// memfd_create fails, -1 is returned. Note, the mappings should be
-// MAP_PRIVATE so that underlying pages aren't shared.
-int anonymousFd()
-{
- static int fd = memfd_create("SwiftShader JIT", 0);
- return fd;
-}
-
-// Ensure there is enough space in the "anonymous" fd for length.
-void ensureAnonFileSize(int anonFd, size_t length)
-{
- static size_t fileSize = 0;
- if(length > fileSize)
- {
- ftruncate(anonFd, length);
- fileSize = length;
- }
-}
-#endif // defined(LINUX_ENABLE_NAMED_MMAP)
-
} // anonymous namespace
size_t memoryPageSize()
@@ -173,65 +125,6 @@
#endif
}
-void *allocateExecutable(size_t bytes)
-{
- size_t pageSize = memoryPageSize();
- size_t length = (bytes + pageSize - 1) & ~(pageSize - 1);
- void *mapping;
-
- #if defined(LINUX_ENABLE_NAMED_MMAP)
- // Try to name the memory region for the executable code,
- // to aid profilers.
- int anonFd = anonymousFd();
- if(anonFd == -1)
- {
- mapping = mmap(nullptr, length, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- }
- else
- {
- ensureAnonFileSize(anonFd, length);
- mapping = mmap(nullptr, length, PROT_READ | PROT_WRITE,
- MAP_PRIVATE, anonFd, 0);
- }
-
- if(mapping == MAP_FAILED)
- {
- mapping = nullptr;
- }
- #else
- mapping = allocate(length, pageSize);
- #endif
-
- return mapping;
-}
-
-void markExecutable(void *memory, size_t bytes)
-{
- #if defined(_WIN32)
- unsigned long oldProtection;
- VirtualProtect(memory, bytes, PAGE_EXECUTE_READ, &oldProtection);
- #else
- mprotect(memory, bytes, PROT_READ | PROT_EXEC);
- #endif
-}
-
-void deallocateExecutable(void *memory, size_t bytes)
-{
- #if defined(_WIN32)
- unsigned long oldProtection;
- VirtualProtect(memory, bytes, PAGE_READWRITE, &oldProtection);
- deallocate(memory);
- #elif defined(LINUX_ENABLE_NAMED_MMAP)
- size_t pageSize = memoryPageSize();
- size_t length = (bytes + pageSize - 1) & ~(pageSize - 1);
- munmap(memory, length);
- #else
- mprotect(memory, bytes, PROT_READ | PROT_WRITE);
- deallocate(memory);
- #endif
-}
-
void clear(uint16_t *memory, uint16_t element, size_t count)
{
#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
diff --git a/src/Common/Memory.hpp b/src/Common/Memory.hpp
index 8d3a159..0e8d188 100644
--- a/src/Common/Memory.hpp
+++ b/src/Common/Memory.hpp
@@ -25,10 +25,6 @@
void *allocate(size_t bytes, size_t alignment = 16);
void deallocate(void *memory);
-void *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable()
-void markExecutable(void *memory, size_t bytes);
-void deallocateExecutable(void *memory, size_t bytes);
-
void clear(uint16_t *memory, uint16_t element, size_t count);
void clear(uint32_t *memory, uint32_t element, size_t count);
}
diff --git a/src/Reactor/LLVMRoutine.cpp b/src/Reactor/LLVMRoutine.cpp
index 6b37fa6..92bb898 100644
--- a/src/Reactor/LLVMRoutine.cpp
+++ b/src/Reactor/LLVMRoutine.cpp
@@ -16,7 +16,6 @@
#include "Memory.hpp"
#include "Thread.hpp"
-#include "Types.hpp"
namespace rr
{
diff --git a/src/Reactor/Memory.cpp b/src/Reactor/Memory.cpp
index c7c3d6d..8f8e7ac 100644
--- a/src/Reactor/Memory.cpp
+++ b/src/Reactor/Memory.cpp
@@ -14,7 +14,6 @@
#include "Memory.hpp"
-#include "Types.hpp"
#include "Debug.hpp"
#if defined(_WIN32)
@@ -231,32 +230,4 @@
deallocate(memory);
#endif
}
-
-void clear(uint16_t *memory, uint16_t element, size_t count)
-{
- #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __stosw(memory, element, count);
- #elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __asm__("rep stosw" : : "D"(memory), "a"(element), "c"(count));
- #else
- for(size_t i = 0; i < count; i++)
- {
- memory[i] = element;
- }
- #endif
-}
-
-void clear(uint32_t *memory, uint32_t element, size_t count)
-{
- #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __stosd((unsigned long*)memory, element, count);
- #elif defined(__GNUC__) && defined(__x86__) && !defined(MEMORY_SANITIZER)
- __asm__("rep stosl" : : "D"(memory), "a"(element), "c"(count));
- #else
- for(size_t i = 0; i < count; i++)
- {
- memory[i] = element;
- }
- #endif
-}
}
diff --git a/src/Reactor/Memory.hpp b/src/Reactor/Memory.hpp
index 3517f3c..53b9446 100644
--- a/src/Reactor/Memory.hpp
+++ b/src/Reactor/Memory.hpp
@@ -22,15 +22,9 @@
{
size_t memoryPageSize();
-void *allocate(size_t bytes, size_t alignment = 16);
-void deallocate(void *memory);
-
void *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable()
void markExecutable(void *memory, size_t bytes);
void deallocateExecutable(void *memory, size_t bytes);
-
-void clear(uint16_t *memory, uint16_t element, size_t count);
-void clear(uint32_t *memory, uint32_t element, size_t count);
}
#endif // rr_Memory_hpp
diff --git a/src/Reactor/MutexLock.hpp b/src/Reactor/MutexLock.hpp
index c2d00eb..759e5d5 100644
--- a/src/Reactor/MutexLock.hpp
+++ b/src/Reactor/MutexLock.hpp
@@ -18,7 +18,7 @@
#include "Thread.hpp"
#if defined(__linux__)
-// Use a pthread mutex on Linux. Since many processes may use SwiftShader
+// Use a pthread mutex on Linux. Since many processes may use Reactor
// at the same time it's best to just have the scheduler overhead.
#include <pthread.h>
diff --git a/src/Reactor/Reactor.vcxproj b/src/Reactor/Reactor.vcxproj
index dbf7b5f..9cf4aed 100644
--- a/src/Reactor/Reactor.vcxproj
+++ b/src/Reactor/Reactor.vcxproj
@@ -297,7 +297,6 @@
<ClInclude Include="Reactor.hpp" />
<ClInclude Include="Routine.hpp" />
<ClInclude Include="Thread.hpp" />
- <ClInclude Include="Types.hpp" />
<ClInclude Include="x86.hpp" />
</ItemGroup>
<ItemGroup>
diff --git a/src/Reactor/Reactor.vcxproj.filters b/src/Reactor/Reactor.vcxproj.filters
index 34bb0f1..0bdda47 100644
--- a/src/Reactor/Reactor.vcxproj.filters
+++ b/src/Reactor/Reactor.vcxproj.filters
@@ -74,8 +74,5 @@
<ClInclude Include="Thread.hpp">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="Types.hpp">
- <Filter>Header Files</Filter>
- </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/Reactor/Types.hpp b/src/Reactor/Types.hpp
deleted file mode 100644
index 428da51..0000000
--- a/src/Reactor/Types.hpp
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef r3_Types_hpp
-#define r3_Types_hpp
-
-#include <limits>
-#include <type_traits>
-
-// GCC warns against bitfields not fitting the entire range of an enum with a fixed underlying type of unsigned int, which gets promoted to an error with -Werror and cannot be suppressed.
-// However, GCC already defaults to using unsigned int as the underlying type of an unscoped enum without a fixed underlying type. So we can just omit it.
-#if defined(__GNUC__) && !defined(__clang__)
-namespace {enum E {}; static_assert(!std::numeric_limits<std::underlying_type<E>::type>::is_signed, "expected unscoped enum whose underlying type is not fixed to be unsigned");}
-#define ENUM_UNDERLYING_TYPE_UNSIGNED_INT
-#else
-#define ENUM_UNDERLYING_TYPE_UNSIGNED_INT : unsigned int
-#endif
-
-#if defined(_MSC_VER)
- typedef signed __int8 int8_t;
- typedef signed __int16 int16_t;
- typedef signed __int32 int32_t;
- typedef signed __int64 int64_t;
- typedef unsigned __int8 uint8_t;
- typedef unsigned __int16 uint16_t;
- typedef unsigned __int32 uint32_t;
- typedef unsigned __int64 uint64_t;
- #define ALIGN(bytes, type) __declspec(align(bytes)) type
-#else
- #include <stdint.h>
- #define ALIGN(bytes, type) type __attribute__((aligned(bytes)))
-#endif
-
-namespace rr
-{
- typedef ALIGN(1, uint8_t) byte;
- typedef ALIGN(2, uint16_t) word;
- typedef ALIGN(4, uint32_t) dword;
- typedef ALIGN(8, uint64_t) qword;
- typedef ALIGN(16, uint64_t) qword2[2];
- typedef ALIGN(4, uint8_t) byte4[4];
- typedef ALIGN(8, uint8_t) byte8[8];
- typedef ALIGN(16, uint8_t) byte16[16];
- typedef ALIGN(8, uint16_t) word4[4];
- typedef ALIGN(8, uint32_t) dword2[2];
- typedef ALIGN(16, uint32_t) dword4[4];
- typedef ALIGN(16, uint64_t) xword[2];
-
- typedef ALIGN(1, int8_t) sbyte;
- typedef ALIGN(4, int8_t) sbyte4[4];
- typedef ALIGN(8, int8_t) sbyte8[8];
- typedef ALIGN(16, int8_t) sbyte16[16];
- typedef ALIGN(8, short) short4[4];
- typedef ALIGN(8, unsigned short) ushort4[4];
- typedef ALIGN(16, short) short8[8];
- typedef ALIGN(16, unsigned short) ushort8[8];
- typedef ALIGN(8, int) int2[2];
- typedef ALIGN(8, unsigned int) uint2[2];
- typedef ALIGN(16, unsigned int) uint4[4];
-
- typedef ALIGN(8, float) float2[2];
-
- ALIGN(16, struct int4
- {
- int x;
- int y;
- int z;
- int w;
-
- int &operator[](int i)
- {
- return (&x)[i];
- }
-
- const int &operator[](int i) const
- {
- return (&x)[i];
- }
-
- bool operator!=(const int4 &rhs)
- {
- return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
- }
-
- bool operator==(const int4 &rhs)
- {
- return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
- }
- });
-
- ALIGN(16, struct float4
- {
- float x;
- float y;
- float z;
- float w;
-
- float &operator[](int i)
- {
- return (&x)[i];
- }
-
- const float &operator[](int i) const
- {
- return (&x)[i];
- }
-
- bool operator!=(const float4 &rhs)
- {
- return x != rhs.x || y != rhs.y || z != rhs.z || w != rhs.w;
- }
-
- bool operator==(const float4 &rhs)
- {
- return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
- }
- });
-
- inline float4 vector(float x, float y, float z, float w)
- {
- float4 v;
-
- v.x = x;
- v.y = y;
- v.z = z;
- v.w = w;
-
- return v;
- }
-
- inline float4 replicate(float f)
- {
- float4 v;
-
- v.x = f;
- v.y = f;
- v.z = f;
- v.w = f;
-
- return v;
- }
-
- #define OFFSET(s,m) (int)(size_t)&reinterpret_cast<const volatile char&>((((s*)0)->m))
-}
-
-#endif // r3_Types_hpp
diff --git a/src/System/Memory.cpp b/src/System/Memory.cpp
index 45fef40..f44fc9e 100644
--- a/src/System/Memory.cpp
+++ b/src/System/Memory.cpp
@@ -78,54 +78,6 @@
return aligned;
#endif
}
-
-#if defined(LINUX_ENABLE_NAMED_MMAP)
-// Create a file descriptor for anonymous memory with the given
-// name. Returns -1 on failure.
-// TODO: remove once libc wrapper exists.
-int memfd_create(const char* name, unsigned int flags)
-{
- #if __aarch64__
- #define __NR_memfd_create 279
- #elif __arm__
- #define __NR_memfd_create 279
- #elif __powerpc64__
- #define __NR_memfd_create 360
- #elif __i386__
- #define __NR_memfd_create 356
- #elif __x86_64__
- #define __NR_memfd_create 319
- #endif /* __NR_memfd_create__ */
- #ifdef __NR_memfd_create
- // In the event of no system call this returns -1 with errno set
- // as ENOSYS.
- return syscall(__NR_memfd_create, name, flags);
- #else
- return -1;
- #endif
-}
-
-// Returns a file descriptor for use with an anonymous mmap, if
-// memfd_create fails, -1 is returned. Note, the mappings should be
-// MAP_PRIVATE so that underlying pages aren't shared.
-int anonymousFd()
-{
- static int fd = memfd_create("SwiftShader JIT", 0);
- return fd;
-}
-
-// Ensure there is enough space in the "anonymous" fd for length.
-void ensureAnonFileSize(int anonFd, size_t length)
-{
- static size_t fileSize = 0;
- if(length > fileSize)
- {
- ftruncate(anonFd, length);
- fileSize = length;
- }
-}
-#endif // defined(LINUX_ENABLE_NAMED_MMAP)
-
} // anonymous namespace
size_t memoryPageSize()
@@ -173,65 +125,6 @@
#endif
}
-void *allocateExecutable(size_t bytes)
-{
- size_t pageSize = memoryPageSize();
- size_t length = (bytes + pageSize - 1) & ~(pageSize - 1);
- void *mapping;
-
- #if defined(LINUX_ENABLE_NAMED_MMAP)
- // Try to name the memory region for the executable code,
- // to aid profilers.
- int anonFd = anonymousFd();
- if(anonFd == -1)
- {
- mapping = mmap(nullptr, length, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
- }
- else
- {
- ensureAnonFileSize(anonFd, length);
- mapping = mmap(nullptr, length, PROT_READ | PROT_WRITE,
- MAP_PRIVATE, anonFd, 0);
- }
-
- if(mapping == MAP_FAILED)
- {
- mapping = nullptr;
- }
- #else
- mapping = allocate(length, pageSize);
- #endif
-
- return mapping;
-}
-
-void markExecutable(void *memory, size_t bytes)
-{
- #if defined(_WIN32)
- unsigned long oldProtection;
- VirtualProtect(memory, bytes, PAGE_EXECUTE_READ, &oldProtection);
- #else
- mprotect(memory, bytes, PROT_READ | PROT_EXEC);
- #endif
-}
-
-void deallocateExecutable(void *memory, size_t bytes)
-{
- #if defined(_WIN32)
- unsigned long oldProtection;
- VirtualProtect(memory, bytes, PAGE_READWRITE, &oldProtection);
- deallocate(memory);
- #elif defined(LINUX_ENABLE_NAMED_MMAP)
- size_t pageSize = memoryPageSize();
- size_t length = (bytes + pageSize - 1) & ~(pageSize - 1);
- munmap(memory, length);
- #else
- mprotect(memory, bytes, PROT_READ | PROT_WRITE);
- deallocate(memory);
- #endif
-}
-
void clear(uint16_t *memory, uint16_t element, size_t count)
{
#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
diff --git a/src/System/Memory.hpp b/src/System/Memory.hpp
index 8d3a159..0e8d188 100644
--- a/src/System/Memory.hpp
+++ b/src/System/Memory.hpp
@@ -25,10 +25,6 @@
void *allocate(size_t bytes, size_t alignment = 16);
void deallocate(void *memory);
-void *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable()
-void markExecutable(void *memory, size_t bytes);
-void deallocateExecutable(void *memory, size_t bytes);
-
void clear(uint16_t *memory, uint16_t element, size_t count);
void clear(uint32_t *memory, uint32_t element, size_t count);
}