Wrong ffi_type for unsigned numbers causes bugs on some platforms
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 领域
- devtools, mobile-dev
调研方向
从报告中链接的最小可复现示例开始,重点关注 JNA 的 IntegerType 以及传递给原生 hello 函数的 UINT16 参数。复现优化和未优化 Android 构建之间的差异,然后跟踪 unsigned short 的 FFI 表示;当 hello 在受影响的架构上以预期值返回 true 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Provide complete information about the problem
- Version of JNA and related jars
5.11.0@aar - Version and vendor of the java virtual machine
ART @ Android 11 - Operating system
Android 11 - System architecture (CPU type, bitness of the JVM)
arm64-v8a, x86_64, possibly more
Output ofclang --version:
Compiler Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn). - Complete description of the problem
Function argument of typeunsigned shortpassed by JNA to native code does not behave correctly when the code is compiled with optimizations enabled. The is caused by the fact that LLVM is counting on the argument being stored in straight format (as it should be) instead of two's complement. - Steps to reproduce
Minimal reproducible example available here.
Thehellofunction in the following code should returntrue, but returnsfalse.
const unsigned short CONSTANT = 0x8810u;
bool hello(unsigned short argument) {
__android_log_print(ANDROID_LOG_WARN, TAG, "argument value as %%#010x=%#010x %%d=%d, as %%u=%u, as %%hu=%hu", argument, argument, argument, argument);
__android_log_print(ANDROID_LOG_WARN, TAG, "CONSTANT value as %%#010x=%#010x %%d=%d, as %%u=%u, as %%hu=%hu", CONSTANT, CONSTANT, CONSTANT, CONSTANT);
switch (argument) {
case CONSTANT:
return true;
default:
return false;
}
}
private void logValueFromJna() {
boolean on = lib.hello(new UINT16(0x8810));
Log.w("JNA-BUG", "hello returned correct value? " + on);
}
public static class UINT16 extends IntegerType {
@SuppressWarnings("unused")
public UINT16() {
this(0);
}
public UINT16(int value) {
super(2, value, true);
}
}
interface TestLibrary extends Library {
boolean hello(UINT16 argument);
}
Log output with optimizations disabled:
W/JNA-BUG-NATIVE: argument value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG-NATIVE: CONSTANT value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG: hello returned correct value? true
Log output with optimizations enabled:
W/JNA-BUG-NATIVE: argument value as %#010x=0xffff8810 %d=-30704, as %u=4294936592, as %hu=34832
W/JNA-BUG-NATIVE: CONSTANT value as %#010x=0x00008810 %d=34832, as %u=34832, as %hu=34832
W/JNA-BUG: hello returned correct value? false
- 主要语言
- Java
- 星标
- 8.9k
- 派生
- 1.7k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
java-native-access/jna 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
java-native-access/jna#1740 ·
-
难度 4/5 3-5 天 新手友好度 66/100
java-native-access/jna#1738 ·
-
难度 4/5 3-5 天 新手友好度 45/100
java-native-access/jna#1736 ·
-
难度 3/5 1-2 天 新手友好度 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrect可能重新可做 @marktech0813 于 331 天前认领,目前没有进行中的 PR。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
java-native-access/jna#1700 · 11 条评论 ·
查看 java-native-access/jna 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
waiting-for-triage
难度 1/5 1 小时以内 新手友好度 72/100
spring-cloud/spring-cloud-openfeign#1443 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 84/100
ADORSYS-GIS/keycloak-oid4vp-plugin#221 ·
维护者通常 2 天内回复
-
status: team-only type: dependency-upgrade
难度 2/5 1-3 小时 新手友好度 65/100
spring-projects/spring-boot#52099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
tchiotludo/akhq#3307 · 1 个 reaction ·
维护者通常 1 天内回复