[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 40/43] bsd-user: Implement interlock for atomic operations
From: |
imp |
Subject: |
[PATCH v2 40/43] bsd-user: Implement interlock for atomic operations |
Date: |
Thu, 26 Aug 2021 15:11:58 -0600 |
From: Warner Losh <imp@FreeBSD.org>
Implement the internlock in fork_start() and fork_end() to properly cope
with atomic operations and to safely keep state for parent and child
processes.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/main.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index d60a0a7ee2..e2ed9e32ba 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -69,15 +69,38 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial
data size limit */
unsigned long target_maxssiz = TARGET_MAXSSIZ; /* max stack size */
unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */
+/* Helper routines for implementing atomic operations. */
void fork_start(void)
{
+ start_exclusive();
+ cpu_list_lock();
+ mmap_fork_start();
}
void fork_end(int child)
{
if (child) {
+ CPUState *cpu, *next_cpu;
+ /*
+ * Child processes created by fork() only have a single thread.
+ * Discard information about the parent threads.
+ */
+ CPU_FOREACH_SAFE(cpu, next_cpu) {
+ if (cpu != thread_cpu) {
+ QTAILQ_REMOVE_RCU(&cpus, cpu, node);
+ }
+ }
+ mmap_fork_end(child);
+ /* qemu_init_cpu_list() takes care of reinitializing the
+ * exclusive state, so we don't need to end_exclusive() here.
+ */
+ qemu_init_cpu_list();
gdbserver_fork(thread_cpu);
+ } else {
+ mmap_fork_end(child);
+ cpu_list_unlock();
+ end_exclusive();
}
}
--
2.32.0
- Re: [PATCH v2 30/43] bsd-user: Remove dead #ifdefs from elfload.c, (continued)
- [PATCH v2 36/43] bsd-user: add stubbed out core dump support, imp, 2021/08/26
- [PATCH v2 38/43] bsd-user: Refactor load_elf_sections and is_target_elf_binary, imp, 2021/08/26
- [PATCH v2 42/43] bsd-user: Add '-0 argv0' option to bsd-user/main.c, imp, 2021/08/26
- [PATCH v2 37/43] bsd-user: elfload.c style catch up patch, imp, 2021/08/26
- [PATCH v2 41/43] bsd-user: Implement cpu_copy() helper routine, imp, 2021/08/26
- [PATCH v2 35/43] bsd-user: Add target_os_user.h to capture the user/kernel structures, imp, 2021/08/26
- [PATCH v2 23/43] bsd-user: define max args in terms of pages, imp, 2021/08/26
- [PATCH v2 40/43] bsd-user: Implement interlock for atomic operations,
imp <=
- [PATCH v2 43/43] bsd-user: Update mapping to handle reserved and starting conditions, imp, 2021/08/26