Skip to content

Instantly share code, notes, and snippets.

@lodle
Created October 28, 2015 15:39
Show Gist options
  • Save lodle/5e26b6694e591455e25f to your computer and use it in GitHub Desktop.
Save lodle/5e26b6694e591455e25f to your computer and use it in GitHub Desktop.
From cb1ed02e82b8db7fc67f2094f1bd7e346f383042 Mon Sep 17 00:00:00 2001
From: Mark Chandler <mchandler@blizzard.com>
Date: Wed, 28 Oct 2015 07:38:53 -0700
Subject: [PATCH] Centos 5 fixes
---
blizzard/build.sh | 4 +++
.../tools/lldb/include/lldb/Host/linux/Signalfd.h | 12 ++++++-
vendor/tools/lldb/source/Host/common/File.cpp | 16 ++++++++++
.../lldb/source/Host/linux/HostThreadLinux.cpp | 3 +-
vendor/tools/lldb/source/Host/posix/PipePosix.cpp | 32 ++++++++++++++++++-
.../Plugins/Process/Linux/NativeProcessLinux.cpp | 37 ++++++++++++++++++++++
.../tools/lldb/source/Target/ProcessLaunchInfo.cpp | 6 +++-
.../tools/lldb/source/Utility/PseudoTerminal.cpp | 7 ++++
8 files changed, 113 insertions(+), 4 deletions(-)
diff --git a/blizzard/build.sh b/blizzard/build.sh
index 8d903ca..49ca8d8 100755
--- a/blizzard/build.sh
+++ b/blizzard/build.sh
@@ -35,6 +35,10 @@ mkdir build
pushd build
../cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_TARGETS_TO_BUILD="X86" -DLLDB_DISABLE_PYTHON=true -DLLDB_DISABLE_LIBEDIT=true $PYTHON_BIN ../vendor
+
+KERNEL_HEADER_VER=`rpm -qa | grep kernel-headers | sed 's/kernel-headers-//'`
+export CPATH=/usr/src/kernels/$KERNEL_HEADER_VER-x86_64/include
+
make -j 8
popd
diff --git a/vendor/tools/lldb/include/lldb/Host/linux/Signalfd.h b/vendor/tools/lldb/include/lldb/Host/linux/Signalfd.h
index cf50e87..f77a202 100644
--- a/vendor/tools/lldb/include/lldb/Host/linux/Signalfd.h
+++ b/vendor/tools/lldb/include/lldb/Host/linux/Signalfd.h
@@ -12,14 +12,24 @@
#ifndef liblldb_Host_linux_Signalfd_h_
#define liblldb_Host_linux_Signalfd_h_
+//Blizzard
+#include <linux/version.h>
+
#ifdef __ANDROID_NDK__
#include <android/api-level.h>
#endif
-#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+//Blizzard
+#if (defined(__ANDROID_API__) && __ANDROID_API__ < 21) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
#include <linux/types.h>
+
+//Blizzard
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
#include <linux/fcntl.h>
+#else
+#include <fcntl.h>
+#endif
#define SFD_CLOEXEC O_CLOEXEC
#define SFD_NONBLOCK O_NONBLOCK
diff --git a/vendor/tools/lldb/source/Host/common/File.cpp b/vendor/tools/lldb/source/Host/common/File.cpp
index 71a6149..ca166c1 100644
--- a/vendor/tools/lldb/source/Host/common/File.cpp
+++ b/vendor/tools/lldb/source/Host/common/File.cpp
@@ -20,6 +20,8 @@
#include "lldb/Host/windows/windows.h"
#else
#include <sys/ioctl.h>
+//Blizzard
+#include <linux/version.h>
#endif
#include "llvm/Support/Process.h" // for llvm::sys::Process::FileDescriptorHasColors()
@@ -296,8 +298,12 @@ File::Open (const char *path, uint32_t options, uint32_t permissions)
#ifndef _WIN32
if (options & eOpenOptionNonBlocking)
oflag |= O_NONBLOCK;
+
+//Blizzard
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
if (options & eOpenOptionCloseOnExec)
oflag |= O_CLOEXEC;
+#endif
#else
oflag |= O_BINARY;
#endif
@@ -325,6 +331,16 @@ File::Open (const char *path, uint32_t options, uint32_t permissions)
error.SetErrorToErrno();
else
{
+//Blizzard
+#ifndef _WIN32
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+ if (options & eOpenOptionCloseOnExec)
+ {
+ int oldFlags = fcntl(m_descriptor, F_GETFD, 0);
+ fcntl(m_descriptor, F_SETFD, FD_CLOEXEC|oldFlags);
+ }
+#endif
+#endif
m_should_close_fd = true;
m_options = options;
}
diff --git a/vendor/tools/lldb/source/Host/linux/HostThreadLinux.cpp b/vendor/tools/lldb/source/Host/linux/HostThreadLinux.cpp
index 2312ced..85b3d22 100644
--- a/vendor/tools/lldb/source/Host/linux/HostThreadLinux.cpp
+++ b/vendor/tools/lldb/source/Host/linux/HostThreadLinux.cpp
@@ -30,7 +30,8 @@ HostThreadLinux::HostThreadLinux(lldb::thread_t thread)
void
HostThreadLinux::SetName(lldb::thread_t thread, llvm::StringRef name)
{
-#if (defined(__GLIBC__) && defined(_GNU_SOURCE)) || defined(__ANDROID__)
+//Blizzard
+#if (defined(__GLIBC__) && defined(_GNU_SOURCE) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 12) || defined(__ANDROID__)
::pthread_setname_np(thread, name.data());
#else
(void) thread;
diff --git a/vendor/tools/lldb/source/Host/posix/PipePosix.cpp b/vendor/tools/lldb/source/Host/posix/PipePosix.cpp
index 353faae..0854a4b 100644
--- a/vendor/tools/lldb/source/Host/posix/PipePosix.cpp
+++ b/vendor/tools/lldb/source/Host/posix/PipePosix.cpp
@@ -29,6 +29,9 @@
#include <sys/types.h>
#include <sys/stat.h>
+//Blizzard
+#include <linux/version.h>
+
using namespace lldb;
using namespace lldb_private;
@@ -38,7 +41,8 @@ enum PIPES { READ, WRITE }; // Constants 0 and 1 for READ and WRITE
// pipe2 is supported by a limited set of platforms
// TODO: Add more platforms that support pipe2.
-#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
+// Blizzard
+#if (defined(__linux__) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) || (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
#define PIPE2_SUPPORTED 1
#else
#define PIPE2_SUPPORTED 0
@@ -248,13 +252,27 @@ PipePosix::OpenAsReader(llvm::StringRef name, bool child_process_inherit)
return Error("Pipe is already opened");
int flags = O_RDONLY | O_NONBLOCK;
+
+//Blizzard
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
if (!child_process_inherit)
flags |= O_CLOEXEC;
+#endif
Error error;
int fd = ::open(name.data(), flags);
if (fd != -1)
+ {
+//Blizzard
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+ if (!child_process_inherit)
+ {
+ int oldFlags = fcntl(fd, F_GETFD, 0);
+ fcntl(fd, F_SETFD, FD_CLOEXEC|oldFlags);
+ }
+#endif
m_fds[READ] = fd;
+ }
else
error.SetErrorToErrno();
@@ -268,8 +286,12 @@ PipePosix::OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inhe
return Error("Pipe is already opened");
int flags = O_WRONLY | O_NONBLOCK;
+
+//Blizzard
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
if (!child_process_inherit)
flags |= O_CLOEXEC;
+#endif
using namespace std::chrono;
const auto finish_time = Now() + timeout;
@@ -296,6 +318,14 @@ PipePosix::OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inhe
}
else
{
+//Blizzard
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
+ if (!child_process_inherit)
+ {
+ int oldFlags = fcntl(fd, F_GETFD, 0);
+ fcntl(fd, F_SETFD, FD_CLOEXEC|oldFlags);
+ }
+#endif
m_fds[WRITE] = fd;
}
}
diff --git a/vendor/tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/vendor/tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 284dbee..4ce76ef 100644
--- a/vendor/tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/vendor/tools/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -69,6 +69,43 @@
#define TRAP_HWBKPT 4
#endif
+// Missing defines due to bug: https://sourceware.org/bugzilla/show_bug.cgi?id=4125
+
+//Blizzard
+#if !HAVE_DECL_ADDR_NO_RANDOMIZE
+ #define ADDR_NO_RANDOMIZE 0x0040000
+#endif
+
+//Blizzard
+#ifndef PTRACE_O_TRACECLONE
+ #define PTRACE_O_TRACECLONE 0x00000008
+#endif
+
+//Blizzard
+#ifndef PTRACE_O_TRACEEXEC
+ #define PTRACE_O_TRACEEXEC 0x00000010
+#endif
+
+//Blizzard
+#ifndef PTRACE_O_TRACEEXIT
+ #define PTRACE_O_TRACEEXIT 0x00000040
+#endif
+
+//Blizzard
+#ifndef PTRACE_EVENT_CLONE
+ #define PTRACE_EVENT_CLONE 3
+#endif
+
+//Blizzard
+#ifndef PTRACE_EVENT_EXEC
+ #define PTRACE_EVENT_EXEC 4
+#endif
+
+//Blizzard
+#ifndef PTRACE_EVENT_EXIT
+ #define PTRACE_EVENT_EXIT 6
+#endif
+
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_linux;
diff --git a/vendor/tools/lldb/source/Target/ProcessLaunchInfo.cpp b/vendor/tools/lldb/source/Target/ProcessLaunchInfo.cpp
index fc17fe6..bd7fcca 100644
--- a/vendor/tools/lldb/source/Target/ProcessLaunchInfo.cpp
+++ b/vendor/tools/lldb/source/Target/ProcessLaunchInfo.cpp
@@ -18,6 +18,9 @@
#if !defined(_WIN32)
#include <limits.h>
+
+//Blizzard
+#include <linux/version.h>
#endif
using namespace lldb;
@@ -360,7 +363,8 @@ ProcessLaunchInfo::FinalizeFileActions (Target *target, bool default_to_use_pty)
__FUNCTION__);
int open_flags = O_RDWR | O_NOCTTY;
-#if !defined(_MSC_VER)
+//Blizzard
+#if !defined(_MSC_VER) && LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
// We really shouldn't be specifying platform specific flags
// that are intended for a system call in generic code. But
// this will have to do for now.
diff --git a/vendor/tools/lldb/source/Utility/PseudoTerminal.cpp b/vendor/tools/lldb/source/Utility/PseudoTerminal.cpp
index bc3cfee..ecefe92 100644
--- a/vendor/tools/lldb/source/Utility/PseudoTerminal.cpp
+++ b/vendor/tools/lldb/source/Utility/PseudoTerminal.cpp
@@ -32,6 +32,9 @@ char *ptsname(int fd) { return 0; }
pid_t fork(void) { return 0; }
pid_t setsid(void) { return 0; }
+
+//Blizzard
+#include <linux/version.h>
#elif defined(__ANDROID_NDK__)
#include "lldb/Host/android/Android.h"
int posix_openpt(int flags);
@@ -242,7 +245,11 @@ PseudoTerminal::Fork (char *error_str, size_t error_len)
pid_t pid = LLDB_INVALID_PROCESS_ID;
#if !defined(LLDB_DISABLE_POSIX)
int flags = O_RDWR;
+
+//Blizzard
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
flags |= O_CLOEXEC;
+#endif
if (OpenFirstAvailableMaster (flags, error_str, error_len))
{
// Successfully opened our master pseudo terminal
--
1.8.3.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment