blob: f13f40f733ea988d64d17e7927c4b5f5e1072c17 (
plain) (
tree)
|
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#include "generated/integers.c"
#define X(ARCH, CHARBITS, INTPTR_BITS, SIZE_BITS, INTMAX_ALIGN, ENDIAN, SIGN) [ARCH] = INTMAX_ALIGN
static const unsigned char aligntable[] = {LIST_ARCH_SPECS(X, COMMA)};
#undef X
enum libsyscalls_error
libsyscalls_get_integer_alignment(enum libsyscalls_os os, enum libsyscalls_arch arch,
unsigned width_in_bits, unsigned *alignment_out)
{
unsigned maxalign;
if (!width_in_bits)
return LIBSYSCALLS_E_INVAL;
if ((size_t)arch >= ELEMSOF(aligntable))
return LIBSYSCALLS_E_ARCHNOSUP;
maxalign = aligntable[(size_t)arch];
if (!maxalign)
return LIBSYSCALLS_E_ARCHNOSUP;
if (IS_NOT_2POW(width_in_bits) || width_in_bits % 8 || width_in_bits > 64)
return LIBSYSCALLS_E_NOSUCHTYPE;
*alignment_out = width_in_bits < maxalign ? width_in_bits : maxalign;
#define CASE(UPPERCASE, LOWERCASE)\
case LIBSYSCALLS_OS_##UPPERCASE:\
return get_##LOWERCASE##_integer_alignment(arch, width_in_bits, alignment_out)
switch ((int)os) {
LIST_OSES(CASE, ;);
default:
return LIBSYSCALLS_E_OSNOSUP;
}
#undef CASE
}
|