1*7c478bd9Sstevel@tonic-gate /*- 2*7c478bd9Sstevel@tonic-gate * See the file LICENSE for redistribution information. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1997, 1998 5*7c478bd9Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 6*7c478bd9Sstevel@tonic-gate */ 7*7c478bd9Sstevel@tonic-gate 8*7c478bd9Sstevel@tonic-gate #include "config.h" 9*7c478bd9Sstevel@tonic-gate 10*7c478bd9Sstevel@tonic-gate #ifndef lint 11*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)os_config.c 10.30 (Sleepycat) 10/12/98"; 12*7c478bd9Sstevel@tonic-gate #endif /* not lint */ 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES 15*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 16*7c478bd9Sstevel@tonic-gate 17*7c478bd9Sstevel@tonic-gate #include <errno.h> 18*7c478bd9Sstevel@tonic-gate #endif 19*7c478bd9Sstevel@tonic-gate 20*7c478bd9Sstevel@tonic-gate #include "db_int.h" 21*7c478bd9Sstevel@tonic-gate #include "os_jump.h" 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate struct __db_jumptab __db_jump; 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate DB_GLOBALS __db_global_values = { 26*7c478bd9Sstevel@tonic-gate 1, /* DB_MUTEXLOCKS */ 27*7c478bd9Sstevel@tonic-gate 0, /* DB_PAGEYIELD */ 28*7c478bd9Sstevel@tonic-gate 0, /* DB_REGION_ANON, DB_REGION_NAME */ 29*7c478bd9Sstevel@tonic-gate 0, /* DB_REGION_INIT */ 30*7c478bd9Sstevel@tonic-gate 0, /* DB_TSL_SPINS */ 31*7c478bd9Sstevel@tonic-gate {NULL, &__db_global_values.db_envq.tqh_first}, /* Environemnt queue */ 32*7c478bd9Sstevel@tonic-gate {NULL, &__db_global_values.db_nameq.tqh_first} /* Name queue */ 33*7c478bd9Sstevel@tonic-gate }; 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate /* 36*7c478bd9Sstevel@tonic-gate * db_jump_set -- 37*7c478bd9Sstevel@tonic-gate * Replace functions for the DB package. 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate int 40*7c478bd9Sstevel@tonic-gate db_jump_set(func, which) 41*7c478bd9Sstevel@tonic-gate void *func; 42*7c478bd9Sstevel@tonic-gate int which; 43*7c478bd9Sstevel@tonic-gate { 44*7c478bd9Sstevel@tonic-gate switch (which) { 45*7c478bd9Sstevel@tonic-gate case DB_FUNC_CLOSE: 46*7c478bd9Sstevel@tonic-gate __db_jump.j_close = (int (*) __P((int)))func; 47*7c478bd9Sstevel@tonic-gate break; 48*7c478bd9Sstevel@tonic-gate case DB_FUNC_DIRFREE: 49*7c478bd9Sstevel@tonic-gate __db_jump.j_dirfree = (void (*) __P((char **, int)))func; 50*7c478bd9Sstevel@tonic-gate break; 51*7c478bd9Sstevel@tonic-gate case DB_FUNC_DIRLIST: 52*7c478bd9Sstevel@tonic-gate __db_jump.j_dirlist = 53*7c478bd9Sstevel@tonic-gate (int (*) __P((const char *, char ***, int *)))func; 54*7c478bd9Sstevel@tonic-gate break; 55*7c478bd9Sstevel@tonic-gate case DB_FUNC_EXISTS: 56*7c478bd9Sstevel@tonic-gate __db_jump.j_exists = (int (*) __P((const char *, int *)))func; 57*7c478bd9Sstevel@tonic-gate break; 58*7c478bd9Sstevel@tonic-gate case DB_FUNC_FREE: 59*7c478bd9Sstevel@tonic-gate __db_jump.j_free = (void (*) __P((void *)))func; 60*7c478bd9Sstevel@tonic-gate break; 61*7c478bd9Sstevel@tonic-gate case DB_FUNC_FSYNC: 62*7c478bd9Sstevel@tonic-gate __db_jump.j_fsync = (int (*) __P((int)))func; 63*7c478bd9Sstevel@tonic-gate break; 64*7c478bd9Sstevel@tonic-gate case DB_FUNC_IOINFO: 65*7c478bd9Sstevel@tonic-gate __db_jump.j_ioinfo = (int (*) __P((const char *, 66*7c478bd9Sstevel@tonic-gate int, u_int32_t *, u_int32_t *, u_int32_t *)))func; 67*7c478bd9Sstevel@tonic-gate break; 68*7c478bd9Sstevel@tonic-gate case DB_FUNC_MALLOC: 69*7c478bd9Sstevel@tonic-gate __db_jump.j_malloc = (void *(*) __P((size_t)))func; 70*7c478bd9Sstevel@tonic-gate break; 71*7c478bd9Sstevel@tonic-gate case DB_FUNC_MAP: 72*7c478bd9Sstevel@tonic-gate __db_jump.j_map = (int (*) 73*7c478bd9Sstevel@tonic-gate __P((char *, int, size_t, int, int, int, void **)))func; 74*7c478bd9Sstevel@tonic-gate break; 75*7c478bd9Sstevel@tonic-gate case DB_FUNC_OPEN: 76*7c478bd9Sstevel@tonic-gate __db_jump.j_open = (int (*) __P((const char *, int, ...)))func; 77*7c478bd9Sstevel@tonic-gate break; 78*7c478bd9Sstevel@tonic-gate case DB_FUNC_READ: 79*7c478bd9Sstevel@tonic-gate __db_jump.j_read = 80*7c478bd9Sstevel@tonic-gate (ssize_t (*) __P((int, void *, size_t)))func; 81*7c478bd9Sstevel@tonic-gate break; 82*7c478bd9Sstevel@tonic-gate case DB_FUNC_REALLOC: 83*7c478bd9Sstevel@tonic-gate __db_jump.j_realloc = (void *(*) __P((void *, size_t)))func; 84*7c478bd9Sstevel@tonic-gate break; 85*7c478bd9Sstevel@tonic-gate case DB_FUNC_RUNLINK: 86*7c478bd9Sstevel@tonic-gate __db_jump.j_runlink = (int (*) __P((char *)))func; 87*7c478bd9Sstevel@tonic-gate break; 88*7c478bd9Sstevel@tonic-gate case DB_FUNC_SEEK: 89*7c478bd9Sstevel@tonic-gate __db_jump.j_seek = (int (*) 90*7c478bd9Sstevel@tonic-gate __P((int, size_t, db_pgno_t, u_int32_t, int, int)))func; 91*7c478bd9Sstevel@tonic-gate break; 92*7c478bd9Sstevel@tonic-gate case DB_FUNC_SLEEP: 93*7c478bd9Sstevel@tonic-gate __db_jump.j_sleep = (int (*) __P((u_long, u_long)))func; 94*7c478bd9Sstevel@tonic-gate break; 95*7c478bd9Sstevel@tonic-gate case DB_FUNC_UNLINK: 96*7c478bd9Sstevel@tonic-gate __db_jump.j_unlink = (int (*) __P((const char *)))func; 97*7c478bd9Sstevel@tonic-gate break; 98*7c478bd9Sstevel@tonic-gate case DB_FUNC_UNMAP: 99*7c478bd9Sstevel@tonic-gate __db_jump.j_unmap = (int (*) __P((void *, size_t)))func; 100*7c478bd9Sstevel@tonic-gate break; 101*7c478bd9Sstevel@tonic-gate case DB_FUNC_WRITE: 102*7c478bd9Sstevel@tonic-gate __db_jump.j_write = 103*7c478bd9Sstevel@tonic-gate (ssize_t (*) __P((int, const void *, size_t)))func; 104*7c478bd9Sstevel@tonic-gate break; 105*7c478bd9Sstevel@tonic-gate case DB_FUNC_YIELD: 106*7c478bd9Sstevel@tonic-gate __db_jump.j_yield = (int (*) __P((void)))func; 107*7c478bd9Sstevel@tonic-gate break; 108*7c478bd9Sstevel@tonic-gate default: 109*7c478bd9Sstevel@tonic-gate return (EINVAL); 110*7c478bd9Sstevel@tonic-gate } 111*7c478bd9Sstevel@tonic-gate return (0); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* 115*7c478bd9Sstevel@tonic-gate * db_value_set -- 116*7c478bd9Sstevel@tonic-gate * Replace values for the DB package. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate int 119*7c478bd9Sstevel@tonic-gate db_value_set(value, which) 120*7c478bd9Sstevel@tonic-gate int value, which; 121*7c478bd9Sstevel@tonic-gate { 122*7c478bd9Sstevel@tonic-gate int ret; 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate switch (which) { 125*7c478bd9Sstevel@tonic-gate case DB_MUTEXLOCKS: 126*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_mutexlocks) = value; 127*7c478bd9Sstevel@tonic-gate break; 128*7c478bd9Sstevel@tonic-gate case DB_PAGEYIELD: 129*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_pageyield) = value; 130*7c478bd9Sstevel@tonic-gate break; 131*7c478bd9Sstevel@tonic-gate case DB_REGION_ANON: 132*7c478bd9Sstevel@tonic-gate if (value != 0 && (ret = __db_mapanon_ok(0)) != 0) 133*7c478bd9Sstevel@tonic-gate return (ret); 134*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_region_anon) = value; 135*7c478bd9Sstevel@tonic-gate break; 136*7c478bd9Sstevel@tonic-gate case DB_REGION_INIT: 137*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_region_init) = value; 138*7c478bd9Sstevel@tonic-gate break; 139*7c478bd9Sstevel@tonic-gate case DB_REGION_NAME: 140*7c478bd9Sstevel@tonic-gate if (value != 0 && (ret = __db_mapanon_ok(1)) != 0) 141*7c478bd9Sstevel@tonic-gate return (ret); 142*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_region_anon) = value; 143*7c478bd9Sstevel@tonic-gate break; 144*7c478bd9Sstevel@tonic-gate case DB_TSL_SPINS: 145*7c478bd9Sstevel@tonic-gate if (value <= 0) 146*7c478bd9Sstevel@tonic-gate return (EINVAL); 147*7c478bd9Sstevel@tonic-gate DB_GLOBAL(db_tsl_spins) = value; 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate default: 150*7c478bd9Sstevel@tonic-gate return (EINVAL); 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate return (0); 153*7c478bd9Sstevel@tonic-gate } 154