Lind-Project / lind-wasm

https://lind-project.github.io/lind-wasm-docs/
Apache License 2.0
1 stars 1 forks source link

Fix Stat Syscall #19

Closed qianxichen233 closed 6 days ago

qianxichen233 commented 2 months ago

The stat struct in glibc does not match rawposix. This causes the value assigned to stat struct in rawposix failed to update in glibc. Now all the testsuite that is using stat-related syscalls are running and will not yield any error, but the information in stat struct is incorrectly updated. I've talked with Alice about this, and in nacl, there seems to be some kind of transformation happened in nacl runtime on stat struct to make it work. And after discussion with Nick, we decided to make the stat struct in rawposix match glibc, so no extra steps should be involved in wasmtime.

rennergade commented 2 months ago

We talked about this briefly at some point with @JustinCappos and I'm tagging him to clarify. The struct thats actually passed to the native kernel has a defined structure, and we want to match that. I believe the best way is to change the libc struct to match?

JustinCappos commented 2 months ago

The stat struct in glibc does not match rawposix.

Why is this the case? Isn't glibc what is used by Rust's libc which rawposix calls?

qianxichen233 commented 2 months ago

rawposix has its own statData definition (https://github.com/Lind-Project/RawPOSIX/blob/main/src/interface/types.rs#L55) So the stat_syscall in rawposix basically defines a libc_statbuf and pass to libc::stat, then assigns the corresponding field in libc_statbuf to rawposix statData

Yaxuan-w commented 2 months ago

When implementing RawPOSIX, there were conflicts between NaCl stat struct and libc stat struct. I think the issue is cause by pre-allocated memory region in 32-bit NaCl doesn't fit 64-bit kernel results. To integrate NaCl, I chose to manually copy out rust libc stat result to NaCl's structure at that time

rennergade commented 2 months ago

When implementing RawPOSIX, there were conflicts between NaCl stat struct and libc stat struct. I think the issue is cause by pre-allocated memory region in 32-bit NaCl doesn't fit 64-bit kernel results. To integrate NaCl, I chose to manually copy out rust libc stat result to NaCl's structure at that time

Right, that makes sense. There is most likely problems with the struct layout when translating from 32 to 64 bit, hence the weird nacl layout.

rennergade commented 1 week ago

@robinyuan1002 this issue got fixed in the last merge, correct?

qianxichen233 commented 1 week ago

@rennergade there is still a minor issue with stat stuff when compile bash, so I guess let's leave this issue until this has been figured out

robinyuan1002 commented 1 week ago

@rennergade Yes, the problem of 64bit and 32bit is solved for stat.