Skip to content

Commit

Permalink
Fix SeattleTestbed#98, GETTID on MIPS
Browse files Browse the repository at this point in the history
This commit fixes an issue with the GETTID syscall on MIPS-based
systems such as most of our OpenWrt routers.

At the same time, it *creates* an issue on non-x86 and non-MIPS
systems, as I don't know and can't test the GETTID for, say,
ARMs right now. A friendly TODO comment points out this situation.
  • Loading branch information
aaaaalbert committed Jul 19, 2017
1 parent bc08a1c commit 643b912
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 12 additions & 12 deletions linux_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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)


Expand Down
8 changes: 7 additions & 1 deletion nix_common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 643b912

Please sign in to comment.