Wed Dec 19 16:27:26 2018 UTC ()
compat/svr4* is gone - adapt


(martin)
diff -r1.29 -r1.30 src/usr.bin/kdump/setemul.c

cvs diff -r1.29 -r1.30 src/usr.bin/kdump/setemul.c (switch to unified diff)

--- src/usr.bin/kdump/setemul.c 2011/04/26 16:57:42 1.29
+++ src/usr.bin/kdump/setemul.c 2018/12/19 16:27:26 1.30
@@ -1,329 +1,315 @@ @@ -1,329 +1,315 @@
1/* $NetBSD: setemul.c,v 1.29 2011/04/26 16:57:42 joerg Exp $ */ 1/* $NetBSD: setemul.c,v 1.30 2018/12/19 16:27:26 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Copyright (c) 1988, 1993 30 * Copyright (c) 1988, 1993
31 * The Regents of the University of California. All rights reserved. 31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc. 32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed 33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph 34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc. 36 * the permission of UNIX System Laboratories, Inc.
37 * 37 *
38 * Redistribution and use in source and binary forms, with or without 38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions 39 * modification, are permitted provided that the following conditions
40 * are met: 40 * are met:
41 * 1. Redistributions of source code must retain the above copyright 41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer. 42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright 43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the 44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution. 45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors 46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software 47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission. 48 * without specific prior written permission.
49 * 49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE. 60 * SUCH DAMAGE.
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64#ifndef lint 64#ifndef lint
65__RCSID("$NetBSD: setemul.c,v 1.29 2011/04/26 16:57:42 joerg Exp $"); 65__RCSID("$NetBSD: setemul.c,v 1.30 2018/12/19 16:27:26 martin Exp $");
66#endif /* not lint */ 66#endif /* not lint */
67 67
68#include <sys/param.h> 68#include <sys/param.h>
69#include <sys/errno.h> 69#include <sys/errno.h>
70#include <sys/time.h> 70#include <sys/time.h>
71#include <sys/queue.h> 71#include <sys/queue.h>
72 72
73#include <err.h> 73#include <err.h>
74#include <stdio.h> 74#include <stdio.h>
75#include <stdlib.h> 75#include <stdlib.h>
76#include <string.h> 76#include <string.h>
77#include <unistd.h> 77#include <unistd.h>
78#include <vis.h> 78#include <vis.h>
79 79
80#include "setemul.h" 80#include "setemul.h"
81 81
82#include <sys/syscall.h> 82#include <sys/syscall.h>
83 83
84#include "../../sys/compat/netbsd32/netbsd32_syscall.h" 84#include "../../sys/compat/netbsd32/netbsd32_syscall.h"
85#include "../../sys/compat/freebsd/freebsd_syscall.h" 85#include "../../sys/compat/freebsd/freebsd_syscall.h"
86#include "../../sys/compat/ibcs2/ibcs2_syscall.h" 86#include "../../sys/compat/ibcs2/ibcs2_syscall.h"
87#include "../../sys/compat/linux/linux_syscall.h" 87#include "../../sys/compat/linux/linux_syscall.h"
88#include "../../sys/compat/linux32/linux32_syscall.h" 88#include "../../sys/compat/linux32/linux32_syscall.h"
89#include "../../sys/compat/osf1/osf1_syscall.h" 89#include "../../sys/compat/osf1/osf1_syscall.h"
90#include "../../sys/compat/sunos32/sunos32_syscall.h" 90#include "../../sys/compat/sunos32/sunos32_syscall.h"
91#include "../../sys/compat/sunos/sunos_syscall.h" 91#include "../../sys/compat/sunos/sunos_syscall.h"
92#include "../../sys/compat/svr4/svr4_syscall.h" 
93#include "../../sys/compat/svr4_32/svr4_32_syscall.h" 
94#include "../../sys/compat/ultrix/ultrix_syscall.h" 92#include "../../sys/compat/ultrix/ultrix_syscall.h"
95#ifdef __m68k__ 93#ifdef __m68k__
96#include "../../sys/compat/aoutm68k/aoutm68k_syscall.h" 94#include "../../sys/compat/aoutm68k/aoutm68k_syscall.h"
97#endif 95#endif
98 96
99#define KTRACE 97#define KTRACE
100#include "../../sys/kern/syscalls.c" 98#include "../../sys/kern/syscalls.c"
101 99
102#include "../../sys/compat/netbsd32/netbsd32_syscalls.c" 100#include "../../sys/compat/netbsd32/netbsd32_syscalls.c"
103#include "../../sys/compat/freebsd/freebsd_syscalls.c" 101#include "../../sys/compat/freebsd/freebsd_syscalls.c"
104#include "../../sys/compat/ibcs2/ibcs2_syscalls.c" 102#include "../../sys/compat/ibcs2/ibcs2_syscalls.c"
105#include "../../sys/compat/linux/linux_syscalls.c" 103#include "../../sys/compat/linux/linux_syscalls.c"
106#include "../../sys/compat/linux32/linux32_syscalls.c" 104#include "../../sys/compat/linux32/linux32_syscalls.c"
107#include "../../sys/compat/osf1/osf1_syscalls.c" 105#include "../../sys/compat/osf1/osf1_syscalls.c"
108#include "../../sys/compat/sunos/sunos_syscalls.c" 106#include "../../sys/compat/sunos/sunos_syscalls.c"
109#include "../../sys/compat/sunos32/sunos32_syscalls.c" 107#include "../../sys/compat/sunos32/sunos32_syscalls.c"
110#include "../../sys/compat/svr4/svr4_syscalls.c" 
111#include "../../sys/compat/svr4_32/svr4_32_syscalls.c" 
112#include "../../sys/compat/ultrix/ultrix_syscalls.c" 108#include "../../sys/compat/ultrix/ultrix_syscalls.c"
113#ifdef __m68k__ 109#ifdef __m68k__
114#include "../../sys/compat/aoutm68k/aoutm68k_syscalls.c" 110#include "../../sys/compat/aoutm68k/aoutm68k_syscalls.c"
115#endif 111#endif
116 112
117#include "../../sys/compat/svr4/svr4_errno.c" 
118#include "../../sys/compat/ibcs2/ibcs2_errno.c" 113#include "../../sys/compat/ibcs2/ibcs2_errno.c"
119#include "../../sys/compat/osf1/osf1_errno.c" 114#include "../../sys/compat/osf1/osf1_errno.c"
120#include "../../sys/compat/linux/common/linux_errno.c" 115#include "../../sys/compat/linux/common/linux_errno.c"
121#undef KTRACE 116#undef KTRACE
122 117
123#define SIGRTMIN 33 /* XXX */ 118#define SIGRTMIN 33 /* XXX */
124#include "../../sys/compat/svr4/svr4_signo.c" 
125#include "../../sys/compat/ibcs2/ibcs2_signo.c" 119#include "../../sys/compat/ibcs2/ibcs2_signo.c"
126#include "../../sys/compat/osf1/osf1_signo.c" 120#include "../../sys/compat/osf1/osf1_signo.c"
127#include "../../sys/compat/linux/common/linux_signo.c" 121#include "../../sys/compat/linux/common/linux_signo.c"
128 122
129#define NELEM(a) (sizeof(a) / sizeof(a[0])) 123#define NELEM(a) (sizeof(a) / sizeof(a[0]))
130 124
131/* static */ 125/* static */
132const struct emulation emulations[] = { 126const struct emulation emulations[] = {
133 { "netbsd", syscallnames, SYS_MAXSYSCALL, 127 { "netbsd", syscallnames, SYS_MAXSYSCALL,
134 NULL, 0, 128 NULL, 0,
135 NULL, 0, 0 }, 129 NULL, 0, 0 },
136 130
137 { "netbsd32", netbsd32_syscallnames, SYS_MAXSYSCALL, 131 { "netbsd32", netbsd32_syscallnames, SYS_MAXSYSCALL,
138 NULL, 0, 132 NULL, 0,
139 NULL, 0, EMUL_FLAG_NETBSD32 }, 133 NULL, 0, EMUL_FLAG_NETBSD32 },
140 134
141 { "freebsd", freebsd_syscallnames, FREEBSD_SYS_MAXSYSCALL, 135 { "freebsd", freebsd_syscallnames, FREEBSD_SYS_MAXSYSCALL,
142 NULL, 0, 136 NULL, 0,
143 NULL, 0, 0 }, 137 NULL, 0, 0 },
144 138
145 { "ibcs2", ibcs2_syscallnames, IBCS2_SYS_MAXSYSCALL, 139 { "ibcs2", ibcs2_syscallnames, IBCS2_SYS_MAXSYSCALL,
146 native_to_ibcs2_errno, NELEM(native_to_ibcs2_errno), 140 native_to_ibcs2_errno, NELEM(native_to_ibcs2_errno),
147 ibcs2_to_native_signo, NSIG, 0 }, 141 ibcs2_to_native_signo, NSIG, 0 },
148 142
149 { "linux", linux_syscallnames, LINUX_SYS_MAXSYSCALL, 143 { "linux", linux_syscallnames, LINUX_SYS_MAXSYSCALL,
150 native_to_linux_errno, NELEM(native_to_linux_errno), 144 native_to_linux_errno, NELEM(native_to_linux_errno),
151 linux_to_native_signo, NSIG, 0 }, 145 linux_to_native_signo, NSIG, 0 },
152 146
153 { "linux32", linux32_syscallnames, LINUX32_SYS_MAXSYSCALL, 147 { "linux32", linux32_syscallnames, LINUX32_SYS_MAXSYSCALL,
154 native_to_linux_errno, NELEM(native_to_linux_errno), 148 native_to_linux_errno, NELEM(native_to_linux_errno),
155 linux_to_native_signo, NSIG, EMUL_FLAG_NETBSD32 }, 149 linux_to_native_signo, NSIG, EMUL_FLAG_NETBSD32 },
156 150
157 { "osf1", osf1_syscallnames, OSF1_SYS_MAXSYSCALL, 151 { "osf1", osf1_syscallnames, OSF1_SYS_MAXSYSCALL,
158 native_to_osf1_errno, NELEM(native_to_osf1_errno), 152 native_to_osf1_errno, NELEM(native_to_osf1_errno),
159 osf1_to_native_signo, NSIG, 0 }, 153 osf1_to_native_signo, NSIG, 0 },
160 154
161 { "sunos32", sunos32_syscallnames, SUNOS32_SYS_MAXSYSCALL, 155 { "sunos32", sunos32_syscallnames, SUNOS32_SYS_MAXSYSCALL,
162 NULL, 0, 156 NULL, 0,
163 NULL, 0, EMUL_FLAG_NETBSD32 }, 157 NULL, 0, EMUL_FLAG_NETBSD32 },
164 158
165 { "sunos", sunos_syscallnames, SUNOS_SYS_MAXSYSCALL, 159 { "sunos", sunos_syscallnames, SUNOS_SYS_MAXSYSCALL,
166 NULL, 0, 160 NULL, 0,
167 NULL, 0, 0 }, 161 NULL, 0, 0 },
168 162
169 { "svr4", svr4_syscallnames, SVR4_SYS_MAXSYSCALL, 
170 native_to_svr4_errno, NELEM(native_to_svr4_errno), 
171 svr4_to_native_signo, NSIG, 0 }, 
172 
173 { "svr4_32", svr4_syscallnames, SVR4_SYS_MAXSYSCALL, 
174 native_to_svr4_errno, NELEM(native_to_svr4_errno), 
175 svr4_to_native_signo, NSIG, EMUL_FLAG_NETBSD32 }, 
176 
177 { "ultrix", ultrix_syscallnames, ULTRIX_SYS_MAXSYSCALL, 163 { "ultrix", ultrix_syscallnames, ULTRIX_SYS_MAXSYSCALL,
178 NULL, 0, 164 NULL, 0,
179 NULL, 0, 0 }, 165 NULL, 0, 0 },
180 166
181#ifdef __m68k__ 167#ifdef __m68k__
182 { "aoutm68k", aoutm68k_syscallnames, AOUTM68K_SYS_MAXSYSCALL, 168 { "aoutm68k", aoutm68k_syscallnames, AOUTM68K_SYS_MAXSYSCALL,
183 NULL, 0, 169 NULL, 0,
184 NULL, 0, 0 }, 170 NULL, 0, 0 },
185#endif 171#endif
186 172
187 { NULL, NULL, 0, 173 { NULL, NULL, 0,
188 NULL, 0, 174 NULL, 0,
189 NULL, 0, 0 } 175 NULL, 0, 0 }
190}; 176};
191 177
192struct emulation_ctx { 178struct emulation_ctx {
193 pid_t pid; 179 pid_t pid;
194 const struct emulation *emulation; 180 const struct emulation *emulation;
195 LIST_ENTRY(emulation_ctx) ctx_link; 181 LIST_ENTRY(emulation_ctx) ctx_link;
196}; 182};
197 183
198const struct emulation *cur_emul; 184const struct emulation *cur_emul;
199const struct emulation *prev_emul; 185const struct emulation *prev_emul;
200 186
201static const struct emulation *default_emul = &emulations[0]; 187static const struct emulation *default_emul = &emulations[0];
202 188
203struct emulation_ctx *current_ctx; 189struct emulation_ctx *current_ctx;
204static LIST_HEAD(, emulation_ctx) emul_ctx = 190static LIST_HEAD(, emulation_ctx) emul_ctx =
205 LIST_HEAD_INITIALIZER(emul_ctx); 191 LIST_HEAD_INITIALIZER(emul_ctx);
206 192
207static struct emulation_ctx *ectx_find(pid_t); 193static struct emulation_ctx *ectx_find(pid_t);
208static void ectx_update(pid_t, const struct emulation *); 194static void ectx_update(pid_t, const struct emulation *);
209 195
210void 196void
211setemul(const char *name, pid_t pid, int update_ectx) 197setemul(const char *name, pid_t pid, int update_ectx)
212{ 198{
213 int i; 199 int i;
214 const struct emulation *match = NULL; 200 const struct emulation *match = NULL;
215 201
216 for (i = 0; emulations[i].name != NULL; i++) { 202 for (i = 0; emulations[i].name != NULL; i++) {
217 if (strcmp(emulations[i].name, name) == 0) { 203 if (strcmp(emulations[i].name, name) == 0) {
218 match = &emulations[i]; 204 match = &emulations[i];
219 break; 205 break;
220 } 206 }
221 } 207 }
222 208
223 if (!match) { 209 if (!match) {
224 warnx("Emulation `%s' unknown", name); 210 warnx("Emulation `%s' unknown", name);
225 return; 211 return;
226 } 212 }
227 213
228 if (update_ectx) 214 if (update_ectx)
229 ectx_update(pid, match); 215 ectx_update(pid, match);
230 else 216 else
231 default_emul = match; 217 default_emul = match;
232 218
233 if (cur_emul != NULL)  219 if (cur_emul != NULL)
234 prev_emul = cur_emul; 220 prev_emul = cur_emul;
235 else 221 else
236 prev_emul = match; 222 prev_emul = match;
237 223
238 cur_emul = match; 224 cur_emul = match;
239} 225}
240 226
241/* 227/*
242 * Emulation context list is very simple chained list, not even hashed. 228 * Emulation context list is very simple chained list, not even hashed.
243 * We expect the number of separate traced contexts/processes to be 229 * We expect the number of separate traced contexts/processes to be
244 * fairly low, so it's not worth it to optimize this. 230 * fairly low, so it's not worth it to optimize this.
245 * MMMmmmm not when I use it, it is only bounded PID_MAX! 231 * MMMmmmm not when I use it, it is only bounded PID_MAX!
246 * Requeue looked up item at start of list to cache result since the 232 * Requeue looked up item at start of list to cache result since the
247 * trace file tendes to have a burst of calls for a single process. 233 * trace file tendes to have a burst of calls for a single process.
248 */ 234 */
249 235
250/* 236/*
251 * Find an emulation context appropriate for the given pid. 237 * Find an emulation context appropriate for the given pid.
252 */ 238 */
253static struct emulation_ctx * 239static struct emulation_ctx *
254ectx_find(pid_t pid) 240ectx_find(pid_t pid)
255{ 241{
256 struct emulation_ctx *ctx; 242 struct emulation_ctx *ctx;
257 243
258 /* Find an existing entry */ 244 /* Find an existing entry */
259 LIST_FOREACH(ctx, &emul_ctx, ctx_link) { 245 LIST_FOREACH(ctx, &emul_ctx, ctx_link) {
260 if (ctx->pid == pid) 246 if (ctx->pid == pid)
261 break; 247 break;
262 } 248 }
263 249
264 if (ctx == NULL) { 250 if (ctx == NULL) {
265 /* create entry with default emulation */ 251 /* create entry with default emulation */
266 ctx = malloc(sizeof *ctx); 252 ctx = malloc(sizeof *ctx);
267 if (ctx == NULL) 253 if (ctx == NULL)
268 err(1, "malloc emul context"); 254 err(1, "malloc emul context");
269 ctx->pid = pid; 255 ctx->pid = pid;
270 ctx->emulation = default_emul; 256 ctx->emulation = default_emul;
271 257
272 /* chain into the list */ 258 /* chain into the list */
273 LIST_INSERT_HEAD(&emul_ctx, ctx, ctx_link); 259 LIST_INSERT_HEAD(&emul_ctx, ctx, ctx_link);
274 } else { 260 } else {
275 /* move entry to head to optimize lookup for syscall bursts */ 261 /* move entry to head to optimize lookup for syscall bursts */
276 LIST_REMOVE(ctx, ctx_link); 262 LIST_REMOVE(ctx, ctx_link);
277 LIST_INSERT_HEAD(&emul_ctx, ctx, ctx_link); 263 LIST_INSERT_HEAD(&emul_ctx, ctx, ctx_link);
278 } 264 }
279 265
280 return ctx; 266 return ctx;
281} 267}
282 268
283/* 269/*
284 * Update emulation context for given pid, or create new if no context 270 * Update emulation context for given pid, or create new if no context
285 * for this pid exists. 271 * for this pid exists.
286 */ 272 */
287static void 273static void
288ectx_update(pid_t pid, const struct emulation *emul) 274ectx_update(pid_t pid, const struct emulation *emul)
289{ 275{
290 struct emulation_ctx *ctx; 276 struct emulation_ctx *ctx;
291 277
292 ctx = ectx_find(pid); 278 ctx = ectx_find(pid);
293 ctx->emulation = emul; 279 ctx->emulation = emul;
294} 280}
295 281
296/* 282/*
297 * Ensure current emulation context is correct for given pid. 283 * Ensure current emulation context is correct for given pid.
298 */ 284 */
299void 285void
300ectx_sanify(pid_t pid) 286ectx_sanify(pid_t pid)
301{ 287{
302 struct emulation_ctx *ctx; 288 struct emulation_ctx *ctx;
303 289
304 ctx = ectx_find(pid); 290 ctx = ectx_find(pid);
305 cur_emul = ctx->emulation; 291 cur_emul = ctx->emulation;
306} 292}
307 293
308/* 294/*
309 * Delete emulation context for current pid. 295 * Delete emulation context for current pid.
310 * (eg when tracing exit()) 296 * (eg when tracing exit())
311 * Defer delete just in case we've cached a pointer... 297 * Defer delete just in case we've cached a pointer...
312 */ 298 */
313void 299void
314ectx_delete(void) 300ectx_delete(void)
315{ 301{
316 static struct emulation_ctx *ctx = NULL; 302 static struct emulation_ctx *ctx = NULL;
317 303
318 if (ctx != NULL) 304 if (ctx != NULL)
319 free(ctx); 305 free(ctx);
320 306
321 /* 307 /*
322 * The emulation for current syscall entry is always on HEAD, due 308 * The emulation for current syscall entry is always on HEAD, due
323 * to code in ectx_find(). 309 * to code in ectx_find().
324 */ 310 */
325 ctx = LIST_FIRST(&emul_ctx); 311 ctx = LIST_FIRST(&emul_ctx);
326 312
327 if (ctx) 313 if (ctx)
328 LIST_REMOVE(ctx, ctx_link); 314 LIST_REMOVE(ctx, ctx_link);
329} 315}