Skip to content
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

Implement libc thunk library #1505

Open
neobrain opened this issue Jan 9, 2022 · 1 comment
Open

Implement libc thunk library #1505

neobrain opened this issue Jan 9, 2022 · 1 comment
Assignees
Milestone

Comments

@neobrain
Copy link
Member

neobrain commented Jan 9, 2022

Thunking libc itself has the potential to make thunking other libraries significantly more robust by making various workarounds unnecessary (see #1208). Here's an (incomplete) list of nontrivial things that need to be tackled:

  • Program startup (__libc_start_main)
  • printf-like functions (including fprintf, sprintf, snprintf, vprintf, ...)
  • Functions with function pointer arguments (qsort)
  • Data symbol handling:
    • errno
    • getopt: optarg/optind/opterr/optopt
  • Struct repacking:
    • Repacking of data in parameter structs that have different layouts across architectures (e.g. stat)
    • Repacking for arguments passed to callbacks
  • __lxstat/__fxstat/...: Data layout of parameter struct is determined by a version field
@neobrain
Copy link
Member Author

neobrain commented Jan 9, 2022

errno handling

errno is a data symbol exported by libc.so, written to by many (but not all) libc functions on error (and written to by guest application to "reset" errors). When thunking libc, the problem that arises is that the errno symbol exposed by thunked libc to guest applications is a different symbol than the native errno symbol that host libc functions write to. Unless we find magic to allow for sharing the same data symbol, some mechanism to synchronize the value between the two data symbols is needed.

A lot of functions set errno, so a scalable approach is needed for synchronizing the native/thunk errno values. Here are some potential options to handle this:

  • Brute-force synchronize errno before/after every libc function
  • Add a thunkgen annotation to mark functions that potentially set errno and autogenerate synchronization code for annotated functions, only
  • memprotect the errno symbol to catch reads/writes by the guest applications in a SIGSEV handler and synchronize on-demand
  • Use a custom dynamic loader that relocates matching data symbols where possible given ABI compatibility constraints

@neobrain neobrain self-assigned this Jan 25, 2022
@skmp skmp added this to the LTE milestone Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 Unschedulled
Development

No branches or pull requests

2 participants