2011年4月6日 星期三

mac crash log

location
/Library/Logs/DiagnosticReports

read log from Console App:

mac driver command

ioclasscount
displays the instance counts of OSObject-based C++ classes in the kernel
ex:
ioclasscount | grep My

->
com_MyCompany_driver_MyDriver = 1

kextutil:

load, diagnose problems with, and generate symbols for kernel extensions
ex:
kextutil test.kext

iokit driver

TestIokit.h


#include <IOKit/IOService.h>

class com_MyCompany_driver_MyDriver : public IOService
{
OSDeclareDefaultStructors(com_MyCompany_driver_MyDriver)
public:
    virtual bool init(OSDictionary *dictionary = 0);
    virtual void free(void);
    virtual IOService *probe(IOService *provider, SInt32 *score);
    virtual bool start(IOService *provider);
    virtual void stop(IOService *provider);
};

TestIokit.cpp


#include <IOKit/IOLib.h>
#include "MyDriver.h"

// This required macro defines the class's constructors, destructors,
// and several other methods I/O Kit requires.
OSDefineMetaClassAndStructors(com_MyCompany_driver_MyDriver, IOService)

// Define the driver's superclass.
#define super IOService

bool com_MyCompany_driver_MyDriver::init(OSDictionary *dict)
{
    bool result = super::init(dict);
    IOLog("Initializing\n");
    return result;
}

void com_MyCompany_driver_MyDriver::free(void)
{
    IOLog("Freeing\n");
    super::free();
}

IOService *com_MyCompany_driver_MyDriver::probe(IOService *provider,
SInt32 *score)
{
    IOService *result = super::probe(provider, score);
    IOLog("Probing\n");
    return result;
}

bool com_MyCompany_driver_MyDriver::start(IOService *provider)
{
    bool result = super::start(provider);
    IOLog("Starting\n");
    return result;
}

void com_MyCompany_driver_MyDriver::stop(IOService *provider)
{
    IOLog("Stopping\n");
    super::stop(provider);
}

TestIokit-Info.plist


gcd: Grand Central Dispatch

provide a number of predefined queues

we can create our own queue

queue is FIFO

block in Objective-C

also known as closures or lambdas

block syntax:
1. ^
2. ( parameterType parameterName )
3. { code to be executed }


ex:
// declare a block variable test
void (^test)(void);
//  define block's code
test = ^ { NSLog("test"); };
// execute block
test();

ex:
void (^test)(void) = ^ { NSLog("test"); };

solaris service

steps to create service:

1. Create a service manifest file.
this file defines dependency and start/stop script location
ex:
nfs server's manifest file
/lib/svc/manifest/network/nfs/server.xml
content ex:

 <exec_method
        type='method'
        name='start'
        exec='/lib/svc/method/nfs-server %m'
        timeout_seconds='3600' />


2. Create a methods script file to define the start, stop, and restart methods for the service.
ex:
nfs server's script
/lib/svc/method/nfs-server

3. Validate and import the service manifest using svccfg(1M).
4. Enable or start the service using svcadm(1M).
5. Verify the service is running using svcs(1).