diff --git a/src/libs/compat/freebsd_network/Jamfile b/src/libs/compat/freebsd_network/Jamfile index 2e5219f646..d84533ebb3 100644 --- a/src/libs/compat/freebsd_network/Jamfile +++ b/src/libs/compat/freebsd_network/Jamfile @@ -17,6 +17,7 @@ KernelStaticLibrary libfreebsd_network.a : callout.c clock.c compat.c + compat_cpp.cpp condvar.c Condvar.cpp device.c diff --git a/src/libs/compat/freebsd_network/compat.c b/src/libs/compat/freebsd_network/compat.c index d2e780daa2..b5c6cc663f 100644 --- a/src/libs/compat/freebsd_network/compat.c +++ b/src/libs/compat/freebsd_network/compat.c @@ -22,6 +22,8 @@ #include +#include "compat_cpp.h" + spinlock __haiku_intr_spinlock; @@ -587,24 +589,8 @@ _kernel_contigmalloc(const char *file, int line, size_t size, int flags, vm_paddr_t low, vm_paddr_t high, unsigned long alignment, unsigned long boundary) { - char name[256]; - area_id area; - void *addr; - - snprintf(name, sizeof(name), "contig:%s:%d", file, line); - - area = create_area(name, &addr, B_ANY_KERNEL_ADDRESS, size, - B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); - if (area < 0) - return NULL; - - if (flags & M_ZERO) - memset(addr, 0, size); - - //driver_printf("(%s) addr = %p, area = %ld, size = %lu\n", - // name, addr, area, size); - - return addr; + return _kernel_contigmalloc_cpp(file, line, size, low, high, + alignment, boundary, (flags & M_ZERO) != 0, (flags & M_NOWAIT) != 0); } diff --git a/src/libs/compat/freebsd_network/compat_cpp.cpp b/src/libs/compat/freebsd_network/compat_cpp.cpp new file mode 100644 index 0000000000..97c9243c83 --- /dev/null +++ b/src/libs/compat/freebsd_network/compat_cpp.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "compat_cpp.h" + +#include +#include + +#include + + +void* +_kernel_contigmalloc_cpp(const char* file, int line, size_t size, + phys_addr_t low, phys_addr_t high, phys_size_t alignment, + phys_size_t boundary, bool zero, bool dontWait) +{ + size = ROUNDUP(size, B_PAGE_SIZE); + + uint32 creationFlags = (zero ? 0 : CREATE_AREA_DONT_CLEAR) + | (dontWait ? CREATE_AREA_DONT_WAIT : 0); + + char name[B_OS_NAME_LENGTH]; + const char* baseName = strrchr(file, '/'); + baseName = baseName != NULL ? baseName + 1 : file; + snprintf(name, sizeof(name), "contig:%s:%d", baseName, line); + + virtual_address_restrictions virtualRestrictions = {}; + + physical_address_restrictions physicalRestrictions = {}; + physicalRestrictions.low_address = low; + physicalRestrictions.high_address = high; + physicalRestrictions.alignment = alignment; + physicalRestrictions.boundary = boundary; + + void* address; + area_id area = create_area_etc(B_SYSTEM_TEAM, name, size, B_CONTIGUOUS, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, creationFlags, + &virtualRestrictions, &physicalRestrictions, &address); + if (area < 0) + return NULL; + + return address; +} diff --git a/src/libs/compat/freebsd_network/compat_cpp.h b/src/libs/compat/freebsd_network/compat_cpp.h new file mode 100644 index 0000000000..ee531b4f2e --- /dev/null +++ b/src/libs/compat/freebsd_network/compat_cpp.h @@ -0,0 +1,27 @@ +/* + * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _FREE_BSD_NETWORK_COMPAT_CPP_H +#define _FREE_BSD_NETWORK_COMPAT_CPP_H + + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +void* _kernel_contigmalloc_cpp(const char* file, int line, size_t size, + phys_addr_t low, phys_addr_t high, phys_size_t alignment, + phys_size_t boundary, bool zero, bool dontWait); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _FREE_BSD_NETWORK_COMPAT_CPP_H */