aboutsummaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/CrashRecoveryContext.cpp6
-rw-r--r--lib/Support/DynamicLibrary.cpp1
-rw-r--r--lib/Support/LockFileManager.cpp4
-rw-r--r--lib/Support/MemoryBuffer.cpp17
-rw-r--r--lib/Support/Mutex.cpp2
-rw-r--r--lib/Support/Unix/Host.inc6
-rw-r--r--lib/Support/Unix/Memory.inc10
-rw-r--r--lib/Support/Unix/Path.inc51
-rw-r--r--lib/Support/Unix/PathV2.inc45
-rw-r--r--lib/Support/Unix/Process.inc22
-rw-r--r--lib/Support/Unix/Program.inc24
-rw-r--r--lib/Support/Unix/Signals.inc6
-rw-r--r--lib/Support/Unix/TimeValue.inc7
13 files changed, 187 insertions, 14 deletions
diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp
index e175056279..508bec4028 100644
--- a/lib/Support/CrashRecoveryContext.cpp
+++ b/lib/Support/CrashRecoveryContext.cpp
@@ -267,6 +267,7 @@ void CrashRecoveryContext::Enable() {
gCrashRecoveryEnabled = true;
+#if !defined(__native_client__)
// Setup the signal handler.
struct sigaction Handler;
Handler.sa_handler = CrashRecoverySignalHandler;
@@ -276,6 +277,9 @@ void CrashRecoveryContext::Enable() {
for (unsigned i = 0; i != NumSignals; ++i) {
sigaction(Signals[i], &Handler, &PrevActions[i]);
}
+#else
+#warning Cannot setup the signal handler on this machine
+#endif
}
void CrashRecoveryContext::Disable() {
@@ -286,9 +290,11 @@ void CrashRecoveryContext::Disable() {
gCrashRecoveryEnabled = false;
+#if !defined(__native_client__)
// Restore the previous signal handlers.
for (unsigned i = 0; i != NumSignals; ++i)
sigaction(Signals[i], &PrevActions[i], 0);
+#endif
}
#endif
diff --git a/lib/Support/DynamicLibrary.cpp b/lib/Support/DynamicLibrary.cpp
index 45fec361c1..d8884381ab 100644
--- a/lib/Support/DynamicLibrary.cpp
+++ b/lib/Support/DynamicLibrary.cpp
@@ -187,3 +187,4 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
}
#endif // LLVM_ON_WIN32
+
diff --git a/lib/Support/LockFileManager.cpp b/lib/Support/LockFileManager.cpp
index 59bfcfcd25..7610d281f0 100644
--- a/lib/Support/LockFileManager.cpp
+++ b/lib/Support/LockFileManager.cpp
@@ -19,7 +19,7 @@
#include <unistd.h>
#endif
using namespace llvm;
-
+#ifndef __native_client__
/// \brief Attempt to read the lock file with the given name, if it exists.
///
/// \param LockFileName The name of the lock file to read.
@@ -214,3 +214,5 @@ void LockFileManager::waitForUnlock() {
// Give up.
}
+
+#endif
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index e7080701eb..8b009b84a5 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -240,7 +240,7 @@ error_code MemoryBuffer::getFile(const char *Filename,
static bool shouldUseMmap(int FD,
size_t FileSize,
size_t MapSize,
- off_t Offset,
+ int64_t Offset,
bool RequiresNullTerminator,
int PageSize) {
// We don't use mmap for small files because this can severely fragment our
@@ -252,6 +252,10 @@ static bool shouldUseMmap(int FD,
return true;
+// LLVM uses mmap to read the file contents. This disallows use of the
+// wrapper syscalls defined in tools/llc/nacl_file.c. Thus, when NACL_SRPC
+// is specified, code sequence execising the read syscall below is used.
+#if !defined(NACL_SRPC)
// If we don't know the file size, use fstat to find out. fstat on an open
// file descriptor is cheaper than stat on a random path.
// FIXME: this chunk of code is duplicated, but it avoids a fstat when
@@ -264,6 +268,9 @@ static bool shouldUseMmap(int FD,
}
FileSize = FileInfo.st_size;
}
+#else
+ assert(FileSize != -1 && "invalid file size!");
+#endif
// If we need a null terminator and the end of the map is inside the file,
// we cannot use mmap.
@@ -291,6 +298,7 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
if (MapSize == uint64_t(-1)) {
// If we don't know the file size, use fstat to find out. fstat on an open
// file descriptor is cheaper than stat on a random path.
+#if !defined(NACL_SRPC)
if (FileSize == uint64_t(-1)) {
struct stat FileInfo;
// TODO: This should use fstat64 when available.
@@ -299,13 +307,16 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
}
FileSize = FileInfo.st_size;
}
+#else
+ assert(FileSize != -1 && "invalid file size!");
+#endif
MapSize = FileSize;
}
if (shouldUseMmap(FD, FileSize, MapSize, Offset, RequiresNullTerminator,
PageSize)) {
- off_t RealMapOffset = Offset & ~(PageSize - 1);
- off_t Delta = Offset - RealMapOffset;
+ int64_t RealMapOffset = Offset & ~(PageSize - 1);
+ int64_t Delta = Offset - RealMapOffset;
size_t RealMapSize = MapSize + Delta;
if (const char *Pages = sys::Path::MapInFilePages(FD,
diff --git a/lib/Support/Mutex.cpp b/lib/Support/Mutex.cpp
index 4e4a026b2f..586392fc1e 100644
--- a/lib/Support/Mutex.cpp
+++ b/lib/Support/Mutex.cpp
@@ -60,7 +60,7 @@ MutexImpl::MutexImpl( bool recursive)
assert(errorcode == 0);
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \
- !defined(__DragonFly__) && !defined(__Bitrig__)
+ !defined(__DragonFly__) && !defined(__Bitrig__) && !defined(__native_client__)
// Make it a process local mutex
errorcode = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE);
assert(errorcode == 0);
diff --git a/lib/Support/Unix/Host.inc b/lib/Support/Unix/Host.inc
index 726e2fbcf0..aa06763258 100644
--- a/lib/Support/Unix/Host.inc
+++ b/lib/Support/Unix/Host.inc
@@ -19,7 +19,9 @@
#include "llvm/Config/config.h"
#include "llvm/ADT/StringRef.h"
#include "Unix.h"
+#if !defined(__native_client__)
#include <sys/utsname.h>
+#endif // (__native_client__)
#include <cctype>
#include <string>
#include <cstdlib> // ::getenv
@@ -27,12 +29,16 @@
using namespace llvm;
static std::string getOSVersion() {
+#if !defined(__native_client__)
struct utsname info;
if (uname(&info))
return "";
return info.release;
+#else // (__native_client__)
+ return "";
+#endif // (__native_client__)
}
std::string sys::getDefaultTargetTriple() {
diff --git a/lib/Support/Unix/Memory.inc b/lib/Support/Unix/Memory.inc
index 9a8abd27f1..f4cfbc65cf 100644
--- a/lib/Support/Unix/Memory.inc
+++ b/lib/Support/Unix/Memory.inc
@@ -12,9 +12,11 @@
//===----------------------------------------------------------------------===//
#include "Unix.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/Debug.h"
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
@@ -145,8 +147,12 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
return error_code(EINVAL, generic_category());
int Protect = getPosixProtectionFlags(Flags);
-
+#ifndef __native_client__
int Result = ::mprotect(M.Address, M.Size, Protect);
+#else
+ int Result = -1;
+ llvm_unreachable("Native client does not support mprotect");
+#endif
if (Result != 0)
return error_code(errno, system_category());
@@ -194,8 +200,10 @@ Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock,
void *pa = ::mmap(start, pageSize*NumPages, PROT_READ|PROT_EXEC,
flags, fd, 0);
#else
+dbgs() << "calling mmap, start " << start << "\n";
void *pa = ::mmap(start, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
flags, fd, 0);
+ DEBUG(dbgs() << "mmap returned " << pa<<"\n");
#endif
if (pa == MAP_FAILED) {
if (NearBlock) //Try again without a near hint
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index 6a5ebb8cd9..b82371a7b6 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -133,7 +133,9 @@ Path::GetRootDirectory() {
Path
Path::GetTemporaryDirectory(std::string *ErrMsg) {
-#if defined(HAVE_MKDTEMP)
+#if defined(__native_client__)
+ return Path("");
+#elif defined(HAVE_MKDTEMP)
// The best way is with mkdtemp but that's not available on many systems,
// Linux and FreeBSD have it. Others probably won't.
char pathname[] = "/tmp/llvm_XXXXXX";
@@ -251,6 +253,7 @@ Path::GetUserHomeDirectory() {
Path
Path::GetCurrentDirectory() {
+#if !defined(__native_client__)
char pathname[MAXPATHLEN];
if (!getcwd(pathname, MAXPATHLEN)) {
assert(false && "Could not query current working directory.");
@@ -258,6 +261,9 @@ Path::GetCurrentDirectory() {
}
return Path(pathname);
+#else // (__native_client__)
+ return Path("./");
+#endif // (__native_client__)
}
#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
@@ -319,7 +325,9 @@ getprogpath(char ret[PATH_MAX], const char *bin)
/// GetMainExecutable - Return the path to the main executable, given the
/// value of argv[0] from program startup.
Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
-#if defined(__APPLE__)
+#if defined(__native_client__)
+ return Path(std::string("./") + std::string(argv0));
+#elif defined(__APPLE__)
// On OS X the executable path is saved to the stack by dyld. Reading it
// from there is much faster than calling dladdr, especially for large
// binaries with symbols.
@@ -420,7 +428,11 @@ bool Path::getMagicNumber(std::string &Magic, unsigned len) const {
bool
Path::exists() const {
+#if !defined(__native_client__)
return 0 == access(path.c_str(), F_OK );
+#else // (__native_client__)
+ return true;
+#endif // (__native_client__)
}
bool
@@ -433,21 +445,33 @@ Path::isDirectory() const {
bool
Path::isSymLink() const {
+#if defined(__native_client__)
+ return false;
+#else
struct stat buf;
if (0 != lstat(path.c_str(), &buf))
return false;
return S_ISLNK(buf.st_mode);
+#endif
}
bool
Path::canRead() const {
+#if !defined(__native_client__)
return 0 == access(path.c_str(), R_OK);
+#else // (__native_client__)
+ return true;
+#endif // (__native_client__)
}
bool
Path::canWrite() const {
+#if !defined(__native_client__)
return 0 == access(path.c_str(), W_OK);
+#else // (__native_client__)
+ return true;
+#endif // (__native_client__)
}
bool
@@ -466,6 +490,7 @@ Path::isRegularFile() const {
bool
Path::canExecute() const {
+#if !defined(__native_client__)
if (0 != access(path.c_str(), R_OK | X_OK ))
return false;
struct stat buf;
@@ -473,6 +498,7 @@ Path::canExecute() const {
return false;
if (!S_ISREG(buf.st_mode))
return false;
+#endif // (__native_client__)
return true;
}
@@ -520,6 +546,7 @@ PathWithStatus::getFileStatus(bool update, std::string *ErrStr) const {
}
static bool AddPermissionBits(const Path &File, int bits) {
+#if !defined(__native_client__)
// Get the umask value from the operating system. We want to use it
// when changing the file's permissions. Since calling umask() sets
// the umask and returns its old value, we must call it a second
@@ -535,6 +562,7 @@ static bool AddPermissionBits(const Path &File, int bits) {
// that the umask would not disable.
if ((chmod(File.c_str(), (buf.st_mode | (bits & ~mask)))) == -1)
return false;
+#endif // (__native_client__)
return true;
}
@@ -558,6 +586,7 @@ bool Path::makeExecutableOnDisk(std::string* ErrMsg) {
bool
Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
+#if !defined(__native_client__)
DIR* direntries = ::opendir(path.c_str());
if (direntries == 0)
return MakeErrMsg(ErrMsg, path + ": can't open directory");
@@ -583,6 +612,7 @@ Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
}
closedir(direntries);
+#endif
return false;
}
@@ -635,7 +665,7 @@ Path::eraseSuffix() {
}
static bool createDirectoryHelper(char* beg, char* end, bool create_parents) {
-
+#if !defined(__native_client__)
if (access(beg, R_OK | W_OK) == 0)
return false;
@@ -660,6 +690,9 @@ static bool createDirectoryHelper(char* beg, char* end, bool create_parents) {
}
return mkdir(beg, S_IRWXU | S_IRWXG) != 0;
+#else // (__native_client__)
+ return false;
+#endif // (__native_client__)
}
bool
@@ -683,11 +716,13 @@ Path::createDirectoryOnDisk( bool create_parents, std::string* ErrMsg ) {
bool
Path::createFileOnDisk(std::string* ErrMsg) {
+#if !defined(__native_client__)
// Create the file
int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR);
if (fd < 0)
return MakeErrMsg(ErrMsg, path + ": can't create file");
::close(fd);
+#endif // (__native_client__)
return false;
}
@@ -707,6 +742,7 @@ Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) {
bool
Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
+#if !defined(__native_client__)
// Get the status so we can determine if it's a file or directory.
struct stat buf;
if (0 != stat(path.c_str(), &buf)) {
@@ -751,18 +787,26 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
if (rmdir(pathname.c_str()) != 0)
return MakeErrMsg(ErrStr, pathname + ": can't erase directory");
return false;
+#else // (__native_client__)
+ MakeErrMsg(ErrStr, ": PNACL does not know how to erase directories!");
+ return false;
+#endif // (__native_client__)
+
}
bool
Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
+#if !defined(__native_client__)
if (0 != ::rename(path.c_str(), newName.c_str()))
return MakeErrMsg(ErrMsg, std::string("can't rename '") + path + "' as '" +
newName.str() + "'");
+#endif
return false;
}
bool
Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrStr) const {
+#if !defined(__native_client__)
struct utimbuf utb;
utb.actime = si.modTime.toPosixTime();
utb.modtime = utb.actime;
@@ -770,6 +814,7 @@ Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrStr) const {
return MakeErrMsg(ErrStr, path + ": can't set file modification time");
if (0 != ::chmod(path.c_str(),si.mode))
return MakeErrMsg(ErrStr, path + ": can't set mode");
+#endif // (__native_client__)
return false;
}
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc
index d04f590f87..59c5ae5808 100644
--- a/lib/Support/Unix/PathV2.inc
+++ b/lib/Support/Unix/PathV2.inc
@@ -117,7 +117,9 @@ error_code current_path(SmallVectorImpl<char> &result) {
// For GNU Hurd
result.reserve(1024);
#endif
-
+#ifdef __native_client__
+ llvm_unreachable("current_path() not implemented for Native Client");
+#else
while (true) {
if (::getcwd(result.data(), result.capacity()) == 0) {
// See if there was a real error.
@@ -130,6 +132,7 @@ error_code current_path(SmallVectorImpl<char> &result) {
}
result.set_size(strlen(result.data()));
+#endif
return error_code::success();
}
@@ -193,6 +196,9 @@ error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
}
error_code create_directory(const Twine &path, bool &existed) {
+#ifdef __native_client__
+ llvm_unreachable("create_directory() not implemented for Native Client");
+#else
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
@@ -204,9 +210,13 @@ error_code create_directory(const Twine &path, bool &existed) {
existed = false;
return error_code::success();
+#endif
}
error_code create_hard_link(const Twine &to, const Twine &from) {
+#ifdef __native_client__
+ llvm_unreachable("create_hard_link() not implemented for Native Client");
+#else
// Get arguments.
SmallString<128> from_storage;
SmallString<128> to_storage;
@@ -217,9 +227,13 @@ error_code create_hard_link(const Twine &to, const Twine &from) {
return error_code(errno, system_category());
return error_code::success();
+#endif
}
error_code create_symlink(const Twine &to, const Twine &from) {
+#ifdef __native_client__
+ llvm_unreachable("create_symlink() not implemented for Native Client");
+#else
// Get arguments.
SmallString<128> from_storage;
SmallString<128> to_storage;
@@ -230,9 +244,13 @@ error_code create_symlink(const Twine &to, const Twine &from) {
return error_code(errno, system_category());
return error_code::success();
+#endif
}
error_code remove(const Twine &path, bool &existed) {
+#ifdef __native_client__
+ llvm_unreachable("remove() not implemented for Native Client");
+#else
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
@@ -242,11 +260,14 @@ error_code remove(const Twine &path, bool &existed) {
existed = false;
} else
existed = true;
-
return error_code::success();
+#endif
}
error_code rename(const Twine &from, const Twine &to) {
+#ifdef __native_client__
+ llvm_unreachable("rename() not implemented for Native Client");
+#else
// Get arguments.
SmallString<128> from_storage;
SmallString<128> to_storage;
@@ -266,9 +287,13 @@ error_code rename(const Twine &from, const Twine &to) {
}
return error_code::success();
+#endif
}
error_code resize_file(const Twine &path, uint64_t size) {
+#ifdef __native_client__
+ llvm_unreachable("resize_file() not implemented for Native Client");
+#else
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
@@ -276,6 +301,7 @@ error_code resize_file(const Twine &path, uint64_t size) {
return error_code(errno, system_category());
return error_code::success();
+#endif
}
error_code exists(const Twine &path, bool &result) {
@@ -390,6 +416,9 @@ error_code permissions(const Twine &path, perms prms) {
error_code unique_file(const Twine &model, int &result_fd,
SmallVectorImpl<char> &result_path,
bool makeAbsolute, unsigned mode) {
+#ifdef __native_client__
+ llvm_unreachable("unique_file() not implemented for Native Client");
+#else
SmallString<128> Model;
model.toVector(Model);
// Null terminate.
@@ -463,9 +492,14 @@ rety_open_create:
result_fd = RandomFD;
return error_code::success();
+#endif
}
error_code mapped_file_region::init(int fd, uint64_t offset) {
+#ifdef __native_client__
+ // Newlib does not have ftruncate.
+ llvm_unreachable("mapped_file_region not implemented for native client");
+#else
AutoFD FD(fd);
// Figure out how large the file is.
@@ -491,6 +525,7 @@ error_code mapped_file_region::init(int fd, uint64_t offset) {
if (Mapping == MAP_FAILED)
return error_code(errno, system_category());
return error_code::success();
+#endif // __native_client__
}
mapped_file_region::mapped_file_region(const Twine &path,
@@ -501,6 +536,9 @@ mapped_file_region::mapped_file_region(const Twine &path,
: Mode(mode)
, Size(length)
, Mapping() {
+#ifdef __native_client__
+ llvm_unreachable("mapped_file_region not implemented for native client");
+#endif
// Make sure that the requested size fits within SIZE_T.
if (length > std::numeric_limits<size_t>::max()) {
ec = make_error_code(errc::invalid_argument);
@@ -529,6 +567,9 @@ mapped_file_region::mapped_file_region(int fd,
: Mode(mode)
, Size(length)
, Mapping() {
+#ifdef __native_client__
+ llvm_unreachable("mapped_file_region not implemented for native client");
+#endif
// Make sure that the requested size fits within SIZE_T.
if (length > std::numeric_limits<size_t>::max()) {
ec = make_error_code(errc::invalid_argument);
diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc
index 5204147ce3..b2983b21f7 100644
--- a/lib/Support/Unix/Process.inc
+++ b/lib/Support/Unix/Process.inc
@@ -36,6 +36,8 @@
# include <termios.h>
#endif
+#include <sys/unistd.h>
+
//===----------------------------------------------------------------------===//
//=== WARNING: Implementation here must contain only generic UNIX code that
//=== is guaranteed to work on *all* UNIX variants.
@@ -54,9 +56,10 @@ Process::GetPageSize()
const int page_size = 0x1000;
#elif defined(HAVE_GETPAGESIZE)
const int page_size = ::getpagesize();
-#elif defined(HAVE_SYSCONF)
+#elif defined(HAVE_SYSCONF) && !defined(__native_client__)
long page_size = ::sysconf(_SC_PAGE_SIZE);
#else
+ const int page_size = 0;
#warning Cannot get the page size on this machine
#endif
return static_cast<unsigned>(page_size);
@@ -111,7 +114,7 @@ Process::GetTimeUsage(TimeValue& elapsed, TimeValue& user_time,
TimeValue& sys_time)
{
elapsed = TimeValue::now();
-#if defined(HAVE_GETRUSAGE)
+#if defined(HAVE_GETRUSAGE) && !defined(__native_client__)
struct rusage usage;
::getrusage(RUSAGE_SELF, &usage);
user_time = TimeValue(
@@ -132,11 +135,23 @@ Process::GetTimeUsage(TimeValue& elapsed, TimeValue& user_time,
}
int Process::GetCurrentUserId() {
+#if !defined(__native_client__)
return getuid();
+#else // (__native_client__)
+// TODO(abetul): What the proper return value should be for this function?
+// What about having a reserved user_id or the user "nobody" for PNACL?
+ return -1;
+#endif // (__native_client__)
}
int Process::GetCurrentGroupId() {
+#if !defined(__native_client__)
return getgid();
+#else // (__native_client__)
+// TODO(abetul): What the proper return value should be for this function?
+// What about having a reserved/unused group_id?
+ return -1;
+#endif // (__native_client__)
}
#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
@@ -332,3 +347,6 @@ unsigned llvm::sys::Process::GetRandomNumber() {
return ::rand();
#endif
}
+
+#if !defined(__native_client__)
+#endif
diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc
index e5990d06ec..049c41b742 100644
--- a/lib/Support/Unix/Program.inc
+++ b/lib/Support/Unix/Program.inc
@@ -103,6 +103,10 @@ Program::FindProgramByName(const std::string& progName) {
}
static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
+#if defined(__native_client__)
+ MakeErrMsg(ErrMsg, "Cannot redirect I/O in NaCl");
+ return true;
+#else // (__native_client__)
if (Path == 0) // Noop
return false;
const char *File;
@@ -119,7 +123,6 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
+ (FD == 0 ? "input" : "output"));
return true;
}
-
// Install it as the requested FD
if (dup2(InFD, FD) == -1) {
MakeErrMsg(ErrMsg, "Cannot dup2");
@@ -128,6 +131,7 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
}
close(InFD); // Close the original FD
return false;
+#endif // (__native_client__)
}
#ifdef HAVE_POSIX_SPAWN
@@ -233,6 +237,7 @@ Program::Execute(const Path &path, const char **args, const char **envp,
}
#endif
+#if !defined(__native_client__)
// Create a child process.
int child = fork();
switch (child) {
@@ -293,6 +298,10 @@ Program::Execute(const Path &path, const char **args, const char **envp,
Data_ = reinterpret_cast<void*>(child);
return true;
+#else // (__native_client__)
+ MakeErrMsg(ErrMsg, "PNACL does not know how to execute child processes!");
+ return false;
+#endif // (__native_client__)
}
int
@@ -300,6 +309,7 @@ Program::Wait(const sys::Path &path,
unsigned secondsToWait,
std::string* ErrMsg)
{
+#if !defined(__native_client__)
#ifdef HAVE_SYS_WAIT_H
struct sigaction Act, Old;
@@ -392,10 +402,16 @@ Program::Wait(const sys::Path &path,
*ErrMsg = "Program::Wait is not implemented on this platform yet!";
return -1;
#endif
+#else // (__native_client__)
+// TODO(abetul): What should the proper return value be here?
+ MakeErrMsg(ErrMsg, "PNACL does not know how to wait for a child process!");
+ return -1;
+#endif // (__native_client__)
}
bool
Program::Kill(std::string* ErrMsg) {
+#if !defined(__native_client__)
if (Data_ == 0) {
MakeErrMsg(ErrMsg, "Process not started!");
return true;
@@ -410,6 +426,12 @@ Program::Kill(std::string* ErrMsg) {
}
return false;
+
+#else // (__native_client__)
+ MakeErrMsg(ErrMsg, "PNACL does not know how to kill processes!");
+ return true;
+#endif // (__native_client__)
+
}
error_code Program::ChangeStdinToBinary(){
diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc
index 9e94068c9c..264fa5dbde 100644
--- a/lib/Support/Unix/Signals.inc
+++ b/lib/Support/Unix/Signals.inc
@@ -82,6 +82,7 @@ static struct {
static void RegisterHandler(int Signal) {
+#if !defined(__native_client__)
assert(NumRegisteredSignals <
sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) &&
"Out of space for signal handlers!");
@@ -97,6 +98,7 @@ static void RegisterHandler(int Signal) {
&RegisteredSignalInfo[NumRegisteredSignals].SA);
RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal;
++NumRegisteredSignals;
+#endif // (__native_client__)
}
static void RegisterHandlers() {
@@ -108,11 +110,13 @@ static void RegisterHandlers() {
}
static void UnregisterHandlers() {
+#if !defined(__native_client__)
// Restore all of the signal handlers to how they were before we showed up.
for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i)
sigaction(RegisteredSignalInfo[i].SigNo,
&RegisteredSignalInfo[i].SA, 0);
NumRegisteredSignals = 0;
+#endif // (__native_client__)
}
@@ -155,10 +159,12 @@ static RETSIGTYPE SignalHandler(int Sig) {
// instead of recursing in the signal handler.
UnregisterHandlers();
+#if !defined(__native_client__)
// Unmask all potentially blocked kill signals.
sigset_t SigMask;
sigfillset(&SigMask);
sigprocmask(SIG_UNBLOCK, &SigMask, 0);
+#endif
SignalsMutex.acquire();
RemoveFilesToRemove();
diff --git a/lib/Support/Unix/TimeValue.inc b/lib/Support/Unix/TimeValue.inc
index 5cf5a9d44e..0eb4ac8ad3 100644
--- a/lib/Support/Unix/TimeValue.inc
+++ b/lib/Support/Unix/TimeValue.inc
@@ -18,6 +18,13 @@
#include "Unix.h"
+// @LOCALMOD-START
+#ifndef timerclear
+// Newlib does not have the timer{clear,add,sub} macros
+#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
+#endif
+// @LOCALMOD-END
+
namespace llvm {
using namespace sys;