Change the read/write permissions of an address.

Source: Internet
Author: User
Change the read and write permissions of an address-General Linux technology-Linux programming and kernel information. For more information, see the following. 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 */
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;
}

Use the above code to modify the read and write permissions of a space with the length of ulLength starting from the memory space ulAddr. Is there a problem?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.