Repository: angr/angr

Issue:
TypeError angr 9.2.16 and PyPy 7.3.9 (CPython 3.9)
<!--
*Disclaimer:
The angr suite is maintained by a small team of volunteers.
While we cannot guarantee any timeliness for fixes and enhancements, we will do our best.
For more real-time help with angr, from us and the community, join our [Slack.](https://angr.io/invite/)*
-->
---

**Describe the bug.**
<!--
Please include a clear and concise description of what the bug is.
-->

The latest version of angr appears to have issues when ran with the latest version of PyPy (I haven't tested with CPython). This issue affects all angr versions newer than 9.2.11:

```text
$ python --version
Python 3.9.12 (05fbe3aa5b0845e6c37239768aa455451aa5faba, Mar 29 2022, 08:15:34)
[PyPy 7.3.9 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]
$ python -c "import angr; p = angr.Project('/bin/ls')"
WARNING | 2022-08-31 09:52:12,054 | cle.loader | The main binary is a position-independent executable. It is being loaded with a base address of 0x400000.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/project.py", line 230, in __init__
    self.simos.configure_project()
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/simos/linux.py", line 161, in configure_project
    super(SimLinux, self).configure_project(syscall_abis)
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/simos/userland.py", line 49, in configure_project
    super().configure_project()
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/simos/simos.py", line 82, in configure_project
    self.project.loader.perform_irelative_relocs(irelative_resolver)
  File "/home/carter/env/lib/pypy3.9/site-packages/cle/loader.py", line 601, in perform_irelative_relocs
    val = resolver_func(resolver)
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/simos/simos.py", line 72, in irelative_resolver
    val = resolver()
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/callable.py", line 55, in __call__
    self.perform_call(*args, prototype=prototype)
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/callable.py", line 78, in perform_call
    caller = self._project.factory.simulation_manager(state)
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/factory.py", line 181, in simulation_manager
    return SimulationManager(self.project, active_states=thing, **kwargs)
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/sim_manager.py", line 94, in __init__
    self._hierarchy = StateHierarchy() if hierarchy is None else hierarchy
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/state_hierarchy.py", line 31, in __init__
    self._lock = PicklableRLock()
  File "/home/carter/env/lib/pypy3.9/site-packages/angr/misc/picklable_lock.py", line 11, in __init__
    self._lock = self._LOCK(*args, **kwargs)  # pylint: disable=too-many-function-args
  File "/home/carter/pypy3.9/lib/pypy3.9/threading.py", line 93, in RLock
    return _CRLock(*args, **kwargs)
TypeError: __new__() takes 1 positional argument but 2 were given
```

**Environment Information.**
<!--
Many common issues are caused by problems with the local Python environment.
Before submitting, double-check that your versions of all modules in the angr suite (angr, cle, pyvex, ...) are up to date.
Please include the output of `python -m angr.misc.bug_report` here.
-->

* Affects angr versions 9.2.12 through 9.2.16
* PyPy version 7.3.9 (latest release at time of writing)
* Debian Bullseye

**To Reproduce.**
<!--
Please include *both a script to reproduce the crash, and attach the binary used, if possible*
-->

1. Install latest PyPy release
2. Install angr version 9.2.16
3. Run: `python -c "import angr; p = angr.Project('/bin/ls')`


Discussion:
I am 98% certain that this is caused by a discrepancy between CPython and PyPy (and I believe PyPy is wrong here). We can workaround this problem by not passing in any arguments to `self._LOCK()`.

Resolving patch:
diff --git a/angr/misc/picklable_lock.py b/angr/misc/picklable_lock.py
--- a/angr/misc/picklable_lock.py
+++ b/angr/misc/picklable_lock.py
@@ -1,5 +1,6 @@
 import threading
 
+
 class PicklableLock:
     """
     Normal thread-locks are not pickleable. This provides a pickleable lock by mandating that the lock is unlocked
@@ -8,7 +9,7 @@ class PicklableLock:
     _LOCK = threading.Lock
 
     def __init__(self, *args, **kwargs):
-        self._lock = self._LOCK(*args, **kwargs)  # pylint: disable=too-many-function-args
+        self._lock = self.__class__._LOCK(*args, **kwargs)  # pylint: disable=too-many-function-args
 
     def __enter__(self):
         return self._lock.__enter__()
@@ -30,6 +31,7 @@ def __reduce__(self):
             raise TypeError("Why are you pickling a locked lock")
         return type(self), ()
 
+
 class PicklableRLock(PicklableLock):
     """
     Same as above, but uses RLock instead of Lock for locking. Note that RLock does not provide an interface to tell


Test patch: