zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    企业如何在智能制造的时代保持竞争力?
    汽车行业MES系统在产品追溯方面的应用分析
    你能想象未来的MES系统是什么样吗?
    智能制造进入下半场?APS如何进行优化
    【案例】如何让阀门制造提高排产效率?APS系统帮你实现
    APS系统的现状以及与MES系统的关联
    MES被重新定义?做到这几点才算智能制造
    python部分笔记
    BUUCTF Hack World
    BUUCTF--checkin
  • 原文地址:https://www.cnblogs.com/signal/p/15066139.html
Copyright © 2011-2022 走看看