#ifndef _XTRACE_H_
#define _XTRACE_H_
#ifdef KERNEL
#include <IOKit/IOService.h>
#include <IOKit/IOUserClient.h>
#endif // KERNEL
#define XTRACE_HELPER(global, id, x, y, msg) \
do { \
if (global) { \
static char *__xtrace = 0; \
if (__xtrace) global->LogAdd((UInt32)id, (UInt32)(x), (UInt32)(y), __xtrace); \
else __xtrace = global->LogAdd((UInt32)id, (UInt32)(x), (UInt32)(y), msg, false); \
} \
} while(0)
#define kXTraceKextName "com_apple_iokit_XTrace"
typedef struct { UInt32 id; UInt32 data1; UInt32 data2;
UInt32 timeStamp; char *msg; } EventDesc;
enum { cmdXTrace_GetLog = 201, cmdXTrace_GetLogSizes, XTRACE_Magic_Key = 'JDG!' };
typedef struct { EventDesc *eventLog; UInt32 eventLogSize; char *msgBuffer; UInt32 msgBufferSize; char *fNextMsg;
UInt32 fNumEntries; UInt32 fEventIndex; UInt32 fPrintIndex; Boolean fTracingOn; Boolean fWrapped; Boolean fWrappingEnabled; } XTraceLogInfo;
typedef struct {
UInt32 fBufferSize; UInt32 fMsgBufSize; } XTraceLogSizes;
#ifdef KERNEL
enum { kEntryCount = (200*1024), kMsgBufSize = (20*1024) };
class com_apple_iokit_XTrace : public IOService
{
OSDeclareDefaultStructors(com_apple_iokit_XTrace)
private:
XTraceLogInfo fInfo; IOLock *fMyLock; UInt32 fId;
char *fErrorMsg; char *GetCachedMsg(char *msg, bool compress);
char *CopyMsg(char *msg);
void dumpbuffers();
public:
virtual bool init(OSDictionary *dictionary);
virtual void free(void);
virtual bool start(IOService *provider);
virtual void stop(IOService *provider);
virtual IOService *probe(IOService *provider, SInt32 *score);
virtual IOReturn newUserClient( task_t owningTask, void * securityID, UInt32 type, IOUserClient ** handler );
virtual UInt32 GetNewId(void);
virtual char * LogAdd(UInt32 id, UInt32 data1, UInt32 data2, char *msg, Boolean compress);
virtual void LogAdd(UInt32 id, UInt32 data1, UInt32 data2, char *cachedtext);
virtual void LogTracingOn(void); virtual void LogTracingOff(void);
virtual void LogWrappingOn(void); virtual void LogWrappingOff(void);
virtual XTraceLogInfo *LogGetInfo(void);
virtual void LogReset(UInt32 printIndex);
virtual void LogLock();
virtual void LogUnlock();
};
void inline com_apple_iokit_XTrace::LogTracingOn(void) { fInfo.fTracingOn = true; }
void inline com_apple_iokit_XTrace::LogTracingOff(void) { fInfo.fTracingOn = false; }
void inline com_apple_iokit_XTrace::LogWrappingOn(void) { fInfo.fWrappingEnabled = true; }
void inline com_apple_iokit_XTrace::LogWrappingOff(void) { fInfo.fWrappingEnabled = false; }
UInt32 inline com_apple_iokit_XTrace::GetNewId(void) { return ++fId; }
void inline com_apple_iokit_XTrace::LogLock(void) { IOLockLock(fMyLock); }
void inline com_apple_iokit_XTrace::LogUnlock(void) { IOLockUnlock(fMyLock); }
class com_apple_iokit_XTrace;
class com_apple_iokit_XTraceUserClient : public IOUserClient
{
OSDeclareDefaultStructors(com_apple_iokit_XTraceUserClient)
private:
com_apple_iokit_XTrace *fProvider;
IOExternalMethod fMethods[1]; task_t fTask;
public:
static com_apple_iokit_XTraceUserClient *withTask(task_t owningTask); IOReturn clientClose();
IOReturn clientDied();
bool start(IOService *provider);
IOReturn connectClient(IOUserClient *client);
IOExternalMethod* getExternalMethodForIndex(UInt32 index);
IOReturn doRequest(void *pIn, void *pOut, IOByteCount inputSize, IOByteCount *outPutSize);
private:
IOReturn getLog(void *pIn, void *pOut, IOByteCount inputSize, IOByteCount *outPutSize);
IOReturn getLogSizes(void *pIn, void *pOut, IOByteCount inputSize, IOByteCount *outPutSize);
IOReturn copyLogEntries (IOMemoryDescriptor *md, EventDesc *eventLog, UInt32 first, UInt32 next); };
#endif // KERNEL
#endif // _XTRACE_H_