diff options
author | plopresti <lopresti@gmail.com> | 2019-06-12 09:14:47 -0700 |
---|---|---|
committer | Dave Watson <dade.watson@gmail.com> | 2019-06-12 09:14:47 -0700 |
commit | 0efe1db0ebf03ed8b7004c75c15cfd286854137f (patch) | |
tree | 27ec720cd7b9efb129aaf08c3219ebdf69dd9ee7 | |
parent | 4b68214f1b1a6dd9cf09d8c0f6db7ebdb8ec3b8a (diff) | |
download | libunwind-0efe1db0ebf03ed8b7004c75c15cfd286854137f.tar.gz |
Older systems (e.g. RHEL5) do not have pipe2(). (#122)
Add a check and compatibility code.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/x86_64/Ginit.c | 31 |
2 files changed, 31 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 2697065e..8e62b8bd 100644 --- a/configure.ac +++ b/configure.ac @@ -70,7 +70,7 @@ PT_STEP, PT_SYSCALL], [], [], dnl Checks for library functions. AC_CHECK_FUNCS(dl_iterate_phdr dl_phdr_removals_counter dlmodinfo getunwind \ - ttrace mincore) + ttrace mincore pipe2) AC_MSG_CHECKING([if building with AltiVec]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ diff --git a/src/x86_64/Ginit.c b/src/x86_64/Ginit.c index 6161da64..63a53907 100644 --- a/src/x86_64/Ginit.c +++ b/src/x86_64/Ginit.c @@ -75,6 +75,35 @@ get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr, static int mem_validate_pipe[2] = {-1, -1}; +#ifdef HAVE_PIPE2 +static inline void +do_pipe2 (int pipefd[2]) +{ + pipe2 (pipefd, O_CLOEXEC | O_NONBLOCK); +} +#else +static inline void +set_pipe_flags (int fd) +{ + int fd_flags = fcntl (fd, F_GETFD, 0); + int status_flags = fcntl (fd, F_GETFL, 0); + + fd_flags |= FD_CLOEXEC; + fcntl (fd, F_SETFD, fd_flags); + + status_flags |= O_NONBLOCK; + fcntl (fd, F_SETFL, status_flags); +} + +static inline void +do_pipe2 (int pipefd[2]) +{ + pipe (pipefd); + set_pipe_flags(pipefd[0]); + set_pipe_flags(pipefd[1]); +} +#endif + static inline void open_pipe (void) { @@ -83,7 +112,7 @@ open_pipe (void) if (mem_validate_pipe[1] != -1) close (mem_validate_pipe[1]); - pipe2 (mem_validate_pipe, O_CLOEXEC | O_NONBLOCK); + do_pipe2 (mem_validate_pipe); } ALWAYS_INLINE |