30 #include <winpr/wlog.h>
32 #include "TPCircularBuffer.h"
33 #include "rdpsnd_main.h"
35 #include <mach/mach.h>
38 #define reportResult(result, operation) (_reportResult((result), (operation), __FILE__, __LINE__))
39 static inline bool _reportResult(kern_return_t result,
const char* operation,
const char* file,
42 if (result != ERR_SUCCESS)
44 WLog_DBG(TAG,
"%s:%d: %s: %s\n", file, line, operation, mach_error_string(result));
58 buffer->length = round_page(length);
62 vm_address_t bufferAddress;
63 kern_return_t result = vm_allocate(mach_task_self(), &bufferAddress, buffer->length * 2,
65 if (result != ERR_SUCCESS)
69 reportResult(result,
"Buffer allocation");
78 result = vm_deallocate(mach_task_self(), bufferAddress + buffer->length, buffer->length);
79 if (result != ERR_SUCCESS)
83 reportResult(result,
"Buffer deallocation");
87 vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
92 vm_address_t virtualAddress = bufferAddress + buffer->length;
93 vm_prot_t cur_prot, max_prot;
94 result = vm_remap(mach_task_self(),
105 if (result != ERR_SUCCESS)
109 reportResult(result,
"Remap buffer memory");
113 vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
117 if (virtualAddress != bufferAddress + buffer->length)
122 WLog_DBG(TAG,
"Couldn't map buffer memory to end of buffer");
126 vm_deallocate(mach_task_self(), virtualAddress, buffer->length);
127 vm_deallocate(mach_task_self(), bufferAddress, buffer->length);
131 buffer->buffer = (
void*)bufferAddress;
132 buffer->fillCount = 0;
133 buffer->head = buffer->tail = 0;
142 vm_deallocate(mach_task_self(), (vm_address_t)buffer->buffer, buffer->length * 2);
149 if (TPCircularBufferTail(buffer, &fillCount))
151 TPCircularBufferConsume(buffer, fillCount);