mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-24 21:28:10 +02:00
intel/executor: Add an overflow check for alloc function
Assisted-by: Pi coding agent (GPT-5.5) Acked-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41610>
This commit is contained in:
parent
3522f0f24c
commit
8d237b5408
1 changed files with 11 additions and 6 deletions
|
|
@ -348,12 +348,17 @@ executor_alloc_bytes(executor_bo *bo, uint32_t size)
|
|||
void *
|
||||
executor_alloc_bytes_aligned(executor_bo *bo, uint32_t size, uint32_t alignment)
|
||||
{
|
||||
void *r = bo->cursor;
|
||||
if (alignment) {
|
||||
r = (void *)(((uintptr_t)r + alignment-1) & ~((uintptr_t)alignment-1));
|
||||
}
|
||||
bo->cursor = r + size;
|
||||
return r;
|
||||
uintptr_t r = (uintptr_t)bo->cursor;
|
||||
if (alignment)
|
||||
r = (r + alignment - 1) & ~((uintptr_t)alignment - 1);
|
||||
|
||||
uint64_t offset = r - (uintptr_t)bo->map;
|
||||
if (offset > bo->size || size > bo->size - offset)
|
||||
failf("executor BO overflow");
|
||||
|
||||
void *ptr = (void *)r;
|
||||
bo->cursor = ptr + size;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
executor_address
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue