aboutsummaryrefslogtreecommitdiffstats
path: root/include/internal/c89_relo.h
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2024-06-11 23:40:34 -0400
committerGravatar Peter McGoron 2024-06-11 23:40:34 -0400
commitfe131f6e4b80bad56be3e1f6e79f4defa61aa99b (patch)
tree518f236ea2e8bbdc76021ccf3d8f509310aff4aa /include/internal/c89_relo.h
cheney copying collector
Diffstat (limited to 'include/internal/c89_relo.h')
-rw-r--r--include/internal/c89_relo.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/internal/c89_relo.h b/include/internal/c89_relo.h
new file mode 100644
index 0000000..5347aa8
--- /dev/null
+++ b/include/internal/c89_relo.h
@@ -0,0 +1,52 @@
+#ifndef UNS_FORMAT_C89_H
+#define UNS_FORMAT_C89_H
+/* Copyright (C) 2024 Peter McGoron
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, see
+ * <https://www.gnu.org/licenses/>.
+*/
+
+#include "uns.h"
+
+/* This is a strictly C89+ header format with relocation pointers and
+ * lengths.
+ *
+ * Forwarding pointers need to be stored in the header because in strict
+ * C, arithmetic on pointers is undefined for pointers not pointing into
+ * the same object.
+ *
+ * The length of the string is limited to "len" bytes and is stored as
+ * a `uns_sword`. If the word is negative, then the region is a record,
+ * and if the number is positive then the region is just bytes.
+ */
+
+struct uns_c89_relo_hdr {
+ void *relo;
+ uns_sword len;
+};
+#define uns_c89_relo_get_hdr(p)((struct uns_c89_relo_hdr *)(p) - 1)
+
+size_t uns_c89_relo_get_len(void *p);
+size_t uns_c89_relo_get_record_len(void *p);
+
+#define uns_c89_relo_get_relo(p) (uns_c89_relo_get_hdr(p)->relo)
+#define uns_c89_relo_set_relo(p, v) (uns_c89_relo_get_relo(p) = (v))
+#define uns_c89_relo_is_record(p) (uns_c89_relo_get_hdr(p)->len < 0)
+
+void *uns_c89_relo_init(void *p, size_t len_size, int is_record);
+
+void uns_c89_relo_record_set(void *rec, size_t i, void *v);
+void *uns_c89_relo_record_get(void *rec, size_t i);
+
+#endif