feat(guest): replace musl with picolibc#831
feat(guest): replace musl with picolibc#831andreiltd wants to merge 2 commits intohyperlight-dev:mainfrom
Conversation
617d834 to
3f8ffcf
Compare
eaf1d54 to
b18a374
Compare
| ) | ||
| .unwrap_or_default(); | ||
|
|
||
| let n = bytes.len(); |
There was a problem hiding this comment.
Do we want to assert n <= count?
A wrongly implemented HostRead could cause a buffer overflow
| } | ||
|
|
||
| let slice = unsafe { core::slice::from_raw_parts(buf as *const u8, count) }; | ||
| let s = core::str::from_utf8(slice).unwrap_or("<invalid utf8>"); |
There was a problem hiding this comment.
question: what do you think of using String::from_utf8_lossy instead? we are doing s.to_string() anyway.
There was a problem hiding this comment.
Sure! As long as from_utf8_lossy doesn't allocate if string is valid utf-8 which I believe is the case?
There was a problem hiding this comment.
It returns a Cow, so, that's correct, but you will need to allocate a string to send it to the host function anyway... so... ¯\_(ツ)_/¯
| [features] | ||
| default = ["libc", "printf"] | ||
| libc = [] # compile musl libc | ||
| printf = [ "libc" ] # compile printf |
There was a problem hiding this comment.
opinion: I would just put everything under the same libc feature
There was a problem hiding this comment.
Sure, I guess any code from libc if not referenced will be DCE anyway 🤷
| pub extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize { | ||
| // Only stdout (fd=1) and stderr (fd=2) | ||
| if fd != 1 && fd != 2 { | ||
| return count as isize; |
There was a problem hiding this comment.
question: shuoldn't this return -1, or some other indication of error? and set errno?
There was a problem hiding this comment.
Right, I think that in order to support this properly we would need to generate the bindings to libc headers and use that to reference errno, EBADF etc. But then, it might be better to just have picolibc-sys crate. Anyway I agree we should report an error here somehow.
| pub extern "C" fn read(fd: c_int, buf: *mut c_void, count: usize) -> isize { | ||
| // Only stdin (fd=0) and only if HostRead is defined | ||
| if fd != 0 || !CAPS.host_read() { | ||
| return 0; |
There was a problem hiding this comment.
question: should the case of fd != 0 return -1 and set errno instead?
|
will help with #282 |
499c59d to
2ae0a3a
Compare
2ae0a3a to
d3826af
Compare
d2043ac to
2bd1ff4
Compare
9f5c6c1 to
a59c7ce
Compare
|
Is this still on the table ? |
|
Yes but need approval on licensing before being able to move forward: cncf/foundation#1117 |
65634a7 to
980cb20
Compare
| @@ -1,2 +1,3 @@ | |||
| [build] | |||
| target = "x86_64-unknown-none" | |||
| rustflags = ["-Zdirect-access-external-data"] | |||
There was a problem hiding this comment.
Where does this come from?
There was a problem hiding this comment.
IIRC rustc generated unsupported reallocations without this flag
There was a problem hiding this comment.
This is a nightly flag, right?
Also, this will not apply to comsumers of hyperlight-guest-bin, right?
There was a problem hiding this comment.
I think it's worth to recheck and try to remove it.
There was a problem hiding this comment.
Everything seems to work without the flag, I remove it for now 🤷♂️
c24ce45 to
d9fb9e5
Compare
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
e4caabe to
7b99307
Compare
Signed-off-by: Tomasz Andrzejak <andreiltd@gmail.com>
7b99307 to
fb1549f
Compare
No description provided.