wasmer_wasix/syscalls/journal/
play_event.rs

1use std::ops::Range;
2
3use super::*;
4
5impl<'a> JournalSyscallPlayer<'a, '_> {
6    #[allow(clippy::result_large_err)]
7    pub(super) unsafe fn play_event(
8        &mut self,
9        next: JournalEntry<'a>,
10        differ_ethereal: Option<&mut Vec<JournalEntry<'a>>>,
11    ) -> Result<(), WasiRuntimeError> {
12        match next {
13            JournalEntry::InitModuleV1 { wasm_hash } => {
14                unsafe { self.action_init_module(wasm_hash, differ_ethereal) }?;
15            }
16            JournalEntry::ClearEtherealV1 => {
17                self.clear_ethereal(differ_ethereal);
18            }
19            JournalEntry::ProcessExitV1 { exit_code } => {
20                unsafe { self.action_process_exit(exit_code, differ_ethereal) }?;
21            }
22            JournalEntry::FileDescriptorWriteV1 {
23                fd,
24                offset,
25                data,
26                is_64bit,
27            } => {
28                if self.real_fd.contains(&fd) {
29                    unsafe { self.action_fd_write(fd, offset, data, is_64bit) }?;
30                } else if let Some(differ_ethereal) = differ_ethereal {
31                    tracing::trace!(%fd, %offset, "Differ(ether) journal - FdWrite");
32                    differ_ethereal.push(JournalEntry::FileDescriptorWriteV1 {
33                        fd,
34                        offset,
35                        data,
36                        is_64bit,
37                    });
38                } else {
39                    unsafe { self.action_fd_write(fd, offset, data, is_64bit) }?;
40                }
41            }
42            JournalEntry::FileDescriptorSeekV1 { fd, offset, whence } => {
43                if self.real_fd.contains(&fd) {
44                    unsafe { self.action_fd_seek(fd, offset, whence) }?;
45                } else if let Some(differ_ethereal) = differ_ethereal {
46                    tracing::trace!(%fd, %offset, ?whence, "Differ(ether) journal - FdSeek");
47                    differ_ethereal.push(JournalEntry::FileDescriptorSeekV1 { fd, offset, whence });
48                } else {
49                    unsafe { self.action_fd_seek(fd, offset, whence) }?;
50                }
51            }
52            JournalEntry::UpdateMemoryRegionV1 {
53                region,
54                compressed_data,
55            } => {
56                unsafe {
57                    self.action_update_compressed_memory(region, compressed_data, differ_ethereal)
58                }?;
59            }
60            JournalEntry::CloseThreadV1 { id, exit_code } => {
61                unsafe { self.action_close_thread(id, exit_code, differ_ethereal) }?;
62            }
63            JournalEntry::SetThreadV1 {
64                id,
65                call_stack,
66                memory_stack,
67                store_data,
68                is_64bit,
69                start,
70                layout,
71            } => {
72                unsafe {
73                    self.action_set_thread(
74                        id,
75                        call_stack,
76                        memory_stack,
77                        store_data,
78                        is_64bit,
79                        start,
80                        layout,
81                        differ_ethereal,
82                    )
83                }?;
84            }
85            JournalEntry::CloseFileDescriptorV1 { fd } => {
86                if self.real_fd.contains(&fd) {
87                    unsafe { self.action_fd_close(fd) }?;
88                } else if let Some(differ_ethereal) = differ_ethereal {
89                    tracing::trace!(%fd, "Differ(ether) journal - FdClose");
90                    differ_ethereal.push(JournalEntry::CloseFileDescriptorV1 { fd });
91                } else {
92                    unsafe { self.action_fd_close(fd) }?;
93                }
94            }
95            JournalEntry::OpenFileDescriptorV1 {
96                fd,
97                dirfd,
98                dirflags,
99                path,
100                o_flags,
101                fs_rights_base,
102                fs_rights_inheriting,
103                fs_flags,
104            } => {
105                self.real_fd.insert(fd);
106                unsafe {
107                    self.action_fd_open(
108                        fd,
109                        dirfd,
110                        dirflags,
111                        path,
112                        o_flags,
113                        fs_rights_base,
114                        fs_rights_inheriting,
115                        fs_flags,
116                        Fdflagsext::empty(),
117                    )
118                }?;
119            }
120            JournalEntry::OpenFileDescriptorV2 {
121                fd,
122                dirfd,
123                dirflags,
124                path,
125                o_flags,
126                fs_rights_base,
127                fs_rights_inheriting,
128                fs_flags,
129                fd_flags,
130            } => {
131                self.real_fd.insert(fd);
132                unsafe {
133                    self.action_fd_open(
134                        fd,
135                        dirfd,
136                        dirflags,
137                        path,
138                        o_flags,
139                        fs_rights_base,
140                        fs_rights_inheriting,
141                        fs_flags,
142                        fd_flags,
143                    )
144                }?;
145            }
146            JournalEntry::RemoveDirectoryV1 { fd, path } => {
147                tracing::trace!("Replay journal - RemoveDirectory {}", path);
148                JournalEffector::apply_path_remove_directory(&mut self.ctx, fd, &path)
149                    .map_err(anyhow_err_to_runtime_err)?;
150            }
151            JournalEntry::UnlinkFileV1 { fd, path } => {
152                tracing::trace!("Replay journal - UnlinkFile {}", path);
153                JournalEffector::apply_path_unlink(&mut self.ctx, fd, &path)
154                    .map_err(anyhow_err_to_runtime_err)?;
155            }
156            JournalEntry::PathRenameV1 {
157                old_fd,
158                old_path,
159                new_fd,
160                new_path,
161            } => {
162                tracing::trace!("Replay journal - PathRename {}->{}", old_path, new_path);
163                JournalEffector::apply_path_rename(
164                    &mut self.ctx,
165                    old_fd,
166                    &old_path,
167                    new_fd,
168                    &new_path,
169                )
170                .map_err(anyhow_err_to_runtime_err)?;
171            }
172            JournalEntry::SnapshotV1 { when, trigger } => {
173                unsafe { self.action_snapshot(when, trigger, differ_ethereal) }?;
174            }
175            JournalEntry::SetClockTimeV1 { clock_id, time } => {
176                tracing::trace!(?clock_id, %time, "Replay journal - ClockTimeSet");
177                JournalEffector::apply_clock_time_set(&mut self.ctx, clock_id, time)
178                    .map_err(anyhow_err_to_runtime_err)?;
179            }
180            JournalEntry::RenumberFileDescriptorV1 { old_fd, new_fd } => {
181                if self.real_fd.remove(&old_fd) {
182                    unsafe { self.action_fd_renumber(old_fd, new_fd) }?;
183                } else if let Some(differ_ethereal) = differ_ethereal {
184                    tracing::trace!(%old_fd, %new_fd, "Differ(ether) journal - FdRenumber");
185                    differ_ethereal.push(JournalEntry::RenumberFileDescriptorV1 { old_fd, new_fd });
186                } else {
187                    unsafe { self.action_fd_renumber(old_fd, new_fd) }?;
188                }
189            }
190            JournalEntry::DuplicateFileDescriptorV1 {
191                original_fd,
192                copied_fd,
193            } => {
194                if self.real_fd.contains(&original_fd) {
195                    unsafe { self.action_fd_dup(original_fd, copied_fd, false) }?;
196                } else if let Some(differ_ethereal) = differ_ethereal {
197                    tracing::trace!(%original_fd, %copied_fd, "Differ(ether) journal - FdDuplicate");
198                    differ_ethereal.push(JournalEntry::DuplicateFileDescriptorV1 {
199                        original_fd,
200                        copied_fd,
201                    });
202                } else {
203                    unsafe { self.action_fd_dup(original_fd, copied_fd, false) }?;
204                }
205            }
206            JournalEntry::DuplicateFileDescriptorV2 {
207                original_fd,
208                copied_fd,
209                cloexec,
210            } => {
211                if self.real_fd.contains(&original_fd) {
212                    unsafe { self.action_fd_dup(original_fd, copied_fd, cloexec) }?;
213                } else if let Some(differ_ethereal) = differ_ethereal {
214                    tracing::trace!(%original_fd, %copied_fd, %cloexec, "Differ(ether) journal - FdDuplicate");
215                    differ_ethereal.push(JournalEntry::DuplicateFileDescriptorV2 {
216                        original_fd,
217                        copied_fd,
218                        cloexec,
219                    });
220                } else {
221                    unsafe { self.action_fd_dup(original_fd, copied_fd, cloexec) }?;
222                }
223            }
224            JournalEntry::CreateDirectoryV1 { fd, path } => {
225                tracing::trace!(%fd, %path, "Replay journal - CreateDirectory");
226                JournalEffector::apply_path_create_directory(&mut self.ctx, fd, &path)
227                    .map_err(anyhow_err_to_runtime_err)?;
228            }
229            JournalEntry::PathSetTimesV1 {
230                fd,
231                flags,
232                path,
233                st_atim,
234                st_mtim,
235                fst_flags,
236            } => {
237                if self.real_fd.contains(&fd) {
238                    unsafe {
239                        self.action_path_set_times(fd, flags, path, st_atim, st_mtim, fst_flags)
240                    }?;
241                } else if let Some(differ_ethereal) = differ_ethereal {
242                    tracing::trace!(%fd, "Differ(ether) journal - PathSetTimes");
243                    differ_ethereal.push(JournalEntry::PathSetTimesV1 {
244                        fd,
245                        flags,
246                        path,
247                        st_atim,
248                        st_mtim,
249                        fst_flags,
250                    });
251                } else {
252                    unsafe {
253                        self.action_path_set_times(fd, flags, path, st_atim, st_mtim, fst_flags)
254                    }?;
255                }
256            }
257            JournalEntry::FileDescriptorSetTimesV1 {
258                fd,
259                st_atim,
260                st_mtim,
261                fst_flags,
262            } => {
263                if self.real_fd.contains(&fd) {
264                    unsafe { self.action_fd_set_times(fd, st_atim, st_mtim, fst_flags) }?;
265                } else if let Some(differ_ethereal) = differ_ethereal {
266                    tracing::trace!(
267                        %fd,
268                        %st_atim,
269                        %st_mtim,
270                        ?fst_flags,
271                        "Differ(ether) journal - FdSetTimes"
272                    );
273                    differ_ethereal.push(JournalEntry::FileDescriptorSetTimesV1 {
274                        fd,
275                        st_atim,
276                        st_mtim,
277                        fst_flags,
278                    });
279                } else {
280                    unsafe { self.action_fd_set_times(fd, st_atim, st_mtim, fst_flags) }?;
281                }
282            }
283            JournalEntry::FileDescriptorSetSizeV1 { fd, st_size } => {
284                if self.real_fd.contains(&fd) {
285                    unsafe { self.action_fd_set_size(fd, st_size) }?;
286                } else if let Some(differ_ethereal) = differ_ethereal {
287                    tracing::trace!(%fd, %st_size, "Differ(ether) journal - FdSetSize");
288                    differ_ethereal.push(JournalEntry::FileDescriptorSetSizeV1 { fd, st_size });
289                } else {
290                    unsafe { self.action_fd_set_size(fd, st_size) }?;
291                }
292            }
293            JournalEntry::FileDescriptorSetFdFlagsV1 { fd, flags } => {
294                if self.real_fd.contains(&fd) {
295                    unsafe { self.action_fd_set_fdflags(fd, flags) }?;
296                } else if let Some(differ_ethereal) = differ_ethereal {
297                    tracing::trace!(%fd, ?flags, "Differ(ether) journal - FdSetFdFlags");
298                    differ_ethereal.push(JournalEntry::FileDescriptorSetFdFlagsV1 { fd, flags });
299                } else {
300                    unsafe { self.action_fd_set_fdflags(fd, flags) }?;
301                }
302            }
303            JournalEntry::FileDescriptorSetFlagsV1 { fd, flags } => {
304                if self.real_fd.contains(&fd) {
305                    unsafe { self.action_fd_set_flags(fd, flags) }?;
306                } else if let Some(differ_ethereal) = differ_ethereal {
307                    tracing::trace!(%fd, ?flags, "Differ(ether) journal - FdSetFlags");
308                    differ_ethereal.push(JournalEntry::FileDescriptorSetFlagsV1 { fd, flags });
309                } else {
310                    unsafe { self.action_fd_set_flags(fd, flags) }?;
311                }
312            }
313            JournalEntry::FileDescriptorSetRightsV1 {
314                fd,
315                fs_rights_base,
316                fs_rights_inheriting,
317            } => {
318                if self.real_fd.contains(&fd) {
319                    unsafe { self.action_fd_set_rights(fd, fs_rights_base, fs_rights_inheriting) }?;
320                } else if let Some(differ_ethereal) = differ_ethereal {
321                    tracing::trace!(%fd, "Differ(ether) journal - FdSetRights");
322                    differ_ethereal.push(JournalEntry::FileDescriptorSetRightsV1 {
323                        fd,
324                        fs_rights_base,
325                        fs_rights_inheriting,
326                    });
327                } else {
328                    unsafe { self.action_fd_set_rights(fd, fs_rights_base, fs_rights_inheriting) }?;
329                }
330            }
331            JournalEntry::FileDescriptorAdviseV1 {
332                fd,
333                offset,
334                len,
335                advice,
336            } => {
337                if self.real_fd.contains(&fd) {
338                    unsafe { self.action_fd_advise(fd, offset, len, advice) }?;
339                } else if let Some(differ_ethereal) = differ_ethereal {
340                    tracing::trace!(%fd, %offset, %len, ?advice, "Differ(ether) journal - FdAdvise");
341                    differ_ethereal.push(JournalEntry::FileDescriptorAdviseV1 {
342                        fd,
343                        offset,
344                        len,
345                        advice,
346                    });
347                } else {
348                    unsafe { self.action_fd_advise(fd, offset, len, advice) }?;
349                }
350            }
351            JournalEntry::FileDescriptorAllocateV1 { fd, offset, len } => {
352                if self.real_fd.contains(&fd) {
353                    unsafe { self.action_fd_allocate(fd, offset, len) }?;
354                } else if let Some(differ_ethereal) = differ_ethereal {
355                    tracing::trace!(%fd, %offset, %len, "Differ(ether) journal - FdAllocate");
356                    differ_ethereal.push(JournalEntry::FileDescriptorAllocateV1 {
357                        fd,
358                        offset,
359                        len,
360                    });
361                } else {
362                    unsafe { self.action_fd_allocate(fd, offset, len) }?;
363                }
364            }
365            JournalEntry::CreateHardLinkV1 {
366                old_fd,
367                old_path,
368                old_flags,
369                new_fd,
370                new_path,
371            } => {
372                tracing::trace!("Replay journal - PathLink {}->{}", old_path, new_path);
373                JournalEffector::apply_path_link(
374                    &mut self.ctx,
375                    old_fd,
376                    old_flags,
377                    &old_path,
378                    new_fd,
379                    &new_path,
380                )
381                .map_err(anyhow_err_to_runtime_err)?;
382            }
383            JournalEntry::CreateSymbolicLinkV1 {
384                old_path,
385                fd,
386                new_path,
387            } => {
388                tracing::trace!("Replay journal - PathSymlink {}->{}", old_path, new_path);
389                JournalEffector::apply_path_symlink(&mut self.ctx, &old_path, fd, &new_path)
390                    .map_err(anyhow_err_to_runtime_err)?;
391            }
392            JournalEntry::ChangeDirectoryV1 { path } => {
393                tracing::trace!("Replay journal - ChangeDirection {}", path);
394                JournalEffector::apply_chdir(&mut self.ctx, &path)
395                    .map_err(anyhow_err_to_runtime_err)?;
396            }
397            JournalEntry::CreatePipeV1 { read_fd, write_fd } => {
398                if let Some(differ_ethereal) = differ_ethereal {
399                    tracing::trace!(%read_fd, %write_fd,  "Differ(ether) journal - CreatePipe");
400                    differ_ethereal.push(JournalEntry::CreatePipeV1 { read_fd, write_fd });
401                } else {
402                    tracing::trace!(%read_fd, %write_fd,  "Replay journal - CreatePipe");
403                    JournalEffector::apply_fd_pipe(&mut self.ctx, read_fd, write_fd)
404                        .map_err(anyhow_err_to_runtime_err)?;
405                }
406            }
407            JournalEntry::EpollCreateV1 { fd } => {
408                if let Some(differ_ethereal) = differ_ethereal {
409                    tracing::trace!(%fd, "Differ(ether) journal - EpollCreate");
410                    differ_ethereal.push(JournalEntry::EpollCreateV1 { fd });
411                } else {
412                    tracing::trace!(%fd, "Replay journal - EpollCreate");
413                    JournalEffector::apply_epoll_create(&mut self.ctx, fd)
414                        .map_err(anyhow_err_to_runtime_err)?;
415                }
416            }
417            JournalEntry::EpollCtlV1 {
418                epfd,
419                op,
420                fd,
421                event,
422            } => {
423                if let Some(differ_ethereal) = differ_ethereal {
424                    tracing::trace!(%epfd, %fd, ?op, "Differ(ether) journal - EpollCtl");
425                    differ_ethereal.push(JournalEntry::EpollCtlV1 {
426                        epfd,
427                        op,
428                        fd,
429                        event,
430                    });
431                } else {
432                    tracing::trace!(%epfd, %fd, ?op, "Replay journal - EpollCtl");
433                    JournalEffector::apply_epoll_ctl(&mut self.ctx, epfd, op, fd, event)
434                        .map_err(anyhow_err_to_runtime_err)?;
435                }
436            }
437            JournalEntry::TtySetV1 { tty, line_feeds } => {
438                if let Some(differ_ethereal) = differ_ethereal {
439                    tracing::trace!("Differ(ether) journal - TtySet");
440                    differ_ethereal.push(JournalEntry::TtySetV1 { tty, line_feeds });
441                } else {
442                    unsafe { self.action_tty_set(tty, line_feeds) }?;
443                }
444            }
445            JournalEntry::PortAddAddrV1 { cidr } => {
446                tracing::trace!(?cidr, "Replay journal - PortAddAddr");
447                JournalEffector::apply_port_addr_add(&mut self.ctx, cidr)
448                    .map_err(anyhow_err_to_runtime_err)?
449            }
450            JournalEntry::PortDelAddrV1 { addr } => {
451                tracing::trace!(?addr, "Replay journal - PortDelAddr");
452                JournalEffector::apply_port_addr_remove(&mut self.ctx, addr)
453                    .map_err(anyhow_err_to_runtime_err)?
454            }
455            JournalEntry::PortAddrClearV1 => {
456                tracing::trace!("Replay journal - PortAddrClear");
457                JournalEffector::apply_port_addr_clear(&mut self.ctx)
458                    .map_err(anyhow_err_to_runtime_err)?
459            }
460            JournalEntry::PortBridgeV1 {
461                network,
462                token,
463                security,
464            } => {
465                tracing::trace!("Replay journal - PortBridge");
466                JournalEffector::apply_port_bridge(&mut self.ctx, &network, &token, security)
467                    .map_err(anyhow_err_to_runtime_err)?
468            }
469            JournalEntry::PortUnbridgeV1 => {
470                tracing::trace!("Replay journal - PortUnBridge");
471                JournalEffector::apply_port_unbridge(&mut self.ctx)
472                    .map_err(anyhow_err_to_runtime_err)?
473            }
474            JournalEntry::PortDhcpAcquireV1 => {
475                tracing::trace!("Replay journal - PortDhcpAcquire");
476                JournalEffector::apply_port_dhcp_acquire(&mut self.ctx)
477                    .map_err(anyhow_err_to_runtime_err)?
478            }
479            JournalEntry::PortGatewaySetV1 { ip } => {
480                tracing::trace!(?ip, "Replay journal - PortGatewaySet");
481                JournalEffector::apply_port_gateway_set(&mut self.ctx, ip)
482                    .map_err(anyhow_err_to_runtime_err)?
483            }
484            JournalEntry::PortRouteAddV1 {
485                cidr,
486                via_router,
487                preferred_until,
488                expires_at,
489            } => {
490                tracing::trace!(?cidr, "Replay journal - PortRouteAdd");
491                JournalEffector::apply_port_route_add(
492                    &mut self.ctx,
493                    cidr,
494                    via_router,
495                    preferred_until,
496                    expires_at,
497                )
498                .map_err(anyhow_err_to_runtime_err)?
499            }
500            JournalEntry::PortRouteClearV1 => {
501                tracing::trace!("Replay journal - PortRouteClear");
502                JournalEffector::apply_port_route_clear(&mut self.ctx)
503                    .map_err(anyhow_err_to_runtime_err)?
504            }
505            JournalEntry::PortRouteDelV1 { ip } => {
506                tracing::trace!(?ip, "Replay journal - PortRouteDel");
507                JournalEffector::apply_port_route_remove(&mut self.ctx, ip)
508                    .map_err(anyhow_err_to_runtime_err)?
509            }
510            JournalEntry::SocketOpenV1 { af, ty, pt, fd } => {
511                if let Some(differ_ethereal) = differ_ethereal {
512                    tracing::trace!(?af, ?ty, ?pt, %fd, "Differ(ether) journal - SocketOpen");
513                    differ_ethereal.push(JournalEntry::SocketOpenV1 { af, ty, pt, fd });
514                } else {
515                    tracing::trace!(?af, ?ty, ?pt, %fd, "Replay journal - SocketOpen");
516                    JournalEffector::apply_sock_open(&mut self.ctx, af, ty, pt, fd)
517                        .map_err(anyhow_err_to_runtime_err)?
518                }
519            }
520            JournalEntry::SocketPairV1 { fd1, fd2 } => {
521                if let Some(differ_ethereal) = differ_ethereal {
522                    tracing::trace!(%fd1, %fd2, "Differ(ether) journal - SocketPair");
523                    differ_ethereal.push(JournalEntry::SocketPairV1 { fd1, fd2 });
524                } else {
525                    tracing::trace!(%fd1, %fd2, "Replay journal - SocketOpen");
526                    JournalEffector::apply_sock_pair(&mut self.ctx, fd1, fd2)
527                        .map_err(anyhow_err_to_runtime_err)?
528                }
529            }
530            JournalEntry::SocketListenV1 { fd, backlog } => {
531                if let Some(differ_ethereal) = differ_ethereal {
532                    tracing::trace!(%fd, "Differ(ether) journal - SocketListen");
533                    differ_ethereal.push(JournalEntry::SocketListenV1 { fd, backlog });
534                } else {
535                    tracing::trace!(%fd, "Replay journal - SocketListen");
536                    JournalEffector::apply_sock_listen(&mut self.ctx, fd, backlog as usize)
537                        .map_err(anyhow_err_to_runtime_err)?
538                }
539            }
540            JournalEntry::SocketBindV1 { fd, addr } => {
541                if let Some(differ_ethereal) = differ_ethereal {
542                    tracing::trace!(%fd, ?addr, "Differ(ether) journal - SocketBind");
543                    differ_ethereal.push(JournalEntry::SocketBindV1 { fd, addr });
544                } else {
545                    tracing::trace!(%fd, ?addr, "Replay journal - SocketBind");
546                    JournalEffector::apply_sock_bind(&mut self.ctx, fd, addr)
547                        .map_err(anyhow_err_to_runtime_err)?
548                }
549            }
550            JournalEntry::SocketConnectedV1 {
551                fd,
552                local_addr,
553                peer_addr,
554            } => {
555                if let Some(differ_ethereal) = differ_ethereal {
556                    tracing::trace!(%fd, ?peer_addr, "Differ(ether) journal - SockConnect");
557                    differ_ethereal.push(JournalEntry::SocketConnectedV1 {
558                        fd,
559                        local_addr,
560                        peer_addr,
561                    });
562                } else {
563                    let connected_sockets_are_dead = self.connected_sockets_are_dead;
564                    tracing::trace!(%fd, ?peer_addr, "Replay journal - SockConnect");
565                    JournalEffector::apply_sock_connect(
566                        &mut self.ctx,
567                        fd,
568                        local_addr,
569                        peer_addr,
570                        connected_sockets_are_dead,
571                    )
572                    .map_err(anyhow_err_to_runtime_err)?
573                }
574            }
575            JournalEntry::SocketAcceptedV1 {
576                listen_fd,
577                fd,
578                local_addr: addr,
579                peer_addr,
580                fd_flags,
581                non_blocking: nonblocking,
582            } => {
583                if let Some(differ_ethereal) = differ_ethereal {
584                    tracing::trace!(%listen_fd, %fd, ?peer_addr, "Differ(ether) journal - SocketAccept");
585                    differ_ethereal.push(JournalEntry::SocketAcceptedV1 {
586                        listen_fd,
587                        fd,
588                        local_addr: addr,
589                        peer_addr,
590                        fd_flags,
591                        non_blocking: nonblocking,
592                    });
593                } else {
594                    tracing::trace!(%listen_fd, %fd, ?peer_addr, "Replay journal - SocketAccept");
595                    JournalEffector::apply_sock_accepted(
596                        &mut self.ctx,
597                        listen_fd,
598                        fd,
599                        addr,
600                        peer_addr,
601                        fd_flags,
602                        nonblocking,
603                    )
604                    .map_err(anyhow_err_to_runtime_err)?
605                }
606            }
607            JournalEntry::SocketJoinIpv4MulticastV1 {
608                fd,
609                multiaddr,
610                iface,
611            } => {
612                if let Some(differ_ethereal) = differ_ethereal {
613                    tracing::trace!(%fd, ?multiaddr, "Differ(ether) journal - JoinIpv4Multicast");
614                    differ_ethereal.push(JournalEntry::SocketJoinIpv4MulticastV1 {
615                        fd,
616                        multiaddr,
617                        iface,
618                    });
619                } else {
620                    tracing::trace!(%fd, ?multiaddr, "Replay journal - JoinIpv4Multicast");
621                    JournalEffector::apply_sock_join_ipv4_multicast(
622                        &mut self.ctx,
623                        fd,
624                        multiaddr,
625                        iface,
626                    )
627                    .map_err(anyhow_err_to_runtime_err)?
628                }
629            }
630            JournalEntry::SocketJoinIpv6MulticastV1 {
631                fd,
632                multi_addr: multiaddr,
633                iface,
634            } => {
635                if let Some(differ_ethereal) = differ_ethereal {
636                    tracing::trace!(%fd, ?multiaddr, "Differ(ether) journal - JoinIpv6Multicast");
637                    differ_ethereal.push(JournalEntry::SocketJoinIpv6MulticastV1 {
638                        fd,
639                        multi_addr: multiaddr,
640                        iface,
641                    });
642                } else {
643                    tracing::trace!(%fd, ?multiaddr, "Replay journal - JoinIpv6Multicast");
644                    JournalEffector::apply_sock_join_ipv6_multicast(
645                        &mut self.ctx,
646                        fd,
647                        multiaddr,
648                        iface,
649                    )
650                    .map_err(anyhow_err_to_runtime_err)?
651                }
652            }
653            JournalEntry::SocketLeaveIpv4MulticastV1 {
654                fd,
655                multi_addr: multiaddr,
656                iface,
657            } => {
658                if let Some(differ_ethereal) = differ_ethereal {
659                    tracing::trace!(%fd, ?multiaddr, "Differ(ether) journal - LeaveIpv4Multicast");
660                    differ_ethereal.push(JournalEntry::SocketLeaveIpv4MulticastV1 {
661                        fd,
662                        multi_addr: multiaddr,
663                        iface,
664                    });
665                } else {
666                    tracing::trace!(%fd, ?multiaddr, "Replay journal - LeaveIpv4Multicast");
667                    JournalEffector::apply_sock_leave_ipv4_multicast(
668                        &mut self.ctx,
669                        fd,
670                        multiaddr,
671                        iface,
672                    )
673                    .map_err(anyhow_err_to_runtime_err)?
674                }
675            }
676            JournalEntry::SocketLeaveIpv6MulticastV1 {
677                fd,
678                multi_addr: multiaddr,
679                iface,
680            } => {
681                if let Some(differ_ethereal) = differ_ethereal {
682                    tracing::trace!(%fd, ?multiaddr, "Differ(ether) journal - LeaveIpv6Multicast");
683                    differ_ethereal.push(JournalEntry::SocketLeaveIpv6MulticastV1 {
684                        fd,
685                        multi_addr: multiaddr,
686                        iface,
687                    });
688                } else {
689                    tracing::trace!(%fd, ?multiaddr, "Replay journal - LeaveIpv6Multicast");
690                    JournalEffector::apply_sock_leave_ipv6_multicast(
691                        &mut self.ctx,
692                        fd,
693                        multiaddr,
694                        iface,
695                    )
696                    .map_err(anyhow_err_to_runtime_err)?
697                }
698            }
699            JournalEntry::SocketSendFileV1 {
700                socket_fd,
701                file_fd,
702                offset,
703                count,
704            } => {
705                if self.connected_sockets_are_dead {
706                    return Ok(());
707                }
708                if let Some(differ_ethereal) = differ_ethereal {
709                    tracing::trace!(%socket_fd, %file_fd, %offset, %count, "Differ(ether) journal - SockSendFile");
710                    differ_ethereal.push(JournalEntry::SocketSendFileV1 {
711                        socket_fd,
712                        file_fd,
713                        offset,
714                        count,
715                    });
716                } else {
717                    tracing::trace!(%socket_fd, %file_fd, %offset, %count, "Replay journal - SockSendFile");
718                    JournalEffector::apply_sock_send_file(
719                        &mut self.ctx,
720                        socket_fd,
721                        file_fd,
722                        offset,
723                        count,
724                    )
725                    .map_err(anyhow_err_to_runtime_err)?
726                }
727            }
728            JournalEntry::SocketSendToV1 {
729                fd,
730                data,
731                flags,
732                addr,
733                is_64bit,
734            } => {
735                if self.connected_sockets_are_dead {
736                    return Ok(());
737                }
738                if let Some(differ_ethereal) = differ_ethereal {
739                    tracing::trace!(%fd, "Differ(ether) journal - SocketSendTo data={} bytes", data.len());
740                    differ_ethereal.push(JournalEntry::SocketSendToV1 {
741                        fd,
742                        data,
743                        flags,
744                        addr,
745                        is_64bit,
746                    });
747                } else {
748                    tracing::trace!(%fd, "Replay journal - SocketSendTo data={} bytes", data.len());
749                    if is_64bit {
750                        JournalEffector::apply_sock_send_to::<Memory64>(
751                            &mut self.ctx,
752                            fd,
753                            data,
754                            flags,
755                            addr,
756                        )
757                    } else {
758                        JournalEffector::apply_sock_send_to::<Memory32>(
759                            &mut self.ctx,
760                            fd,
761                            data,
762                            flags,
763                            addr,
764                        )
765                    }
766                    .map_err(anyhow_err_to_runtime_err)?
767                }
768            }
769            JournalEntry::SocketSendV1 {
770                fd,
771                data,
772                flags,
773                is_64bit,
774            } => {
775                if self.connected_sockets_are_dead {
776                    return Ok(());
777                }
778                if let Some(differ_ethereal) = differ_ethereal {
779                    tracing::trace!(%fd, "Differ(ether) journal - SocketSend data={} bytes", data.len());
780                    differ_ethereal.push(JournalEntry::SocketSendV1 {
781                        fd,
782                        data,
783                        flags,
784                        is_64bit,
785                    });
786                } else {
787                    tracing::trace!(%fd, "Replay journal - SocketSend data={} bytes", data.len());
788                    if is_64bit {
789                        JournalEffector::apply_sock_send::<Memory64>(&self.ctx, fd, data, flags)
790                    } else {
791                        JournalEffector::apply_sock_send::<Memory32>(&self.ctx, fd, data, flags)
792                    }
793                    .map_err(anyhow_err_to_runtime_err)?
794                }
795            }
796            JournalEntry::SocketSetOptFlagV1 { fd, opt, flag } => {
797                if let Some(differ_ethereal) = differ_ethereal {
798                    tracing::trace!(%fd, ?opt, %flag, "Differ(ether) journal - SocketSetOptFlag");
799                    differ_ethereal.push(JournalEntry::SocketSetOptFlagV1 { fd, opt, flag });
800                } else {
801                    tracing::trace!(%fd, ?opt, %flag, "Replay journal - SocketSetOptFlag");
802                    JournalEffector::apply_sock_set_opt_flag(&mut self.ctx, fd, opt, flag)
803                        .map_err(anyhow_err_to_runtime_err)?
804                }
805            }
806            JournalEntry::SocketSetOptSizeV1 { fd, opt, size } => {
807                if let Some(differ_ethereal) = differ_ethereal {
808                    tracing::trace!(%fd, ?opt, %size, "Differ(ether) journal - SocketSetOptSize");
809                    differ_ethereal.push(JournalEntry::SocketSetOptSizeV1 { fd, opt, size });
810                } else {
811                    tracing::trace!(%fd, ?opt, %size, "Replay journal - SocketSetOptSize");
812                    JournalEffector::apply_sock_set_opt_size(&mut self.ctx, fd, opt, size)
813                        .map_err(anyhow_err_to_runtime_err)?
814                }
815            }
816            JournalEntry::SocketSetOptTimeV1 { fd, ty, time } => {
817                if let Some(differ_ethereal) = differ_ethereal {
818                    tracing::trace!(%fd, ?ty, ?time, "Differ(ether) journal - SocketSetOptTime");
819                    differ_ethereal.push(JournalEntry::SocketSetOptTimeV1 { fd, ty, time });
820                } else {
821                    tracing::trace!(%fd, ?ty, ?time, "Replay journal - SocketSetOptTime");
822                    JournalEffector::apply_sock_set_opt_time(&mut self.ctx, fd, ty.into(), time)
823                        .map_err(anyhow_err_to_runtime_err)?
824                }
825            }
826            JournalEntry::SocketShutdownV1 { fd, how } => {
827                if let Some(differ_ethereal) = differ_ethereal {
828                    tracing::trace!(%fd, ?how, "Differ(ether) journal - SocketShutdown");
829                    differ_ethereal.push(JournalEntry::SocketShutdownV1 { fd, how });
830                } else {
831                    tracing::trace!(%fd, ?how, "Replay journal - SocketShutdown");
832                    JournalEffector::apply_sock_shutdown(&mut self.ctx, fd, how.into())
833                        .map_err(anyhow_err_to_runtime_err)?
834                }
835            }
836            JournalEntry::CreateEventV1 {
837                initial_val,
838                flags,
839                fd,
840            } => {
841                if let Some(differ_ethereal) = differ_ethereal {
842                    tracing::trace!(%fd, %flags, "Differ(ether) journal - CreateEvent");
843                    differ_ethereal.push(JournalEntry::CreateEventV1 {
844                        initial_val,
845                        flags,
846                        fd,
847                    });
848                } else {
849                    tracing::trace!(%fd, %flags, "Replay journal - CreateEvent");
850                    JournalEffector::apply_fd_event(&mut self.ctx, initial_val, flags, fd)
851                        .map_err(anyhow_err_to_runtime_err)?
852                }
853            }
854        }
855        Ok(())
856    }
857}