diff --git a/linux_api.py b/linux_api.py index bc4e91dc..a0b24a43 100644 --- a/linux_api.py +++ b/linux_api.py @@ -18,11 +18,6 @@ import platform -# Determine if we are 32 bit or 64 bit -running_32bit = True -architecture = platform.architecture() -if "64" in architecture[0]: - running_32bit = False # Manually import the common functions we want exists_outgoing_network_socket = nix_api.exists_outgoing_network_socket @@ -43,11 +38,6 @@ JIFFIES_PER_SECOND = 100.0 PAGE_SIZE = os.sysconf('SC_PAGESIZE') -# Get the thread id of the currently executing thread -if running_32bit: - GETTID = 224 -else: - GETTID = 186 # Maps each field in /proc/{pid}/stat to an index when split by spaces FIELDS = { @@ -196,9 +186,19 @@ def get_process_rss(force_update=False, pid=None): return rss_bytes -# Get the id of the currently executing thread +# Get the id of the currently executing thread. def _get_current_thread_id(): - # Syscall for GETTID + # The actual GETTID syscall number depends on the machine type. + machine = platform.machine() + architecture = platform.architecture()[0] + if "x86" in machine or "i386" in machine: + if "64" in architecture: + GETTID = 186 + elif "32" in architecture: + GETTID = 224 + elif machine.startswith("mips"): + GETTID = 4222 + # TODO Needs ARM and possibly other clauses! return syscall(GETTID) diff --git a/nix_common_api.py b/nix_common_api.py index a856720c..0458763a 100644 --- a/nix_common_api.py +++ b/nix_common_api.py @@ -22,7 +22,13 @@ import android libc = ctypes.CDLL("/system/lib/libc.so") except ImportError: - libc = ctypes.CDLL(ctypes.util.find_library("c")) + path_to_libc = ctypes.util.find_library("c") + if path_to_libc is None: + # `find_library` failed. Use the hardcoded location. + # valid on OpenWrt. + path_to_libc = "/lib/libc.so.0" + libc = ctypes.CDLL(path_to_libc) + # Functions _strerror = libc.strerror