binderfs.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .. SPDX-License-Identifier: GPL-2.0
  2. The Android binderfs Filesystem
  3. ===============================
  4. Android binderfs is a filesystem for the Android binder IPC mechanism. It
  5. allows to dynamically add and remove binder devices at runtime. Binder devices
  6. located in a new binderfs instance are independent of binder devices located in
  7. other binderfs instances. Mounting a new binderfs instance makes it possible
  8. to get a set of private binder devices.
  9. Mounting binderfs
  10. -----------------
  11. Android binderfs can be mounted with::
  12. mkdir /dev/binderfs
  13. mount -t binder binder /dev/binderfs
  14. at which point a new instance of binderfs will show up at ``/dev/binderfs``.
  15. In a fresh instance of binderfs no binder devices will be present. There will
  16. only be a ``binder-control`` device which serves as the request handler for
  17. binderfs. Mounting another binderfs instance at a different location will
  18. create a new and separate instance from all other binderfs mounts. This is
  19. identical to the behavior of e.g. ``devpts`` and ``tmpfs``. The Android
  20. binderfs filesystem can be mounted in user namespaces.
  21. Options
  22. -------
  23. max
  24. binderfs instances can be mounted with a limit on the number of binder
  25. devices that can be allocated. The ``max=<count>`` mount option serves as
  26. a per-instance limit. If ``max=<count>`` is set then only ``<count>`` number
  27. of binder devices can be allocated in this binderfs instance.
  28. stats
  29. Using ``stats=global`` enables global binder statistics.
  30. ``stats=global`` is only available for a binderfs instance mounted in the
  31. initial user namespace. An attempt to use the option to mount a binderfs
  32. instance in another user namespace will return a permission error.
  33. Allocating binder Devices
  34. -------------------------
  35. .. _ioctl: http://man7.org/linux/man-pages/man2/ioctl.2.html
  36. To allocate a new binder device in a binderfs instance a request needs to be
  37. sent through the ``binder-control`` device node. A request is sent in the form
  38. of an `ioctl() <ioctl_>`_.
  39. What a program needs to do is to open the ``binder-control`` device node and
  40. send a ``BINDER_CTL_ADD`` request to the kernel. Users of binderfs need to
  41. tell the kernel which name the new binder device should get. By default a name
  42. can only contain up to ``BINDERFS_MAX_NAME`` chars including the terminating
  43. zero byte.
  44. Once the request is made via an `ioctl() <ioctl_>`_ passing a ``struct
  45. binder_device`` with the name to the kernel it will allocate a new binder
  46. device and return the major and minor number of the new device in the struct
  47. (This is necessary because binderfs allocates a major device number
  48. dynamically.). After the `ioctl() <ioctl_>`_ returns there will be a new
  49. binder device located under /dev/binderfs with the chosen name.
  50. Deleting binder Devices
  51. -----------------------
  52. .. _unlink: http://man7.org/linux/man-pages/man2/unlink.2.html
  53. .. _rm: http://man7.org/linux/man-pages/man1/rm.1.html
  54. Binderfs binder devices can be deleted via `unlink() <unlink_>`_. This means
  55. that the `rm() <rm_>`_ tool can be used to delete them. Note that the
  56. ``binder-control`` device cannot be deleted since this would make the binderfs
  57. instance unusable. The ``binder-control`` device will be deleted when the
  58. binderfs instance is unmounted and all references to it have been dropped.
  59. Binder features
  60. ---------------
  61. Assuming an instance of binderfs has been mounted at ``/dev/binderfs``, the
  62. features supported by the binder driver can be located under
  63. ``/dev/binderfs/features/``. The presence of individual files can be tested
  64. to determine whether a particular feature is supported by the driver.
  65. Example::
  66. cat /dev/binderfs/features/oneway_spam_detection
  67. 1