summaryrefslogtreecommitdiffstats
path: root/linux/types.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linux/types.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/linux/types.c b/linux/types.c
new file mode 100644
index 0000000..fee69fe
--- /dev/null
+++ b/linux/types.c
@@ -0,0 +1,54 @@
+/* See LICENSE file for copyright and license details. */
+
+/* This file is included from ../libsyscalls_get_datatype_description.c */
+
+
+/* If new architectures are added, the table at the top of
+ * ../libsyscalls_get_datatype_description.c 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 used
+ * 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;
+ }
+ return LIBSYSCALLS_E_OK;
+}