From cbad701d0b6fd42112e121e2d7af9c70aaee7440 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sat, 11 Sep 2004 04:59:30 +0000 Subject: [PATCH] Provide initial implementations of Memory and Process concepts for various platforms. Implement GetLLVMSuffix function for the Path concept. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16292 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/AIX/Memory.cpp | 54 +++++++++++++++++++++++++++++ lib/System/AIX/Path.cpp | 5 +++ lib/System/AIX/Process.cpp | 22 ++++++++++++ lib/System/Cygwin/Memory.cpp | 54 +++++++++++++++++++++++++++++ lib/System/Cygwin/Path.cpp | 5 +++ lib/System/Cygwin/Process.cpp | 22 ++++++++++++ lib/System/Darwin/Memory.cpp | 62 ++++++++++++++++++++++++++++++++++ lib/System/Darwin/Path.cpp | 5 +++ lib/System/Darwin/Process.cpp | 22 ++++++++++++ lib/System/FreeBSD/Memory.cpp | 53 +++++++++++++++++++++++++++++ lib/System/FreeBSD/Path.cpp | 5 +++ lib/System/FreeBSD/Process.cpp | 22 ++++++++++++ lib/System/Interix/Memory.cpp | 53 +++++++++++++++++++++++++++++ lib/System/Interix/Path.cpp | 5 +++ lib/System/Interix/Process.cpp | 22 ++++++++++++ lib/System/Linux/Memory.cpp | 62 ++++++++++++++++++++++++++++++++++ lib/System/Linux/Path.cpp | 5 +++ lib/System/Linux/Process.cpp | 22 ++++++++++++ lib/System/Memory.cpp | 30 ++++++++++++++++ lib/System/Path.cpp | 10 ------ lib/System/Process.cpp | 29 ++++++++++++++++ lib/System/SunOS/Memory.cpp | 54 +++++++++++++++++++++++++++++ lib/System/SunOS/Path.cpp | 5 +++ lib/System/SunOS/Process.cpp | 22 ++++++++++++ lib/System/Win32/Memory.cpp | 44 ++++++++++++++++++++++++ lib/System/Win32/Memory.inc | 44 ++++++++++++++++++++++++ lib/System/Win32/Path.cpp | 33 ++++++++++++++++++ lib/System/Win32/Path.inc | 33 ++++++++++++++++++ 28 files changed, 794 insertions(+), 10 deletions(-) create mode 100644 lib/System/AIX/Memory.cpp create mode 100644 lib/System/AIX/Process.cpp create mode 100644 lib/System/Cygwin/Memory.cpp create mode 100644 lib/System/Cygwin/Process.cpp create mode 100644 lib/System/Darwin/Memory.cpp create mode 100644 lib/System/Darwin/Process.cpp create mode 100644 lib/System/FreeBSD/Memory.cpp create mode 100644 lib/System/FreeBSD/Process.cpp create mode 100644 lib/System/Interix/Memory.cpp create mode 100644 lib/System/Interix/Process.cpp create mode 100644 lib/System/Linux/Memory.cpp create mode 100644 lib/System/Linux/Process.cpp create mode 100644 lib/System/Memory.cpp create mode 100644 lib/System/Process.cpp create mode 100644 lib/System/SunOS/Memory.cpp create mode 100644 lib/System/SunOS/Process.cpp create mode 100644 lib/System/Win32/Memory.cpp create mode 100644 lib/System/Win32/Memory.inc create mode 100644 lib/System/Win32/Path.cpp create mode 100644 lib/System/Win32/Path.inc diff --git a/lib/System/AIX/Memory.cpp b/lib/System/AIX/Memory.cpp new file mode 100644 index 00000000000..b4e9a9f5b48 --- /dev/null +++ b/lib/System/AIX/Memory.cpp @@ -0,0 +1,54 @@ +//===- AIX/Memory.cpp - AIX Memory Implementation ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the AIX specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only AIX specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (pa == (void*)-1) { + throw std::string("Can't allocate RWX Memory: ") + strerror(errno); + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + throw std::string("Can't release RWX Memory: ") + sterror(errno); + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/AIX/Path.cpp b/lib/System/AIX/Path.cpp index e49a593bc89..aef8e033ecd 100644 --- a/lib/System/AIX/Path.cpp +++ b/lib/System/AIX/Path.cpp @@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "so"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/AIX/Process.cpp b/lib/System/AIX/Process.cpp new file mode 100644 index 00000000000..53b724ade6b --- /dev/null +++ b/lib/System/AIX/Process.cpp @@ -0,0 +1,22 @@ +//===- AIX/Process.cpp - AIX Process Implementation ----------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the AIX specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only AIX specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Cygwin/Memory.cpp b/lib/System/Cygwin/Memory.cpp new file mode 100644 index 00000000000..4c0123b7f92 --- /dev/null +++ b/lib/System/Cygwin/Memory.cpp @@ -0,0 +1,54 @@ +//===- Cygwin/Memory.cpp - Cygwin Memory Implementation ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Cygwin specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Cygwin specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (pa == (void*)-1) { + throw std::string("Can't allocate RWX Memory: ") + strerror(errno); + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + throw std::string("Can't release RWX Memory: ") + sterror(errno); + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Cygwin/Path.cpp b/lib/System/Cygwin/Path.cpp index 658c0cbe43b..5b7d02ff937 100644 --- a/lib/System/Cygwin/Path.cpp +++ b/lib/System/Cygwin/Path.cpp @@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "dll.a"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Cygwin/Process.cpp b/lib/System/Cygwin/Process.cpp new file mode 100644 index 00000000000..46bcbcc4fc8 --- /dev/null +++ b/lib/System/Cygwin/Process.cpp @@ -0,0 +1,22 @@ +//===- Cygwin/Process.cpp - Cygwin Process Implementation ----- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Cygwin specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Cygwin specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Darwin/Memory.cpp b/lib/System/Darwin/Memory.cpp new file mode 100644 index 00000000000..a6a88835ad9 --- /dev/null +++ b/lib/System/Darwin/Memory.cpp @@ -0,0 +1,62 @@ +//===- Darwin/Memory.cpp - Darwin Memory Implementation ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Darwin specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Darwin specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute +/// permissions. This is typically used for JIT applications where we want +/// to emit code to the memory then jump to it. Getting this type of memory +/// is very OS specific. +/// +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANON, -1, 0); + if (pa == MAP_FAILED) { + char msg[MAXPATHLEN]; + strerror_r(errno, msg, MAXPATHLEN-1); + throw std::string("Can't allocate RWX Memory: ") + msg; + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + char msg[MAXPATHLEN]; + strerror_r(errno, msg, MAXPATHLEN-1); + throw std::string("Can't release RWX Memory: ") + msg; + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Darwin/Path.cpp b/lib/System/Darwin/Path.cpp index 165bbc64b5e..33d15d1fb97 100644 --- a/lib/System/Darwin/Path.cpp +++ b/lib/System/Darwin/Path.cpp @@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "dyld"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Darwin/Process.cpp b/lib/System/Darwin/Process.cpp new file mode 100644 index 00000000000..a9e6c11e919 --- /dev/null +++ b/lib/System/Darwin/Process.cpp @@ -0,0 +1,22 @@ +//===- Darwin/Process.cpp - Darwin Process Implementation ----- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Darwin specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Darwin specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/FreeBSD/Memory.cpp b/lib/System/FreeBSD/Memory.cpp new file mode 100644 index 00000000000..16fa849c55c --- /dev/null +++ b/lib/System/FreeBSD/Memory.cpp @@ -0,0 +1,53 @@ +//===- FreeBSD/Memory.cpp - FreeBSD Memory Implementation -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the FreeBSD specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only FreeBSD specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANON|MAP_NOCORE, -1, 0); + if (pa == (void*)-1) { + throw std::string("Can't allocate RWX Memory: ") + strerror(errno); + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + throw std::string("Can't release RWX Memory: ") + sterror(errno); + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/FreeBSD/Path.cpp b/lib/System/FreeBSD/Path.cpp index 3722b1e6a57..61b25024b1e 100644 --- a/lib/System/FreeBSD/Path.cpp +++ b/lib/System/FreeBSD/Path.cpp @@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "so"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/FreeBSD/Process.cpp b/lib/System/FreeBSD/Process.cpp new file mode 100644 index 00000000000..92341c0dd71 --- /dev/null +++ b/lib/System/FreeBSD/Process.cpp @@ -0,0 +1,22 @@ +//===- FreeBSD/Process.cpp - FreeBSD Process Implementation --- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the FreeBSD specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only FreeBSD specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Interix/Memory.cpp b/lib/System/Interix/Memory.cpp new file mode 100644 index 00000000000..b0791ef7d14 --- /dev/null +++ b/lib/System/Interix/Memory.cpp @@ -0,0 +1,53 @@ +//===- Interix/Memory.cpp - Interix Memory Implementation -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Interix specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Interix specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANON|MAP_NOCORE, -1, 0); + if (pa == (void*)-1) { + throw std::string("Can't allocate RWX Memory: ") + strerror(errno); + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + throw std::string("Can't release RWX Memory: ") + sterror(errno); + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Interix/Path.cpp b/lib/System/Interix/Path.cpp index ea009e232de..47f6c5d7db1 100644 --- a/lib/System/Interix/Path.cpp +++ b/lib/System/Interix/Path.cpp @@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "dll"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Interix/Process.cpp b/lib/System/Interix/Process.cpp new file mode 100644 index 00000000000..2890a785797 --- /dev/null +++ b/lib/System/Interix/Process.cpp @@ -0,0 +1,22 @@ +//===- Interix/Process.cpp - Interix Process Implementation --- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Interix specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Interix specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Linux/Memory.cpp b/lib/System/Linux/Memory.cpp new file mode 100644 index 00000000000..1bc6fd98bb4 --- /dev/null +++ b/lib/System/Linux/Memory.cpp @@ -0,0 +1,62 @@ +//===- Linux/Memory.cpp - Linux Memory Implementation -----*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Linux specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Linux specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute +/// permissions. This is typically used for JIT applications where we want +/// to emit code to the memory then jump to it. Getting this type of memory +/// is very OS specific. +/// +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, 0, 0); + if (pa == MAP_FAILED) { + char msg[MAXPATHLEN]; + strerror_r(errno, msg, MAXPATHLEN-1); + throw std::string("Can't allocate RWX Memory: ") + msg; + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + char msg[MAXPATHLEN]; + strerror_r(errno, msg, MAXPATHLEN-1); + throw std::string("Can't release RWX Memory: ") + msg; + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Linux/Path.cpp b/lib/System/Linux/Path.cpp index 8ec35b3c4a4..665c272841e 100644 --- a/lib/System/Linux/Path.cpp +++ b/lib/System/Linux/Path.cpp @@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "so"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Linux/Process.cpp b/lib/System/Linux/Process.cpp new file mode 100644 index 00000000000..a779f70581a --- /dev/null +++ b/lib/System/Linux/Process.cpp @@ -0,0 +1,22 @@ +//===- Linux/Process.cpp - Linux Process Implementation ------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Linux specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/SUS/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Linux specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Memory.cpp b/lib/System/Memory.cpp new file mode 100644 index 00000000000..6aa5cbc73ee --- /dev/null +++ b/lib/System/Memory.cpp @@ -0,0 +1,30 @@ +//===- Memory.cpp - Memory Handling Support ---------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines some helpful functions for allocating memory and dealing +// with memory mapped files +// +//===----------------------------------------------------------------------===// + +#include "llvm/System/Memory.h" + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only TRULY operating system +//=== independent code. +//===----------------------------------------------------------------------===// + +} + +// Include the platform-specific parts of this class. +#include "platform/Memory.cpp" + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp index fd7fd4f665b..ace8505d613 100644 --- a/lib/System/Path.cpp +++ b/lib/System/Path.cpp @@ -21,16 +21,6 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// -bool -Path::is_file() const { - return (is_valid() && path[path.length()-1] != '/'); -} - -bool -Path::is_directory() const { - return (is_valid() && path[path.length()-1] == '/'); -} - } // Include the truly platform-specific parts of this class. diff --git a/lib/System/Process.cpp b/lib/System/Process.cpp new file mode 100644 index 00000000000..aba9bfa27c3 --- /dev/null +++ b/lib/System/Process.cpp @@ -0,0 +1,29 @@ +//===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header file implements the operating system Process concept. +// +//===----------------------------------------------------------------------===// + +#include "llvm/System/Process.h" + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only TRULY operating system +//=== independent code. +//===----------------------------------------------------------------------===// + +} + +// Include the platform-specific parts of this class. +#include "platform/Process.cpp" + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/SunOS/Memory.cpp b/lib/System/SunOS/Memory.cpp new file mode 100644 index 00000000000..dd15f13495b --- /dev/null +++ b/lib/System/SunOS/Memory.cpp @@ -0,0 +1,54 @@ +//===- SunOS/Memory.cpp - SunOS Memory Implementation -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the SunOS specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +// Include the generic unix implementation +#include "../Unix/Memory.cpp" +#include "llvm/System/Process.h" +#include +#include + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only SunOS specific code +//=== and must not be generic UNIX code (see ../Unix/Memory.cpp) +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + static const long pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + + void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (pa == (void*)-1) { + throw std::string("Can't allocate RWX Memory: ") + strerror(errno); + } + M.Address = pa; + M.AllocSize = NumPages*pageSize; + return pa; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 || M.AllocSize == 0) return; + if (0 != munmap(M.Address, M.AllocSize)) { + throw std::string("Can't release RWX Memory: ") + sterror(errno); + } +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/SunOS/Path.cpp b/lib/System/SunOS/Path.cpp index 3499d525874..4ba83ff89ee 100644 --- a/lib/System/SunOS/Path.cpp +++ b/lib/System/SunOS/Path.cpp @@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() { return result; } +std::string +Path::GetDLLSuffix() { + return "so"; +} + } // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/SunOS/Process.cpp b/lib/System/SunOS/Process.cpp new file mode 100644 index 00000000000..f8b11b0125d --- /dev/null +++ b/lib/System/SunOS/Process.cpp @@ -0,0 +1,22 @@ +//===- SunOS/Process.cpp - SunOS Process Implementation ------- -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the SunOS specific implementation of the Process class. +// +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Process.cpp" + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only SunOS specific code +//=== and must not be generic UNIX code (see ../Unix/Process.cpp) +//===----------------------------------------------------------------------===// + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Win32/Memory.cpp b/lib/System/Win32/Memory.cpp new file mode 100644 index 00000000000..8a9ae05f374 --- /dev/null +++ b/lib/System/Win32/Memory.cpp @@ -0,0 +1,44 @@ +//===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Win32 specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +#include +#include "windows.h" + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Win32 specific code. +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + unsigned pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + void *P = VirtualAlloc(0, NumPages*pageSize, MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (P == 0) { + throw std::string("Couldn't allocate ") + utostr(NumBytes) + + " bytes of executable memory!"; + } + M.Address = P; + M.AllocSize = NumBytes; + return P; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 ) return; + VirtualFree(M.Address, M.AllocSize, MEM_DECOMMIT, PAGE_NOACCESS); +} diff --git a/lib/System/Win32/Memory.inc b/lib/System/Win32/Memory.inc new file mode 100644 index 00000000000..8a9ae05f374 --- /dev/null +++ b/lib/System/Win32/Memory.inc @@ -0,0 +1,44 @@ +//===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Win32 specific implementation of various Memory +// management utilities +// +//===----------------------------------------------------------------------===// + +#include +#include "windows.h" + +namespace llvm { +using namespace sys; + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Win32 specific code. +//===----------------------------------------------------------------------===// + +void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) { + if (NumBytes == 0) return 0; + + unsigned pageSize = Process::GetPageSize(); + unsigned NumPages = (NumBytes+pageSize-1)/pageSize; + void *P = VirtualAlloc(0, NumPages*pageSize, MEM_COMMIT, + PAGE_EXECUTE_READWRITE); + if (P == 0) { + throw std::string("Couldn't allocate ") + utostr(NumBytes) + + " bytes of executable memory!"; + } + M.Address = P; + M.AllocSize = NumBytes; + return P; +} + +void Memory::ReleaseRWX(Memory& M) { + if (M.Address == 0 ) return; + VirtualFree(M.Address, M.AllocSize, MEM_DECOMMIT, PAGE_NOACCESS); +} diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp new file mode 100644 index 00000000000..1a0eda40f35 --- /dev/null +++ b/lib/System/Win32/Path.cpp @@ -0,0 +1,33 @@ +//===- Win32/Path.cpp - Win32 Path Implementation ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Win32 specific implementation of the Path class. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Win32 specific code +//=== and must not be generic UNIX code (see ../Unix/Path.cpp) +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Path.cpp" + +namespace llvm { +using namespace sys; + + +std::string +Path::GetDLLSuffix() { + return "dll"; +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc new file mode 100644 index 00000000000..1a0eda40f35 --- /dev/null +++ b/lib/System/Win32/Path.inc @@ -0,0 +1,33 @@ +//===- Win32/Path.cpp - Win32 Path Implementation ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Reid Spencer and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file provides the Win32 specific implementation of the Path class. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +//=== WARNING: Implementation here must contain only Win32 specific code +//=== and must not be generic UNIX code (see ../Unix/Path.cpp) +//===----------------------------------------------------------------------===// + +// Include the generic Unix implementation +#include "../Unix/Path.cpp" + +namespace llvm { +using namespace sys; + + +std::string +Path::GetDLLSuffix() { + return "dll"; +} + +} + +// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab -- 2.34.1