33#include < sys/param.h> // powerof2 ---> ((((x) - 1) & (x)) == 0)
44#include < unistd.h>
55#include < sys/stat.h>
6+ #include < linux/dma-heap.h>
67
78#include < cstring>
89#include < string>
@@ -334,7 +335,32 @@ int debug_ioctl(int fd, unsigned int request, void* arg) {
334335 gpu_ioctl_alloc = true ; // Only the calling thread will set this to true
335336 }
336337
337- return (int )syscall (SYS_ioctl, fd, request, arg);
338+ int ret = (int )syscall (SYS_ioctl, fd, request, arg);
339+ if (g_debug->TrackPointers () && request == DMA_HEAP_IOCTL_ALLOC) {
340+ struct dma_heap_allocation_data * heap = (struct dma_heap_allocation_data *)arg;
341+ if (DMA_BUF::is_dma_buf (heap->fd )) {
342+ void * ptr = reinterpret_cast <void *>(heap->fd );
343+ g_debug->pointer ->Add (ptr, heap->len , DMA);
344+ }
345+ }
346+
347+ return ret;
348+ }
349+
350+ int debug_close (int fd) {
351+ if (DebugCallsDisabled ()) {
352+ return (int )syscall (SYS_close, fd);
353+ }
354+
355+ ScopedConcurrentLock lock;
356+ ScopedDisableDebugCalls disable;
357+
358+ if (g_debug->TrackPointers ()) {
359+ void * ptr = reinterpret_cast <void *>(fd);
360+ g_debug->pointer ->Remove (ptr);
361+ }
362+
363+ return (int )syscall (SYS_close, fd);
338364}
339365
340366void * debug_mmap64 (void * addr, size_t size, int prot, int flags, int fd, off_t offset) {
@@ -361,7 +387,7 @@ void* debug_mmap64(void* addr, size_t size, int prot, int flags, int fd, off_t o
361387}
362388
363389void * debug_mmap (void * addr, size_t size, int prot, int flags, int fd, off_t offset) {
364- if (DebugCallsDisabled () || addr != nullptr ) {
390+ if (DebugCallsDisabled ()) {
365391 return (void *)syscall (SYS_mmap, addr, size, prot, flags, fd, offset);
366392 }
367393
@@ -377,8 +403,10 @@ void* debug_mmap(void* addr, size_t size, int prot, int flags, int fd, off_t off
377403 if (g_debug->TrackPointers ()) {
378404 if (fd < 0 )
379405 g_debug->pointer ->Add (result, size, MMAP);
380- else if (DMA_BUF::is_dma_buf (fd))
381- g_debug->pointer ->Add (result, size, DMA);
406+ else if (DMA_BUF::is_dma_buf (fd)) {
407+ void * ptr = reinterpret_cast <void *>(fd);
408+ g_debug->pointer ->Add (ptr, size, DMA);
409+ }
382410 }
383411
384412 return result;
0 commit comments