C Library Models¶
SmallWorld provides a number of function models for standard C functions. Models are implemented as ABI-agnostic models, and then paired with ABI-specific mixins to create platform-specific classes.
The SmallWorld model corpus is a work in progress. This page lists the status of our model support
We are planning to have at least stub models for the following API standards:
C99
POSIX
Win32
ABI Support¶
SmallWorld currently provides basic C calling convention definitions for the following ABIs:
- System V
aarch64
amd64
armel (arm v5t)
armhf (arm v7a)
i386
mips
mipsel
mips64
mips64el
powerpc
riscv64
The model API currently supports six arguments, the maximum of any standard C function. The underlying calling convention model supports arbitrary arguments.
The models support variadic arguments; see the printf or scanf models for examples on how to use these.
The models do not support returning structs or multiple values.
The models have no way of expressing struct arguments passed by value.
The models currently don’t support va_list arguments. These are opaque structs defined as compiler intrinsics, making them annoying to model.
The System V i386 calling convention uses the x87 registers to return floating-point values. None of our emulators support this.
Function Support by Header¶
The following tables present the current status of the function models. They are grouped by API standard, and then by header file.
The options for the “support” field mean the following:
Full: Model is complete.
Imprecise: Model missing critical behavior. Will raise an exception unless otherwise configured.
N/I: Not implemented, but planned.
None: Not modeled. Will raise an exception.
Support |
Notes |
|
|---|---|---|
memchr |
Full |
|
memcmp |
Full |
|
memcpy |
Full |
|
memmove |
Full |
|
memset |
Full |
|
strchr |
Full |
|
strcmp |
Full |
|
strcoll |
Imprecise |
Relies on locale; prototype model. |
strcpy |
Full |
|
strcspn |
Full |
|
strerror |
None |
Needs platform-specific lookup table. |
strlen |
Full |
|
strncmp |
Full |
|
strncpy |
Full |
|
strpbrk |
Full |
|
strrchr |
Full |
|
strspn |
Full |
|
strstr |
Full |
|
strtok |
Full |
|
strxfrm |
Imprecise |
Relies on locale; prototype model. |
Support |
Notes |
|
|---|---|---|
Abs |
Full |
|
LAbs |
Full |
|
LLAbs |
Full |
|
Abort |
Full |
|
Atexit |
Imprecise |
Does not actually register an on-exit call. |
Atof |
Full |
i386 ABI uses x87 registers; not supported. |
Atoi |
Full |
|
Atol |
Full |
|
Atoll |
Full |
|
Calloc |
Full |
|
Div |
None |
Requires returning a struct by value. |
LDiv |
None |
Requires returning a struct by value. |
LLDiv |
None |
Requires returning a struct by value. |
Exit |
Full |
|
Free |
Full |
|
Getenv |
Imprecise |
envp not modeled |
Malloc |
Full |
|
Mblen |
None |
Requires locale |
Mbstowcs |
None |
Requires locale |
Mbtowc |
None |
Requires locale |
QSort |
None |
Requires calling a function pointer |
Rand |
Full |
|
Realloc |
Full |
|
Srand |
Full |
|
System |
Imprecise |
Does not actually invoke subprocess |
Wcstombs |
None |
Requires locale |
Wctomb |
None |
Requires locale |
Support |
Notes |
|
|---|---|---|
Clearerror |
Full |
|
Fclose |
Full |
|
Feof |
Full |
No error conditions in current models |
Ferror |
Full |
|
Fflush |
Full |
|
Fgetc |
Full |
|
Fgetpos |
Full |
|
Fgets |
Full |
|
Fopen |
Full |
|
Fprintf |
Full |
|
Fputc |
Full |
|
Fputs |
Full |
|
Fread |
Full |
|
Freopen |
Full |
|
Fscanf |
Full |
|
Fseek |
Full |
|
Fsetpos |
Full |
|
Ftell |
Full |
|
Fwrite |
Full |
|
Getc |
Full |
|
Getchar |
Full |
|
Printf |
Full |
|
Putc |
Full |
|
Putchar |
Full |
|
Puts |
Full |
|
Remove |
Imprecise |
File system model is optional |
Rename |
Imprecise |
File system model is optional |
Rewind |
Full |
|
Scanf |
Full |
|
Snprintf |
Full |
|
Sprintf |
Full |
|
Sscanf |
Full |
|
Tmpfile |
Imprecise |
File system model is optional |
Tmpnam |
Imprecise |
File system model is optional |
Ungetc |
Full |
LOTS of undefined behavor relative to other functions |
Vfprintf |
N/I |
Varargs function. ABIs not modeled. |
Vfscanf |
N/I |
Varargs function. ABIs not modeled. |
Vprintf |
N/I |
Varargs function. ABIs mot modeled. |
Vscanf |
N/I |
Varargs function. ABIs not modeled. |
Vsnprintf |
N/I |
Varargs function. ABIs not modeled. |
Vsprintf |
N/I |
Varargs function. ABIs not modeled. |
Vsscanf |
N/I |
Varargs function. ABIs not modeled. |