# HG changeset patch # User Paul Boddie # Date 1655049058 -7200 # Node ID 1483c00724a191ce8dd6264791218dcda78cbb4f # Parent ae353e4c7b792ee37cd0fdb6129c3580cdb7a92d Introduced a common region structure and l4re_aux_t structure location function. diff -r ae353e4c7b79 -r 1483c00724a1 libexec/include/exec/common.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libexec/include/exec/common.h Sun Jun 12 17:50:58 2022 +0200 @@ -0,0 +1,58 @@ +/* + * Common structures and functions. + * + * Copyright (C) 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#include + +#include + + + +EXTERN_C_BEGIN + +/* Auxiliary vector key-value pair. */ + +struct auxv_entry +{ + l4_umword_t key, value; +}; + +/* Region description. */ + +struct exec_region +{ + l4_addr_t start; + offset_t size; + l4_umword_t flags; + l4_cap_idx_t ds; +}; + + + +/* Utility functions. */ + +l4re_aux_t *exec_get_l4re_aux(int argc, char *argv[]); + +EXTERN_C_END + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/ diff -r ae353e4c7b79 -r 1483c00724a1 libexec/lib/src/common.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libexec/lib/src/common.cc Sun Jun 12 17:50:58 2022 +0200 @@ -0,0 +1,59 @@ +/* + * Common functionality. + * + * Copyright (C) 2022 Paul Boddie + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 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 General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include "common.h" + + + +/* Find the L4Re auxiliary structure from program argument details. */ + +l4re_aux_t *exec_get_l4re_aux(int argc, char *argv[]) +{ + /* Start after the final terminator (at argc) of the argument vector. */ + + l4_umword_t *arg = ((l4_umword_t *) &argv[argc]) + 1; + + /* The environment vector is traversed. */ + + while (*arg) + arg++; + + /* Skip the terminating null entry. */ + + arg++; + + /* Traverse the auxiliary vector. */ + + struct auxv_entry *entry = (struct auxv_entry *) arg; + + for (; entry->key; entry++) + { + if (entry->key == AT_L4_AUX) + return (l4re_aux_t *) entry->value; + } + + return NULL; +} + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/