Backport more of spice-core.c