diff options
Diffstat (limited to 'lib/Support/Unix')
-rw-r--r-- | lib/Support/Unix/Host.inc | 6 | ||||
-rw-r--r-- | lib/Support/Unix/Memory.inc | 10 | ||||
-rw-r--r-- | lib/Support/Unix/Path.inc | 51 | ||||
-rw-r--r-- | lib/Support/Unix/PathV2.inc | 45 | ||||
-rw-r--r-- | lib/Support/Unix/Process.inc | 22 | ||||
-rw-r--r-- | lib/Support/Unix/Program.inc | 24 | ||||
-rw-r--r-- | lib/Support/Unix/Signals.inc | 6 | ||||
-rw-r--r-- | lib/Support/Unix/TimeValue.inc | 7 |
8 files changed, 162 insertions, 9 deletions
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 6bddbdf7bd..f70e60d3f5 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__) || \ @@ -318,7 +324,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. @@ -411,7 +419,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 @@ -424,21 +436,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 @@ -457,6 +481,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; @@ -464,6 +489,7 @@ Path::canExecute() const { return false; if (!S_ISREG(buf.st_mode)) return false; +#endif // (__native_client__) return true; } @@ -511,6 +537,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 @@ -526,6 +553,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; } @@ -549,6 +577,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"); @@ -574,6 +603,7 @@ Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const { } closedir(direntries); +#endif return false; } @@ -626,7 +656,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; @@ -651,6 +681,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 @@ -674,11 +707,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; } @@ -698,6 +733,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)) { @@ -742,18 +778,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; @@ -761,6 +805,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 7d161a6a05..e05e81acaf 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__) } @@ -143,10 +147,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; |