Commit 43a69f86 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Henrik Brix Andersen
Browse files

llext: make llext_loaded_sect_ptr() available to all LLEXT code



Make llext_loaded_sect_ptr() a proper function to be able to call it
from platform LLEXT code.

Signed-off-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
parent 09fab7e6
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2024 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_LLEXT_INTERNAL_H
#define ZEPHYR_LLEXT_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @file
 * @brief Private header for linkable loadable extensions
 */

/** @cond ignore */

struct llext_loader;
struct llext;

const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext, unsigned int sh_ndx);

/** @endcond */

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_LLEXT_INTERNAL_H */
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <zephyr/llext/elf.h>
#include <zephyr/llext/loader.h>
#include <zephyr/llext/llext.h>
#include <zephyr/llext/llext_internal.h>
#include <zephyr/kernel.h>
#include <zephyr/cache.h>

+12 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <zephyr/llext/elf.h>
#include <zephyr/llext/loader.h>
#include <zephyr/llext/llext.h>
#include <zephyr/llext/llext_internal.h>
#include <zephyr/kernel.h>

#include <zephyr/logging/log.h>
@@ -38,6 +39,17 @@ LOG_MODULE_DECLARE(llext, CONFIG_LLEXT_LOG_LEVEL);

static const char ELF_MAGIC[] = {0x7f, 'E', 'L', 'F'};

const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext, unsigned int sh_ndx)
{
	enum llext_mem mem_idx = ldr->sect_map[sh_ndx].mem_idx;

	if (mem_idx == LLEXT_MEM_COUNT) {
		return NULL;
	}

	return (const uint8_t *)ext->mem[mem_idx] + ldr->sect_map[sh_ndx].offset;
}

/*
 * Load basic ELF file data
 */
+0 −12
Original line number Diff line number Diff line
@@ -58,18 +58,6 @@ static inline const char *llext_string(struct llext_loader *ldr, struct llext *e
	return (char *)ext->mem[mem_idx] + idx;
}

static inline const void *llext_loaded_sect_ptr(struct llext_loader *ldr, struct llext *ext,
						unsigned int sh_ndx)
{
	enum llext_mem mem_idx = ldr->sect_map[sh_ndx].mem_idx;

	if (mem_idx == LLEXT_MEM_COUNT) {
		return NULL;
	}

	return (const uint8_t *)ext->mem[mem_idx] + ldr->sect_map[sh_ndx].offset;
}

/*
 * Relocation (llext_link.c)
 */