/*
 * wnix, a Unix-like operating system for WebAssembly applications.
 * Copyright (C) 2025  Xavier Del Campo Romero
 *
 * 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 <https://www.gnu.org/licenses/>.
 */

#ifndef BIN_PROC_H
#define BIN_PROC_H

#include <bin/types.h>
#include <nanowasm/nw.h>
#include <stddef.h>

int bin_proc_init(struct bin_proc *p);
int bin_proc_add(struct bin_proc *p);
void bin_proc_free(struct bin_proc *p);
int bin_proc_read(void *buf, size_t n, void *user);
int bin_proc_eof(void *user);
enum nw_state bin_proc_pc(long offset, struct nw_next *next, void *user);
enum nw_state bin_proc_seek(long offset, void *user);
enum nw_state bin_proc_tell(long *offset, void *user);
int bin_proc_lock(struct bin_proc *p);
int bin_proc_unlock(struct bin_proc *p);
int bin_proc_move(struct bin_proc *p, struct bin *from, struct bin *to);
int bin_proc_l_load(unsigned long pos, void *dst, size_t n, void *user);
int bin_proc_l_store(unsigned long pos, const void *src, size_t n, void *user);
int bin_proc_g_load(unsigned long pos, void *dst, size_t n, void *user);
int bin_proc_g_store(unsigned long pos, const void *src, size_t n, void *user);
int bin_proc_s_push(const void *src, size_t n, void *user);
int bin_proc_s_pop(void *dst, size_t n, void *user);
int bin_proc_s_read(size_t offset, void *dst, size_t n, void *user);
int bin_proc_s_write(size_t offset, const void *dst, size_t n, void *user);
size_t bin_proc_s_ptr(void *user);
struct bin_proc_fd *bin_proc_fd_find(const struct bin_proc *p, int fd);
int bin_proc_fd_alloc(struct bin_proc *p, const struct fs_fd *fd, int flags);

extern const struct nw_inst_cfg bin_proc_cfg;

#endif
