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/mem_ipc.h> 30 31 32 33 int main(void) 34 { 35 l4_cap_idx_t server = l4re_env_get_cap("server"); 36 37 /* Some memory to be mapped. */ 38 39 char *memory; 40 unsigned long size = 40960; 41 long err = ipc_attach_dataspace(server, size, (void **) &memory); 42 43 if (err) 44 { 45 printf("Could not map memory: %s\n", l4sys_errtostr(err)); 46 return 1; 47 } 48 49 printf("Mapped memory at %p\n", memory); 50 51 for (unsigned long offset = 0; offset < size; offset += 1024) 52 { 53 printf("10 bytes from %p...\n", (memory + offset)); 54 fwrite((memory + offset), sizeof(char), 10, stdout); 55 fputs("\n", stdout); 56 } 57 58 return 0; 59 }