应用对系统的跨进程调用次数太多,超过了系统规定的阈值,导致应用被Kill

1.问题描述:
【Super Cleaner-Antivirus..】【必现】【非单机问题】点击进入软件,软件闪退

2.根本原因
从log来看,是由于应用发送了太多Binder给系统,也就是应用对系统的跨进程调用次数太多,超过了系统规定的阈值,导致应用被Kill。

05-29 12:04:32.364 1218 1374 E ActivityManager: Uid 10109 sent too many Binders to uid 1000
05-29 12:04:32.365 1218 1374 I ActivityManager: Killing 8231:com.apps.go.clean.boost.master:applockLibService/u0a109 (adj 500): Too many Binders sent to SYSTEM
05-29 12:04:32.368 1218 1377 W libprocessgroup: kill(-8231, 9) failed: No such process
05-29 12:04:32.369 748 748 E ANDR-IOP: IOP HAL: Received pkg_name = com.apps.go.clean.boost.master:applockLibService pid = 0
05-29 12:04:32.371 1218 1374 W ActivityManager: Scheduling restart of crashed service com.apps.go.clean.boost.master/com.clean.spaceplus.batterysaver.BatteryService in 1000ms
05-29 12:04:32.377 1218 1374 I ActivityManager: Killing 8317:com.apps.go.clean.boost.master/u0a109 (adj 500): Too many Binders sent to SYSTEM
05-29 12:04:32.377 1218 1225 I BpBinder: Limit reached bit reset for uid 1000 (fewer than 10109 proxies from uid 5500 held)
05-29 12:04:32.379 748 748 E ANDR-IOP: IOP HAL: Received pkg_name = com.apps.go.clean.boost.master pid = 0
05-29 12:04:32.380 1218 1374 W ActivityManager: Scheduling restart of crashed service com.apps.go.clean.boost.master/com.power.PowerService in 10992ms
05-29 12:04:32.412 663 663 I Zygote : Process 8317 exited due to signal (9)
05-29 12:04:32.419 663 663 I Zygote : Process 8231 exited due to signal (9)
05-29 12:04:32.419 1218 1377 W libprocessgroup: kill(-8231, 9) failed: No such process
05-29 12:04:32.420 1218 1377 I libprocessgroup: Successfully killed process cgroup uid 10109 pid 8231 in 52ms
05-29 12:04:32.420 1218 1377 W libprocessgroup: kill(-8317, 9) failed: No such process
05-29 12:04:32.421 1218 1377 I libprocessgroup: Successfully killed process cgroup uid 10109 pid 8317 in 0ms

在Android P源码的ActivityManagerService.java中:

    BinderInternal.nSetBinderProxyCountWatermarks(6000,5500);
    BinderInternal.nSetBinderProxyCountEnabled(true);
    BinderInternal.setBinderProxyCountCallback(
            new BinderInternal.BinderProxyLimitListener() {
                @Override
                public void onLimitReached(int uid) {
                    Slog.wtf(TAG, "Uid " + uid + " sent too many Binders to uid "
                            + Process.myUid());
                    if (uid == Process.SYSTEM_UID) {
                        Slog.i(TAG, "Skipping kill (uid is SYSTEM)");
                    } else {
                        killUid(UserHandle.getAppId(uid), UserHandle.getUserId(uid),
                                "Too many Binders sent to SYSTEM");
                    }
                }
            }, mHandler);

这是Android P新增的代码,目的是对Binder的创建与销毁进行管理,第一行代码是给整个Android系统所能创建的Binder数量的最大值进行了限制,如果超过了6000,就会回调第三行设置的接口回调。
如果进程的UID不是SYSTEM_UID,就会被Kill掉。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里给出一个伪代码实现: 1. 定义一个全局变量,用于记录特定系统调用被使用的次数,初始值为 0。 ``` int count = 0; ``` 2. 在系统调用实现函数中,每次调用特定系统调用时,将该全局变量加 1。 ``` // 假设特定系统调用的编号为 123 if (syscall_number == 123) { count++; } ``` 3. 定义一个新的系统调用,用于查询特定系统调用被使用的次数。 ``` long sys_get_count(void) { return count; } ``` 4. 将该系统调用注册到内核中。 ``` // 假设系统调用号为 4242 static const struct file_operations count_fops = { .owner = THIS_MODULE, .unlocked_ioctl = sys_get_count }; static int __init init_syscalls(void) { int err; err = register_chrdev(4242, "count", &count_fops); if (err < 0) { return err; } return 0; } static void __exit exit_syscalls(void) { unregister_chrdev(4242, "count"); } module_init(init_syscalls); module_exit(exit_syscalls); ``` 5. 用户程序可以通过调用新注册的系统调用来查询特定系统调用被使用的次数。 ``` #include <sys/ioctl.h> #include <stdio.h> #define GET_COUNT _IOR('c', 1, int) int main() { int fd, count; fd = open("/dev/count", 0); if (fd < 0) { perror("open"); return 1; } if (ioctl(fd, GET_COUNT, &count) < 0) { perror("ioctl"); return 1; } printf("count = %d\n", count); close(fd); return 0; } ``` 注意事项: 1. 实际的实现需要考虑多线程并发访问的问题,可以使用原子操作或锁来保护全局变量。 2. 特定系统调用的编号需要根据实际情况进行调整。 3. 系统调用号需要在内核中唯一,不与其他系统调用冲突。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值