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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Portions Copyright 2006 OmniTI, Inc.
30 /* #pragma ident "@(#)init_lib.c 1.2 05/06/08 SMI" */
33 * Initialization routines for the library version of libumem.
37 #include "umem_base.h"
38 #include "vmem_base.h"
51 #include <machine/param.h>
58 vmem_backend = VMEM_BACKEND_MMAP;
61 void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD);
65 log_message("sbrk backend disabled\n");
66 vmem_backend = VMEM_BACKEND_MMAP;
72 if ((vmem_backend & VMEM_BACKEND_MMAP) != 0) {
73 vmem_backend = VMEM_BACKEND_MMAP;
74 (void) vmem_mmap_arena(NULL, NULL);
77 vmem_backend = VMEM_BACKEND_SBRK;
78 (void) vmem_sbrk_arena(NULL, NULL);
85 umem_type_init(caddr_t start, size_t len, size_t pgsize)
90 pagesize = info.dwPageSize;
91 #elif !defined(__FreeBSD__)
92 pagesize = _sysconf(_SC_PAGESIZE);
99 umem_get_max_ncpus(void)
103 * HACK: sysconf() will invoke malloc() on Linux as part of reading
104 * in /proc/stat. To avoid recursion in the malloc replacement
105 * version of libumem, read /proc/stat into a static buffer.
107 static char proc_stat[8192];
111 fd = open("/proc/stat", O_RDONLY);
113 const ssize_t n = read(fd, proc_stat, sizeof(proc_stat) - 1);
120 while (*cur && (next = strstr(cur + 3, "cpu"))) {
125 ncpus = atoi(cur + 3) + 1;
135 #if _SC_NPROCESSORS_ONLN
136 return (2 * sysconf(_SC_NPROCESSORS_ONLN));
137 #elif defined(_SC_NPROCESSORS_CONF)
138 return (2 * sysconf(_SC_NPROCESSORS_CONF));
139 #elif defined(_WIN32)
141 GetSystemInfo(&info);
142 return info.dwNumberOfProcessors;
144 /* XXX: determine CPU count on other platforms */