paul@0 | 1 | /* |
paul@0 | 2 | * Test dataspace operations. |
paul@0 | 3 | * |
paul@1 | 4 | * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #include <l4/re/env.h> |
paul@0 | 23 | #include <l4/sys/err.h> |
paul@0 | 24 | |
paul@0 | 25 | #include <stdio.h> |
paul@0 | 26 | #include <string.h> |
paul@0 | 27 | #include <stdlib.h> |
paul@0 | 28 | |
paul@0 | 29 | #include <ipc/server.h> |
paul@0 | 30 | |
paul@7 | 31 | #include "mapped_file_object_server.h" |
paul@6 | 32 | #include "page_mapper.h" |
paul@7 | 33 | #include "file_pager.h" |
paul@6 | 34 | #include "pages.h" |
paul@6 | 35 | #include "test_file_accessor.h" |
paul@0 | 36 | |
paul@0 | 37 | |
paul@0 | 38 | |
paul@7 | 39 | /* A component exposing the dataspace and mapped file interfaces. */ |
paul@7 | 40 | |
paul@7 | 41 | class MappedFileServer : public FilePager, public MappedFileObject |
paul@7 | 42 | { |
paul@7 | 43 | public: |
paul@7 | 44 | explicit MappedFileServer(fileid_t fileid, PageMapper *mapper) |
paul@7 | 45 | : FilePager(fileid, mapper) |
paul@7 | 46 | { |
paul@7 | 47 | } |
paul@7 | 48 | |
paul@7 | 49 | virtual long map(unsigned long offset, l4_addr_t hot_spot, unsigned long flags, l4_snd_fpage_t *region) |
paul@7 | 50 | { return FilePager::map(offset, hot_spot, flags, region); } |
paul@7 | 51 | |
paul@7 | 52 | virtual long mmap(size_t position, size_t length, size_t *start_pos, size_t *end_pos, size_t *data_end) |
paul@7 | 53 | { return FilePager::mmap(position, length, start_pos, end_pos, data_end); } |
paul@7 | 54 | }; |
paul@7 | 55 | |
paul@7 | 56 | |
paul@7 | 57 | |
paul@0 | 58 | int main(void) |
paul@0 | 59 | { |
paul@0 | 60 | /* Some memory. */ |
paul@0 | 61 | |
paul@6 | 62 | Memory mem(10); |
paul@6 | 63 | Pages pages(&mem); |
paul@6 | 64 | TestFileAccessor a(123UL); |
paul@6 | 65 | PageMapper m(&a, &pages); |
paul@7 | 66 | MappedFileServer obj(123UL, &m); |
paul@0 | 67 | |
paul@0 | 68 | /* Server capability. */ |
paul@0 | 69 | |
paul@0 | 70 | l4_cap_idx_t server; |
paul@0 | 71 | |
paul@0 | 72 | /* Register a server associating it with the given object. */ |
paul@0 | 73 | |
paul@7 | 74 | long err = ipc_server_bind("server", (l4_umword_t) &obj, &server); |
paul@0 | 75 | |
paul@0 | 76 | if (err) |
paul@0 | 77 | { |
paul@0 | 78 | printf("Could not bind server: %s\n", l4sys_errtostr(err)); |
paul@0 | 79 | return 1; |
paul@0 | 80 | } |
paul@0 | 81 | |
paul@0 | 82 | /* Wait for messages, dispatching to the handler. */ |
paul@0 | 83 | |
paul@7 | 84 | ipc_server_loop_for(MappedFileObject, &obj); |
paul@0 | 85 | |
paul@0 | 86 | return 0; |
paul@0 | 87 | } |