Open Saikatsaha1996 opened 2 years ago
clone
operation is available in Android.
#define _GNU_SOURCE
#include <signal.h>
#include <sched.h>
static int child_func(void* arg) {
char* buf = (char*)arg;
printf("Child sees buf = \"%s\"\n", buf);
strcpy(buf, "hello from child");
return 0;
}
int main(int argc, char** argv) {
// Allocate stack for child task.
const int STACK_SIZE = 65536;
char* stack = malloc(STACK_SIZE);
if (!stack) {
perror("malloc");
exit(1);
}
// When called with the command-line argument "vm", set the CLONE_VM flag on.
unsigned long flags = 0;
if (argc > 1 && !strcmp(argv[1], "vm")) {
flags |= CLONE_VM;
}
char buf[100];
strcpy(buf, "hello from parent");
if (clone(child_func, stack + STACK_SIZE, CLONE_VM | SIGCHLD, buf) == -1) {
perror("clone");
exit(1);
}
int status;
if (wait(&status) == -1) {
perror("wait");
exit(1);
}
printf("Child exited with status %d. buf = \"%s\"\n", status, buf);
return 0;
}
#define _GNU_SOURCE #include <signal.h> #include <sched.h> static int child_func(void* arg) { char* buf = (char*)arg; printf("Child sees buf = \"%s\"\n", buf); strcpy(buf, "hello from child"); return 0; } int main(int argc, char** argv) { // Allocate stack for child task. const int STACK_SIZE = 65536; char* stack = malloc(STACK_SIZE); if (!stack) { perror("malloc"); exit(1); } // When called with the command-line argument "vm", set the CLONE_VM flag on. unsigned long flags = 0; if (argc > 1 && !strcmp(argv[1], "vm")) { flags |= CLONE_VM; } char buf[100]; strcpy(buf, "hello from parent"); if (clone(child_func, stack + STACK_SIZE, CLONE_VM | SIGCHLD, buf) == -1) { perror("clone"); exit(1); } int status; if (wait(&status) == -1) { perror("wait"); exit(1); } printf("Child exited with status %d. buf = \"%s\"\n", status, buf); return 0; }
I should create .so
file with this ? And need to set as LD_PRELOAD ?
Found more information https://github.com/DynamoRIO/dynamorio/blob/master/suite/tests/linux/clone.c
I should create
.so
file with this ?
No, it's a clone
working test example. Just compile it with gcc
and run it. Test it in Android and in Exagear. In Exagear it will not run, in Android it will.
I should create
.so
file with this ?No, it's a
clone
working test example. Just compile it withgcc
and run it. Test it in Android and in Exagear. In Exagear it will not run, in Android it will.
gcc hello.c -o hello
hello.c:7:3: warning: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
printf("Child sees buf = \"%s\"\n", buf);
^
hello.c:7:3: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
hello.c:8:3: warning: call to undeclared library function 'strcpy' with type 'char *(char *, const char *)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
strcpy(buf, "hello from child");
^
hello.c:8:3: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
hello.c:15:17: warning: call to undeclared library function 'malloc' with type 'void *(unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
char* stack = malloc(STACK_SIZE);
^
hello.c:15:17: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
hello.c:17:5: warning: call to undeclared function 'perror'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
perror("malloc");
^
hello.c:18:5: warning: call to undeclared library function 'exit' with type 'void (int) __attribute__((noreturn))'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
exit(1);
^
hello.c:18:5: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit'
hello.c:23:20: warning: call to undeclared library function 'strcmp' with type 'int (const char *, const char *)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
if (argc > 1 && !strcmp(argv[1], "vm")) {
^
hello.c:23:20: note: include the header <string.h> or explicitly provide a declaration for 'strcmp'
hello.c:30:5: warning: call to undeclared function 'perror'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
perror("clone");
^
hello.c:35:7: warning: call to undeclared function 'wait'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
if (wait(&status) == -1) {
^
hello.c:36:5: warning: call to undeclared function 'perror'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
perror("wait");
^
9 warnings generated.
~ $ ls
ExaTermux hello storage
fs-manager-udroid hello.c termux-android12-phantom-fix
~ $ ./he*
Child sees buf = "hello from parent"
Child exited with status 0. buf = "hello from child"
~ $
Which distribution do you use ? Debian 11? The problem seems to be closely related to the operating system. I confirm this but in different environment. I've Odroid xu4 armhf SOC with Debian 11 as a host and Exagear Debian 9 as a guest . I've build Acestreamplayer in guest. If I start play any file Acestreamplayer crash with that issue. NOTE. vlc play well NOTE. Ubuntu version do not have this issue.