aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/SystemUtils.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-05-28 01:20:58 +0000
committerChris Lattner <sabre@nondot.org>2004-05-28 01:20:58 +0000
commit49f61c4ea499d93f10dfe1b1da2563d4875c3f7e (patch)
treeb07845c150ad41e56b1111c48b0a42149f8c4f1f /lib/Support/SystemUtils.cpp
parentc89fe6da17970f61ec1f4e6a5bf75156cc96a1b4 (diff)
downloadexternal_llvm-49f61c4ea499d93f10dfe1b1da2563d4875c3f7e.zip
external_llvm-49f61c4ea499d93f10dfe1b1da2563d4875c3f7e.tar.gz
external_llvm-49f61c4ea499d93f10dfe1b1da2563d4875c3f7e.tar.bz2
Add support for getting executable memory on Windows. This is actually
much easier than on unix. :) The only evil thing is that windows.h defines a macro named FindExecutable, which collides with one of our names. The JIT now runs on windows, but it cannot resolve external functions (like printf) yet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13871 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SystemUtils.cpp')
-rw-r--r--lib/Support/SystemUtils.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index 2400445..c0fb772 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -25,6 +25,7 @@
#include <iostream>
#include <cstdlib>
#include <cerrno>
+#include "Config/windows.h"
using namespace llvm;
/// isExecutableFile - This function returns true if the filename specified
@@ -63,6 +64,7 @@ bool llvm::isStandardOutAConsole() {
/// directory, nor in the PATH. If the executable cannot be found, return an
/// empty string.
///
+#undef FindExecutable // needed on windows :(
std::string llvm::FindExecutable(const std::string &ExeName,
const std::string &ProgramPath) {
// First check the directory that bugpoint is in. We can do this if
@@ -277,6 +279,17 @@ int llvm::ExecWait(const char * const old_argv[],
///
void *llvm::AllocateRWXMemory(unsigned NumBytes) {
if (NumBytes == 0) return 0;
+
+#if defined(HAVE_WINDOWS_H)
+ // On windows we use VirtualAlloc.
+ void *P = VirtualAlloc(0, NumBytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ if (P == 0) {
+ std::cerr << "Error allocating executable memory!\n";
+ abort();
+ }
+ return P;
+
+#elif defined(HAVE_MMAP)
static const long pageSize = sysconf(_SC_PAGESIZE);
unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
@@ -289,12 +302,11 @@ void *llvm::AllocateRWXMemory(unsigned NumBytes) {
#elif defined(sparc) || defined(__sparc__) || defined(__sparcv9)
/* nothing */
#else
- std::cerr << "This architecture is not supported by the JIT!\n";
+ std::cerr << "This architecture has an unknown MMAP implementation!\n";
abort();
return 0;
#endif
-#ifdef HAVE_MMAP
int fd = -1;
#if defined(__linux__)
fd = 0;