红联Linux门户
Linux帮助

改变一段地址的读写权限

发布时间:2010-08-19 23:39:07来源:红联作者:vfdff
unsigned int ChangeProtection(const unsigned int ulAddr, const unsigned int ulLength, const unsigned int ulMode )
{
int iRtn;
unsigned int ulLastPageEnd;
unsigned int ulFirstPageStart;

/* Find the start address of the page to which the adress belongs to */
ulFirstPageStart = ulAddr - (ulAddr % 4096);

ulLastPageEnd = ulAddr + ulLength;
ulLastPageEnd += 4096 - (ulLastPageEnd % 4096);

iRtn = mprotect((void*)ulFirstPageStart, ulLastPageEnd - ulFirstPageStart, ulMode );
//iRtn = mprotect((void*)ulFirstPageStart, 4096, ulMode );
if (0 != iRtn)
{
printf("\r\nCall mprotect fail!\n");
return FALSE;
}

return TRUE;
}

使用上述代码修改内存空间 ulAddr开始,长度为 ulLength的一段空间的读写权限,有问题吗?
文章评论

共有 3 条评论

  1. vfdff 于 2010-08-21 01:35:11发表:

    1# vfdff


    程序做微笑调整、
    if (TRUE != mprotect((void*)ulFirstPageStart, ulLastPageEnd - ulFirstPageStart, ulMode ))
    {
    return FALSE;
    }

  2. yanlong938 于 2010-08-20 10:03:30发表:

    看不太懂。。。

  3. qtsmy 于 2010-08-20 08:27:52发表:

    帮顶