Skip to content

Commit

Permalink
teec: use multiple of page size for page aligned buffers
Browse files Browse the repository at this point in the history
When allocating a page aligned buffer, round the size up the next
multiple of page size. With this we can guarantee that a part of that
page isn't registered already.

Signed-off-by: Jens Wiklander <[email protected]>
  • Loading branch information
jenswi-linaro committed Sep 28, 2023
1 parent 8533e0e commit ede2cde
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libteec/src/tee_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ static void teec_mutex_unlock(pthread_mutex_t *mu)
static void *teec_paged_aligned_alloc(size_t sz)
{
void *p = NULL;
size_t page_sz = sysconf(_SC_PAGESIZE);
size_t aligned_sz = ((sz + page_sz - 1) / page_sz) * page_sz;

if (!posix_memalign(&p, sysconf(_SC_PAGESIZE), sz))
if (!posix_memalign(&p, page_sz, aligned_sz))
return p;

return NULL;
Expand Down

0 comments on commit ede2cde

Please sign in to comment.