/*
 * module.c
 *
 * Copyright (C) 2018 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _MODULE_H_
#define _MODULE_H_

#include <common.h>
#include <sdk/list.h>

typedef dword_t (*module_load_proc_t)(const char *parameters);
typedef dword_t (*module_unload_proc_t)(void);

typedef struct
{
    list_entry_t link;
    void *address;
    size_t size;
} module_segment_t;

typedef struct
{
    list_entry_t link;
    uintptr_t physical_address;
    size_t size;
    char *name;
    void *base_address;
    module_load_proc_t load_proc;
    module_unload_proc_t unload_proc;
    list_entry_t segments;
} module_t;

module_t *get_module_from_address(void *address);
dword_t module_load_from_physical(module_t *module, const char *parameters);
dword_t module_unload(module_t *module);

#endif
