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