/* * shim_posix.c — the few POSIX entry points anthy calls that WASI does not provide. * * Measured on the wasi-sdk-25 sysroot: libc.a defines neither getuid, getpwuid nor * gethostname, while anthy uses getpwuid(getuid()) in conf.c and gethostname() when * it builds the session id. Linking without these fails with undefined symbols. * * Nothing here is security relevant: the module runs inside the embedder's own * process, HOME only decides where anthy looks for the private dictionary, and the * session id only has to be unique within the process. */ #include #include #include #include #include "pwd.h" uid_t getuid(void) { return 0; } uid_t geteuid(void) { return 0; } static struct passwd fake_pw; static char home_dir[512]; struct passwd *getpwuid(uid_t uid) { const char *h; (void)uid; h = getenv("HOME"); snprintf(home_dir, sizeof(home_dir), "%s", (h && *h) ? h : "/work"); fake_pw.pw_name = (char *)"wasm"; fake_pw.pw_passwd = (char *)""; fake_pw.pw_uid = 0; fake_pw.pw_gid = 0; fake_pw.pw_gecos = (char *)""; fake_pw.pw_dir = home_dir; fake_pw.pw_shell = (char *)"/"; return &fake_pw; } struct passwd *getpwnam(const char *name) { (void)name; return getpwuid(0); } /* declared in , but the definition is missing from libc.a */ int gethostname(char *name, size_t len) { if (!name || len == 0) return -1; snprintf(name, len, "wasm"); return 0; }