diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c94cada5..731e9f9bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). * Add `Sandbox::recreate()`, which rebuilds a sandbox's VM and memory from a snapshot. It recovers unrecoverable sandboxes and keeps configuration, host functions, and interrupt handles by @ludfjig in https://github.com/hyperlight-dev/hyperlight/pull/1751 ### Changed +* **Breaking:** In the guest libc bindings, `timeval.tv_usec` is now + `suseconds_t` (`i32`) instead of `c_long`. Use `suseconds_t` for values assigned + to the field, or convert existing `c_long` values with + `suseconds_t::try_from(value)`. * `Snapshot::save` caches memory-layer hashes and trusts existing same-length regular blobs by their content-addressed filenames without verifying their contents. Callers must keep blobs immutable. Use the new diff --git a/NOTICE.txt b/NOTICE.txt index 6c1513e6f7..c7ca756536 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -7,7 +7,7 @@ Component. picolibc picolibc is a C library designed for embedded systems, derived from newlib. https://github.com/picolibc/picolibc -Version: 1.8.11 +Version: 1.8.12 (upstream snapshot ff59ec82f) Open Source License/Copyright Notice. diff --git a/docs/picolibc.md b/docs/picolibc.md index e37a6a816c..c480394358 100644 --- a/docs/picolibc.md +++ b/docs/picolibc.md @@ -55,6 +55,13 @@ For full details on available picolibc build options, see the The file list of picolibc sources to compile is maintained in `build_files.rs`. +## Pinned Snapshot + +Hyperlight uses the BSD-filtered snapshot of upstream +[`ff59ec82f`](https://github.com/picolibc/picolibc/commit/ff59ec82f), based on Picolibc +1.8.12. This snapshot includes the buffered `fwrite` fixes and follow-up fixes for +error reporting on `fclose` and buffered stream positioning. + ## Updating Picolibc To update picolibc to a new version: diff --git a/src/hyperlight_libc/build.rs b/src/hyperlight_libc/build.rs index f2bf3708c7..1136923ed9 100644 --- a/src/hyperlight_libc/build.rs +++ b/src/hyperlight_libc/build.rs @@ -12,6 +12,7 @@ use bindgen::Formatter::Prettyplease; use bindgen::RustEdition::Edition2021; use build_files::{ LIBC_FILES, LIBC_FILES_AARCH64, LIBC_FILES_X86, LIBM_FILES, LIBM_FILES_AARCH64, LIBM_FILES_X86, + LIBOS_FALLBACK_FILES, }; fn copy_includes, Q: AsRef + std::fmt::Debug>( @@ -159,6 +160,10 @@ fn add_libc(build: &mut cc::Build, picolibc_dir: &Path, target: Target) -> Resul let source_path = picolibc_dir.join("libc").join(file); build.file(&source_path); } + let fallback_dir = picolibc_dir.join("libos/fallback"); + for file in LIBOS_FALLBACK_FILES { + build.file(fallback_dir.join(file)); + } Ok(()) } diff --git a/src/hyperlight_libc/build_files.rs b/src/hyperlight_libc/build_files.rs index 2a9cec715a..3f3a812223 100644 --- a/src/hyperlight_libc/build_files.rs +++ b/src/hyperlight_libc/build_files.rs @@ -119,14 +119,11 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "misc/init.c", "misc/inittls.c", "misc/lock.c", - "misc/picosbrk.c", "misc/unctrl.c", "posix/basename.c", "posix/collcmp.c", "posix/dirname.c", "posix/fnmatch.c", - "posix/fpathconf.c", - "posix/pathconf.c", "posix/regcomp.c", "posix/regerror.c", "posix/regexec.c", @@ -154,7 +151,6 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "search/twalk.c", "signal/psignal.c", "signal/sig2str.c", - "signal/signal.c", "ssp/chk_fail.c", "ssp/gets_chk.c", "ssp/memcpy_chk.c", @@ -213,6 +209,7 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "stdio/fgetwc.c", "stdio/fgetws.c", "stdio/fileno.c", + "stdio/filewstrput.c", "stdio/filestrget.c", "stdio/filestrput.c", "stdio/filestrputalloc.c", @@ -221,6 +218,7 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "stdio/flockfile_init.c", "stdio/fmemopen.c", "stdio/fopen.c", + "stdio/fopencookie.c", "stdio/fprintf.c", "stdio/fputc.c", "stdio/fputs.c", @@ -385,8 +383,8 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "stdlib/erand48.c", "stdlib/exit.c", "stdlib/exitprocs.c", + "stdlib/_findenv.c", "stdlib/getenv.c", - "stdlib/getenv_r.c", "stdlib/getopt.c", "stdlib/getsubopt.c", "stdlib/ignore_handler_s.c", @@ -434,6 +432,7 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "stdlib/uctoej.c", "stdlib/uctoji.c", "stdlib/uctosj.c", + "stdlib/unsetenv.c", "stdlib/utoa.c", "stdlib/wcrtomb.c", "stdlib/wcsnrtombs.c", @@ -558,7 +557,6 @@ pub(crate) const LIBC_FILES: &[&str] = &[ "time/difftime.c", "time/getdate.c", "time/getdate_r.c", - "time/gettzinfo.c", "time/gmtime.c", "time/gmtime_r.c", "time/lcltime.c", @@ -668,6 +666,16 @@ pub(crate) const LIBC_FILES_AARCH64: &[&str] = &[ "machine/aarch64/tls.c", ]; +// Bare-metal functions that moved out of libc in Picolibc 1.8.12. +pub(crate) const LIBOS_FALLBACK_FILES: &[&str] = &[ + "fpathconf.c", + "pathconf.c", + "raise.c", + "sbrk.c", + "signal.c", + "sigprocmask.c", +]; + pub(crate) const LIBM_FILES: &[&str] = &[ "common/copysignl.c", "common/exp10l.c", @@ -805,7 +813,7 @@ pub(crate) const LIBM_FILES: &[&str] = &[ "ld/e_tgammal.c", "ld/invtrig.c", "ld/k_cosl.c", - "ld/k_rem_pio2.c", + "ld/k_rem_pio2l.c", "ld/k_sinl.c", "ld/k_tanl.c", "ld/math_errl_check_oflowl.c", diff --git a/src/hyperlight_libc/include/picolibc.h b/src/hyperlight_libc/include/picolibc.h index a2a1fa5ab2..e997ce1b4c 100644 --- a/src/hyperlight_libc/include/picolibc.h +++ b/src/hyperlight_libc/include/picolibc.h @@ -9,10 +9,10 @@ #define __NEWLIB__ 4 #define __NEWLIB_MINOR__ 3 #define __NEWLIB_PATCHLEVEL__ 0 -#define __PICOLIBC_VERSION__ "1.8.11" +#define __PICOLIBC_VERSION__ "1.8.12" #define __PICOLIBC__ 1 #define __PICOLIBC_MINOR__ 8 -#define __PICOLIBC_PATCHLEVEL__ 11 +#define __PICOLIBC_PATCHLEVEL__ 12 // static configuration - enabled features #define __ASSERT_VERBOSE diff --git a/src/hyperlight_libc/src/stubs.rs b/src/hyperlight_libc/src/stubs.rs index d5a5f8fbd1..b7279dc0c1 100644 --- a/src/hyperlight_libc/src/stubs.rs +++ b/src/hyperlight_libc/src/stubs.rs @@ -18,7 +18,8 @@ extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut c_void) -> c_int { unsafe { (*tv).tv_sec = ts.tv_sec; - (*tv).tv_usec = ts.tv_nsec / 1000; + // A normalized timespec converts to at most 999_999 microseconds. + (*tv).tv_usec = (ts.tv_nsec / 1000) as _; } 0 diff --git a/src/hyperlight_libc/third_party/picolibc b/src/hyperlight_libc/third_party/picolibc index 12ecf5273b..229d31d89a 160000 --- a/src/hyperlight_libc/third_party/picolibc +++ b/src/hyperlight_libc/third_party/picolibc @@ -1 +1 @@ -Subproject commit 12ecf5273bd3c44d1b95085b47ca394841965ba0 +Subproject commit 229d31d89ad704958f5fed08338c13d66604fca9