]> git.proxmox.com Git - mirror_qemu.git/blob - replay/replay-random.c
bsd-user: Implement shm_open(2)
[mirror_qemu.git] / replay / replay-random.c
1 /*
2 * replay-random.c
3 *
4 * Copyright (c) 2010-2020 Institute for System Programming
5 * of the Russian Academy of Sciences.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 *
10 */
11
12 #include "qemu/osdep.h"
13 #include "qemu/error-report.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16
17 void replay_save_random(int ret, void *buf, size_t len)
18 {
19 g_assert(replay_mutex_locked());
20
21 replay_save_instructions();
22 replay_put_event(EVENT_RANDOM);
23 replay_put_dword(ret);
24 replay_put_array(buf, len);
25 }
26
27 int replay_read_random(void *buf, size_t len)
28 {
29 int ret = 0;
30 g_assert(replay_mutex_locked());
31
32 replay_account_executed_instructions();
33 if (replay_next_event_is(EVENT_RANDOM)) {
34 size_t buf_size = 0;
35 ret = replay_get_dword();
36 replay_get_array(buf, &buf_size);
37 replay_finish_event();
38 g_assert(buf_size == len);
39 } else {
40 error_report("Missing random event in the replay log");
41 exit(1);
42 }
43 return ret;
44 }