2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id: os_region.c,v 11.15 2002/07/12 18:56:51 bostic Exp $";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
23
* Attach to a shared memory region.
25
* PUBLIC: int __os_r_attach __P((DB_ENV *, REGINFO *, REGION *));
28
__os_r_attach(dbenv, infop, rp)
34
/* Round off the requested size for the underlying VM. */
35
OS_VMROUNDOFF(rp->size);
37
#ifdef DB_REGIONSIZE_MAX
38
/* Some architectures have hard limits on the maximum region size. */
39
if (rp->size > DB_REGIONSIZE_MAX) {
40
__db_err(dbenv, "region size %lu is too large; maximum is %lu",
41
(u_long)rp->size, (u_long)DB_REGIONSIZE_MAX);
47
* If a region is private, malloc the memory.
50
* If this fails because the region is too large to malloc, mmap(2)
51
* using the MAP_ANON or MAP_ANONYMOUS flags would be an alternative.
52
* I don't know of any architectures (yet!) where malloc is a problem.
54
if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
55
#if defined(MUTEX_NO_MALLOC_LOCKS)
58
* There exist spinlocks that don't work in malloc memory, e.g.,
59
* the HP/UX msemaphore interface. If we don't have locks that
60
* will work in malloc memory, we better not be private or not
63
if (F_ISSET(dbenv, DB_ENV_THREAD)) {
65
"architecture does not support locks inside process-local (malloc) memory");
67
"application may not specify both DB_PRIVATE and DB_THREAD");
72
__os_malloc(dbenv, rp->size, &infop->addr)) != 0)
74
#if defined(UMRW) && !defined(DIAGNOSTIC)
75
memset(infop->addr, CLEAR_BYTE, rp->size);
80
/* If the user replaced the map call, call through their interface. */
81
if (DB_GLOBAL(j_map) != NULL)
82
return (DB_GLOBAL(j_map)(infop->name,
83
rp->size, 1, 0, &infop->addr));
85
return (__os_r_sysattach(dbenv, infop, rp));
90
* Detach from a shared memory region.
92
* PUBLIC: int __os_r_detach __P((DB_ENV *, REGINFO *, int));
95
__os_r_detach(dbenv, infop, destroy)
104
/* If a region is private, free the memory. */
105
if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
106
__os_free(dbenv, infop->addr);
110
/* If the user replaced the map call, call through their interface. */
111
if (DB_GLOBAL(j_unmap) != NULL)
112
return (DB_GLOBAL(j_unmap)(infop->addr, rp->size));
114
return (__os_r_sysdetach(dbenv, infop, destroy));