summaryrefslogtreecommitdiffstats
path: root/testutil
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--testutil/get-integer-alignment.c2
-rw-r--r--testutil/make-signed.c56
-rw-r--r--testutil/parse-signed.c56
-rw-r--r--testutil/section-value.c52
-rw-r--r--testutil/to-tracee-endian.c111
-rw-r--r--testutil/to-tracer-endian.c83
-rw-r--r--testutil/unsection-value.c52
7 files changed, 411 insertions, 1 deletions
diff --git a/testutil/get-integer-alignment.c b/testutil/get-integer-alignment.c
index 6c91824..7d0fcc3 100644
--- a/testutil/get-integer-alignment.c
+++ b/testutil/get-integer-alignment.c
@@ -15,7 +15,7 @@ int
main(int argc, char **argv)
{
int os, arch, width;
- unsigned alignment = -1;
+ unsigned alignment = 0;
enum libsyscalls_error err;
if (argc != 6) {
diff --git a/testutil/make-signed.c b/testutil/make-signed.c
new file mode 100644
index 0000000..7cd0134
--- /dev/null
+++ b/testutil/make-signed.c
@@ -0,0 +1,56 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ int sign, neg = -1;
+ size_t bits;
+ const char *xval;
+ enum libsyscalls_error err;
+ unsigned long long int value;
+ char *end;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ sign = atoi(argv[1]);
+ bits = (unsigned long long int)atoll(argv[2]);
+ xval = argv[3];
+ neg = *xval == '-';
+ xval = &xval[neg];
+ errno = 0;
+ value = strtoull(xval, &end, 16);
+ if (errno || *end)
+ goto usage;
+
+ err = libsyscalls_make_signed_integer(value, neg, (enum libsyscalls_datatype_sign_representation)sign, bits, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ printf("%0*llX\n", (int)strlen(xval), value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/parse-signed.c b/testutil/parse-signed.c
new file mode 100644
index 0000000..0fea405
--- /dev/null
+++ b/testutil/parse-signed.c
@@ -0,0 +1,56 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ int sign, neg = -1;
+ size_t bits;
+ const char *xval;
+ enum libsyscalls_error err;
+ unsigned long long int value;
+ char *end;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ sign = atoi(argv[1]);
+ bits = (unsigned long long int)atoll(argv[2]);
+ xval = argv[3];
+ errno = 0;
+ value = strtoull(xval, &end, 16);
+ if (errno || *end)
+ goto usage;
+
+ err = libsyscalls_parse_signed_integer(value, (enum libsyscalls_datatype_sign_representation)sign, bits, &value, &neg);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ if (neg != 0 && neg != 1)
+ abort();
+ printf("%.*s%0*llX\n", neg, "-", (int)strlen(xval), value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/section-value.c b/testutil/section-value.c
new file mode 100644
index 0000000..b4c0304
--- /dev/null
+++ b/testutil/section-value.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ enum libsyscalls_datatype_section section;
+ unsigned long long int value;
+ size_t bits;
+ char *end;
+ enum libsyscalls_error err;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ section = (enum libsyscalls_datatype_section)atoi(argv[1]);
+ errno = 0;
+ value = strtoull(argv[2], &end, 16);
+ if (errno || *end)
+ goto usage;
+ bits = (size_t)atol(argv[3]);
+
+ err = libsyscalls_section_value(value, bits, section, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/to-tracee-endian.c b/testutil/to-tracee-endian.c
new file mode 100644
index 0000000..4346883
--- /dev/null
+++ b/testutil/to-tracee-endian.c
@@ -0,0 +1,111 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+static void
+make_hex(char *out, const char *in, size_t n)
+{
+ for (; n--; in++) {
+ *out++ = "0123456789ABCDEF"[((unsigned)*in >> 4) & 0xFU];
+ *out++ = "0123456789ABCDEF"[((unsigned)*in >> 0) & 0xFU];
+ }
+ *out = '\0';
+}
+
+
+int
+main(int argc, char **argv)
+{
+ struct libsyscalls_datatype_description type;
+ char *data, *end, *text0, *text1;
+ size_t dataoff, i, datasize;
+ unsigned long long int value;
+ enum libsyscalls_error err;
+
+ _Static_assert(CHAR_BIT, "We only support 8-bit char at the moment in testutil/to-tracee-endian.c");
+
+ if (argc < 5) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
+ errno = 0;
+ value = strtoull(argv[1], &end, 16);
+ if (errno || *end)
+ goto usage;
+ dataoff = (size_t)atol(argv[2]);
+ type.width_in_bits = (unsigned short int)atoi(argv[3]);
+ argv = &argv[4];
+ i = 0;
+ for (; argv[i] && i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++)
+ type.byteorder[i] = (unsigned)atoi(argv[i]);
+ if (argv[i])
+ goto usage;
+ for (; i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++) {
+ type.byteorder[i] = 0U;
+ type.byteorder[i] = ~type.byteorder[i];
+ }
+
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+ datasize = ((size_t)type.width_in_bits + dataoff + 7UL) / 8UL;
+ data = malloc(datasize);
+ text0 = malloc(datasize * 2UL + 1UL);
+ text1 = malloc(datasize * 2UL + 1UL);
+
+ memset(data, 0, datasize);
+ err = libsyscalls_to_tracee_endian(value, &type, data, dataoff);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ free(data);
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ make_hex(text0, data, datasize);
+
+ memset(data, ~0, datasize);
+ err = libsyscalls_to_tracee_endian(value, &type, data, dataoff);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ free(data);
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ make_hex(text1, data, datasize);
+
+ free(data);
+
+ printf("%s %s\n", text0, text1);
+
+ free(text0);
+ free(text1);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/to-tracer-endian.c b/testutil/to-tracer-endian.c
new file mode 100644
index 0000000..53cb380
--- /dev/null
+++ b/testutil/to-tracer-endian.c
@@ -0,0 +1,83 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ struct libsyscalls_datatype_description type;
+ const char *text;
+ char *data;
+ size_t dataoff, i;
+ unsigned long long int value;
+ unsigned char high, low;
+ enum libsyscalls_error err;
+
+ _Static_assert(CHAR_BIT, "We only support 8-bit char at the moment in testutil/to-tracer-endian.c");
+
+ if (argc < 5) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
+
+ text = argv[1];
+ dataoff = (size_t)atol(argv[2]);
+ type.width_in_bits = (unsigned short int)atoi(argv[3]);
+ argv = &argv[4];
+ i = 0;
+ for (; argv[i] && i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++)
+ type.byteorder[i] = (unsigned)atoi(argv[i]);
+ if (argv[i])
+ goto usage;
+ for (; i < sizeof(type.byteorder) / sizeof(*type.byteorder); i++) {
+ type.byteorder[i] = 0U;
+ type.byteorder[i] = ~type.byteorder[i];
+ }
+
+#if defined(__clang__)
+# pragma GCC diagnostic pop
+#endif
+
+ if (strlen(text) & 1 || !strlen(text))
+ goto usage;
+ data = malloc(strlen(text) / 2);
+ for (i = 0; *text; i++) {
+ high = (unsigned char)*text++;
+ low = (unsigned char)*text++;
+ high = (unsigned char)((high & 15U) + (high > '9' ? 9U : 0U));
+ low = (unsigned char)((low & 15U) + (low > '9' ? 9U : 0U));
+ data[i] = (char)((high << 4) | low);
+ }
+
+ err = libsyscalls_to_tracer_endian(data, dataoff, &type, &value);
+ free(data);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}
diff --git a/testutil/unsection-value.c b/testutil/unsection-value.c
new file mode 100644
index 0000000..9c85b3b
--- /dev/null
+++ b/testutil/unsection-value.c
@@ -0,0 +1,52 @@
+/* See LICENSE file for copyright and license details. */
+#include "../libsyscalls.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang is just being silly */
+#endif
+
+
+int
+main(int argc, char **argv)
+{
+ enum libsyscalls_datatype_section section;
+ unsigned long long int value;
+ size_t bits;
+ char *end;
+ enum libsyscalls_error err;
+
+ if (argc != 4) {
+ usage:
+ fprintf(stderr, "usage error\n");
+ return 1;
+ }
+
+ section = (enum libsyscalls_datatype_section)atoi(argv[1]);
+ errno = 0;
+ value = strtoull(argv[2], &end, 16);
+ if (errno || *end)
+ goto usage;
+ bits = (size_t)atol(argv[3]);
+
+ err = libsyscalls_unsection_value(value, bits, section, &value);
+ if (err == LIBSYSCALLS_E_INVAL) {
+ printf("inval\n");
+ goto out;
+ } else if (err) {
+ libsyscalls_perror(NULL, err);
+ return 1;
+ }
+
+ printf("%llX\n", value);
+
+out:
+ if (fflush(stdout) || fclose(stdout)) {
+ perror(NULL);
+ return 1;
+ }
+ return 0;
+}