David Sarrazin
|
RE: Changing the access rigths of address space created by mmap()
|
David Sarrazin
10/15/2018 11:25 AM
post119217
|
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
|
|
|
John Kearney
|
Re: Changing the access rigths of address space created by mmap()
|
John Kearney
10/17/2018 9:31 AM
post119221
|
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;
}
|
|
|