Commit a527eb0e by Nicolas Capens Committed by Nicolas Capens

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/21369Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent c07dc4be
...@@ -78,54 +78,6 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -78,54 +78,6 @@ void *allocateRaw(size_t bytes, size_t alignment)
return aligned; return aligned;
#endif #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 } // anonymous namespace
size_t memoryPageSize() size_t memoryPageSize()
...@@ -173,65 +125,6 @@ void deallocate(void *memory) ...@@ -173,65 +125,6 @@ void deallocate(void *memory)
#endif #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) void clear(uint16_t *memory, uint16_t element, size_t count)
{ {
#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER) #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
......
...@@ -25,10 +25,6 @@ size_t memoryPageSize(); ...@@ -25,10 +25,6 @@ size_t memoryPageSize();
void *allocate(size_t bytes, size_t alignment = 16); void *allocate(size_t bytes, size_t alignment = 16);
void deallocate(void *memory); 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(uint16_t *memory, uint16_t element, size_t count);
void clear(uint32_t *memory, uint32_t element, size_t count); void clear(uint32_t *memory, uint32_t element, size_t count);
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "Memory.hpp" #include "Memory.hpp"
#include "Thread.hpp" #include "Thread.hpp"
#include "Types.hpp"
namespace rr namespace rr
{ {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "Memory.hpp" #include "Memory.hpp"
#include "Types.hpp"
#include "Debug.hpp" #include "Debug.hpp"
#if defined(_WIN32) #if defined(_WIN32)
...@@ -231,32 +230,4 @@ void deallocateExecutable(void *memory, size_t bytes) ...@@ -231,32 +230,4 @@ void deallocateExecutable(void *memory, size_t bytes)
deallocate(memory); deallocate(memory);
#endif #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
}
} }
...@@ -22,15 +22,9 @@ namespace rr ...@@ -22,15 +22,9 @@ namespace rr
{ {
size_t memoryPageSize(); 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 *allocateExecutable(size_t bytes); // Allocates memory that can be made executable using markExecutable()
void markExecutable(void *memory, size_t bytes); void markExecutable(void *memory, size_t bytes);
void deallocateExecutable(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 #endif // rr_Memory_hpp
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "Thread.hpp" #include "Thread.hpp"
#if defined(__linux__) #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. // at the same time it's best to just have the scheduler overhead.
#include <pthread.h> #include <pthread.h>
......
...@@ -297,7 +297,6 @@ ...@@ -297,7 +297,6 @@
<ClInclude Include="Reactor.hpp" /> <ClInclude Include="Reactor.hpp" />
<ClInclude Include="Routine.hpp" /> <ClInclude Include="Routine.hpp" />
<ClInclude Include="Thread.hpp" /> <ClInclude Include="Thread.hpp" />
<ClInclude Include="Types.hpp" />
<ClInclude Include="x86.hpp" /> <ClInclude Include="x86.hpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -74,8 +74,5 @@ ...@@ -74,8 +74,5 @@
<ClInclude Include="Thread.hpp"> <ClInclude Include="Thread.hpp">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
// 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
...@@ -78,54 +78,6 @@ void *allocateRaw(size_t bytes, size_t alignment) ...@@ -78,54 +78,6 @@ void *allocateRaw(size_t bytes, size_t alignment)
return aligned; return aligned;
#endif #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 } // anonymous namespace
size_t memoryPageSize() size_t memoryPageSize()
...@@ -173,65 +125,6 @@ void deallocate(void *memory) ...@@ -173,65 +125,6 @@ void deallocate(void *memory)
#endif #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) void clear(uint16_t *memory, uint16_t element, size_t count)
{ {
#if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER) #if defined(_MSC_VER) && defined(__x86__) && !defined(MEMORY_SANITIZER)
......
...@@ -25,10 +25,6 @@ size_t memoryPageSize(); ...@@ -25,10 +25,6 @@ size_t memoryPageSize();
void *allocate(size_t bytes, size_t alignment = 16); void *allocate(size_t bytes, size_t alignment = 16);
void deallocate(void *memory); 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(uint16_t *memory, uint16_t element, size_t count);
void clear(uint32_t *memory, uint32_t element, size_t count); void clear(uint32_t *memory, uint32_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