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