Skip to content

Commit

Permalink
[doc] Add warnings about an ART bug
Browse files Browse the repository at this point in the history
  • Loading branch information
canyie committed Dec 1, 2023
1 parent 1d5e6bc commit 5358344
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private static void methodLocked() {
```
In the example, we recommend you to hook `methodLocked` instead of `method`.

- Pine will disable hidden api policy on initialization by default. Due to an ART bug, if a thread changes hidden api policy while another thread is calling a API that lists members of a class, a out-of-bounds write may occur and causes crashes. We have no way to fix system bugs, so the only way is, initialize our library before other threads is started to avoid the race condition. For more info, see tiann/FreeReflection#60.

- For more, see [issues](https://github.com/canyie/pine/issues).

## Discussion
Expand Down
2 changes: 2 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ private static void methodLocked() {
```
在这个例子里,我们更建议hook `methodLocked` 而非 `method`

- Pine 默认情况下会在初始化时禁用系统的隐藏 API 限制。系统有一个 bug,当一个线程更改隐藏 API 策略时另一个线程在列出一个类的所有成员时,系统内部可能会发生越界写并导致崩溃。我们没法修复系统 bug,所以我建议你在其他所有线程初始化之前就初始化我们的库以避免这个 race condition。更多信息请参阅 tiann/FreeReflection#60

- 更多请参见[issues](https://github.com/canyie/pine/issues)

## 交流讨论
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/top/canyie/pine/Pine.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ private Pine() {

/**
* Initialize the Pine library if not initialized.
* WARNING: Calling this API will disable hidden api policy when
* {@code PineConfig.disableHiddenApiPolicy} or {@code PineConfig.disableHiddenApiPolicyForPlatformDomain}.
* Due to an ART bug, if a thread changes hidden api policy while another thread is calling
* a API that lists members of a class, a out-of-bounds write may occur and causes crashes.
* See <a href="https://github.com/tiann/FreeReflection/issues/60">...</a> for more details.
*/
public static void ensureInitialized() {
if (initialized) return;
Expand Down

0 comments on commit 5358344

Please sign in to comment.