| 1 |
/* |
|---|
| 2 |
* CDDL HEADER START |
|---|
| 3 |
* |
|---|
| 4 |
* The contents of this file are subject to the terms of the |
|---|
| 5 |
* Common Development and Distribution License, Version 1.0 only |
|---|
| 6 |
* (the "License"). You may not use this file except in compliance |
|---|
| 7 |
* with the License. |
|---|
| 8 |
* |
|---|
| 9 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|---|
| 10 |
* or http://www.opensolaris.org/os/licensing. |
|---|
| 11 |
* See the License for the specific language governing permissions |
|---|
| 12 |
* and limitations under the License. |
|---|
| 13 |
* |
|---|
| 14 |
* When distributing Covered Code, include this CDDL HEADER in each |
|---|
| 15 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|---|
| 16 |
* If applicable, add the following below this CDDL HEADER, with the |
|---|
| 17 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|---|
| 18 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|---|
| 19 |
* |
|---|
| 20 |
* CDDL HEADER END |
|---|
| 21 |
*/ |
|---|
| 22 |
/* |
|---|
| 23 |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved. |
|---|
| 24 |
* Use is subject to license terms. |
|---|
| 25 |
*/ |
|---|
| 26 |
/* |
|---|
| 27 |
* Portions Copyright 2006 OmniTI, Inc. |
|---|
| 28 |
*/ |
|---|
| 29 |
|
|---|
| 30 |
/* #pragma ident "@(#)init_lib.c 1.2 05/06/08 SMI" */ |
|---|
| 31 |
|
|---|
| 32 |
/* |
|---|
| 33 |
* Initialization routines for the library version of libumem. |
|---|
| 34 |
*/ |
|---|
| 35 |
|
|---|
| 36 |
#include "config.h" |
|---|
| 37 |
#include "umem_base.h" |
|---|
| 38 |
#include "vmem_base.h" |
|---|
| 39 |
|
|---|
| 40 |
#if HAVE_UNISTD_H |
|---|
| 41 |
#include <unistd.h> |
|---|
| 42 |
#endif |
|---|
| 43 |
#if HAVE_DLFCN_H |
|---|
| 44 |
#include <dlfcn.h> |
|---|
| 45 |
#endif |
|---|
| 46 |
|
|---|
| 47 |
void |
|---|
| 48 |
vmem_heap_init(void) |
|---|
| 49 |
{ |
|---|
| 50 |
#ifdef _WIN32 |
|---|
| 51 |
vmem_backend = VMEM_BACKEND_MMAP; |
|---|
| 52 |
#else |
|---|
| 53 |
#if 0 |
|---|
| 54 |
void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD); |
|---|
| 55 |
|
|---|
| 56 |
if (handle != NULL) { |
|---|
| 57 |
#endif |
|---|
| 58 |
log_message("sbrk backend disabled\n"); |
|---|
| 59 |
vmem_backend = VMEM_BACKEND_MMAP; |
|---|
| 60 |
#if 0 |
|---|
| 61 |
} |
|---|
| 62 |
#endif |
|---|
| 63 |
#endif |
|---|
| 64 |
|
|---|
| 65 |
if ((vmem_backend & VMEM_BACKEND_MMAP) != 0) { |
|---|
| 66 |
vmem_backend = VMEM_BACKEND_MMAP; |
|---|
| 67 |
(void) vmem_mmap_arena(NULL, NULL); |
|---|
| 68 |
} else { |
|---|
| 69 |
#ifndef _WIN32 |
|---|
| 70 |
vmem_backend = VMEM_BACKEND_SBRK; |
|---|
| 71 |
(void) vmem_sbrk_arena(NULL, NULL); |
|---|
| 72 |
#endif |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
/*ARGSUSED*/ |
|---|
| 77 |
void |
|---|
| 78 |
umem_type_init(caddr_t start, size_t len, size_t pgsize) |
|---|
| 79 |
{ |
|---|
| 80 |
#ifdef _WIN32 |
|---|
| 81 |
SYSTEM_INFO info; |
|---|
| 82 |
GetSystemInfo(&info); |
|---|
| 83 |
pagesize = info.dwPageSize; |
|---|
| 84 |
#else |
|---|
| 85 |
pagesize = _sysconf(_SC_PAGESIZE); |
|---|
| 86 |
#endif |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
int |
|---|
| 90 |
umem_get_max_ncpus(void) |
|---|
| 91 |
{ |
|---|
| 92 |
#ifdef _SC_NPROCESSORS_ONLN |
|---|
| 93 |
return (2 * sysconf(_SC_NPROCESSORS_ONLN)); |
|---|
| 94 |
#elif defined(_SC_NPROCESSORS_CONF) |
|---|
| 95 |
return (2 * sysconf(_SC_NPROCESSORS_CONF)); |
|---|
| 96 |
#elif defined(_WIN32) |
|---|
| 97 |
SYSTEM_INFO info; |
|---|
| 98 |
GetSystemInfo(&info); |
|---|
| 99 |
return info.dwNumberOfProcessors; |
|---|
| 100 |
#else |
|---|
| 101 |
/* XXX: determine CPU count on other platforms */ |
|---|
| 102 |
return (1); |
|---|
| 103 |
#endif |
|---|
| 104 |
} |
|---|