@@ -38,8 +38,8 @@ pub fn deinit(ma: *MemoryAccessor) void {
38
38
39
39
fn read (ma : * MemoryAccessor , address : usize , buf : []u8 ) bool {
40
40
switch (native_os ) {
41
- .linux = > while ( true ) switch (ma .mem .handle ) {
42
- -2 = > break ,
41
+ .linux = > linux : switch (ma .mem .handle ) {
42
+ -2 = > break : linux ,
43
43
-1 = > {
44
44
const linux = std .os .linux ;
45
45
const pid = switch (@atomicLoad (posix .pid_t , & cached_pid , .monotonic )) {
@@ -59,7 +59,15 @@ fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
59
59
switch (linux .E .init (bytes_read )) {
60
60
.SUCCESS = > return bytes_read == buf .len ,
61
61
.FAULT = > return false ,
62
- .INVAL , .SRCH = > unreachable , // own pid is always valid
62
+ .INVAL = > unreachable , // EINVAL is returned when flags to process_vm_readv is non-zero
63
+ .SRCH = > {
64
+ // process with pid does not exist, but it should be our pid, so we'll try again.
65
+ const pid = linux .getpid ();
66
+ if (@atomicLoad (posix .pid_t , & cached_pid , .monotonic ) == pid ) {
67
+ @atomicStore (posix .pid_t , & cached_pid , , .monotonic );
68
+ continue :linux -1 ;
69
+ } else unreachable ;
70
+ },
63
71
.PERM = > {}, // Known to happen in containers.
64
72
.NOMEM = > {},
65
73
.NOSYS = > {}, // QEMU is known not to implement this syscall.
@@ -72,7 +80,7 @@ fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
72
80
unreachable ;
73
81
ma .mem = std .fs .openFileAbsolute (path , .{}) catch {
74
82
ma .mem .handle = -2 ;
75
- break ;
83
+ break : linux ;
76
84
};
77
85
},
78
86
else = > return (ma .mem .pread (buf , address ) catch return false ) == buf .len ,
0 commit comments