diff options
author | Nikias Bassen | 2021-09-13 20:28:16 +0200 |
---|---|---|
committer | Nikias Bassen | 2021-09-13 20:28:16 +0200 |
commit | 40b25fd572bf94d65e880a216bba5e825e5bbf2d (patch) | |
tree | b6df709be2dbdec2186df1c7e2bec211b8d0dec5 | |
parent | bcf56b30fea3b841ee11a9b4f3ac74f6de465f3d (diff) | |
download | libirecovery-40b25fd572bf94d65e880a216bba5e825e5bbf2d.tar.gz libirecovery-40b25fd572bf94d65e880a216bba5e825e5bbf2d.tar.bz2 |
Remove duplicated thread/collection code and use new libimobiledevice-glue instead
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | m4/ax_pthread.m4 | 522 | ||||
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/libirecovery-1.0.pc.in | 2 | ||||
-rw-r--r-- | src/libirecovery.c | 11 | ||||
-rw-r--r-- | src/thread.c | 215 | ||||
-rw-r--r-- | src/thread.h | 87 | ||||
-rw-r--r-- | src/utils.c | 92 | ||||
-rw-r--r-- | src/utils.h | 52 |
9 files changed, 15 insertions, 983 deletions
diff --git a/configure.ac b/configure.ac index 7617d61..d571f48 100644 --- a/configure.ac +++ b/configure.ac @@ -19,8 +19,10 @@ LIBIRECOVERY_SO_VERSION=3:0:0 dnl Minimum package versions LIBUSB_VERSION=1.0.3 +LIMD_GLUE_VERSION=1.0.0 AC_SUBST(LIBIRECOVERY_SO_VERSION) +AC_SUBST(LIMD_GLUE_VERSION) # Checks for programs. AC_PROG_CC @@ -28,6 +30,9 @@ AC_PROG_CC AM_PROG_CC_C_O LT_INIT +# Checks for libraries. +PKG_CHECK_MODULES(limd_glue, libimobiledevice-glue-1.0 >= $LIMD_GLUE_VERSION) + # Checks for header files. AC_CHECK_HEADERS([stdint.h stdlib.h string.h]) @@ -58,7 +63,6 @@ case ${host_os} in have_iokit=yes ], []) ], []) - AX_PTHREAD([], [AC_MSG_ERROR([pthread is required to build $PACKAGE])]) ;; mingw32*) AC_MSG_RESULT([${host_os}]) @@ -74,7 +78,6 @@ case ${host_os} in ;; *) AC_MSG_RESULT([${host_os}]) - AX_PTHREAD([], [AC_MSG_ERROR([pthread is required to build $PACKAGE])]) ;; esac AM_CONDITIONAL(WIN32, test x$win32 = xtrue) @@ -111,8 +114,7 @@ AS_IF([test "x$with_dummy" = "xyes"], [ ]) ]) -AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fvisibility=hidden $PTHREAD_CFLAGS") -GLOBAL_LDFLAGS+=" $PTHREAD_LIBS" +AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fvisibility=hidden") AC_SUBST(GLOBAL_CFLAGS) AC_SUBST(GLOBAL_LDFLAGS) diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 deleted file mode 100644 index 9f35d13..0000000 --- a/m4/ax_pthread.m4 +++ /dev/null @@ -1,522 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_pthread.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -# -# DESCRIPTION -# -# This macro figures out how to build C programs using POSIX threads. It -# sets the PTHREAD_LIBS output variable to the threads library and linker -# flags, and the PTHREAD_CFLAGS output variable to any special C compiler -# flags that are needed. (The user can also force certain compiler -# flags/libs to be tested by setting these environment variables.) -# -# Also sets PTHREAD_CC and PTHREAD_CXX to any special C compiler that is -# needed for multi-threaded programs (defaults to the value of CC -# respectively CXX otherwise). (This is necessary on e.g. AIX to use the -# special cc_r/CC_r compiler alias.) -# -# NOTE: You are assumed to not only compile your program with these flags, -# but also to link with them as well. For example, you might link with -# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS -# -# If you are only building threaded programs, you may wish to use these -# variables in your default LIBS, CFLAGS, and CC: -# -# LIBS="$PTHREAD_LIBS $LIBS" -# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" -# CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" -# CC="$PTHREAD_CC" -# CXX="$PTHREAD_CXX" -# -# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant -# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to -# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -# -# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the -# PTHREAD_PRIO_INHERIT symbol is defined when compiling with -# PTHREAD_CFLAGS. -# -# ACTION-IF-FOUND is a list of shell commands to run if a threads library -# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it -# is not found. If ACTION-IF-FOUND is not specified, the default action -# will define HAVE_PTHREAD. -# -# Please let the authors know if this macro fails on any platform, or if -# you have any other suggestions or comments. This macro was based on work -# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help -# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by -# Alejandro Forero Cuervo to the autoconf macro repository. We are also -# grateful for the helpful feedback of numerous users. -# -# Updated for Autoconf 2.68 by Daniel Richard G. -# -# LICENSE -# -# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> -# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG> -# Copyright (c) 2019 Marc Stevens <marc.stevens@cwi.nl> -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see <https://www.gnu.org/licenses/>. -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 31 - -AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) -AC_DEFUN([AX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -AC_REQUIRE([AC_PROG_CC]) -AC_REQUIRE([AC_PROG_SED]) -AC_LANG_PUSH([C]) -ax_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on Tru64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then - ax_pthread_save_CC="$CC" - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) - AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"]) - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) - AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) - AC_MSG_RESULT([$ax_pthread_ok]) - if test "x$ax_pthread_ok" = "xno"; then - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" - fi - CC="$ax_pthread_save_CC" - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items with a "," contain both -# C compiler flags (before ",") and linker flags (after ","). Other items -# starting with a "-" are C compiler flags, and remaining items are -# library names, except for "none" which indicates that we try without -# any flags at all, and "pthread-config" which is a program returning -# the flags for the Pth emulation library. - -ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 -# (Note: HP C rejects this with "bad form for `-t' option") -# -pthreads: Solaris/gcc (Note: HP C also rejects) -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads and -# -D_REENTRANT too), HP C (must be checked before -lpthread, which -# is present but should not be used directly; and before -mthreads, -# because the compiler interprets this as "-mt" + "-hreads") -# -mthreads: Mingw32/gcc, Lynx/gcc -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -case $host_os in - - freebsd*) - - # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) - # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) - - ax_pthread_flags="-kthread lthread $ax_pthread_flags" - ;; - - hpux*) - - # From the cc(1) man page: "[-mt] Sets various -D flags to enable - # multi-threading and also sets -lpthread." - - ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" - ;; - - openedition*) - - # IBM z/OS requires a feature-test macro to be defined in order to - # enable POSIX threads at all, so give the user a hint if this is - # not set. (We don't define these ourselves, as they can affect - # other portions of the system API in unpredictable ways.) - - AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], - [ -# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) - AX_PTHREAD_ZOS_MISSING -# endif - ], - [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) - ;; - - solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (N.B.: The stubs are missing - # pthread_cleanup_push, or rather a function called by this macro, - # so we could check for that, but who knows whether they'll stub - # that too in a future libc.) So we'll check first for the - # standard Solaris way of linking pthreads (-mt -lpthread). - - ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" - ;; -esac - -# Are we compiling with Clang? - -AC_CACHE_CHECK([whether $CC is Clang], - [ax_cv_PTHREAD_CLANG], - [ax_cv_PTHREAD_CLANG=no - # Note that Autoconf sets GCC=yes for Clang as well as GCC - if test "x$GCC" = "xyes"; then - AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], - [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ -# if defined(__clang__) && defined(__llvm__) - AX_PTHREAD_CC_IS_CLANG -# endif - ], - [ax_cv_PTHREAD_CLANG=yes]) - fi - ]) -ax_pthread_clang="$ax_cv_PTHREAD_CLANG" - - -# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) - -# Note that for GCC and Clang -pthread generally implies -lpthread, -# except when -nostdlib is passed. -# This is problematic using libtool to build C++ shared libraries with pthread: -# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 -# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 -# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 -# To solve this, first try -pthread together with -lpthread for GCC - -AS_IF([test "x$GCC" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) - -# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first - -AS_IF([test "x$ax_pthread_clang" = "xyes"], - [ax_pthread_flags="-pthread,-lpthread -pthread"]) - - -# The presence of a feature test macro requesting re-entrant function -# definitions is, on some systems, a strong hint that pthreads support is -# correctly enabled - -case $host_os in - darwin* | hpux* | linux* | osf* | solaris*) - ax_pthread_check_macro="_REENTRANT" - ;; - - aix*) - ax_pthread_check_macro="_THREAD_SAFE" - ;; - - *) - ax_pthread_check_macro="--" - ;; -esac -AS_IF([test "x$ax_pthread_check_macro" = "x--"], - [ax_pthread_check_cond=0], - [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) - - -if test "x$ax_pthread_ok" = "xno"; then -for ax_pthread_try_flag in $ax_pthread_flags; do - - case $ax_pthread_try_flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - *,*) - PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` - PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` - AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) - PTHREAD_CFLAGS="$ax_pthread_try_flag" - ;; - - pthread-config) - AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) - AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) - PTHREAD_CFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) - PTHREAD_LIBS="-l$ax_pthread_try_flag" - ;; - esac - - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h> -# if $ax_pthread_check_cond -# error "$ax_pthread_check_macro must be defined" -# endif - static void *some_global = NULL; - static void routine(void *a) - { - /* To avoid any unused-parameter or - unused-but-set-parameter warning. */ - some_global = a; - } - static void *start_routine(void *a) { return a; }], - [pthread_t th; pthread_attr_t attr; - pthread_create(&th, 0, start_routine, 0); - pthread_join(th, 0); - pthread_attr_init(&attr); - pthread_cleanup_push(routine, 0); - pthread_cleanup_pop(0) /* ; */])], - [ax_pthread_ok=yes], - []) - - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" - - AC_MSG_RESULT([$ax_pthread_ok]) - AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) - - PTHREAD_LIBS="" - PTHREAD_CFLAGS="" -done -fi - - -# Clang needs special handling, because older versions handle the -pthread -# option in a rather... idiosyncratic way - -if test "x$ax_pthread_clang" = "xyes"; then - - # Clang takes -pthread; it has never supported any other flag - - # (Note 1: This will need to be revisited if a system that Clang - # supports has POSIX threads in a separate library. This tends not - # to be the way of modern systems, but it's conceivable.) - - # (Note 2: On some systems, notably Darwin, -pthread is not needed - # to get POSIX threads support; the API is always present and - # active. We could reasonably leave PTHREAD_CFLAGS empty. But - # -pthread does define _REENTRANT, and while the Darwin headers - # ignore this macro, third-party headers might not.) - - # However, older versions of Clang make a point of warning the user - # that, in an invocation where only linking and no compilation is - # taking place, the -pthread option has no effect ("argument unused - # during compilation"). They expect -pthread to be passed in only - # when source code is being compiled. - # - # Problem is, this is at odds with the way Automake and most other - # C build frameworks function, which is that the same flags used in - # compilation (CFLAGS) are also used in linking. Many systems - # supported by AX_PTHREAD require exactly this for POSIX threads - # support, and in fact it is often not straightforward to specify a - # flag that is used only in the compilation phase and not in - # linking. Such a scenario is extremely rare in practice. - # - # Even though use of the -pthread flag in linking would only print - # a warning, this can be a nuisance for well-run software projects - # that build with -Werror. So if the active version of Clang has - # this misfeature, we search for an option to squash it. - - AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], - [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], - [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown - # Create an alternate version of $ac_link that compiles and - # links in two steps (.c -> .o, .o -> exe) instead of one - # (.c -> exe), because the warning occurs only in the second - # step - ax_pthread_save_ac_link="$ac_link" - ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' - ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"` - ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" - ax_pthread_save_CFLAGS="$CFLAGS" - for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do - AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) - CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" - ac_link="$ax_pthread_save_ac_link" - AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], - [ac_link="$ax_pthread_2step_ac_link" - AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], - [break]) - ]) - done - ac_link="$ax_pthread_save_ac_link" - CFLAGS="$ax_pthread_save_CFLAGS" - AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) - ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" - ]) - - case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in - no | unknown) ;; - *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; - esac - -fi # $ax_pthread_clang = yes - - - -# Various other checks: -if test "x$ax_pthread_ok" = "xyes"; then - ax_pthread_save_CFLAGS="$CFLAGS" - ax_pthread_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $PTHREAD_CFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - - # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. - AC_CACHE_CHECK([for joinable pthread attribute], - [ax_cv_PTHREAD_JOINABLE_ATTR], - [ax_cv_PTHREAD_JOINABLE_ATTR=unknown - for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do - AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>], - [int attr = $ax_pthread_attr; return attr /* ; */])], - [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], - []) - done - ]) - AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ - test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ - test "x$ax_pthread_joinable_attr_defined" != "xyes"], - [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], - [$ax_cv_PTHREAD_JOINABLE_ATTR], - [Define to necessary symbol if this constant - uses a non-standard name on your system.]) - ax_pthread_joinable_attr_defined=yes - ]) - - AC_CACHE_CHECK([whether more special flags are required for pthreads], - [ax_cv_PTHREAD_SPECIAL_FLAGS], - [ax_cv_PTHREAD_SPECIAL_FLAGS=no - case $host_os in - solaris*) - ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" - ;; - esac - ]) - AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ - test "x$ax_pthread_special_flags_added" != "xyes"], - [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" - ax_pthread_special_flags_added=yes]) - - AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], - [ax_cv_PTHREAD_PRIO_INHERIT], - [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], - [[int i = PTHREAD_PRIO_INHERIT; - return i;]])], - [ax_cv_PTHREAD_PRIO_INHERIT=yes], - [ax_cv_PTHREAD_PRIO_INHERIT=no]) - ]) - AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ - test "x$ax_pthread_prio_inherit_defined" != "xyes"], - [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) - ax_pthread_prio_inherit_defined=yes - ]) - - CFLAGS="$ax_pthread_save_CFLAGS" - LIBS="$ax_pthread_save_LIBS" - - # More AIX lossage: compile with *_r variant - if test "x$GCC" != "xyes"; then - case $host_os in - aix*) - AS_CASE(["x/$CC"], - [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], - [#handle absolute path differently from PATH based program lookup - AS_CASE(["x$CC"], - [x/*], - [ - AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"]) - AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])]) - ], - [ - AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC]) - AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])]) - ] - ) - ]) - ;; - esac - fi -fi - -test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" -test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX" - -AC_SUBST([PTHREAD_LIBS]) -AC_SUBST([PTHREAD_CFLAGS]) -AC_SUBST([PTHREAD_CC]) -AC_SUBST([PTHREAD_CXX]) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test "x$ax_pthread_ok" = "xyes"; then - ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) - : -else - ax_pthread_ok=no - $2 -fi -AC_LANG_POP -])dnl AX_PTHREAD diff --git a/src/Makefile.am b/src/Makefile.am index 06a6374..f80ffa7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,19 +3,18 @@ AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = \ $(GLOBAL_CFLAGS) \ $(LFS_CFLAGS) \ + $(limd_glue_CFLAGS) \ $(libusb_CFLAGS) AM_LDFLAGS = \ $(GLOBAL_LDFLAGS) \ + $(limd_glue_LIBS) \ $(libusb_LIBS) lib_LTLIBRARIES = libirecovery-1.0.la libirecovery_1_0_la_CFLAGS = $(AM_CFLAGS) libirecovery_1_0_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIRECOVERY_SO_VERSION) -no-undefined -libirecovery_1_0_la_SOURCES = \ - libirecovery.c \ - utils.c utils.h \ - thread.c thread.h +libirecovery_1_0_la_SOURCES = libirecovery.c if WIN32 libirecovery_1_0_la_LDFLAGS += -avoid-version diff --git a/src/libirecovery-1.0.pc.in b/src/libirecovery-1.0.pc.in index 25144da..e6c94a3 100644 --- a/src/libirecovery-1.0.pc.in +++ b/src/libirecovery-1.0.pc.in @@ -8,4 +8,4 @@ Description: A library to communicate with iBoot/iBSS on iOS devices via USB Version: @PACKAGE_VERSION@ Libs: -L${libdir} -lirecovery-1.0 Cflags: -I${includedir} -Requires.private: @LIBUSB_REQUIRED@ +Requires.private: libimobiledevice-glue-1.0 >= @LIMD_GLUE_VERSION@ @LIBUSB_REQUIRED@ diff --git a/src/libirecovery.c b/src/libirecovery.c index 2219f36..0446e01 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -32,11 +32,13 @@ #include <unistd.h> #include <sys/stat.h> +#include <libimobiledevice-glue/collection.h> +#include <libimobiledevice-glue/thread.h> + #ifndef USE_DUMMY #ifndef WIN32 #ifndef HAVE_IOKIT #include <libusb.h> -#include <pthread.h> #if (defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000102)) || (defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01000102)) #define HAVE_LIBUSB_HOTPLUG_API 1 #endif @@ -44,7 +46,6 @@ #include <CoreFoundation/CoreFoundation.h> #include <IOKit/usb/IOUSBLib.h> #include <IOKit/IOCFPlugIn.h> -#include <pthread.h> #endif #else #define WIN32_LEAN_AND_MEAN @@ -67,8 +68,6 @@ #endif #include "libirecovery.h" -#include "utils.h" -#include "thread.h" struct irecv_client_private { int debug; @@ -2977,8 +2976,8 @@ IRECV_API irecv_error_t irecv_trigger_limera1n_exploit(irecv_client_t client) { // which can be accomplished by sending on another thread. void *args[2] = { client->handle, &req }; - pthread_t thread; - pthread_create(&thread, NULL, iokit_limera1n_usb_submit_request, args); + THREAD_T thread; + thread_new(&thread, iokit_limera1n_usb_submit_request, args); usleep(5 * 1000); result = (*client->handle)->USBDeviceAbortPipeZero(client->handle); diff --git a/src/thread.c b/src/thread.c deleted file mode 100644 index 796ea0b..0000000 --- a/src/thread.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * thread.c - * - * Copyright (c) 2012-2019 Nikias Bassen, All Rights Reserved. - * Copyright (c) 2012 Martin Szulecki, All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "thread.h" - -int thread_new(THREAD_T *thread, thread_func_t thread_func, void* data) -{ -#ifdef WIN32 - HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread_func, data, 0, NULL); - if (th == NULL) { - return -1; - } - *thread = th; - return 0; -#else - int res = pthread_create(thread, NULL, thread_func, data); - return res; -#endif -} - -void thread_detach(THREAD_T thread) -{ -#ifdef WIN32 - CloseHandle(thread); -#else - pthread_detach(thread); -#endif -} - -void thread_free(THREAD_T thread) -{ -#ifdef WIN32 - CloseHandle(thread); -#endif -} - -int thread_join(THREAD_T thread) -{ - /* wait for thread to complete */ -#ifdef WIN32 - return (int)WaitForSingleObject(thread, INFINITE); -#else - return pthread_join(thread, NULL); -#endif -} - -int thread_alive(THREAD_T thread) -{ - if (!thread) - return 0; -#ifdef WIN32 - return WaitForSingleObject(thread, 0) == WAIT_TIMEOUT; -#else - return pthread_kill(thread, 0) == 0; -#endif -} - -int thread_cancel(THREAD_T thread) -{ -#ifdef WIN32 - return -1; -#else -#ifdef HAVE_PTHREAD_CANCEL - return pthread_cancel(thread); -#else - return -1; -#endif -#endif -} - -void mutex_init(mutex_t* mutex) -{ -#ifdef WIN32 - InitializeCriticalSection(mutex); -#else - pthread_mutex_init(mutex, NULL); -#endif -} - -void mutex_destroy(mutex_t* mutex) -{ -#ifdef WIN32 - DeleteCriticalSection(mutex); -#else - pthread_mutex_destroy(mutex); -#endif -} - -void mutex_lock(mutex_t* mutex) -{ -#ifdef WIN32 - EnterCriticalSection(mutex); -#else - pthread_mutex_lock(mutex); -#endif -} - -void mutex_unlock(mutex_t* mutex) -{ -#ifdef WIN32 - LeaveCriticalSection(mutex); -#else - pthread_mutex_unlock(mutex); -#endif -} - -void thread_once(thread_once_t *once_control, void (*init_routine)(void)) -{ -#ifdef WIN32 - while (InterlockedExchange(&(once_control->lock), 1) != 0) { - Sleep(1); - } - if (!once_control->state) { - once_control->state = 1; - init_routine(); - } - InterlockedExchange(&(once_control->lock), 0); -#else - pthread_once(once_control, init_routine); -#endif -} - -void cond_init(cond_t* cond) -{ -#ifdef WIN32 - cond->sem = CreateSemaphore(NULL, 0, 32767, NULL); -#else - pthread_cond_init(cond, NULL); -#endif -} - -void cond_destroy(cond_t* cond) -{ -#ifdef WIN32 - CloseHandle(cond->sem); -#else - pthread_cond_destroy(cond); -#endif -} - -int cond_signal(cond_t* cond) -{ -#ifdef WIN32 - int result = 0; - if (!ReleaseSemaphore(cond->sem, 1, NULL)) { - result = -1; - } - return result; -#else - return pthread_cond_signal(cond); -#endif -} - -int cond_wait(cond_t* cond, mutex_t* mutex) -{ -#ifdef WIN32 - mutex_unlock(mutex); - DWORD res = WaitForSingleObject(cond->sem, INFINITE); - switch (res) { - case WAIT_OBJECT_0: - return 0; - default: - return -1; - } -#else - return pthread_cond_wait(cond, mutex); -#endif -} - -int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms) -{ -#ifdef WIN32 - mutex_unlock(mutex); - DWORD res = WaitForSingleObject(cond->sem, timeout_ms); - switch (res) { - case WAIT_OBJECT_0: - case WAIT_TIMEOUT: - return 0; - default: - return -1; - } -#else - struct timespec ts; - struct timeval now; - gettimeofday(&now, NULL); - - ts.tv_sec = now.tv_sec + timeout_ms / 1000; - ts.tv_nsec = now.tv_usec * 1000 + 1000 * 1000 * (timeout_ms % 1000); - ts.tv_sec += ts.tv_nsec / (1000 * 1000 * 1000); - ts.tv_nsec %= (1000 * 1000 * 1000); - - return pthread_cond_timedwait(cond, mutex, &ts); -#endif -} diff --git a/src/thread.h b/src/thread.h deleted file mode 100644 index 2aadc6e..0000000 --- a/src/thread.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * thread.h - * - * Copyright (c) 2012-2019 Nikias Bassen, All Rights Reserved. - * Copyright (c) 2012 Martin Szulecki, All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __THREAD_H -#define __THREAD_H - -#include <stddef.h> - -#ifdef WIN32 -#include <windows.h> -typedef HANDLE THREAD_T; -typedef CRITICAL_SECTION mutex_t; -typedef struct { - HANDLE sem; -} cond_t; -typedef volatile struct { - LONG lock; - int state; -} thread_once_t; -#define THREAD_ONCE_INIT {0, 0} -#define THREAD_ID GetCurrentThreadId() -#define THREAD_T_NULL (THREAD_T)NULL -#else -#include <pthread.h> -#include <signal.h> -#include <sys/time.h> -typedef pthread_t THREAD_T; -typedef pthread_mutex_t mutex_t; -typedef pthread_cond_t cond_t; -typedef pthread_once_t thread_once_t; -#define THREAD_ONCE_INIT PTHREAD_ONCE_INIT -#define THREAD_ID pthread_self() -#define THREAD_T_NULL (THREAD_T)NULL -#endif - -typedef void* (*thread_func_t)(void* data); - -int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data); -void thread_detach(THREAD_T thread); -void thread_free(THREAD_T thread); -int thread_join(THREAD_T thread); -int thread_alive(THREAD_T thread); - -int thread_cancel(THREAD_T thread); - -#ifdef WIN32 -#undef HAVE_THREAD_CLEANUP -#else -#ifdef HAVE_PTHREAD_CANCEL -#define HAVE_THREAD_CLEANUP 1 -#define thread_cleanup_push(routine, arg) pthread_cleanup_push(routine, arg) -#define thread_cleanup_pop(execute) pthread_cleanup_pop(execute) -#endif -#endif - -void mutex_init(mutex_t* mutex); -void mutex_destroy(mutex_t* mutex); -void mutex_lock(mutex_t* mutex); -void mutex_unlock(mutex_t* mutex); - -void thread_once(thread_once_t *once_control, void (*init_routine)(void)); - -void cond_init(cond_t* cond); -void cond_destroy(cond_t* cond); -int cond_signal(cond_t* cond); -int cond_wait(cond_t* cond, mutex_t* mutex); -int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms); - -#endif diff --git a/src/utils.c b/src/utils.c deleted file mode 100644 index 826bfbe..0000000 --- a/src/utils.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * utils.c - * - * Copyright (C) 2009 Hector Martin <hector@marcansoft.com> - * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> - * Copyright (c) 2013 Federico Mena Quintero - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -#include "utils.h" - -#define CAPACITY_STEP 8 - -void collection_init(struct collection *col) -{ - col->list = malloc(sizeof(void *) * CAPACITY_STEP); - memset(col->list, 0, sizeof(void *) * CAPACITY_STEP); - col->capacity = CAPACITY_STEP; -} - -void collection_free(struct collection *col) -{ - free(col->list); - col->list = NULL; - col->capacity = 0; -} - -void collection_add(struct collection *col, void *element) -{ - int i; - for(i=0; i<col->capacity; i++) { - if(!col->list[i]) { - col->list[i] = element; - return; - } - } - col->list = realloc(col->list, sizeof(void*) * (col->capacity + CAPACITY_STEP)); - memset(&col->list[col->capacity], 0, sizeof(void *) * CAPACITY_STEP); - col->list[col->capacity] = element; - col->capacity += CAPACITY_STEP; -} - -void collection_remove(struct collection *col, void *element) -{ - int i; - for(i=0; i<col->capacity; i++) { - if(col->list[i] == element) { - col->list[i] = NULL; - return; - } - } -} - -int collection_count(struct collection *col) -{ - int i, cnt = 0; - for(i=0; i<col->capacity; i++) { - if(col->list[i]) - cnt++; - } - return cnt; -} - -void collection_copy(struct collection *dest, struct collection *src) -{ - if (!dest || !src) return; - dest->capacity = src->capacity; - dest->list = malloc(sizeof(void*) * src->capacity); - memcpy(dest->list, src->list, sizeof(void*) * src->capacity); -} diff --git a/src/utils.h b/src/utils.h deleted file mode 100644 index ccb3a09..0000000 --- a/src/utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * utils.h - * - * Copyright (C) 2009 Hector Martin <hector@marcansoft.com> - * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef UTILS_H -#define UTILS_H - -struct collection { - void **list; - int capacity; -}; - -void collection_init(struct collection *col); -void collection_add(struct collection *col, void *element); -void collection_remove(struct collection *col, void *element); -int collection_count(struct collection *col); -void collection_free(struct collection *col); -void collection_copy(struct collection *dest, struct collection *src); - -#define MERGE_(a,b) a ## _ ## b -#define LABEL_(a,b) MERGE_(a, b) -#define UNIQUE_VAR(a) LABEL_(a, __LINE__) - -#define FOREACH(var, col) \ - do { \ - int UNIQUE_VAR(_iter); \ - for(UNIQUE_VAR(_iter)=0; UNIQUE_VAR(_iter)<(col)->capacity; UNIQUE_VAR(_iter)++) { \ - if(!(col)->list[UNIQUE_VAR(_iter)]) continue; \ - var = (col)->list[UNIQUE_VAR(_iter)]; - -#define ENDFOREACH \ - } \ - } while(0); - -#endif |