1/* 2 * Copyright (c) 2015, ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#include <stdlib.h> 11#include <barrelfish/barrelfish.h> 12#include <errno.h> 13 14#include "posixcompat.h" 15 16int posix_memalign(void **memptr, size_t alignment, size_t size) 17{ 18 errval_t err; 19 20 size_t retbytes; 21 struct capref memory_cap; 22 23 err = frame_alloc(&memory_cap, size, &retbytes); 24 if (err_is_fail(err)) { 25 USER_PANIC_ERR(err, "Can not allocate large enough frame."); 26 } 27 28 err = vspace_map_one_frame(memptr, retbytes, memory_cap, NULL, NULL); 29 if (err_is_fail(err)) { 30 USER_PANIC_ERR(err, "Can not map the frame in the vspace."); 31 } 32 33 // Make sure our alignment is actually ok: 34 assert(((size_t)*memptr) % alignment == 0); 35 36 return 0; 37} 38