os_region.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__region_8c-source.html,v 1.1 2008/06/08 10:21:27 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <errno.h>
00018 #endif
00019 
00020 #include "db_int.h"
00021 #include "os_jump.h"
00022 
00023 /*
00024  * CDB___os_r_attach --
00025  *      Attach to a shared memory region.
00026  *
00027  * PUBLIC: int CDB___os_r_attach __P((DB_ENV *, REGINFO *, REGION *));
00028  */
00029 int
00030 CDB___os_r_attach(dbenv, infop, rp)
00031         DB_ENV *dbenv;
00032         REGINFO *infop;
00033         REGION *rp;
00034 {
00035         /* Round off the requested size for the underlying VM. */
00036         OS_VMROUNDOFF(rp->size);
00037 
00038 #ifdef DB_REGIONSIZE_MAX
00039         /* Some architectures have hard limits on the maximum region size. */
00040         if (rp->size > DB_REGIONSIZE_MAX) {
00041                 CDB___db_err(dbenv, "region size %lu is too large; maximum is %lu",
00042                     (u_long)rp->size, (u_long)DB_REGIONSIZE_MAX);
00043                 return (EINVAL);
00044         }
00045 #endif
00046 
00047         /*
00048          * If a region is private, malloc the memory.
00049          *
00050          * !!!
00051          * If this fails because the region is too large to malloc, mmap(2)
00052          * using the MAP_ANON or MAP_ANONYMOUS flags would be an alternative.
00053          * I don't know of any architectures (yet!) where malloc is a problem.
00054          */
00055         if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
00056 #if defined(MUTEX_NO_MALLOC_LOCKS)
00057                 /*
00058                  * !!!
00059                  * There exist spinlocks that don't work in malloc memory, e.g.,
00060                  * the HP/UX msemaphore interface.  If we don't have locks that
00061                  * will work in malloc memory, we better not be private or not
00062                  * be threaded.
00063                  */
00064                 if (F_ISSET(dbenv, DB_ENV_THREAD)) {
00065                         CDB___db_err(dbenv, "%s",
00066     "architecture does not support locks inside process-local (malloc) memory");
00067                         CDB___db_err(dbenv, "%s",
00068     "application may not specify both DB_PRIVATE and DB_THREAD");
00069                         return (EINVAL);
00070                 }
00071 #endif
00072                 return (CDB___os_malloc(dbenv, rp->size, NULL, &infop->addr));
00073         }
00074 
00075         /* If the user replaced the map call, call through their interface. */
00076         if (CDB___db_jump.j_map != NULL)
00077                 return (CDB___db_jump.j_map(infop->name,
00078                     rp->size, 1, 0, &infop->addr));
00079 
00080         return (CDB___os_r_sysattach(dbenv, infop, rp));
00081 }
00082 
00083 /*
00084  * CDB___os_r_detach --
00085  *      Detach from a shared memory region.
00086  *
00087  * PUBLIC: int CDB___os_r_detach __P((DB_ENV *, REGINFO *, int));
00088  */
00089 int
00090 CDB___os_r_detach(dbenv, infop, destroy)
00091         DB_ENV *dbenv;
00092         REGINFO *infop;
00093         int destroy;
00094 {
00095         REGION *rp;
00096 
00097         rp = infop->rp;
00098 
00099         /* If a region is private, free the memory. */
00100         if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
00101                 CDB___os_free(infop->addr, rp->size);
00102                 return (0);
00103         }
00104 
00105         /* If the user replaced the map call, call through their interface. */
00106         if (CDB___db_jump.j_unmap != NULL)
00107                 return (CDB___db_jump.j_unmap(infop->addr, rp->size));
00108 
00109         return (CDB___os_r_sysdetach(dbenv, infop, destroy));
00110 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5