-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring sockaddr
Handling
#42
Comments
I’d like to remind that after modifying the structure, we also need to update the relevant type conversion logic accordingly |
Talking with @robinyuan1002 a bit about actual implementation here. Now we proposed two solutions: 1. Directly translate using
|
Would this be true because you need to do path manipulation on these? What part requires modification? |
Oh I just realized that the effort of implementing those options is roughly same now. Previously since RawPOSIX and 3i are in same lib, my thought was to use extra mapping table for cageid-sockaddr in order to allow grate serves as external lib and avoid cyclic import. But I have separated cage-vmmap structure / RawPOSIX / 3i to 3 different libs now, the implementation complexity should be roughly same..? @robinyuan1002 has a drafted data structure of option 2 by using third-party lib( |
You can safely ignore the fact that grates exist when thinking about RawPOSIX. Even 3i ignores these details except for the fact that it implements the calls to register system call handlers.
Yes, unfortunately, I think we don't want to go this route. I think the first path makes much more sense. If you're doing anything special to handle this (except removing code and calling through via fdtables), I think you're doing it wrong. |
Description:
This issue tracks the refactoring of sockaddr handling and addresses the problems encountered with
accept_syscall
.Background:
Currently,
sockaddr
is initialized using the default UnixGenSockaddr
borrowed from RustPOSIX, which has the largest memory space. This may cause issues withgetpeername
, as IPv4/IPv6 shouldn't have a path field.It's been observed that byte-level operations should be preferred over struct-type checks.
In Linux, there are various
sockaddr
structures, such assockaddr_in
for IPv4 andsockaddr_in6
for IPv6. However, tracing through the PostgreSQL source code shows that PostgreSQL uses sockaddr_storage, which is cast tosockaddr
when necessary. The key difference betweensockaddr
andsockaddr_storage
is size, withsockaddr_storage
being large enough to accommodate allsockaddr
types.PostgreSQL's
accept
syscall passes asockaddr->family=0
withsock_len=128
, making it impossible to determine the family based on size alone.Problem:
When using
accept
,recvfrom
,getsockname
, orgetpeername
, issues arise because the wrongsockaddr
family is being inferred. The system receives aNULL
sockaddr,
and thecopy_out
function from RustPOSIX doesn't perform any operations.Current Patch
I made a temporary modification to
accept_syscall
to make RawPOSIX work for now:GenSockaddr
struct based on thesockaddr
family received at the dispatcher stage.copy_out
function, the number of bytes to copy will be determined by comparinginitaddrlen
with the actual length of the structure (taking the minimum value), ensuring that no more than the reserved space is copied.Proposed Further Solution:
To resolve this, I suggest:
GenSockAddr
data structure. Directly allocate a buffer of size 128 bytes for syscalls likeaccept
,recvfrom
,getsockname
, andgetpeername
.NULL
values being sent to syscalls.The text was updated successfully, but these errors were encountered: