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