• MAC 下PCIE驱动模板


    写一个MAC下的驱动。 遇坑无数,特此记录。

    本例只是加载,无实际功能。 实现效果: 

    MAC头文件

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

      

    实现文件:

    #include "MedCaptureDriver.hpp"
    #include <IOKit/IOLib.h>
    
    // Define the superclass
    #define super IOService
    
    OSDefineMetaClassAndStructors(com_osxkernel_MedCaptureDriver, IOService)
    
    bool com_osxkernel_MedCaptureDriver::init (OSDictionary* dict)
    {
    	bool res = super::init(dict);
    	IOLog("com_osxkernel_MedCaptureDriver::init
    ");
    	return res;
    }
    
    void com_osxkernel_MedCaptureDriver::free (void)
    {
    	IOLog("com_osxkernel_MedCaptureDriver::free
    ");
    	super::free();
    }
    
    IOService* com_osxkernel_MedCaptureDriver::probe (IOService* provider, SInt32* score)
    {
    	IOService *res = super::probe(provider, score);
    	IOLog("com_osxkernel_MedCaptureDriver::probe
    ");
    	return res;
    }
    
    bool com_osxkernel_MedCaptureDriver::start (IOService *provider)
    {
        IOLog("com_osxkernel_MedCaptureDriver::start
    ");
    
        bool res = super::start(provider);
        setProperty("IOUserClientClass", "com_osxkernel_MedCaptureClient");
        registerService();
        return res;
    }
    
    
    
    
    void com_osxkernel_MedCaptureDriver::stop (IOService *provider)
    {
    	IOLog("com_osxkernel_MedCaptureDriver::stop
    ");
    	super::stop(provider);
    }
    

      

    用户头:

    class com_osxkernel_MedCaptureClient : public IOUserClient
    {
    	OSDeclareDefaultStructors(com_osxkernel_MedCaptureClient)
    	
    private:
    	task_t								m_task;
    	com_osxkernel_MedCaptureDriver*		m_driver;
    	
    public:	
    	virtual bool		initWithTask (task_t owningTask, void* securityToken, UInt32 type, OSDictionary* properties) override;
    	virtual bool		start (IOService* provider) override;
    	virtual void		stop (IOService* provider) override;
    	virtual void		free (void) override;
    	
        // 鎵╁睍鍛戒护...
    	//virtual IOReturn	externalMethod (uint32_t selector, IOExternalMethodArguments* arguments, IOExternalMethodDispatch* dispatch = 0, OSObject* target = 0, void* reference = 0);
    };
    

      

    用户实现:

    OSDefineMetaClassAndStructors(com_osxkernel_MedCaptureClient, IOUserClient)
    
    bool com_osxkernel_MedCaptureClient::initWithTask (task_t owningTask, void* securityToken, UInt32 type, OSDictionary* properties)
    {
    
    	IOLog("com_osxkernel_MedCaptureClient::initWithTask
    ");
    
        if(!owningTask) 
            return false;
    
        if (!super::initWithTask(owningTask, securityToken, type, properties)) {
            return false;
        }
    
        m_task = owningTask;
    
        //鏄�惁鏈夌�鐞嗘潈闄?.
    	IOReturn ret = clientHasPrivilege(securityToken, kIOClientPrivilegeAdministrator);
    	if ( ret == kIOReturnSuccess )
    	{
    		// m_taskIsAdmin = true;
    	}
    
    
    
        return true;
        
    }
    
    bool com_osxkernel_MedCaptureClient::start (IOService* provider)
    {
    	IOLog("com_osxkernel_MedCaptureClient::start
    ");
    
    	if (! super::start(provider))
    		return false;
    	
    	m_driver = OSDynamicCast(com_osxkernel_MedCaptureDriver, provider);
    	if (!m_driver)
    		return false;
    	
    	return true;
    }
    
    void com_osxkernel_MedCaptureClient::stop (IOService* provider)
    {
    	IOLog("com_osxkernel_MedCaptureClient::stop
    ");
    	super::stop(provider);
    }
    
    void com_osxkernel_MedCaptureClient::free (void)
    {
    	IOLog("com_osxkernel_MedCaptureClient::free
    ");
    	super::free();
    }
    

      

    作者微信号: xh66i88
  • 相关阅读:
    Go_海量用户即时通讯系统
    Golang redis学习指南
    Golang 操作_Redis
    十七、Redis
    十六、网络编程-tcp socket编程
    十五、反射
    十四、goroutine(协程)和channel(管道)
    Jmeter笔记(9)Jmeter 性能测试资源监控方法(本地与服务器)(转)
    Fiddler笔记(8)重装时清除已有证书及解决tunnel to 443问题
    Jmeter笔记(8)Jmeter与MySql连接
  • 原文地址:https://www.cnblogs.com/signal/p/15066139.html
Copyright © 2020-2023  润新知