diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-09-11 04:59:30 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-09-11 04:59:30 +0000 |
commit | cbad701d0b6fd42112e121e2d7af9c70aaee7440 (patch) | |
tree | 28df4a540a1096118994fdbc25d07a2d95779c04 /lib | |
parent | 41b21bf2fcd87578a5baa6823b7e5e5ae75089c6 (diff) | |
download | external_llvm-cbad701d0b6fd42112e121e2d7af9c70aaee7440.zip external_llvm-cbad701d0b6fd42112e121e2d7af9c70aaee7440.tar.gz external_llvm-cbad701d0b6fd42112e121e2d7af9c70aaee7440.tar.bz2 |
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
Diffstat (limited to 'lib')
28 files changed, 794 insertions, 10 deletions
diff --git a/lib/System/AIX/Memory.cpp b/lib/System/AIX/Memory.cpp new file mode 100644 index 0000000..b4e9a9f --- /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 <sys/types.h> +#include <sys/mman.h> + +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 e49a593..aef8e03 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 0000000..53b724a --- /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 0000000..4c0123b --- /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 <sys/types.h> +#include <sys/mman.h> + +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 658c0cb..5b7d02f 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 0000000..46bcbcc --- /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 0000000..a6a8883 --- /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 <sys/mman.h> + +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 165bbc6..33d15d1 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 0000000..a9e6c11 --- /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 0000000..16fa849 --- /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 <sys/mman.h> + +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 3722b1e..61b2502 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 0000000..92341c0 --- /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 0000000..b0791ef --- /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 <sys/mman.h> + +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 ea009e2..47f6c5d 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 0000000..2890a78 --- /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 0000000..1bc6fd9 --- /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 <sys/mman.h> + +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 8ec35b3..665c272 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 0000000..a779f70 --- /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 0000000..6aa5cbc --- /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 fd7fd4f..ace8505 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 0000000..aba9bfa --- /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 0000000..dd15f13 --- /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 <sys/types.h> +#include <sys/mman.h> + +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 3499d52..4ba83ff 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 0000000..f8b11b0 --- /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 0000000..8a9ae05 --- /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 <llvm/System/Process.h> +#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 0000000..8a9ae05 --- /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 <llvm/System/Process.h> +#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 0000000..1a0eda4 --- /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 0000000..1a0eda4 --- /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 |