mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 04:48:08 +02:00
util: add os_map_memory_fd_placed for placed mapping support
This completes the opaque fd api coverage, and is needed by lavapipe for sparse binding support with opaque fd external memory. Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38074>
This commit is contained in:
parent
743b9a52d9
commit
8f7543e450
2 changed files with 25 additions and 0 deletions
|
|
@ -105,6 +105,25 @@ os_import_memory_fd(int fd, void **ptr, uint64_t *size, char const *driver_id)
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map memory from a file descriptor at placed address
|
||||
*/
|
||||
bool
|
||||
os_map_memory_fd_placed(int fd, void *addr, uint64_t size, uint64_t offset,
|
||||
char const *driver_id)
|
||||
{
|
||||
struct memory_header header;
|
||||
|
||||
if (!get_fd_header(fd, &header, driver_id))
|
||||
return false;
|
||||
|
||||
if (header.size - header.offset < size + offset)
|
||||
return false;
|
||||
|
||||
return mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd,
|
||||
offset + header.offset) != MAP_FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return memory on given byte alignment
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@
|
|||
bool
|
||||
os_import_memory_fd(int fd, void **ptr, uint64_t *size, char const *driver_id);
|
||||
|
||||
/**
|
||||
* Map memory from a file descriptor at placed address
|
||||
*/
|
||||
bool
|
||||
os_map_memory_fd_placed(int fd, void *addr, uint64_t size, uint64_t offset, char const *driver_id);
|
||||
|
||||
/**
|
||||
* Return memory on given byte alignment
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue