summaryrefslogtreecommitdiffstats
path: root/linux/types.c
blob: 83f2bd1d42a584ec3cd58f326c1420f998397bec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* See LICENSE file for copyright and license details. */

/* This file is included from ../libsyscalls_get_datatype_description.c */


/* If new architectures are added, LIST_ARCH_SPECS in ../common.h must be updated */

static enum libsyscalls_error
get_linux_datatype_description(enum libsyscalls_arch arch, enum libsyscalls_datatype *datatype,
                               struct libsyscalls_datatype_description *description_out,
			       int *divide_array_size_with_type_size_out)
{
	/*
	 * Generally Linux has char as 8 bit, short int as 16, int as 32 bit,
	 * and long long int as 64 bit (it's code even make such assumptions),
	 * however that's is not necessarily the case for more exotic
	 * architectures, for example, some specialised processors have 16 bit
	 * chars and run Linux (although not mainline). Linux also uses
	 * long int for addresses (intptr_t), which is normally how it should
	 * be done but Windows always set long int to 32 bit (at least on x86/amd64)
	 * for backwards compatibility, and of course it cannot be assumed that
	 * Linux does something similar this for some architecture in the future
	 * (although that looks very unlikely, at least 32+-bit architecture,
	 * it is of course possible that if Linux is ported to a 16-bit architecture,
	 * intptr_t would be 16 bits, and thus long int must be something else
	 * as it must be at least 32 bits). It's probably safe to assume,
	 * system calls use intptr_t/uintptr_t.
	 */

	switch ((int)*datatype) {
	case LIBSYSCALLS_TYPE_SCHAR:  description_out->width_in_bits = 8;  break;
	case LIBSYSCALLS_TYPE_SHORT:  description_out->width_in_bits = 16; break;
	case LIBSYSCALLS_TYPE_INT:    description_out->width_in_bits = 32; break;
	case LIBSYSCALLS_TYPE_LLONG:  description_out->width_in_bits = 64; break;

	case LIBSYSCALLS_TYPE_LONG:
	case LIBSYSCALLS_TYPE_DYNAMIC: /* syscall */
		*datatype = LIBSYSCALLS_TYPE_INTPTR;
		break;

	case LIBSYSCALLS_TYPE_FD_SET:
		*datatype = LIBSYSCALLS_TYPE_INTPTR;
		description_out->array_size = 1024;
		*divide_array_size_with_type_size_out = 1;
		break;

	default:
		/* something only defined on some other operating system */
		return LIBSYSCALLS_E_NOSUCHTYPE;
	}
	(void) arch;
	return LIBSYSCALLS_E_OK;
}