Commit fb632b91 by David 'Digit' Turner Committed by David Turner

[linux]: Remove linux namespace.

'linux' turns out to be a prebuilt macro for GCC (not Clang) so using "namespace linux { ... }" actually does not compile. This CL fixes the issue by removing the namespace, and using Linux as a prefix for the corresponding class. Bug: 140419396 Change-Id: I1e980bc66b2cf8f2e21d9f7076918e2b476ae4d4 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37288 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Tested-by: 's avatarDavid Turner <digit@google.com> Presubmit-Ready: David Turner <digit@google.com>
parent 1c462ebc
......@@ -37,21 +37,18 @@
#define __NR_memfd_create 319
#endif /* __NR_memfd_create__ */
namespace linux
{
MemFd::~MemFd()
LinuxMemFd::~LinuxMemFd()
{
close();
}
void MemFd::importFd(int fd)
void LinuxMemFd::importFd(int fd)
{
close();
fd_ = fd;
}
int MemFd::exportFd() const
int LinuxMemFd::exportFd() const
{
if (fd_ < 0)
{
......@@ -62,7 +59,7 @@ int MemFd::exportFd() const
return ::fcntl(fd_, F_DUPFD_CLOEXEC, 0);
}
bool MemFd::allocate(const char* name, size_t size)
bool LinuxMemFd::allocate(const char* name, size_t size)
{
close();
......@@ -89,7 +86,7 @@ bool MemFd::allocate(const char* name, size_t size)
return true;
}
void MemFd::close()
void LinuxMemFd::close()
{
if (fd_ >= 0)
{
......@@ -97,23 +94,21 @@ void MemFd::close()
// https://lwn.net/Articles/576478/ for example.
int ret = ::close(fd_);
if (ret < 0) {
TRACE("MemFd::close() failed with: %s", strerror(errno));
TRACE("LinuxMemFd::close() failed with: %s", strerror(errno));
assert(false);
}
fd_ = -1;
}
}
void* MemFd::mapReadWrite(size_t offset, size_t size)
void* LinuxMemFd::mapReadWrite(size_t offset, size_t size)
{
void* addr = ::mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd_,
static_cast<off_t>(offset));
return (addr == MAP_FAILED) ? nullptr : addr;
}
bool MemFd::unmap(void* addr, size_t size)
bool LinuxMemFd::unmap(void* addr, size_t size)
{
return ::munmap(addr, size) == 0;
}
} // namespace linux
......@@ -22,18 +22,15 @@
// supported by the Linux kernel since 3.17 (good enough for Android and desktop
// Linux).
namespace linux
{
class MemFd {
class LinuxMemFd {
public:
MemFd() = default;
LinuxMemFd() = default;
MemFd(const char* name, size_t size) : MemFd() {
LinuxMemFd(const char* name, size_t size) : LinuxMemFd() {
allocate(name, size);
}
~MemFd();
~LinuxMemFd();
// Return true iff the region is valid/allocated.
bool isValid() const { return fd_ >= 0; }
......@@ -68,6 +65,4 @@ private:
int fd_ = -1;
};
} // namespace linux
#endif // MEMFD_LINUX
......@@ -26,14 +26,14 @@ using namespace sw;
#ifdef __linux__
TEST(MemFd, DefaultConstructor) {
linux::MemFd memfd;
LinuxMemFd memfd;
ASSERT_FALSE(memfd.isValid());
ASSERT_EQ(-1, memfd.exportFd());
}
TEST(MemFd, AllocatingConstructor) {
const size_t kRegionSize = sw::memoryPageSize() * 8;
linux::MemFd memfd("test-region", kRegionSize);
LinuxMemFd memfd("test-region", kRegionSize);
ASSERT_TRUE(memfd.isValid());
ASSERT_GE(memfd.fd(), 0);
void* addr = memfd.mapReadWrite(0, kRegionSize);
......@@ -43,7 +43,7 @@ TEST(MemFd, AllocatingConstructor) {
TEST(MemFd, ExplicitAllocation) {
const size_t kRegionSize = sw::memoryPageSize() * 8;
linux::MemFd memfd;
LinuxMemFd memfd;
ASSERT_FALSE(memfd.isValid());
ASSERT_EQ(-1, memfd.exportFd());
ASSERT_TRUE(memfd.allocate("test-region", kRegionSize));
......@@ -52,7 +52,7 @@ TEST(MemFd, ExplicitAllocation) {
TEST(MemFd, Close) {
const size_t kRegionSize = sw::memoryPageSize() * 8;
linux::MemFd memfd("test-region", kRegionSize);
LinuxMemFd memfd("test-region", kRegionSize);
ASSERT_TRUE(memfd.isValid());
int fd = memfd.exportFd();
memfd.close();
......@@ -63,7 +63,7 @@ TEST(MemFd, Close) {
TEST(MemFd, ExportImportFd) {
const size_t kRegionSize = sw::memoryPageSize() * 8;
linux::MemFd memfd("test-region1", kRegionSize);
LinuxMemFd memfd("test-region1", kRegionSize);
auto* addr = reinterpret_cast<uint8_t*>(memfd.mapReadWrite(0, kRegionSize));
ASSERT_TRUE(addr);
for (size_t n = 0; n < kRegionSize; ++n)
......@@ -74,7 +74,7 @@ TEST(MemFd, ExportImportFd) {
ASSERT_TRUE(memfd.unmap(addr, kRegionSize));
memfd.close();
linux::MemFd memfd2;
LinuxMemFd memfd2;
memfd2.importFd(fd);
ASSERT_TRUE(memfd2.isValid());
addr = reinterpret_cast<uint8_t*>(memfd2.mapReadWrite(0, kRegionSize));
......
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