Blame view
drivers/android/binder_alloc.h
6.15 KB
9c92ab619 treewide: Replace... |
1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
0c972a05c binder: move bind... |
2 3 |
/* * Copyright (C) 2017 Google, Inc. |
0c972a05c binder: move bind... |
4 5 6 7 8 9 10 11 12 13 14 |
*/ #ifndef _LINUX_BINDER_ALLOC_H #define _LINUX_BINDER_ALLOC_H #include <linux/rbtree.h> #include <linux/list.h> #include <linux/mm.h> #include <linux/rtmutex.h> #include <linux/vmalloc.h> #include <linux/slab.h> |
f2517eb76 android: binder: ... |
15 |
#include <linux/list_lru.h> |
1a7c3d9bb binder: create us... |
16 |
#include <uapi/linux/android/binder.h> |
0c972a05c binder: move bind... |
17 |
|
f2517eb76 android: binder: ... |
18 |
extern struct list_lru binder_alloc_lru; |
0c972a05c binder: move bind... |
19 20 21 22 23 24 |
struct binder_transaction; /** * struct binder_buffer - buffer used for binder transactions * @entry: entry alloc->buffers * @rb_node: node for allocated_buffers/free_buffers rb trees |
7a2670a5b binder: fix kerne... |
25 |
* @free: %true if buffer is free |
92b2ec218 UPSTREAM: binder:... |
26 |
* @clear_on_free: %true if buffer must be zeroed after use |
7a2670a5b binder: fix kerne... |
27 28 29 30 31 32 33 34 |
* @allow_user_free: %true if user is allowed to free buffer * @async_transaction: %true if buffer is in use for an async txn * @debug_id: unique ID for debugging * @transaction: pointer to associated struct binder_transaction * @target_node: struct binder_node associated with this buffer * @data_size: size of @transaction data * @offsets_size: size of array of offsets * @extra_buffers_size: size of space for other objects (like sg lists) |
bde4a19fc binder: use users... |
35 |
* @user_data: user pointer to base of buffer space |
261e7818f binder: print war... |
36 |
* @pid: pid to attribute the buffer to (caller) |
0c972a05c binder: move bind... |
37 38 39 40 41 42 43 44 |
* * Bookkeeping structure for binder transaction buffers */ struct binder_buffer { struct list_head entry; /* free and allocated entries by address */ struct rb_node rb_node; /* free entry by size or allocated entry */ /* by address */ unsigned free:1; |
92b2ec218 UPSTREAM: binder:... |
45 |
unsigned clear_on_free:1; |
0c972a05c binder: move bind... |
46 47 |
unsigned allow_user_free:1; unsigned async_transaction:1; |
92b2ec218 UPSTREAM: binder:... |
48 |
unsigned debug_id:28; |
0c972a05c binder: move bind... |
49 50 51 52 53 54 55 |
struct binder_transaction *transaction; struct binder_node *target_node; size_t data_size; size_t offsets_size; size_t extra_buffers_size; |
bde4a19fc binder: use users... |
56 |
void __user *user_data; |
261e7818f binder: print war... |
57 |
int pid; |
0c972a05c binder: move bind... |
58 59 60 |
}; /** |
f2517eb76 android: binder: ... |
61 62 63 64 65 66 67 68 69 70 71 72 |
* struct binder_lru_page - page object used for binder shrinker * @page_ptr: pointer to physical page in mmap'd space * @lru: entry in binder_alloc_lru * @alloc: binder_alloc for a proc */ struct binder_lru_page { struct list_head lru; struct page *page_ptr; struct binder_alloc *alloc; }; /** |
0c972a05c binder: move bind... |
73 74 75 76 77 78 79 |
* struct binder_alloc - per-binder proc state for binder allocator * @vma: vm_area_struct passed to mmap_handler * (invarient after mmap) * @tsk: tid for task that called init for this proc * (invariant after init) * @vma_vm_mm: copy of vma->vm_mm (invarient after mmap) * @buffer: base of per-proc address space mapped via mmap |
0c972a05c binder: move bind... |
80 81 82 83 84 85 |
* @buffers: list of all buffers for this proc * @free_buffers: rb tree of buffers available for allocation * sorted by size * @allocated_buffers: rb tree of allocated buffers sorted by address * @free_async_space: VA space available for async buffers. This is * initialized at mmap time to 1/2 the full VA space |
f2517eb76 android: binder: ... |
86 |
* @pages: array of binder_lru_page |
0c972a05c binder: move bind... |
87 88 |
* @buffer_size: size of address space specified via mmap * @pid: pid for associated binder_proc (invariant after init) |
8d9a3ab6c ANDROID: binder: ... |
89 |
* @pages_high: high watermark of offset in @pages |
0c972a05c binder: move bind... |
90 91 92 93 94 95 96 97 |
* * Bookkeeping structure for per-proc address space management for binder * buffers. It is normally initialized during binder_init() and binder_mmap() * calls. The address space is used for both user-visible buffers and for * struct binder_buffer objects used to track the user buffers */ struct binder_alloc { struct mutex mutex; |
0c972a05c binder: move bind... |
98 99 |
struct vm_area_struct *vma; struct mm_struct *vma_vm_mm; |
bde4a19fc binder: use users... |
100 |
void __user *buffer; |
0c972a05c binder: move bind... |
101 102 103 104 |
struct list_head buffers; struct rb_root free_buffers; struct rb_root allocated_buffers; size_t free_async_space; |
f2517eb76 android: binder: ... |
105 |
struct binder_lru_page *pages; |
0c972a05c binder: move bind... |
106 107 108 |
size_t buffer_size; uint32_t buffer_free; int pid; |
8d9a3ab6c ANDROID: binder: ... |
109 |
size_t pages_high; |
0c972a05c binder: move bind... |
110 |
}; |
4175e2b46 android: binder: ... |
111 112 113 114 115 |
#ifdef CONFIG_ANDROID_BINDER_IPC_SELFTEST void binder_selftest_alloc(struct binder_alloc *alloc); #else static inline void binder_selftest_alloc(struct binder_alloc *alloc) {} #endif |
f2517eb76 android: binder: ... |
116 117 118 |
enum lru_status binder_alloc_free_page(struct list_head *item, struct list_lru_one *lru, spinlock_t *lock, void *cb_arg); |
0c972a05c binder: move bind... |
119 120 121 122 |
extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, size_t data_size, size_t offsets_size, size_t extra_buffers_size, |
261e7818f binder: print war... |
123 124 |
int is_async, int pid); |
0c972a05c binder: move bind... |
125 |
extern void binder_alloc_init(struct binder_alloc *alloc); |
533dfb250 android: binder: ... |
126 |
extern int binder_alloc_shrinker_init(void); |
0c972a05c binder: move bind... |
127 128 |
extern void binder_alloc_vma_close(struct binder_alloc *alloc); extern struct binder_buffer * |
53d311cfa binder: protect a... |
129 130 |
binder_alloc_prepare_to_free(struct binder_alloc *alloc, uintptr_t user_ptr); |
0c972a05c binder: move bind... |
131 132 133 134 135 136 137 138 |
extern void binder_alloc_free_buf(struct binder_alloc *alloc, struct binder_buffer *buffer); extern int binder_alloc_mmap_handler(struct binder_alloc *alloc, struct vm_area_struct *vma); extern void binder_alloc_deferred_release(struct binder_alloc *alloc); extern int binder_alloc_get_allocated_count(struct binder_alloc *alloc); extern void binder_alloc_print_allocated(struct seq_file *m, struct binder_alloc *alloc); |
8ef4665aa android: binder: ... |
139 140 |
void binder_alloc_print_pages(struct seq_file *m, struct binder_alloc *alloc); |
0c972a05c binder: move bind... |
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
/** * binder_alloc_get_free_async_space() - get free space available for async * @alloc: binder_alloc for this proc * * Return: the bytes remaining in the address-space for async transactions */ static inline size_t binder_alloc_get_free_async_space(struct binder_alloc *alloc) { size_t free_async_space; mutex_lock(&alloc->mutex); free_async_space = alloc->free_async_space; mutex_unlock(&alloc->mutex); return free_async_space; } |
1a7c3d9bb binder: create us... |
158 159 160 161 162 163 |
unsigned long binder_alloc_copy_user_to_buffer(struct binder_alloc *alloc, struct binder_buffer *buffer, binder_size_t buffer_offset, const void __user *from, size_t bytes); |
bb4a2e48d binder: return er... |
164 165 166 167 168 169 170 171 172 173 174 |
int binder_alloc_copy_to_buffer(struct binder_alloc *alloc, struct binder_buffer *buffer, binder_size_t buffer_offset, void *src, size_t bytes); int binder_alloc_copy_from_buffer(struct binder_alloc *alloc, void *dest, struct binder_buffer *buffer, binder_size_t buffer_offset, size_t bytes); |
8ced0c623 binder: add funct... |
175 |
|
0c972a05c binder: move bind... |
176 |
#endif /* _LINUX_BINDER_ALLOC_H */ |