Created
September 26, 2021 10:50
-
-
Save sigmaSd/b61466a8aad17468e6214dbaa154f7b6 to your computer and use it in GitHub Desktop.
Allocate binder devices for waydroid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/ioctl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <linux/android/binder.h> | |
#include <linux/android/binderfs.h> | |
int main(int argc, char *argv[]) | |
{ | |
// Prepare binderfs devices | |
struct binderfs_device binder = { 0 }; | |
struct binderfs_device hwbinder = { 0 }; | |
struct binderfs_device vndbinder = { 0 }; | |
memcpy(binder.name, "binder", strlen("binder")); | |
memcpy(hwbinder.name, "hwbinder", strlen("hwbinder")); | |
memcpy(vndbinder.name, "vndbinder", strlen("vndbinder")); | |
// Allocate binderfs devices | |
int fd = open("/dev/binderfs/binder-control", O_RDONLY | O_CLOEXEC); | |
ioctl(fd, BINDER_CTL_ADD, &binder); | |
ioctl(fd, BINDER_CTL_ADD, &hwbinder); | |
ioctl(fd, BINDER_CTL_ADD, &vndbinder); | |
close(fd); | |
// Symlink to dev | |
symlink("/dev/binderfs/binder", "/dev/binder"); | |
symlink("/dev/binderfs/hwbinder", "/dev/hwbinder"); | |
symlink("/dev/binderfs/vndbinder", "/dev/vndbinder"); | |
// Make it accessible to normal users | |
chmod("/dev/binder",strtol("0777",0,8)); | |
chmod("/dev/hwbinder",strtol("0777",0,8)); | |
chmod("/dev/vndbinder",strtol("0777",0,8)); | |
// all good exit | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment