summaryrefslogtreecommitdiff
path: root/firmware/buflib.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/buflib.c')
-rw-r--r--firmware/buflib.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c
index 4233bf9a61..d7a24b8722 100644
--- a/firmware/buflib.c
+++ b/firmware/buflib.c
@@ -117,6 +117,32 @@ buflib_init(struct buflib_context *ctx, void *buf, size_t size)
117 (unsigned long)size / 1024, ((unsigned long)size%1000)/10); 117 (unsigned long)size / 1024, ((unsigned long)size%1000)/10);
118} 118}
119 119
120bool buflib_context_relocate(struct buflib_context *ctx, void *buf)
121{
122 union buflib_data *handle, *bd_buf = buf;
123 ptrdiff_t diff = bd_buf - ctx->buf_start;
124
125 /* cannot continue if the buffer is not aligned, since we would need
126 * to reduce the size of the buffer for aligning */
127 if ((uintptr_t)buf & 0x3)
128 return false;
129
130 /* relocate the handle table entries */
131 for (handle = ctx->last_handle; handle < ctx->handle_table; handle++)
132 {
133 if (handle->alloc)
134 handle->alloc += diff * sizeof(union buflib_data);
135 }
136 /* relocate the pointers in the context */
137 ctx->handle_table += diff;
138 ctx->last_handle += diff;
139 ctx->first_free_handle += diff;
140 ctx->buf_start += diff;
141 ctx->alloc_end += diff;
142
143 return true;
144}
145
120/* Allocate a new handle, returning 0 on failure */ 146/* Allocate a new handle, returning 0 on failure */
121static inline 147static inline
122union buflib_data* handle_alloc(struct buflib_context *ctx) 148union buflib_data* handle_alloc(struct buflib_context *ctx)