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