1.1 --- a/libfsclient/lib/src/client.cc Sat May 14 23:52:24 2022 +0200
1.2 +++ b/libfsclient/lib/src/client.cc Thu May 19 14:08:28 2022 +0200
1.3 @@ -41,6 +41,32 @@
1.4
1.5
1.6
1.7 +/* Merging of region flags from protection and access flags. */
1.8 +
1.9 +static l4re_rm_flags_t _combine_region_flags(l4re_rm_flags_t region_flags,
1.10 + flags_t flags)
1.11 +{
1.12 + return region_flags & (file_region_flags(flags) | L4RE_RM_F_X);
1.13 +}
1.14 +
1.15 +/* Conversion of protection and access flags to region flags. */
1.16 +
1.17 +l4re_rm_flags_t client_region_flags(prot_t prot, flags_t flags)
1.18 +{
1.19 + l4re_rm_flags_t rm_flags = 0;
1.20 +
1.21 + if (prot & PROT_READ)
1.22 + rm_flags |= L4RE_RM_F_R;
1.23 + if (prot & PROT_WRITE)
1.24 + rm_flags |= L4RE_RM_F_W;
1.25 + if (prot & PROT_EXEC)
1.26 + rm_flags |= L4RE_RM_F_X;
1.27 +
1.28 + return _combine_region_flags(rm_flags, flags);
1.29 +}
1.30 +
1.31 +
1.32 +
1.33 /* Access the given position and synchronise state with the file object. Pipe
1.34 objects may return busy conditions indicating that the desired access cannot
1.35 yet be fulfilled. */
1.36 @@ -55,7 +81,8 @@
1.37
1.38 if ((position < file->start_pos) || (position >= file->end_pos))
1.39 {
1.40 - if (file_mmap(file, position, file_span(file)))
1.41 + if (file_mmap(file, position, file_span(file),
1.42 + file_region_flags(file->flags)))
1.43 return -L4_EIO;
1.44 }
1.45
1.46 @@ -164,7 +191,8 @@
1.47 if (file->memory == NULL)
1.48 {
1.49 if (file->object_flags & OBJECT_SUPPORTS_MMAP)
1.50 - return client_mmap(file, client_tell(file), count);
1.51 + return client_mmap(file, client_tell(file), count,
1.52 + file_region_flags(file->flags));
1.53 else if (pipe_current(file))
1.54 return NULL;
1.55 }
1.56 @@ -459,9 +487,10 @@
1.57
1.58 /* Map a memory region to a file. */
1.59
1.60 -void *client_mmap(file_t *file, offset_t position, offset_t length)
1.61 +void *client_mmap(file_t *file, offset_t position, offset_t length,
1.62 + l4re_rm_flags_t region_flags)
1.63 {
1.64 - if ((file == NULL) || (file_mmap(file, position, length)))
1.65 + if ((file == NULL) || file_mmap(file, position, length, region_flags))
1.66 return NULL;
1.67
1.68 return file->memory;