mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-07 14:33:15 +00:00
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
This commit is contained in:
parent
41b21bf2fc
commit
cbad701d0b
54
lib/System/AIX/Memory.cpp
Normal file
54
lib/System/AIX/Memory.cpp
Normal file
@ -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
|
@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "so";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/AIX/Process.cpp
Normal file
22
lib/System/AIX/Process.cpp
Normal file
@ -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
|
54
lib/System/Cygwin/Memory.cpp
Normal file
54
lib/System/Cygwin/Memory.cpp
Normal file
@ -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
|
@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "dll.a";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/Cygwin/Process.cpp
Normal file
22
lib/System/Cygwin/Process.cpp
Normal file
@ -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
|
62
lib/System/Darwin/Memory.cpp
Normal file
62
lib/System/Darwin/Memory.cpp
Normal file
@ -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
|
@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "dyld";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/Darwin/Process.cpp
Normal file
22
lib/System/Darwin/Process.cpp
Normal file
@ -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
|
53
lib/System/FreeBSD/Memory.cpp
Normal file
53
lib/System/FreeBSD/Memory.cpp
Normal file
@ -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
|
@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "so";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/FreeBSD/Process.cpp
Normal file
22
lib/System/FreeBSD/Process.cpp
Normal file
@ -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
|
53
lib/System/Interix/Memory.cpp
Normal file
53
lib/System/Interix/Memory.cpp
Normal file
@ -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
|
@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "dll";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/Interix/Process.cpp
Normal file
22
lib/System/Interix/Process.cpp
Normal file
@ -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
|
62
lib/System/Linux/Memory.cpp
Normal file
62
lib/System/Linux/Memory.cpp
Normal file
@ -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
|
@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "so";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/Linux/Process.cpp
Normal file
22
lib/System/Linux/Process.cpp
Normal file
@ -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
|
30
lib/System/Memory.cpp
Normal file
30
lib/System/Memory.cpp
Normal file
@ -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
|
@ -21,16 +21,6 @@ using namespace sys;
|
|||||||
//=== independent code.
|
//=== 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.
|
// Include the truly platform-specific parts of this class.
|
||||||
|
29
lib/System/Process.cpp
Normal file
29
lib/System/Process.cpp
Normal file
@ -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
|
54
lib/System/SunOS/Memory.cpp
Normal file
54
lib/System/SunOS/Memory.cpp
Normal file
@ -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
|
@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string
|
||||||
|
Path::GetDLLSuffix() {
|
||||||
|
return "so";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
|
||||||
|
22
lib/System/SunOS/Process.cpp
Normal file
22
lib/System/SunOS/Process.cpp
Normal file
@ -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
|
44
lib/System/Win32/Memory.cpp
Normal file
44
lib/System/Win32/Memory.cpp
Normal file
@ -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);
|
||||||
|
}
|
44
lib/System/Win32/Memory.inc
Normal file
44
lib/System/Win32/Memory.inc
Normal file
@ -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);
|
||||||
|
}
|
33
lib/System/Win32/Path.cpp
Normal file
33
lib/System/Win32/Path.cpp
Normal file
@ -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
|
33
lib/System/Win32/Path.inc
Normal file
33
lib/System/Win32/Path.inc
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user