-
Notifications
You must be signed in to change notification settings - Fork 42
/
EWProxyFrameBufferClient.cpp
369 lines (331 loc) · 10.3 KB
/
EWProxyFrameBufferClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*
* PSPScreenClient.cpp
* PSPScreenDriver
*
* Created by Enno Welbers on 28.02.09.
* Copyright 2009 __MyCompanyName__. All rights reserved.
*
*/
#include <IOKit/IOLib.h>
#include <IOKit/IOKitKeys.h>
#include <libkern/OSByteOrder.h>
#include "EWProxyFrameBufferClient.h"
#include "EWProxyFrameBufferFBuffer.h"
#define super IOUserClient
OSDefineMetaClassAndStructors(info_ennowelbers_proxyframebuffer_client, IOUserClient)
#pragma mark Dispatch table
const IOExternalMethodDispatch info_ennowelbers_proxyframebuffer_client::sMethods[kNumberOfMethods] = {
{
(IOExternalMethodAction) &info_ennowelbers_proxyframebuffer_client::sStartFramebuffer,//Action
1,//number of scalar inputs
0,//struct input size
0,//number of scalar outputs
0,//struct output size
},
{
(IOExternalMethodAction) &info_ennowelbers_proxyframebuffer_client::sStopFramebuffer,
0,
0,
0,
0,
},
{
(IOExternalMethodAction) &info_ennowelbers_proxyframebuffer_client::sCheckFramebufferState,
0,
0,
0,
0,
},
{
(IOExternalMethodAction) &info_ennowelbers_proxyframebuffer_client::sUpdateMemory,
0,
0,
0,
0,
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sGetModeCount,
0,
0,
0,
0,
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sGetModeInfo,
1,
0,
0,
sizeof(EWProxyFramebufferModeInfo),
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sGetCursorState,
0,
0,
3,
0,
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sGetCursorResolution,
0,
0,
2,
0,
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sEnableCursorEvents,
2,
0,
0,
0,
},
{
(IOExternalMethodAction)&info_ennowelbers_proxyframebuffer_client::sDisableCursorEvents,
0,
0,
0,
0,
}
};
#pragma mark dispatcher function
//as we're having function adresses in our dispatch table, all we need is a range check and check the target.
IOReturn info_ennowelbers_proxyframebuffer_client::externalMethod(uint32_t selector, IOExternalMethodArguments* arguments, IOExternalMethodDispatch* dispatch, OSObject *target, void *reference)
{
if(selector < (uint32_t) kNumberOfMethods) {
dispatch=(IOExternalMethodDispatch*)&sMethods[selector];
if(!target)
{
target=this;
}
}
return super::externalMethod(selector, arguments, dispatch, target, reference);
}
#pragma mark IOUserClient functions
//for these functions, see apple docs.
bool info_ennowelbers_proxyframebuffer_client::initWithTask(task_t owningTask, void* securityToken, UInt32 type, OSDictionary *properties)
{
bool success;
success=super::initWithTask(owningTask, securityToken, type, properties);
fTask=owningTask;
fProvider=NULL;
owningFB=NULL;
return success;
}
bool info_ennowelbers_proxyframebuffer_client::start(IOService *provider)
{
bool success;
fProvider= OSDynamicCast(info_ennowelbers_proxyframebuffer_driver, provider);
success=(fProvider!=NULL);
if(success) {
success=super::start(provider);
}
return success;
}
IOReturn info_ennowelbers_proxyframebuffer_client::clientClose()
{
if(owningFB)
{
StopFramebuffer();
}
if(eventEnabled)
{
fProvider->eventClient=NULL;
}
terminate();
return kIOReturnSuccess;
}
IOReturn info_ennowelbers_proxyframebuffer_client::clientDied()
{
if(owningFB)
{
StopFramebuffer();
}
if(eventEnabled)
{
fProvider->eventClient=NULL;
}
return super::clientDied();
}
//This one is used to send events to user space.
IOReturn info_ennowelbers_proxyframebuffer_client::registerNotificationPort(mach_port_t port, UInt32 type, UInt32 refCon )
{
eventPort=port;
return kIOReturnSuccess;
}
#pragma mark static functions
//these functions are part of the "calling chain"
//actually they do ... nothing special. Converting parameters, calling member functions.
IOReturn info_ennowelbers_proxyframebuffer_client::sStartFramebuffer(info_ennowelbers_proxyframebuffer_client *target, void * reference, IOExternalMethodArguments *arguments)
{
IOReturn ret=target->StartFramebuffer(arguments->scalarInput[0]);
return ret;
}
IOReturn info_ennowelbers_proxyframebuffer_client::sStopFramebuffer(info_ennowelbers_proxyframebuffer_client *target, void * reference, IOExternalMethodArguments *arguments)
{
IOReturn ret=target->StopFramebuffer();
return ret;
}
IOReturn info_ennowelbers_proxyframebuffer_client::sCheckFramebufferState(info_ennowelbers_proxyframebuffer_client *target, void *reference, IOExternalMethodArguments *arguments)
{
return target->CheckFramebufferState();
}
IOReturn info_ennowelbers_proxyframebuffer_client::sUpdateMemory(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
return target->UpdateMemory();
}
IOReturn info_ennowelbers_proxyframebuffer_client::sGetModeCount(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
return target->GetModeCount();
}
IOReturn info_ennowelbers_proxyframebuffer_client::sGetModeInfo(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
IOLog("EWProxyFrameBuffer: Client static Get Mode Info!\n");
IOReturn ret= target->GetModeInfo(arguments->scalarInput[0], (EWProxyFramebufferModeInfo*)arguments->structureOutput);
arguments->structureOutputSize=sizeof(EWProxyFramebufferModeInfo);
return ret;
}
IOReturn info_ennowelbers_proxyframebuffer_client::sGetCursorState(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
return target->GetCursorState((int*)&arguments->scalarOutput[0], (int*)&arguments->scalarOutput[1], (bool*)&arguments->scalarOutput[2]);
}
IOReturn info_ennowelbers_proxyframebuffer_client::sGetCursorResolution(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
return target->GetCursorResolution((int*)&arguments->scalarOutput[0], (int*)&arguments->scalarOutput[1]);
}
IOReturn info_ennowelbers_proxyframebuffer_client::sEnableCursorEvents(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
#ifdef __LP64__
return target->EnableCursorEvents((mach_vm_address_t)(arguments->scalarInput[0]), (io_user_reference_t)(arguments->scalarInput[1]));
#else
return target->EnableCursorEvents((void*)(arguments->scalarInput[0]), (void*)(arguments->scalarInput[1]));
#endif
}
#pragma mark member functions of the call chaing
//these functions access the driver variables and provides results
IOReturn info_ennowelbers_proxyframebuffer_client::GetCursorState(int *x, int *y, bool *visible)
{
*x=fProvider->fbuffer->cursorX;
*y=fProvider->fbuffer->cursorY;
*visible=fProvider->fbuffer->cursorVisible;
return kIOReturnSuccess;
}
IOReturn info_ennowelbers_proxyframebuffer_client::GetCursorResolution(int *width, int *height)
{
*width=fProvider->fbuffer->cursorWidth;
*height=fProvider->fbuffer->cursorHeight;
return kIOReturnSuccess;
}
IOReturn info_ennowelbers_proxyframebuffer_client::StartFramebuffer(int mode)
{
IOReturn ret= fProvider->StartFramebuffer(mode);
if(ret==kIOReturnSuccess)
{
owningFB=true;
}
return ret;
}
IOReturn info_ennowelbers_proxyframebuffer_client::StopFramebuffer()
{
IOReturn ret= fProvider->StopFramebuffer();
if(ret==kIOReturnSuccess)
{
owningFB=false;
}
return ret;
}
IOReturn info_ennowelbers_proxyframebuffer_client::CheckFramebufferState()
{
return fProvider->CheckFramebufferState();
}
IOReturn info_ennowelbers_proxyframebuffer_client::UpdateMemory()
{
return fProvider->UpdateMemory();
}
IOReturn info_ennowelbers_proxyframebuffer_client::GetModeCount()
{
return fProvider->getModeCount();
}
IOReturn info_ennowelbers_proxyframebuffer_client::GetModeInfo(int mode,EWProxyFramebufferModeInfo *info)
{
IOLog("EWProxyFrameBuffer: client->GetModeInfo(%d)\n",mode);
return fProvider->getmodeInfo(mode, info);
}
IOReturn info_ennowelbers_proxyframebuffer_client::clientMemoryForType( UInt32 type, IOOptionBits * options, IOMemoryDescriptor ** memory )
{
IOMemoryDescriptor *mem;
switch(type)
{
case 0:
mem=(IOMemoryDescriptor*)fProvider->buffer;
break;
case 1:
mem=(IOMemoryDescriptor*)fProvider->fbuffer->cursorMem;
break;
}
mem->retain();
if(mem==NULL)
return kIOReturnError;
*memory=mem;
return kIOReturnSuccess;
}
void info_ennowelbers_proxyframebuffer_client::FireCursorStateChanged()
{
if(eventEnabled)
{
//With the help of a previously registered event we're firing it.
#ifdef __LP64__
io_user_reference_t type[1]={(io_user_reference_t)kEWProxyCursorStateChanged};
sendAsyncResult64(eventFunction, kIOReturnSuccess,type,1);
#else
void *type[1]={(void*)kEWProxyCursorStateChanged};
sendAsyncResult(eventFunction, kIOReturnSuccess, type, 1);
#endif
}
}
void info_ennowelbers_proxyframebuffer_client::FireCursorImageChanged()
{
if(eventEnabled)
{
#ifdef __LP64__
io_user_reference_t type[1]={(io_user_reference_t)kEWProxyCursorImageChanged};
sendAsyncResult64(eventFunction,kIOReturnSuccess, type,1);
#else
void *type[1]={(void*)kEWProxyCursorImageChanged};
sendAsyncResult(eventFunction,kIOReturnSuccess, type,1);
#endif
}
}
//registers an event. This is quite fancy from my point of view.
//user client provides a call pointer, a reference and registers an event port (see above)
//these three together form an OSAsyncReference. the SetAsyncReference fills this opaque structure.
//Later on this opaque structure can be used to fire the event.
//I did not yet get the way this works, however in theory you could even transport parameters.
//we're not using them, though.
#ifdef __LP64__
IOReturn info_ennowelbers_proxyframebuffer_client::EnableCursorEvents(mach_vm_address_t call, io_user_reference_t reference)
#else
IOReturn info_ennowelbers_proxyframebuffer_client::EnableCursorEvents(void *call, void *reference)
#endif
{
if(fProvider->eventClient!=NULL)
return kIOReturnBusy;
#ifdef __LP64__
setAsyncReference64(eventFunction,eventPort,call,reference);
#else
setAsyncReference(eventFunction, eventPort, call, reference);
#endif
eventEnabled=true;
fProvider->eventClient=this;
return kIOReturnSuccess;
}
IOReturn info_ennowelbers_proxyframebuffer_client::sDisableCursorEvents(info_ennowelbers_proxyframebuffer_client* target, void *reference, IOExternalMethodArguments *arguments)
{
return target->DisableCursorEvents();
}
IOReturn info_ennowelbers_proxyframebuffer_client::DisableCursorEvents()
{
if(eventEnabled==false)
return kIOReturnNotAttached;
eventEnabled=false;
fProvider->eventClient=NULL;
return kIOReturnSuccess;
}