Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Changing the access rigths of address space created by mmap(): (4 Items)
   
Changing the access rigths of address space created by mmap()  
Hello,

I have a shared memory object and mapped it into my process address space using mmap() with write access. Lets say the 
base address of the object is 0x01 and length of the mapping be 30 bytes. 

Is it possible to change the access rights of the a memory region in between (eg. 0x06 to 0x09) to read only??
RE: Changing the access rigths of address space created by mmap()  
Which version of the OS are you using?

You can use the mprotect() function to modify the access rights of a mapped page.  All access permissions are set per 
CPU page, which are 4KiB in size.

David
________________________________________
From: Sri Harsha Koribille [community-noreply@qnx.com]
Sent: Monday, October 15, 2018 11:15 AM
To: ostech-core_os
Subject: Changing the access rigths of address space created by mmap()

Hello,

I have a shared memory object and mapped it into my process address space using mmap() with write access. Lets say the 
base address of the object is 0x01 and length of the mapping be 30 bytes.

Is it possible to change the access rights of the a memory region in between (eg. 0x06 to 0x09) to read only??



_______________________________________________

OSTech
http://community.qnx.com/sf/go/post119216
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com
Re: RE: Changing the access rigths of address space created by mmap()  
Hi David,

I'm using QNX 7.0
After using mprotect(), it is changing the access rights of other pointers in the address space too( as mentioned in 
your answer).

If thats the case, in "int mprotect( void * addr, size_t len,int prot )", what is the significance of "len" parameter 

Is it possible to change the access rights of just a single pointer and not the entire CPU page?
Re: Changing the access rigths of address space created by mmap()  
Normally If i want to do something like this I'd just do 
struct shmem_area_rw_s{
    int myelemeta;
}__attribute__((aligned (PAGE_SIZE)));

struct shmem_area_ro_s{
    int my_elemetb;
}__attribute__((aligned (PAGE_SIZE)));

typedef struct shmem_area_s{
    struct shmem_area_rw_s rw;
    struct shmem_area_ro_s ro;
}shmem_area_st;
shmem_area_st d;

int main(){
    printf("%s : %zd\n", "shmem_area_st", sizeof(shmem_area_st));
    printf("%s : %zd\n", "struct shmem_area_rw_s", sizeof(struct shmem_area_rw_s));
    printf("%s : %zd\n", "struct shmem_area_ro_s", sizeof(struct shmem_area_ro_s));
    mprotect(&d.ro, sizeof(d.ro), PROT_READ);
    return 0;
}