Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * Copyright (C) 2008 Google, Inc.
0004  *
0005  * Based on, but no longer compatible with, the original
0006  * OpenBinder.org binder driver interface, which is:
0007  *
0008  * Copyright (c) 2005 Palmsource, Inc.
0009  *
0010  * This software is licensed under the terms of the GNU General Public
0011  * License version 2, as published by the Free Software Foundation, and
0012  * may be copied, distributed, and modified under those terms.
0013  *
0014  * This program is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017  * GNU General Public License for more details.
0018  *
0019  */
0020 
0021 #ifndef _UAPI_LINUX_BINDER_H
0022 #define _UAPI_LINUX_BINDER_H
0023 
0024 #include <linux/types.h>
0025 #include <linux/ioctl.h>
0026 
0027 #define B_PACK_CHARS(c1, c2, c3, c4) \
0028     ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
0029 #define B_TYPE_LARGE 0x85
0030 
0031 enum {
0032     BINDER_TYPE_BINDER  = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
0033     BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
0034     BINDER_TYPE_HANDLE  = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
0035     BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
0036     BINDER_TYPE_FD      = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
0037     BINDER_TYPE_FDA     = B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE),
0038     BINDER_TYPE_PTR     = B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE),
0039 };
0040 
0041 enum {
0042     FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
0043     FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
0044 
0045     /**
0046      * @FLAT_BINDER_FLAG_TXN_SECURITY_CTX: request security contexts
0047      *
0048      * Only when set, causes senders to include their security
0049      * context
0050      */
0051     FLAT_BINDER_FLAG_TXN_SECURITY_CTX = 0x1000,
0052 };
0053 
0054 #ifdef BINDER_IPC_32BIT
0055 typedef __u32 binder_size_t;
0056 typedef __u32 binder_uintptr_t;
0057 #else
0058 typedef __u64 binder_size_t;
0059 typedef __u64 binder_uintptr_t;
0060 #endif
0061 
0062 /**
0063  * struct binder_object_header - header shared by all binder metadata objects.
0064  * @type:   type of the object
0065  */
0066 struct binder_object_header {
0067     __u32        type;
0068 };
0069 
0070 /*
0071  * This is the flattened representation of a Binder object for transfer
0072  * between processes.  The 'offsets' supplied as part of a binder transaction
0073  * contains offsets into the data where these structures occur.  The Binder
0074  * driver takes care of re-writing the structure type and data as it moves
0075  * between processes.
0076  */
0077 struct flat_binder_object {
0078     struct binder_object_header hdr;
0079     __u32               flags;
0080 
0081     /* 8 bytes of data. */
0082     union {
0083         binder_uintptr_t    binder; /* local object */
0084         __u32           handle; /* remote object */
0085     };
0086 
0087     /* extra data associated with local object */
0088     binder_uintptr_t    cookie;
0089 };
0090 
0091 /**
0092  * struct binder_fd_object - describes a filedescriptor to be fixed up.
0093  * @hdr:    common header structure
0094  * @pad_flags:  padding to remain compatible with old userspace code
0095  * @pad_binder: padding to remain compatible with old userspace code
0096  * @fd:     file descriptor
0097  * @cookie: opaque data, used by user-space
0098  */
0099 struct binder_fd_object {
0100     struct binder_object_header hdr;
0101     __u32               pad_flags;
0102     union {
0103         binder_uintptr_t    pad_binder;
0104         __u32           fd;
0105     };
0106 
0107     binder_uintptr_t        cookie;
0108 };
0109 
0110 /* struct binder_buffer_object - object describing a userspace buffer
0111  * @hdr:        common header structure
0112  * @flags:      one or more BINDER_BUFFER_* flags
0113  * @buffer:     address of the buffer
0114  * @length:     length of the buffer
0115  * @parent:     index in offset array pointing to parent buffer
0116  * @parent_offset:  offset in @parent pointing to this buffer
0117  *
0118  * A binder_buffer object represents an object that the
0119  * binder kernel driver can copy verbatim to the target
0120  * address space. A buffer itself may be pointed to from
0121  * within another buffer, meaning that the pointer inside
0122  * that other buffer needs to be fixed up as well. This
0123  * can be done by setting the BINDER_BUFFER_FLAG_HAS_PARENT
0124  * flag in @flags, by setting @parent buffer to the index
0125  * in the offset array pointing to the parent binder_buffer_object,
0126  * and by setting @parent_offset to the offset in the parent buffer
0127  * at which the pointer to this buffer is located.
0128  */
0129 struct binder_buffer_object {
0130     struct binder_object_header hdr;
0131     __u32               flags;
0132     binder_uintptr_t        buffer;
0133     binder_size_t           length;
0134     binder_size_t           parent;
0135     binder_size_t           parent_offset;
0136 };
0137 
0138 enum {
0139     BINDER_BUFFER_FLAG_HAS_PARENT = 0x01,
0140 };
0141 
0142 /* struct binder_fd_array_object - object describing an array of fds in a buffer
0143  * @hdr:        common header structure
0144  * @pad:        padding to ensure correct alignment
0145  * @num_fds:        number of file descriptors in the buffer
0146  * @parent:     index in offset array to buffer holding the fd array
0147  * @parent_offset:  start offset of fd array in the buffer
0148  *
0149  * A binder_fd_array object represents an array of file
0150  * descriptors embedded in a binder_buffer_object. It is
0151  * different from a regular binder_buffer_object because it
0152  * describes a list of file descriptors to fix up, not an opaque
0153  * blob of memory, and hence the kernel needs to treat it differently.
0154  *
0155  * An example of how this would be used is with Android's
0156  * native_handle_t object, which is a struct with a list of integers
0157  * and a list of file descriptors. The native_handle_t struct itself
0158  * will be represented by a struct binder_buffer_objct, whereas the
0159  * embedded list of file descriptors is represented by a
0160  * struct binder_fd_array_object with that binder_buffer_object as
0161  * a parent.
0162  */
0163 struct binder_fd_array_object {
0164     struct binder_object_header hdr;
0165     __u32               pad;
0166     binder_size_t           num_fds;
0167     binder_size_t           parent;
0168     binder_size_t           parent_offset;
0169 };
0170 
0171 /*
0172  * On 64-bit platforms where user code may run in 32-bits the driver must
0173  * translate the buffer (and local binder) addresses appropriately.
0174  */
0175 
0176 struct binder_write_read {
0177     binder_size_t       write_size; /* bytes to write */
0178     binder_size_t       write_consumed; /* bytes consumed by driver */
0179     binder_uintptr_t    write_buffer;
0180     binder_size_t       read_size;  /* bytes to read */
0181     binder_size_t       read_consumed;  /* bytes consumed by driver */
0182     binder_uintptr_t    read_buffer;
0183 };
0184 
0185 /* Use with BINDER_VERSION, driver fills in fields. */
0186 struct binder_version {
0187     /* driver protocol version -- increment with incompatible change */
0188     __s32       protocol_version;
0189 };
0190 
0191 /* This is the current protocol version. */
0192 #ifdef BINDER_IPC_32BIT
0193 #define BINDER_CURRENT_PROTOCOL_VERSION 7
0194 #else
0195 #define BINDER_CURRENT_PROTOCOL_VERSION 8
0196 #endif
0197 
0198 /*
0199  * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields.
0200  * Set ptr to NULL for the first call to get the info for the first node, and
0201  * then repeat the call passing the previously returned value to get the next
0202  * nodes.  ptr will be 0 when there are no more nodes.
0203  */
0204 struct binder_node_debug_info {
0205     binder_uintptr_t ptr;
0206     binder_uintptr_t cookie;
0207     __u32            has_strong_ref;
0208     __u32            has_weak_ref;
0209 };
0210 
0211 struct binder_node_info_for_ref {
0212     __u32            handle;
0213     __u32            strong_count;
0214     __u32            weak_count;
0215     __u32            reserved1;
0216     __u32            reserved2;
0217     __u32            reserved3;
0218 };
0219 
0220 struct binder_freeze_info {
0221     __u32            pid;
0222     __u32            enable;
0223     __u32            timeout_ms;
0224 };
0225 
0226 struct binder_frozen_status_info {
0227     __u32            pid;
0228 
0229     /* process received sync transactions since last frozen
0230      * bit 0: received sync transaction after being frozen
0231      * bit 1: new pending sync transaction during freezing
0232      */
0233     __u32            sync_recv;
0234 
0235     /* process received async transactions since last frozen */
0236     __u32            async_recv;
0237 };
0238 
0239 /* struct binder_extened_error - extended error information
0240  * @id:     identifier for the failed operation
0241  * @command:    command as defined by binder_driver_return_protocol
0242  * @param:  parameter holding a negative errno value
0243  *
0244  * Used with BINDER_GET_EXTENDED_ERROR. This extends the error information
0245  * returned by the driver upon a failed operation. Userspace can pull this
0246  * data to properly handle specific error scenarios.
0247  */
0248 struct binder_extended_error {
0249     __u32   id;
0250     __u32   command;
0251     __s32   param;
0252 };
0253 
0254 #define BINDER_WRITE_READ       _IOWR('b', 1, struct binder_write_read)
0255 #define BINDER_SET_IDLE_TIMEOUT     _IOW('b', 3, __s64)
0256 #define BINDER_SET_MAX_THREADS      _IOW('b', 5, __u32)
0257 #define BINDER_SET_IDLE_PRIORITY    _IOW('b', 6, __s32)
0258 #define BINDER_SET_CONTEXT_MGR      _IOW('b', 7, __s32)
0259 #define BINDER_THREAD_EXIT      _IOW('b', 8, __s32)
0260 #define BINDER_VERSION          _IOWR('b', 9, struct binder_version)
0261 #define BINDER_GET_NODE_DEBUG_INFO  _IOWR('b', 11, struct binder_node_debug_info)
0262 #define BINDER_GET_NODE_INFO_FOR_REF    _IOWR('b', 12, struct binder_node_info_for_ref)
0263 #define BINDER_SET_CONTEXT_MGR_EXT  _IOW('b', 13, struct flat_binder_object)
0264 #define BINDER_FREEZE           _IOW('b', 14, struct binder_freeze_info)
0265 #define BINDER_GET_FROZEN_INFO      _IOWR('b', 15, struct binder_frozen_status_info)
0266 #define BINDER_ENABLE_ONEWAY_SPAM_DETECTION _IOW('b', 16, __u32)
0267 #define BINDER_GET_EXTENDED_ERROR   _IOWR('b', 17, struct binder_extended_error)
0268 
0269 /*
0270  * NOTE: Two special error codes you should check for when calling
0271  * in to the driver are:
0272  *
0273  * EINTR -- The operation has been interupted.  This should be
0274  * handled by retrying the ioctl() until a different error code
0275  * is returned.
0276  *
0277  * ECONNREFUSED -- The driver is no longer accepting operations
0278  * from your process.  That is, the process is being destroyed.
0279  * You should handle this by exiting from your process.  Note
0280  * that once this error code is returned, all further calls to
0281  * the driver from any thread will return this same code.
0282  */
0283 
0284 enum transaction_flags {
0285     TF_ONE_WAY  = 0x01, /* this is a one-way call: async, no return */
0286     TF_ROOT_OBJECT  = 0x04, /* contents are the component's root object */
0287     TF_STATUS_CODE  = 0x08, /* contents are a 32-bit status code */
0288     TF_ACCEPT_FDS   = 0x10, /* allow replies with file descriptors */
0289     TF_CLEAR_BUF    = 0x20, /* clear buffer on txn complete */
0290     TF_UPDATE_TXN   = 0x40, /* update the outdated pending async txn */
0291 };
0292 
0293 struct binder_transaction_data {
0294     /* The first two are only used for bcTRANSACTION and brTRANSACTION,
0295      * identifying the target and contents of the transaction.
0296      */
0297     union {
0298         /* target descriptor of command transaction */
0299         __u32   handle;
0300         /* target descriptor of return transaction */
0301         binder_uintptr_t ptr;
0302     } target;
0303     binder_uintptr_t    cookie; /* target object cookie */
0304     __u32       code;       /* transaction command */
0305 
0306     /* General information about the transaction. */
0307     __u32           flags;
0308     __kernel_pid_t  sender_pid;
0309     __kernel_uid32_t    sender_euid;
0310     binder_size_t   data_size;  /* number of bytes of data */
0311     binder_size_t   offsets_size;   /* number of bytes of offsets */
0312 
0313     /* If this transaction is inline, the data immediately
0314      * follows here; otherwise, it ends with a pointer to
0315      * the data buffer.
0316      */
0317     union {
0318         struct {
0319             /* transaction data */
0320             binder_uintptr_t    buffer;
0321             /* offsets from buffer to flat_binder_object structs */
0322             binder_uintptr_t    offsets;
0323         } ptr;
0324         __u8    buf[8];
0325     } data;
0326 };
0327 
0328 struct binder_transaction_data_secctx {
0329     struct binder_transaction_data transaction_data;
0330     binder_uintptr_t secctx;
0331 };
0332 
0333 struct binder_transaction_data_sg {
0334     struct binder_transaction_data transaction_data;
0335     binder_size_t buffers_size;
0336 };
0337 
0338 struct binder_ptr_cookie {
0339     binder_uintptr_t ptr;
0340     binder_uintptr_t cookie;
0341 };
0342 
0343 struct binder_handle_cookie {
0344     __u32 handle;
0345     binder_uintptr_t cookie;
0346 } __packed;
0347 
0348 struct binder_pri_desc {
0349     __s32 priority;
0350     __u32 desc;
0351 };
0352 
0353 struct binder_pri_ptr_cookie {
0354     __s32 priority;
0355     binder_uintptr_t ptr;
0356     binder_uintptr_t cookie;
0357 };
0358 
0359 enum binder_driver_return_protocol {
0360     BR_ERROR = _IOR('r', 0, __s32),
0361     /*
0362      * int: error code
0363      */
0364 
0365     BR_OK = _IO('r', 1),
0366     /* No parameters! */
0367 
0368     BR_TRANSACTION_SEC_CTX = _IOR('r', 2,
0369                       struct binder_transaction_data_secctx),
0370     /*
0371      * binder_transaction_data_secctx: the received command.
0372      */
0373     BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
0374     BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
0375     /*
0376      * binder_transaction_data: the received command.
0377      */
0378 
0379     BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
0380     /*
0381      * not currently supported
0382      * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
0383      * Else the remote object has acquired a primary reference.
0384      */
0385 
0386     BR_DEAD_REPLY = _IO('r', 5),
0387     /*
0388      * The target of the last transaction (either a bcTRANSACTION or
0389      * a bcATTEMPT_ACQUIRE) is no longer with us.  No parameters.
0390      */
0391 
0392     BR_TRANSACTION_COMPLETE = _IO('r', 6),
0393     /*
0394      * No parameters... always refers to the last transaction requested
0395      * (including replies).  Note that this will be sent even for
0396      * asynchronous transactions.
0397      */
0398 
0399     BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
0400     BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
0401     BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
0402     BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
0403     /*
0404      * void *:  ptr to binder
0405      * void *: cookie for binder
0406      */
0407 
0408     BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
0409     /*
0410      * not currently supported
0411      * int: priority
0412      * void *: ptr to binder
0413      * void *: cookie for binder
0414      */
0415 
0416     BR_NOOP = _IO('r', 12),
0417     /*
0418      * No parameters.  Do nothing and examine the next command.  It exists
0419      * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
0420      */
0421 
0422     BR_SPAWN_LOOPER = _IO('r', 13),
0423     /*
0424      * No parameters.  The driver has determined that a process has no
0425      * threads waiting to service incoming transactions.  When a process
0426      * receives this command, it must spawn a new service thread and
0427      * register it via bcENTER_LOOPER.
0428      */
0429 
0430     BR_FINISHED = _IO('r', 14),
0431     /*
0432      * not currently supported
0433      * stop threadpool thread
0434      */
0435 
0436     BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
0437     /*
0438      * void *: cookie
0439      */
0440     BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
0441     /*
0442      * void *: cookie
0443      */
0444 
0445     BR_FAILED_REPLY = _IO('r', 17),
0446     /*
0447      * The last transaction (either a bcTRANSACTION or
0448      * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory).  No parameters.
0449      */
0450 
0451     BR_FROZEN_REPLY = _IO('r', 18),
0452     /*
0453      * The target of the last transaction (either a bcTRANSACTION or
0454      * a bcATTEMPT_ACQUIRE) is frozen.  No parameters.
0455      */
0456 
0457     BR_ONEWAY_SPAM_SUSPECT = _IO('r', 19),
0458     /*
0459      * Current process sent too many oneway calls to target, and the last
0460      * asynchronous transaction makes the allocated async buffer size exceed
0461      * detection threshold.  No parameters.
0462      */
0463 };
0464 
0465 enum binder_driver_command_protocol {
0466     BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
0467     BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
0468     /*
0469      * binder_transaction_data: the sent command.
0470      */
0471 
0472     BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
0473     /*
0474      * not currently supported
0475      * int:  0 if the last BR_ATTEMPT_ACQUIRE was not successful.
0476      * Else you have acquired a primary reference on the object.
0477      */
0478 
0479     BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
0480     /*
0481      * void *: ptr to transaction data received on a read
0482      */
0483 
0484     BC_INCREFS = _IOW('c', 4, __u32),
0485     BC_ACQUIRE = _IOW('c', 5, __u32),
0486     BC_RELEASE = _IOW('c', 6, __u32),
0487     BC_DECREFS = _IOW('c', 7, __u32),
0488     /*
0489      * int: descriptor
0490      */
0491 
0492     BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
0493     BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
0494     /*
0495      * void *: ptr to binder
0496      * void *: cookie for binder
0497      */
0498 
0499     BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
0500     /*
0501      * not currently supported
0502      * int: priority
0503      * int: descriptor
0504      */
0505 
0506     BC_REGISTER_LOOPER = _IO('c', 11),
0507     /*
0508      * No parameters.
0509      * Register a spawned looper thread with the device.
0510      */
0511 
0512     BC_ENTER_LOOPER = _IO('c', 12),
0513     BC_EXIT_LOOPER = _IO('c', 13),
0514     /*
0515      * No parameters.
0516      * These two commands are sent as an application-level thread
0517      * enters and exits the binder loop, respectively.  They are
0518      * used so the binder can have an accurate count of the number
0519      * of looping threads it has available.
0520      */
0521 
0522     BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14,
0523                         struct binder_handle_cookie),
0524     /*
0525      * int: handle
0526      * void *: cookie
0527      */
0528 
0529     BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15,
0530                         struct binder_handle_cookie),
0531     /*
0532      * int: handle
0533      * void *: cookie
0534      */
0535 
0536     BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
0537     /*
0538      * void *: cookie
0539      */
0540 
0541     BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg),
0542     BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg),
0543     /*
0544      * binder_transaction_data_sg: the sent command.
0545      */
0546 };
0547 
0548 #endif /* _UAPI_LINUX_BINDER_H */
0549