1/*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "compat_cpp.h"
8
9#include <stdio.h>
10#include <string.h>
11
12#include <kernel/vm/vm.h>
13
14
15void*
16_kernel_contigmalloc_cpp(const char* file, int line, size_t size,
17	phys_addr_t low, phys_addr_t high, phys_size_t alignment,
18	phys_size_t boundary, bool zero, bool dontWait)
19{
20	size = ROUNDUP(size, B_PAGE_SIZE);
21
22	uint32 creationFlags = (zero ? 0 : CREATE_AREA_DONT_CLEAR)
23		| (dontWait ? CREATE_AREA_DONT_WAIT : 0);
24
25	char name[B_OS_NAME_LENGTH];
26	const char* baseName = strrchr(file, '/');
27	baseName = baseName != NULL ? baseName + 1 : file;
28	snprintf(name, sizeof(name), "contig:%s:%d", baseName, line);
29
30	virtual_address_restrictions virtualRestrictions = {};
31
32	physical_address_restrictions physicalRestrictions = {};
33	physicalRestrictions.low_address = low;
34	physicalRestrictions.high_address = high;
35	physicalRestrictions.alignment = alignment;
36	physicalRestrictions.boundary = boundary;
37
38	void* address;
39	area_id area = create_area_etc(B_SYSTEM_TEAM, name, size, B_CONTIGUOUS,
40		B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, creationFlags, 0,
41		&virtualRestrictions, &physicalRestrictions, &address);
42	if (area < 0)
43		return NULL;
44
45	return address;
46}
47