Skip to content

Guard fork/execvp in AOT builder for sandboxed platforms#53

Open
lancejpollard wants to merge 1 commit intoHigherOrderCO:mainfrom
cluesurf:guard-aot-build
Open

Guard fork/execvp in AOT builder for sandboxed platforms#53
lancejpollard wants to merge 1 commit intoHigherOrderCO:mainfrom
cluesurf:guard-aot-build

Conversation

@lancejpollard
Copy link

Wraps aot/build.c in #ifdef guards so HVM4 compiles on platforms where fork() and execvp() are unavailable.

Benefits

  • Enables compiling HVM4 to WASM via Emscripten
  • Enables embedding in iOS apps (App Store sandbox prohibits fork apparently)
  • Enables embedding in Android apps (sandbox restricts fork/exec)
  • Opt-in via HVM_NO_AOT_BUILD for other restricted environments

Changes

clang/aot/build.c: Added a platform guard at the top of the file. On sandboxed platforms (__EMSCRIPTEN__, __ANDROID__, TARGET_OS_IPHONE, or user-defined HVM_NO_AOT_BUILD), the three public functions (aot_build_to_c, aot_build_as_c_once, aot_build_to_output) are replaced with stubs that print a clear error and exit. The #else branch contains the original code, unchanged.

This avoids including <sys/wait.h>, <unistd.h>, and other POSIX headers that don't exist on restricted platforms.

Risk

None on existing platforms I don't think. The guard only triggers when one of the platform-specific defines is set. Desktop and server builds take the #else path, which is the original code unchanged. AOT compilation (--to-c, --as-c, -o) is verified working after this change.

Wrap aot/build.c in #ifdef guards for platforms where fork() and
execvp() are unavailable (WASM, iOS, Android). Stub functions print
a clear error. Existing desktop/server builds are unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant