[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: Ben Clayton <bclayton@google.com>
Tested-by: David Turner <digit@google.com>
Presubmit-Ready: David Turner <digit@google.com>
diff --git a/src/System/Linux/MemFd.cpp b/src/System/Linux/MemFd.cpp
index 22b77e4..a8f99e2 100644
--- a/src/System/Linux/MemFd.cpp
+++ b/src/System/Linux/MemFd.cpp
@@ -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 @@
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 @@
return true;
}
-void MemFd::close()
+void LinuxMemFd::close()
{
if (fd_ >= 0)
{
@@ -97,23 +94,21 @@
// 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
diff --git a/src/System/Linux/MemFd.hpp b/src/System/Linux/MemFd.hpp
index 8b88473..209d642 100644
--- a/src/System/Linux/MemFd.hpp
+++ b/src/System/Linux/MemFd.hpp
@@ -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 @@
int fd_ = -1;
};
-} // namespace linux
-
#endif // MEMFD_LINUX
diff --git a/tests/SystemUnitTests/unittests.cpp b/tests/SystemUnitTests/unittests.cpp
index 53ff9ec..9026b55 100644
--- a/tests/SystemUnitTests/unittests.cpp
+++ b/tests/SystemUnitTests/unittests.cpp
@@ -26,14 +26,14 @@
#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, 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, 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, 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 @@
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));