aboutgitcodelistschat:MatrixIRC
path: root/cooker/gluten.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2023-05-02 09:48:50 +0200
committerStefano Brivio <sbrivio@redhat.com>2023-05-02 10:39:32 +0200
commit82b77505f9420f11d614c2ae0f74153ca4ee3cb5 (patch)
treeec93abd39cd8c7ff2818c7446da6cc01864b2ae1 /cooker/gluten.c
parenta2c20b2caf4e9cedb32b0930ffd7ca2e9ec72086 (diff)
downloadseitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar.gz
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar.bz2
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar.lz
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar.xz
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.tar.zst
seitan-82b77505f9420f11d614c2ae0f74153ca4ee3cb5.zip
cooker updates spilling all over the place
Only tangentially related: - make seitan C99 again, so that I can build cooker without warnings - make Makefiles make use of the usual conventions about assigning directory paths in variables, drop numbers.h as requirement for cooker and make it convenient to run stand-alone Makefiles - fix up nr_syscalls.sh to be POSIX, otherwise it will give syntax errors on my system - define a single, common way to refer to offsets in gluten, and functions to use those offsets in a safe way. Immediates are gone: cooker will write any bit of "data" to the read-only section - call const what has to be const - define on-disk layout for gluten - add OP_NR (to check syscall numbers), rename OP_COPY_ARGS to OP_LOAD (it loads _selected_ stuff from arguments) As for cooker itself: - drop ARG_ and arg_ prefixes from struct names, and similar - add/rework functions to build OP_NR, OP_LOAD, OP_CMP, and to write constant data to gluten - add parsing for "compound" arguments, but that's not completely hooked into evaluation for numeric arguments yet Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'cooker/gluten.c')
-rw-r--r--cooker/gluten.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/cooker/gluten.c b/cooker/gluten.c
index 1116e6b..6460798 100644
--- a/cooker/gluten.c
+++ b/cooker/gluten.c
@@ -12,33 +12,47 @@
#include "gluten.h"
#include "util.h"
-#define GLUTEN_INST_SIZE BUFSIZ
-#define GLUTEN_DATA_SIZE BUFSIZ
+size_t gluten_size[TYPE_COUNT] = {
+ [INT] = sizeof(int),
+ [INTMASK] = sizeof(int),
+ [INTFLAGS] = sizeof(int),
-static char gluten[GLUTEN_INST_SIZE + GLUTEN_DATA_SIZE];
+ [U32] = sizeof(uint32_t),
+ [U32MASK] = sizeof(uint32_t),
+ [U32FLAGS] = sizeof(uint32_t),
+
+ [LONG] = sizeof(long),
+ [LONGMASK] = sizeof(long),
+ [LONGFLAGS] = sizeof(long),
+
+ [PID] = sizeof(pid_t),
+ [PORT] = sizeof(in_port_t),
+ [IPV4] = sizeof(struct in_addr),
+ [IPV6] = sizeof(struct in6_addr),
-static size_t gluten_arg_storage[ARG_TYPE_COUNT] = {
- [ARG_INT] = sizeof(int),
- [ARG_INTMASK] = sizeof(int),
};
-int gluten_alloc(struct gluten_ctx *g, size_t size)
+struct gluten_offset gluten_alloc(struct gluten_ctx *g, size_t size)
{
- debug(" allocating %lu at offset %i", size, g->sp);
- if ((g->sp += size) >= GLUTEN_DATA_SIZE)
+ struct gluten_offset ret = g->dp;
+
+ debug(" allocating %lu at offset %i", size, g->dp.offset);
+ if ((g->dp.offset += size) >= DATA_SIZE)
die("Temporary data size exceeded");
- return g->sp - size;
+ return ret;
}
-int gluten_alloc_type(struct gluten_ctx *g, enum arg_type type)
+struct gluten_offset gluten_alloc_type(struct gluten_ctx *g, enum type type)
{
- return gluten_alloc(g, gluten_arg_storage[type]);
+ return gluten_alloc(g, gluten_size[type]);
}
-int gluten_init(struct gluten_ctx *g)
+void gluten_init(struct gluten_ctx *g)
{
- g->gluten = gluten;
+ (void)g;
- return 0;
+ g->ip.type = g->lr.type = OFFSET_INSTRUCTION;
+ g->dp.type = OFFSET_DATA;
+ g->cp.type = OFFSET_RO_DATA;
}