Blob Blame History Raw
#ifndef SOFORT_H
#define SOFORT_H

#include <stdint.h>
#include <stdio.h>

#include "sofort_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/* pre-alpha */
#ifndef SFRT_APP
#ifndef SFRT_PRE_ALPHA
#error  libsofort: pre-alpha: ABI is not final!
#error  to use the library, please pass -DSFRT_PRE_ALPHA to the compiler.
#endif
#endif

/* status codes */
#define SFRT_OK				0x00
#define SFRT_USAGE			0x01
#define SFRT_ERROR			0x02

/* driver flags */
#define SFRT_DRIVER_VERBOSITY_NONE	0x0000
#define SFRT_DRIVER_VERBOSITY_ERRORS	0x0001
#define SFRT_DRIVER_VERBOSITY_STATUS	0x0002
#define SFRT_DRIVER_VERBOSITY_USAGE	0x0004
#define SFRT_DRIVER_CLONE_VECTOR	0x0008

#define SFRT_DRIVER_VERSION		0x0010
#define SFRT_DRIVER_DRY_RUN		0x0020

#define SFRT_DRIVER_ANNOTATE_ALWAYS	0x1000
#define SFRT_DRIVER_ANNOTATE_NEVER	0x2000
#define SFRT_DRIVER_ANNOTATE_FULL	0x4000

/* unit action flags */
#define SFRT_OUTPUT_NAME		0x0001 /* dummy */
#define SFRT_OUTPUT_ADDRESS		0x0002 /* dummy */

/* error flags */
#define SFRT_ERROR_TOP_LEVEL		0x0001
#define SFRT_ERROR_NESTED		0x0002
#define SFRT_ERROR_CHILD		0x0004
#define SFRT_ERROR_CUSTOM		0x0008

enum sfrt_custom_error {
	SFRT_ERR_FLOW_ERROR,
	SFRT_ERR_FLEE_ERROR,
	SFRT_ERR_NULL_CONTEXT,
	SFRT_ERR_NULL_SOURCE,
	SFRT_ERR_INVALID_CONTEXT,
	SFRT_ERR_INVALID_SOURCE,
	SFRT_ERR_SOURCE_SIZE_ZERO,
	SFRT_ERR_CAP,
};

struct sfrt_input {
	void *		addr;
	size_t		size;
};

struct sfrt_source_version {
	int		major;
	int		minor;
	int		revision;
	const char *	commit;
};

struct sfrt_error_info {
	const struct sfrt_driver_ctx *	edctx;
	const struct sfrt_unit_ctx *	euctx;
	const char *			eunit;
	int				esyscode;
	int				elibcode;
	const char *			efunction;
	int				eline;
	unsigned			eflags;
	void *				eany;
};

struct sfrt_common_ctx {
	uint64_t			drvflags;
	uint64_t			actflags;
	uint64_t			fmtflags;
	const char *			anystring; /* dummy */
};

struct sfrt_driver_ctx {
	const char **			units;
	const char *			program;
	const char *			module;
	const struct sfrt_common_ctx *	cctx;
	struct sfrt_error_info **	errv;
	void *				any;
};

struct sfrt_unit_ctx {
	const char * const *		path;
	const struct sfrt_input *	map;
	void *				any;
};

/* driver api */
sfrt_api int  sfrt_get_driver_ctx       (char ** argv, char ** envp, uint32_t flags,
                                         struct sfrt_driver_ctx **);

sfrt_api void sfrt_free_driver_ctx      (struct sfrt_driver_ctx *);

sfrt_api int  sfrt_get_unit_ctx         (const struct sfrt_driver_ctx *, const char * path,
                                         struct sfrt_unit_ctx **);

sfrt_api void sfrt_free_unit_ctx        (struct sfrt_unit_ctx *);

/* utility api */
sfrt_api int  sfrt_main                 (int, char **, char **);
sfrt_api int  sfrt_output_dummy         (const struct sfrt_common_ctx *, FILE *);	/* dummy */
sfrt_api int  sfrt_output_name          (const struct sfrt_unit_ctx *, FILE *);		/* dummy */
sfrt_api int  sfrt_output_address       (const struct sfrt_unit_ctx *, FILE *);		/* dummy */
sfrt_api int  sfrt_output_error_record  (const struct sfrt_driver_ctx *, const struct sfrt_error_info *);
sfrt_api int  sfrt_output_error_vector  (const struct sfrt_driver_ctx *);

/* raw input api */
sfrt_api int  sfrt_map_input            (const struct sfrt_driver_ctx *,
                                         int, const char *, int,
                                         struct sfrt_input *);

sfrt_api int  sfrt_unmap_input          (struct sfrt_input *);

/* package info */
sfrt_api const struct sfrt_source_version * sfrt_source_version(void);

#ifdef __cplusplus
}
#endif

#endif