1.1 --- a/libfsclient/include/fsclient/client.h Sat May 14 23:52:24 2022 +0200
1.2 +++ b/libfsclient/include/fsclient/client.h Thu May 19 14:08:28 2022 +0200
1.3 @@ -64,7 +64,8 @@
1.4 /* File and region operations. */
1.5
1.6 long client_flush(file_t *file);
1.7 -void *client_mmap(file_t *file, offset_t position, offset_t length);
1.8 +void *client_mmap(file_t *file, offset_t position, offset_t length, l4re_rm_flags_t region_flags);
1.9 +l4re_rm_flags_t client_region_flags(prot_t prot, flags_t flags);
1.10
1.11 /* Pipe region operations. */
1.12
2.1 --- a/libfsclient/include/fsclient/file.h Sat May 14 23:52:24 2022 +0200
2.2 +++ b/libfsclient/include/fsclient/file.h Thu May 19 14:08:28 2022 +0200
2.3 @@ -23,6 +23,7 @@
2.4
2.5 #include <sys/stat.h>
2.6
2.7 +#include <l4/re/c/rm.h>
2.8 #include <l4/sys/types.h>
2.9
2.10 #include <systypes/base.h>
2.11 @@ -74,6 +75,10 @@
2.12
2.13 notify_flags_t notifications;
2.14
2.15 + /* Flags indicated when opening the file. */
2.16 +
2.17 + flags_t flags;
2.18 +
2.19 } file_t;
2.20
2.21
2.22 @@ -104,7 +109,8 @@
2.23 /* File and region operations. */
2.24
2.25 long file_flush(file_t *file);
2.26 -long file_mmap(file_t *file, offset_t position, offset_t length);
2.27 +long file_mmap(file_t *file, offset_t position, offset_t length, l4re_rm_flags_t region_flags);
2.28 +l4re_rm_flags_t file_region_flags(flags_t flags);
2.29 long file_resize(file_t *file, offset_t size);
2.30
2.31 /* File and region properties. */
3.1 --- a/libfsclient/lib/src/client.cc Sat May 14 23:52:24 2022 +0200
3.2 +++ b/libfsclient/lib/src/client.cc Thu May 19 14:08:28 2022 +0200
3.3 @@ -41,6 +41,32 @@
3.4
3.5
3.6
3.7 +/* Merging of region flags from protection and access flags. */
3.8 +
3.9 +static l4re_rm_flags_t _combine_region_flags(l4re_rm_flags_t region_flags,
3.10 + flags_t flags)
3.11 +{
3.12 + return region_flags & (file_region_flags(flags) | L4RE_RM_F_X);
3.13 +}
3.14 +
3.15 +/* Conversion of protection and access flags to region flags. */
3.16 +
3.17 +l4re_rm_flags_t client_region_flags(prot_t prot, flags_t flags)
3.18 +{
3.19 + l4re_rm_flags_t rm_flags = 0;
3.20 +
3.21 + if (prot & PROT_READ)
3.22 + rm_flags |= L4RE_RM_F_R;
3.23 + if (prot & PROT_WRITE)
3.24 + rm_flags |= L4RE_RM_F_W;
3.25 + if (prot & PROT_EXEC)
3.26 + rm_flags |= L4RE_RM_F_X;
3.27 +
3.28 + return _combine_region_flags(rm_flags, flags);
3.29 +}
3.30 +
3.31 +
3.32 +
3.33 /* Access the given position and synchronise state with the file object. Pipe
3.34 objects may return busy conditions indicating that the desired access cannot
3.35 yet be fulfilled. */
3.36 @@ -55,7 +81,8 @@
3.37
3.38 if ((position < file->start_pos) || (position >= file->end_pos))
3.39 {
3.40 - if (file_mmap(file, position, file_span(file)))
3.41 + if (file_mmap(file, position, file_span(file),
3.42 + file_region_flags(file->flags)))
3.43 return -L4_EIO;
3.44 }
3.45
3.46 @@ -164,7 +191,8 @@
3.47 if (file->memory == NULL)
3.48 {
3.49 if (file->object_flags & OBJECT_SUPPORTS_MMAP)
3.50 - return client_mmap(file, client_tell(file), count);
3.51 + return client_mmap(file, client_tell(file), count,
3.52 + file_region_flags(file->flags));
3.53 else if (pipe_current(file))
3.54 return NULL;
3.55 }
3.56 @@ -459,9 +487,10 @@
3.57
3.58 /* Map a memory region to a file. */
3.59
3.60 -void *client_mmap(file_t *file, offset_t position, offset_t length)
3.61 +void *client_mmap(file_t *file, offset_t position, offset_t length,
3.62 + l4re_rm_flags_t region_flags)
3.63 {
3.64 - if ((file == NULL) || (file_mmap(file, position, length)))
3.65 + if ((file == NULL) || file_mmap(file, position, length, region_flags))
3.66 return NULL;
3.67
3.68 return file->memory;
4.1 --- a/libfsclient/lib/src/file.cc Sat May 14 23:52:24 2022 +0200
4.2 +++ b/libfsclient/lib/src/file.cc Thu May 19 14:08:28 2022 +0200
4.3 @@ -21,8 +21,10 @@
4.4
4.5 #include <ipc/cap_alloc.h>
4.6 #include <ipc/mem_ipc.h>
4.7 +#include <systypes/fcntl.h>
4.8 #include <systypes/stat.h>
4.9
4.10 +#include <stdio.h>
4.11 #include <string.h>
4.12
4.13 #include "dataspace_client.h"
4.14 @@ -88,6 +90,7 @@
4.15 file->object_flags = 0;
4.16 file->can_block = 0;
4.17 file->notifications = 0;
4.18 + file->flags = 0;
4.19 }
4.20
4.21
4.22 @@ -255,6 +258,7 @@
4.23 long err;
4.24
4.25 file_init(file);
4.26 + file->flags = O_RDWR;
4.27
4.28 err = opener.context(&file->ref);
4.29 if (err)
4.30 @@ -286,6 +290,7 @@
4.31 {
4.32 client_OpenerContext openercontext(context->ref);
4.33 file_init(file);
4.34 + file->flags = flags;
4.35 return openercontext.open(flags, &file->size, &file->ref, &file->object_flags);
4.36 }
4.37
4.38 @@ -346,7 +351,8 @@
4.39 /* Map a region of the given file to a memory region, obtaining an updated file
4.40 size and populated data details. Unmap any previously mapped region. */
4.41
4.42 -long file_mmap(file_t *file, offset_t position, offset_t length)
4.43 +long file_mmap(file_t *file, offset_t position, offset_t length,
4.44 + l4re_rm_flags_t region_flags)
4.45 {
4.46 char *memory = file->memory;
4.47 client_MappedFile mapped_file(file->ref);
4.48 @@ -358,7 +364,10 @@
4.49
4.50 _update_extent(file);
4.51
4.52 - err = ipc_attach_dataspace(file->ref, file_span(file), (void **) &file->memory);
4.53 + err = ipc_attach_dataspace_align(file->ref, file_span(file),
4.54 + L4RE_RM_F_SEARCH_ADDR | region_flags,
4.55 + L4_PAGESHIFT,
4.56 + (void **) &file->memory);
4.57 if (err)
4.58 return err;
4.59
4.60 @@ -368,6 +377,30 @@
4.61 return L4_EOK;
4.62 }
4.63
4.64 +/* Return mmap flags corresponding to the file access flags. */
4.65 +
4.66 +l4re_rm_flags_t file_region_flags(flags_t flags)
4.67 +{
4.68 + l4re_rm_flags_t rm_flags;
4.69 +
4.70 + switch (flags & 3)
4.71 + {
4.72 + case O_WRONLY:
4.73 + rm_flags = L4RE_RM_F_W;
4.74 + break;
4.75 +
4.76 + case O_RDWR:
4.77 + rm_flags = L4RE_RM_F_RW;
4.78 + break;
4.79 +
4.80 + default:
4.81 + rm_flags = L4RE_RM_F_R;
4.82 + break;
4.83 + }
4.84 +
4.85 + return rm_flags;
4.86 +}
4.87 +
4.88 /* Resize a file, obtaining updated file size and populated data details. */
4.89
4.90 long file_resize(file_t *file, offset_t size)
4.91 @@ -624,6 +657,8 @@
4.92
4.93 file_init(reader);
4.94 file_init(writer);
4.95 + reader->flags = O_RDONLY;
4.96 + writer->flags = O_WRONLY;
4.97
4.98 return opener.pipe(size, &reader->ref, &writer->ref);
4.99 }
4.100 @@ -697,6 +732,7 @@
4.101 {
4.102 client_Directory directory(file->ref);
4.103 file_init(reader);
4.104 + reader->flags = O_RDONLY;
4.105 return directory.opendir(&reader->size, &reader->ref, &reader->object_flags);
4.106 }
4.107
5.1 --- a/libfsserver/include/fsserver/directory_provider.h Sat May 14 23:52:24 2022 +0200
5.2 +++ b/libfsserver/include/fsserver/directory_provider.h Thu May 19 14:08:28 2022 +0200
5.3 @@ -1,7 +1,7 @@
5.4 /*
5.5 * An object providing a directory abstraction with notification facilities.
5.6 *
5.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
5.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
5.9 *
5.10 * This program is free software; you can redistribute it and/or
5.11 * modify it under the terms of the GNU General Public License as
5.12 @@ -41,7 +41,8 @@
5.13
5.14 virtual DirectoryAccessor *accessor();
5.15
5.16 - virtual long make_resource(offset_t *size, object_flags_t *object_flags,
5.17 + virtual long make_resource(flags_t flags, offset_t *size,
5.18 + object_flags_t *object_flags,
5.19 Resource **resource);
5.20 };
5.21
6.1 --- a/libfsserver/include/fsserver/file_provider.h Sat May 14 23:52:24 2022 +0200
6.2 +++ b/libfsserver/include/fsserver/file_provider.h Thu May 19 14:08:28 2022 +0200
6.3 @@ -1,7 +1,7 @@
6.4 /*
6.5 * An object encapsulating file resources.
6.6 *
6.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
6.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
6.9 *
6.10 * This program is free software; you can redistribute it and/or
6.11 * modify it under the terms of the GNU General Public License as
6.12 @@ -35,14 +35,15 @@
6.13 PageMapper *_mapper;
6.14
6.15 public:
6.16 - explicit FileProvider(fileid_t fileid, map_flags_t flags,
6.17 - ProviderRegistry *registry, PageMapper *mapper);
6.18 + explicit FileProvider(fileid_t fileid, ProviderRegistry *registry,
6.19 + PageMapper *mapper);
6.20
6.21 virtual ~FileProvider();
6.22
6.23 virtual PageMapper *mapper();
6.24
6.25 - virtual long make_resource(offset_t *size, object_flags_t *object_flags,
6.26 + virtual long make_resource(map_flags_t flags, offset_t *size,
6.27 + object_flags_t *object_flags,
6.28 Resource **resource);
6.29
6.30 virtual void remove();
7.1 --- a/libfsserver/include/fsserver/provider.h Sat May 14 23:52:24 2022 +0200
7.2 +++ b/libfsserver/include/fsserver/provider.h Thu May 19 14:08:28 2022 +0200
7.3 @@ -1,7 +1,7 @@
7.4 /*
7.5 * Filesystem object provider support.
7.6 *
7.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
7.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
7.9 *
7.10 * This program is free software; you can redistribute it and/or
7.11 * modify it under the terms of the GNU General Public License as
7.12 @@ -44,7 +44,8 @@
7.13
7.14 virtual ProviderRegistry *registry();
7.15
7.16 - virtual long make_resource(offset_t *size, object_flags_t *object_flags,
7.17 + virtual long make_resource(flags_t flags, offset_t *size,
7.18 + object_flags_t *object_flags,
7.19 Resource **resource) = 0;
7.20
7.21 /* Lifecycle methods. */
8.1 --- a/libfsserver/lib/directories/directory_provider.cc Sat May 14 23:52:24 2022 +0200
8.2 +++ b/libfsserver/lib/directories/directory_provider.cc Thu May 19 14:08:28 2022 +0200
8.3 @@ -1,7 +1,7 @@
8.4 /*
8.5 * An object providing access to directory functionality.
8.6 *
8.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
8.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
8.9 *
8.10 * This program is free software; you can redistribute it and/or
8.11 * modify it under the terms of the GNU General Public License as
8.12 @@ -48,10 +48,12 @@
8.13
8.14 /* Return a directory resource initialised with this provider. */
8.15
8.16 -long DirectoryProvider::make_resource(offset_t *size,
8.17 +long DirectoryProvider::make_resource(flags_t flags, offset_t *size,
8.18 object_flags_t *object_flags,
8.19 Resource **resource)
8.20 {
8.21 + (void) flags;
8.22 +
8.23 /* Provide non-file values for certain outputs. */
8.24
8.25 *size = 0;
9.1 --- a/libfsserver/lib/files/file_provider.cc Sat May 14 23:52:24 2022 +0200
9.2 +++ b/libfsserver/lib/files/file_provider.cc Thu May 19 14:08:28 2022 +0200
9.3 @@ -1,7 +1,7 @@
9.4 /*
9.5 * An object providing access to file functionality.
9.6 *
9.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
9.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
9.9 *
9.10 * This program is free software; you can redistribute it and/or
9.11 * modify it under the terms of the GNU General Public License as
9.12 @@ -26,9 +26,9 @@
9.13
9.14 /* Initialise the provider with a page 'mapper' for the file's contents. */
9.15
9.16 -FileProvider::FileProvider(fileid_t fileid, map_flags_t flags,
9.17 - ProviderRegistry *registry, PageMapper *mapper)
9.18 -: Provider(fileid, registry), _flags(flags), _mapper(mapper)
9.19 +FileProvider::FileProvider(fileid_t fileid, ProviderRegistry *registry,
9.20 + PageMapper *mapper)
9.21 +: Provider(fileid, registry), _mapper(mapper)
9.22 {
9.23 }
9.24
9.25 @@ -54,13 +54,14 @@
9.26
9.27 /* Return a file pager initialised with a provider, page mapper and accessor. */
9.28
9.29 -long FileProvider::make_resource(offset_t *size, object_flags_t *object_flags,
9.30 +long FileProvider::make_resource(map_flags_t flags, offset_t *size,
9.31 + object_flags_t *object_flags,
9.32 Resource **resource)
9.33 {
9.34 /* Initialise the pager with the provider and a reference to this object for
9.35 detaching from the provider. */
9.36
9.37 - FilePager *pager = new FilePager(_fileid, this, _flags);
9.38 + FilePager *pager = new FilePager(_fileid, this, flags);
9.39
9.40 /* Obtain the size details from the pager, also providing appropriate
9.41 flags. */
10.1 --- a/libfsserver/lib/generic/resource_registry.cc Sat May 14 23:52:24 2022 +0200
10.2 +++ b/libfsserver/lib/generic/resource_registry.cc Thu May 19 14:08:28 2022 +0200
10.3 @@ -23,6 +23,7 @@
10.4 #include "file_pager.h"
10.5 #include "resource_registry.h"
10.6
10.7 +#include <fsclient/file.h> /* file_region_flags */
10.8 #include <systypes/fcntl.h>
10.9
10.10
10.11 @@ -41,7 +42,7 @@
10.12
10.13 map_flags_t ResourceRegistry::get_flags(flags_t flags)
10.14 {
10.15 - return flags & (O_WRONLY | O_RDWR) ? L4RE_DS_MAP_FLAG_RW : L4RE_DS_MAP_FLAG_RO;
10.16 + return file_region_flags(flags);
10.17 }
10.18
10.19
10.20 @@ -81,7 +82,7 @@
10.21 return err;
10.22
10.23 PageMapper *mapper = new PageMapper(accessor, _pages);
10.24 - *provider = new FileProvider(fileid, get_flags(flags), this, mapper);
10.25 + *provider = new FileProvider(fileid, this, mapper);
10.26 return L4_EOK;
10.27 }
10.28
10.29 @@ -167,7 +168,7 @@
10.30
10.31 /* Make a resource for the provider. */
10.32
10.33 - return provider->make_resource(size, object_flags, resource);
10.34 + return provider->make_resource(get_flags(flags), size, object_flags, resource);
10.35 }
10.36
10.37 /* Request the removal of a filesystem object through any active provider or
11.1 --- a/libfsserver/lib/mapping/ipc.cc Sat May 14 23:52:24 2022 +0200
11.2 +++ b/libfsserver/lib/mapping/ipc.cc Thu May 19 14:08:28 2022 +0200
11.3 @@ -1,7 +1,7 @@
11.4 /*
11.5 * Interprocess communication utilities.
11.6 *
11.7 - * Copyright (C) 2021 Paul Boddie <paul@boddie.org.uk>
11.8 + * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
11.9 *
11.10 * This program is free software; you can redistribute it and/or
11.11 * modify it under the terms of the GNU General Public License as
11.12 @@ -28,12 +28,17 @@
11.13 #include "ipc.h"
11.14
11.15
11.16 +
11.17 /* Make an L4 representation of the given flexpage. */
11.18
11.19 static l4_fpage_t ipc_get_fpage(SendFlexpage *send_flexpage)
11.20 {
11.21 - return l4_fpage(send_flexpage->base_addr, send_flexpage->order,
11.22 - (send_flexpage->flags & L4RE_DS_MAP_FLAG_RW) ? L4_FPAGE_RW : L4_FPAGE_RO);
11.23 + unsigned char flags = send_flexpage->flags;
11.24 +
11.25 + if (!flags)
11.26 + flags = L4RE_DS_MAP_FLAG_RO;
11.27 +
11.28 + return l4_fpage(send_flexpage->base_addr, send_flexpage->order, flags);
11.29 }
11.30
11.31 /* Make a representation of a flexpage for the IPC system. */
12.1 --- a/libsystypes/include/systypes/base.h Sat May 14 23:52:24 2022 +0200
12.2 +++ b/libsystypes/include/systypes/base.h Thu May 19 14:08:28 2022 +0200
12.3 @@ -1,7 +1,7 @@
12.4 /*
12.5 * Base types used by various other types.
12.6 *
12.7 - * Copyright (C) 2019, 2021 Paul Boddie <paul@boddie.org.uk>
12.8 + * Copyright (C) 2019, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
12.9 *
12.10 * This program is free software; you can redistribute it and/or
12.11 * modify it under the terms of the GNU General Public License as
12.12 @@ -63,6 +63,19 @@
12.13 OBJECT_HAS_SIZE = 2
12.14 };
12.15
12.16 +/* Memory mapping protection flags compatible with sys/mman.h (and incompatible
12.17 + with comparable L4Re flags). */
12.18 +
12.19 +typedef unsigned long prot_t;
12.20 +
12.21 +enum prot_flags
12.22 +{
12.23 + PROT_NONE = 0,
12.24 + PROT_READ = 1,
12.25 + PROT_WRITE = 2,
12.26 + PROT_EXEC = 4
12.27 +};
12.28 +
12.29 /* Equivalent types are defined in sys/types.h typically. In newlib, they are
12.30 defined in sys/_types.h if not defined elsewhere (such as in
12.31 machine/_types.h).
13.1 --- a/tests/dstest_block_client.cc Sat May 14 23:52:24 2022 +0200
13.2 +++ b/tests/dstest_block_client.cc Thu May 19 14:08:28 2022 +0200
13.3 @@ -1,7 +1,7 @@
13.4 /*
13.5 * Test dataspace operations.
13.6 *
13.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
13.8 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
13.9 *
13.10 * This program is free software; you can redistribute it and/or
13.11 * modify it under the terms of the GNU General Public License as
13.12 @@ -82,7 +82,7 @@
13.13
13.14 /* A region of the file is mapped. */
13.15
13.16 - err = file_mmap(&file, 0, page(10));
13.17 + err = file_mmap(&file, 0, page(10), file_region_flags(file.flags));
13.18
13.19 if (err)
13.20 {
14.1 --- a/tests/dstest_host_client.cc Sat May 14 23:52:24 2022 +0200
14.2 +++ b/tests/dstest_host_client.cc Thu May 19 14:08:28 2022 +0200
14.3 @@ -1,7 +1,7 @@
14.4 /*
14.5 * Test dataspace operations.
14.6 *
14.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
14.8 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
14.9 *
14.10 * This program is free software; you can redistribute it and/or
14.11 * modify it under the terms of the GNU General Public License as
14.12 @@ -68,7 +68,7 @@
14.13
14.14 /* A region of the file is mapped. */
14.15
14.16 - err = file_mmap(&file, 0, page(10));
14.17 + err = file_mmap(&file, 0, page(10), file_region_flags(file.flags));
14.18
14.19 if (err)
14.20 {
15.1 --- a/tests/dstest_test_client.cc Sat May 14 23:52:24 2022 +0200
15.2 +++ b/tests/dstest_test_client.cc Thu May 19 14:08:28 2022 +0200
15.3 @@ -1,7 +1,7 @@
15.4 /*
15.5 * Test dataspace operations.
15.6 *
15.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
15.8 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
15.9 *
15.10 * This program is free software; you can redistribute it and/or
15.11 * modify it under the terms of the GNU General Public License as
15.12 @@ -77,7 +77,7 @@
15.13
15.14 /* A region of the file is mapped. */
15.15
15.16 - err = file_mmap(&file, page(start_page), page(MAP_PAGES));
15.17 + err = file_mmap(&file, page(start_page), page(MAP_PAGES), file_region_flags(file.flags));
15.18
15.19 if (err)
15.20 {