-
Notifications
You must be signed in to change notification settings - Fork 150
feat(guest): replace musl with picolibc #831
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
base: main
Are you sure you want to change the base?
Conversation
617d834
to
3f8ffcf
Compare
eaf1d54
to
b18a374
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this PR!
) | ||
.unwrap_or_default(); | ||
|
||
let n = bytes.len(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opinion: I would just put everything under the same libc feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: shuoldn't this return -1, or some other indication of error? and set errno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
2bd1ff4
to
da6fa41
Compare
Signed-off-by: Tomasz Andrzejak <[email protected]>
c7610ab
to
9f5c6c1
Compare
9f5c6c1
to
a59c7ce
Compare
No description provided.