zoukankan      html  css  js  c++  java
  • windows 驱动开发 MDL 内核层 用户层共享内存

    参考资料

       https://blog.csdn.net/wdykanq/article/details/7752909

       http://blog.51cto.com/laokaddk/404584

    内核层创建内存映射用户层

    PVOID pShareMM_SYS;
    PMDL pShareMM_MDL;
    PVOID pShareMM_User;

    PKUANGKEEPROCESS vEProcess = KuangKeGetProcessById(3412);
    KAPC_STATE vKapcState;

    KeStackAttachProcess((PRKPROCESS)vEProcess, &vKapcState);

    pShareMM_SYS = KuangKeAllocate(1024);//size必须是page的整数倍  也可以使用 ExAllocatePoolWithTag(NonPagedPool, _s, 'KUAN')
    RtlZeroMemory(pShareMM_SYS, 1024);

    pShareMM_MDL = IoAllocateMdl(pShareMM_SYS, 1024, FALSE, FALSE, NULL);
    MmBuildMdlForNonPagedPool(pShareMM_MDL);

    pShareMM_User = MmMapLockedPagesSpecifyCache(pShareMM_MDL, UserMode, MmCached, NULL, FALSE, NormalPagePriority);
    KuangKeDebugPrint("pShareMM_SYS的地址为: 0x%p ", (PUCHAR)pShareMM_SYS);
    KuangKeDebugPrint("pShareMM_User的地址为: 0x%p ", (PUCHAR)pShareMM_User);

    //MmUnMapLockerPages(pShareMM_MDL);
    MmUnmapLockedPages(pShareMM_User, pShareMM_MDL);
    IoFreeMdl(pShareMM_MDL);
    KuangKeFree(pShareMM_SYS);

    KeUnstackDetachProcess(&vKapcState);

    用户层映射内核

    BaseAddr = OpenKernel32();        //映射kernel32的section到本进程的低2G空间
    if (!BaseAddr)
    {
    KdPrint(("DriverEntry--OpenKernel32 failure! "));
    return 0;
    }
    KdPrint(("BaseAddr: 0x%08x ",BaseAddr));
    //创建一个MDL
    pMDL = IoAllocateMdl(BaseAddr,0x11c000,FALSE,FALSE,NULL);
    if (!pMDL)
    {
    KdPrint(("pMDL == NULL "));
    return 0;
    }
    _try
    {
    MmProbeAndLockPages(pMDL,UserMode,IoReadAccess);
    }
    _except(EXCEPTION_EXECUTE_HANDLER)
    {
    KdPrint(("MmProbeAndLockPages exception "));
    }

    _try
    {
    pMapedAddr = MmMapLockedPagesSpecifyCache(pMDL,KernelMode,MmCached,NULL,FALSE,NormalPagePriority);
    if (!pMapedAddr)
    {
    KdPrint(("pMapedAdd == NULL "));
    return 0;
    }
    }
    _except(EXCEPTION_EXECUTE_HANDLER)
    {
    KdPrint(("MmMapLockedPagesSpecifyCache exception "));
    }

  • 相关阅读:
    Distinctive Image Features from ScaleInvariant
    Natural Language Toolkit
    Regression analysis
    泌尿系统 Excretory system
    file_get_contents preg_match php nameisboy
    wWAITING
    instructionset architecture Processor Architecture
    improve performance whilemaintaining the functionality of a simpler and more abstract model design of processor hardware
    cluster analysis in data mining
    Maximum Likelihood
  • 原文地址:https://www.cnblogs.com/kuangke/p/9888671.html
Copyright © 2011-2022 走看看