From 6455b9dff0554adc11e8dbe8027d134c8584bc5d Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Fri, 2 Jun 2023 16:48:29 +0200 Subject: cooker, seitan: OP_FD Signed-off-by: Stefano Brivio --- cooker/emit.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cooker/emit.c') diff --git a/cooker/emit.c b/cooker/emit.c index 05e3f81..b518ff9 100644 --- a/cooker/emit.c +++ b/cooker/emit.c @@ -52,6 +52,31 @@ void emit_nr(struct gluten_ctx *g, struct gluten_offset number) die("Too many instructions"); } +/** + * emit_fd() - Emit OP_FD instruction: add/set file descriptor in target + * @g: gluten context + * @desc: Pointer to file descriptors specification + */ +void emit_fd(struct gluten_ctx *g, struct fd_desc *desc) +{ + struct op *op = (struct op *)gluten_ptr(&g->g, g->ip); + struct op_fd *fd = &op->op.fd; + struct gluten_offset o; + struct fd_desc *dst; + + op->type = OP_FD; + + o = gluten_ro_alloc(g, sizeof(struct fd_desc)); + dst = (struct fd_desc *)gluten_ptr(&g->g, o); + memcpy(dst, desc, sizeof(struct fd_desc)); + fd->desc = o; + + debug(" %i: OP_FD: ...", g->ip.offset); + + if (++g->ip.offset > INST_MAX) + die("Too many instructions"); +} + /** * emit_call() - Emit OP_CALL instruction: execute a system call * @g: gluten context -- cgit v1.2.3