android C native测试程序example Android.bp

一个简单的android测试程序的Android.bp example如下,在android根目录下make slub_debug_test.bin即可:

cc_binary {
    srcs: ["slub_debug_test.c"],
    name: "slub_debug_test.bin",
      proprietary: true,
      owner: "self",
    shared_libs: ["libc"],
}

android native test program

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>

int main(__attribute__ ((unused)) int argc, __attribute__ ((unused)) char *argv[])
{
        int output = open("./test.txt", O_WRONLY);
        const char *val = "test";

        prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);

        write(output, val, strlen(val)+1);

        int input = open("./test.txt", O_RDONLY);
        printf("open test.txt fd: %d.\n", input);

        return 0;
}

 

posted @ 2021-09-05 18:51  aspirs  阅读(93)  评论(0编辑  收藏  举报