00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "db_config.h"
00011
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014
00015 #include <string.h>
00016 #endif
00017
00018 #include "db_int.h"
00019
00020
00021
00022
00023
00024
00025
00026 int
00027 __os_r_attach(dbenv, infop, rp)
00028 DB_ENV *dbenv;
00029 REGINFO *infop;
00030 REGION *rp;
00031 {
00032 int ret;
00033
00034
00035
00036
00037
00038
00039 #define OS_VMPAGESIZE (8 * 1024)
00040 #define OS_VMROUNDOFF(i) { \
00041 if ((i) < \
00042 (UINT32_MAX - OS_VMPAGESIZE) + 1 || (i) < OS_VMPAGESIZE) \
00043 (i) += OS_VMPAGESIZE - 1; \
00044 (i) -= (i) % OS_VMPAGESIZE; \
00045 }
00046 OS_VMROUNDOFF(rp->size);
00047
00048 #ifdef DB_REGIONSIZE_MAX
00049
00050 if (rp->size > DB_REGIONSIZE_MAX) {
00051 __db_err(dbenv, "region size %lu is too large; maximum is %lu",
00052 (u_long)rp->size, (u_long)DB_REGIONSIZE_MAX);
00053 return (EINVAL);
00054 }
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
00066 #if defined(HAVE_MUTEX_HPPA_MSEM_INIT)
00067
00068
00069
00070
00071
00072
00073
00074 if (F_ISSET(dbenv, DB_ENV_THREAD)) {
00075 __db_err(dbenv, "%s",
00076 "architecture does not support locks inside process-local (malloc) memory");
00077 __db_err(dbenv, "%s",
00078 "application may not specify both DB_PRIVATE and DB_THREAD");
00079 return (EINVAL);
00080 }
00081 #endif
00082 if ((ret = __os_malloc(
00083 dbenv, sizeof(REGENV), &infop->addr)) != 0)
00084 return (ret);
00085
00086 infop->max_alloc = rp->size;
00087 } else {
00088
00089
00090
00091
00092 if (DB_GLOBAL(j_map) != NULL && (ret = DB_GLOBAL(j_map)
00093 (infop->name, rp->size, 1, 0, &infop->addr)) != 0)
00094 return (ret);
00095
00096
00097 if ((ret = __os_r_sysattach(dbenv, infop, rp)) != 0)
00098 return (ret);
00099 }
00100
00101
00102
00103
00104
00105
00106 infop->addr_orig = infop->addr;
00107 infop->addr = ALIGNP_INC(infop->addr_orig, sizeof(size_t));
00108
00109 rp->size_orig = rp->size;
00110 if (infop->addr != infop->addr_orig)
00111 rp->size -=
00112 (u_int8_t *)infop->addr - (u_int8_t *)infop->addr_orig;
00113
00114 return (0);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123 int
00124 __os_r_detach(dbenv, infop, destroy)
00125 DB_ENV *dbenv;
00126 REGINFO *infop;
00127 int destroy;
00128 {
00129 REGION *rp;
00130
00131 rp = infop->rp;
00132
00133
00134 if (infop->addr != infop->addr_orig) {
00135 infop->addr = infop->addr_orig;
00136 rp->size = rp->size_orig;
00137 }
00138
00139
00140 if (F_ISSET(dbenv, DB_ENV_PRIVATE)) {
00141 __os_free(dbenv, infop->addr);
00142 return (0);
00143 }
00144
00145
00146 if (DB_GLOBAL(j_unmap) != NULL)
00147 return (DB_GLOBAL(j_unmap)(infop->addr, rp->size));
00148
00149 return (__os_r_sysdetach(dbenv, infop, destroy));
00150 }