./usr/lib/libm_pic.a minix-comp
./usr/lib/libmagic.a minix-comp
./usr/lib/libmagic_pic.a minix-comp
+./usr/lib/libmagicrt.bcc minix-comp magic
./usr/lib/libmenu.a minix-comp
./usr/lib/libmenu_pic.a minix-comp
./usr/lib/libminc.a minix-comp
../minix/lib/libi2cdriver
.endif
+.if (${MKMAGIC} == "yes")
+SUBDIR+= ../minix/lib/libmagicrt
+.endif
+
.endif # defined(__MINIX)
#
# The SUBDIRs above are included here for completeness but should be built
SUBDIR+= libi2cdriver
.endif
+.if (${MKMAGIC} == "yes")
+SUBDIR+= libmagicrt
+.endif
+
.include <bsd.buildinstall.mk>
.include <bsd.subdir.mk>
--- /dev/null
+# Makefile for libmagicrt
+#
+# The magic runtime library is the runtime state transfer component for live
+# update. It is not a regular library. First of all, it is only built when
+# MKMAGIC is enabled, which also implies that we are building bitcode.
+# Second, the produced file is a single bitcode object containing basically the
+# concatenation of the individual bitcode objects produced from the source
+# files. The final bitcode object is used to link against system services
+# during the rest of the compilation process. It is installed only because
+# this makes it easier to refer to it during the rest of the compilation
+# process. However, both the library's generation and its installation cannot
+# be done with regular bsd.lib.mk rules, which is why this Makefile is rather
+# nonstandard.
+
+.include <bsd.own.mk>
+
+LIBNAME= libmagicrt.bcc
+
+SRCS= magic.c magic_analysis.c magic_asr.c magic_ds.c
+SRCS+= magic_eval.c magic_eval_lib.c magic_mem.c magic_range.c
+SRCS+= magic_selement.c magic_sentry.c magic_splay_tree.c
+SRCS+= magic_st.c magic_util.c
+
+OBJS= ${SRCS:.c=.bc}
+
+CPPFLAGS+= -D__MINIX -D_MINIX_SYSTEM -D_SYSTEM
+CPPFLAGS+= -I${.CURDIR}/include
+CPPFLAGS+= -I${NETBSDSRCDIR}/minix/llvm/include # for magic_common.h
+CPPFLAGS.magic_ds.c+= -I${NETBSDSRCDIR}/minix/servers # for ds/store.h
+
+# XXX: there is essential code in assert() statements, so force asserts on..
+CPPFLAGS+= -UNDEBUG
+
+# All functions and data must be assigned to nonstandard sections. However,
+# the magic_st module has different rules from the rest.
+SECTIONIFY= -sectionify-no-override \
+ -sectionify-data-section-map=^_____magic_instr_.*/magic_instr_data,.*/magic_data \
+ -sectionify-function-section-map=.*/magic_functions
+SECTIONIFY.magic_st.c= \
+ -sectionify-data-section-map=.*/magic_data_st \
+ -sectionify-function-section-map=.*/magic_functions_st
+
+# HACK: keep the "temporary" .bc.o files generated as part of running the
+# sectionify pass, so that we can trick clang into taking bitcode objects
+# during the linking phase, because its driver refuses to take objects with
+# the .bc suffix even when using the gold plugin. This works only because
+# we are using sectionify on all objects here, and because bsd.lib.mk uses
+# temporary names convenient for us. See also the comment in bsd.lib.mk.
+SECTIONIFYMV=cp
+
+LDFLAGS+=-nostdlib -rdynamic -shared -Wl,--plugin \
+ -Wl,${NETBSDSRCDIR}/minix/llvm/bin/LLVMgold.so \
+ -Wl,-plugin-opt=-disable-fp-elim -Wl,-plugin-opt=emit-llvm
+
+realall: ${LIBNAME}
+
+${LIBNAME}: ${OBJS}
+ ${_MKTARGET_LINK}
+ ${LINK.c} -o ${.TARGET} ${OBJS:.bc=.bc.o}
+
+# The following block is a modified copy of similar blocks in bsd.lib.mk.
+_LIB=${DESTDIR}/${LIBDIR}/${LIBNAME}
+libinstall:: ${_LIB}
+.PRECIOUS: ${_LIB}
+.if ${MKUPDATE} == "no"
+.if !defined(BUILD) && !make(all) && !make(${LIBNAME})
+${_LIB}! .MADE
+.endif
+${_LIB}! ${LIBNAME} __archiveinstall
+.else
+.if !defined(BUILD) && !make(all) && !make(${LIBNAME})
+${_LIB}: .MADE
+.endif
+${_LIB}: ${LIBNAME} __archiveinstall
+.endif
+
+CLEANFILES+= ${LIBNAME} ${OBJS:.bc=.bc.o}
+
+.include <bsd.lib.mk>
#include <magic_def.h>
#include <magic_common.h>
+#include <magic_extern.h>
#include <magic_structs.h>
#include <magic_sentry.h>
#include <magic_selement.h>
magic_type_walk_root((E)->sentry->type, 0, \
(unsigned long) ((char*)(E)->address - \
(char*)(E)->sentry->address), magic_selement_name_print_cb, \
- (void*)(E)); \
+ (void*)__UNCONST((E))); \
} \
else { \
_magic_printf("???"); \
FUNCTION_BLOCK(
/* Magic vars wrappers. */
-PUBLIC void *_magic_vars_addr();
-PUBLIC size_t _magic_vars_size();
+PUBLIC void *_magic_vars_addr(void);
+PUBLIC size_t _magic_vars_size(void);
/* Magic printf. */
PUBLIC int magic_null_printf(const char* format, ...);
const char *function, const int line);
/* Magic utility functions. */
-PUBLIC unsigned long magic_get_sys_pagesize();
+PUBLIC unsigned long magic_get_sys_pagesize(void);
/* Magic lock primitives. */
typedef int (*magic_lock_t)(void*);
/* Initialization functions. */
PUBLIC void magic_init(void);
-PUBLIC void magic_stack_init();
+PUBLIC void magic_stack_init(void);
/* Dfunction functions. */
PUBLIC int magic_check_dfunction(struct _magic_dfunction *ptr, int flags);
-PUBLIC int magic_check_dfunctions();
-PUBLIC int magic_check_dfunctions_safe();
+PUBLIC int magic_check_dfunctions(void);
+PUBLIC int magic_check_dfunctions_safe(void);
PUBLIC void magic_print_dfunction(struct _magic_dfunction *dfunction);
-PUBLIC void magic_print_dfunctions();
-PUBLIC void magic_print_dfunctions_safe();
+PUBLIC void magic_print_dfunctions(void);
+PUBLIC void magic_print_dfunctions_safe(void);
PUBLIC void magic_copy_dfunction(struct _magic_dfunction *dfunction,
struct _magic_dfunction *dst_dfunction);
/* Dsindex functions. */
PUBLIC void magic_print_dsindex(struct _magic_dsindex *dsindex);
-PUBLIC void magic_print_dsindexes();
+PUBLIC void magic_print_dsindexes(void);
/* Dsentry functions. */
PUBLIC int magic_check_dsentry(struct _magic_dsentry *ptr, int flags);
-PUBLIC int magic_check_dsentries();
-PUBLIC int magic_check_dsentries_safe();
+PUBLIC int magic_check_dsentries(void);
+PUBLIC int magic_check_dsentries_safe(void);
PUBLIC void magic_print_dsentry(struct _magic_dsentry *dsentry);
-PUBLIC void magic_print_dsentries();
-PUBLIC void magic_print_dsentries_safe();
+PUBLIC void magic_print_dsentries(void);
+PUBLIC void magic_print_dsentries_safe(void);
PUBLIC void magic_copy_dsentry(struct _magic_dsentry *dsentry,
struct _magic_dsentry *dst_dsentry);
/* Sodesc functions. */
PUBLIC void magic_print_sodesc(struct _magic_sodesc *sodesc);
-PUBLIC void magic_print_sodescs();
+PUBLIC void magic_print_sodescs(void);
/* Dsodesc functions. */
PUBLIC void magic_print_dsodesc(struct _magic_dsodesc *dsodesc);
-PUBLIC void magic_print_dsodescs();
-PUBLIC void magic_print_dsodescs_safe();
+PUBLIC void magic_print_dsodescs(void);
+PUBLIC void magic_print_dsodescs_safe(void);
/* Section functions. */
-PUBLIC void magic_print_sections();
+PUBLIC void magic_print_sections(void);
/* Lookup functions. */
PUBLIC struct _magic_sentry* magic_mempool_sentry_lookup_by_range(void *addr,
struct _magic_dsentry *dsentry_buff);
-PUBLIC struct _magic_dsindex* magic_dsindex_lookup_by_name(char *parent_name,
- char *name);
+PUBLIC struct _magic_dsindex*
+ magic_dsindex_lookup_by_name(const char *parent_name, const char *name);
PUBLIC struct _magic_dsentry*
magic_dsentry_prev_lookup(struct _magic_dsentry* dsentry);
PUBLIC struct _magic_dsentry*
struct _magic_dfunction *dfunction_buff);
PUBLIC struct _magic_function* magic_function_lookup_by_addr(void *addr,
struct _magic_dfunction *dfunction_buff);
-PUBLIC struct _magic_function* magic_function_lookup_by_name(char *parent_name,
- char *name);
-PUBLIC struct _magic_type* magic_type_lookup_by_name(char *name);
+PUBLIC struct _magic_function*
+ magic_function_lookup_by_name(const char *parent_name, const char *name);
+PUBLIC struct _magic_type* magic_type_lookup_by_name(const char *name);
PUBLIC struct _magic_dsodesc* magic_dsodesc_lookup_by_handle(void *handle);
PUBLIC int magic_selement_lookup_by_name(char* name,
_magic_selement_t *selement, struct _magic_dsentry *dsentry_buff);
/* Magic state function functions. */
PUBLIC void magic_print_function(struct _magic_function *function);
-PUBLIC void magic_print_functions();
+PUBLIC void magic_print_functions(void);
/* Magic state function lookup hash functions. */
PUBLIC void magic_function_hash_build(void *buff, size_t buff_size);
/* Magic state type functions. */
PUBLIC void magic_print_type(const struct _magic_type* type);
-PUBLIC void magic_print_types();
+PUBLIC void magic_print_types(void);
PUBLIC void magic_type_str_set_print_style(const int style);
-PUBLIC int magic_type_str_get_print_style();
+PUBLIC int magic_type_str_get_print_style(void);
PUBLIC void magic_type_str_print(const struct _magic_type* type);
PUBLIC void magic_type_values_print(const struct _magic_type* type);
PUBLIC void magic_type_names_print(const struct _magic_type* type);
/* Special convenience types. */
#define MAGIC_TYPE_SPECIAL_INIT(STR) { 0, STR, NULL, 0, STR, 0, 0, 0, 0, 0, 0, \
- 0, MAGIC_TYPE_FUNCTION, MAGIC_TYPE_EXTERNAL, 0 }
+ 0, MAGIC_TYPE_FUNCTION, MAGIC_TYPE_EXTERNAL, 0, NULL }
EXTERN char magic_ne_str[];
EXTERN char magic_enf_str[];
EXTERN char magic_bo_str[];
((V) && !MAGIC_PTR_IS_LIKELY_INT((void*)V))
/* Magic callbacks. */
-typedef int (*magic_cb_sentries_analyze_pre_t)();
+typedef int (*magic_cb_sentries_analyze_pre_t)(void);
PUBLIC void magic_setcb_sentries_analyze_pre(magic_cb_sentries_analyze_pre_t cb);
/* Magic state entry functions. */
PUBLIC int magic_asr_get_padding_size(int region);
PUBLIC void magic_asr_permute_dsentries(struct _magic_dsentry
**first_dsentry_ptr);
-PUBLIC void magic_asr_init();
+PUBLIC void magic_asr_init(void);
#define MAGIC_FUNC PUBLIC USED __attribute__((noinline))
#define MAGIC_FUNC_BODY() __asm__("")
#define MAGIC_HOOK PUBLIC USED __attribute__((always_inline)) inline
-#define MAGIC_MACRO_FUNC __attribute__((always_inline))
+#define MAGIC_MACRO_FUNC static __attribute__((always_inline))
#define TRUE 1
#define FALSE 0
#ifdef __MINIX
#define _MAGIC_CAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (N)+1)
#define MAGIC_CAS(P, O, N) (_MAGIC_CAS(P, O, N) == (N) ? (O) : *(P))
+#define _MAGIC_PCAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (void *)((intptr_t)(N)+1))
+#define MAGIC_PCAS(P, O, N) (_MAGIC_PCAS(P, O, N) == (N) ? (O) : *(P))
#define MAGIC_FAA(P, V) (((*P)+=V)-V)
#define MAGIC_FAS(P, V) (((*P)-=V)+V)
#else
#define MAGIC_CAS(P, O, N) __sync_val_compare_and_swap((P), (O), (N))
+#define MAGIC_PCAS(P, O, N) MAGIC_CAS(P, O, N)
#define MAGIC_FAA(P, V) __sync_fetch_and_add(P, V)
#define MAGIC_FAS(P, V) __sync_fetch_and_sub(P, V)
#endif
typedef long (*magic_eval_func_t) (long arg);
-PUBLIC void magic_eval_init();
+PUBLIC void magic_eval_init(void);
/* Eval frontends. */
PUBLIC int magic_eval_int(char *expr, long *result);
};
/* creates a new variable table (NULL if no memory) */
-struct vartable *create_vartable();
+struct vartable *create_vartable(void);
/* frees a variable table */
void free_vartable(struct vartable *vt);
--- /dev/null
+#ifndef _MAGIC_EXTERN_H
+#define _MAGIC_EXTERN_H
+
+/*
+ * TODO: libsys/sef_llvm.c should include this file, all weak external
+ * function declarations used in that file should be here, and it should
+ * probably be moved into include/minix/.
+ */
+
+#include <stdlib.h>
+#include <minix/sef.h>
+
+void magic_data_init(void);
+void _magic_ds_st_init(void);
+
+void *magic_nested_mmap(void *start, size_t length, int prot, int flags,
+ int fd, off_t offset);
+int magic_nested_munmap(void *start, size_t length);
+
+int _magic_state_transfer(sef_init_info_t *info);
+void _magic_dump_eval_bool(char *expr);
+void *_magic_real_alloc_contig(size_t len, int flags, uint32_t *phys);
+int _magic_real_free_contig(void *addr, size_t len);
+int _magic_real_brk(char *newbrk);
+void* _magic_real_mmap(void *buf, size_t len, int prot, int flags, int fd,
+ off_t offset);
+int _magic_real_munmap(void *addr, size_t length);
+
+#endif /* !_MAGIC_EXTERN_H */
#include <magic.h>
-#define __MA_ARGS__ struct _magic_type *type, char *name, char *parent_name,
+#define __MA_ARGS__ struct _magic_type *type, const char *name, const char *parent_name,
#define __MA_VALUES__ type, name, parent_name,
#define __MA_VALUES_EXT__ MAGIC_VOID_TYPE, MAGIC_ALLOC_EXT_NAME, MAGIC_ALLOC_EXT_PARENT_NAME,
#define __MD_VALUES_DEFAULT__
/* External callbacks. */
-typedef void *(*magic_mem_heap_alloc_cb_t)(size_t size, char *name, char *parent_name);
+typedef void *(*magic_mem_heap_alloc_cb_t)(size_t size, const char *name, const char *parent_name);
typedef void (*magic_mem_create_dsentry_cb_t)(struct _magic_dsentry *dsentry);
typedef int (*magic_mem_heap_free_cb_t)(struct _magic_dsentry *dsentry);
extern magic_mem_heap_alloc_cb_t magic_mem_heap_alloc_cb;
typedef void (*magic_dsentry_cb_t)(struct _magic_dsentry*);
PUBLIC int magic_create_dsentry(struct _magic_dsentry *dsentry,
void *data_ptr, struct _magic_type *type, size_t size, int flags,
- char *name, char *parent_name);
+ const char *name, const char *parent_name);
PUBLIC struct _magic_obdsentry* magic_create_obdsentry(void *data_ptr,
struct _magic_type *type, size_t size, int flags,
- const char *name, char *parent_name);
+ const char *name, const char *parent_name);
PUBLIC int magic_update_dsentry_state(struct _magic_dsentry *dsentry,
unsigned long mstate);
-PUBLIC void magic_free_dead_dsentries();
+PUBLIC void magic_free_dead_dsentries(void);
PUBLIC void magic_destroy_dsentry(struct _magic_dsentry *dsentry,
struct _magic_dsentry *prev_dsentry);
PUBLIC void magic_destroy_dsentry_set_ext_cb(const magic_dsentry_cb_t cb);
PUBLIC int magic_update_dsentry(void* addr, struct _magic_type *type);
PUBLIC void magic_stack_dsentries_create(
struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries,
- /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, char* function_name, char* name, */ ...);
+ /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, const char* function_name, const char* name, */ ...);
PUBLIC void magic_stack_dsentries_destroy(
struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries,
/* struct _magic_dsentry *dsentry, */ ...);
/* Public dfunction functions. */
PUBLIC int magic_create_dfunction(struct _magic_dfunction *dfunction,
void *data_ptr, struct _magic_type *type, int flags,
- char *name, char *parent_name);
+ const char *name, const char *parent_name);
PUBLIC void magic_destroy_dfunction(struct _magic_dfunction *dfunction);
/* Public sodesc functions. */
/* Pass call site information when logging is activated. */
#if (MAGIC_MEM_USAGE_OUTPUT_CTL == 1)
-#define __MDEBUG_ARGS__ char* name
+#define __MDEBUG_ARGS__ const char* name
#else
#define __MDEBUG_ARGS__
#endif
/* Specific wrappers for the memory pool destruction. */
MAGIC_HOOK void magic_mempool_destroy_begin(void* addr, int memory_reuse);
-MAGIC_HOOK void magic_mempool_destroy_end();
+MAGIC_HOOK void magic_mempool_destroy_end(void);
/* Specific wrappers for the memory pool resetting */
MAGIC_HOOK void magic_mempool_reset_begin(void* addr);
/* Generic wrappers for the rest of the memory pool management functions. */
MAGIC_HOOK void magic_mempool_mgmt_begin(void* addr);
-MAGIC_HOOK void magic_mempool_mgmt_end();
+MAGIC_HOOK void magic_mempool_mgmt_end(void);
/* Pool block allocation template function and magic wrapper. */
MAGIC_FUNC void *mempool_block_alloc_template(void* addr, size_t size);
_magic_printf("SENTRY: (id=%5lu, name=%s, parent=%s, address=0x%08x, " \
"flags(RLDCdeTAOSNrwxtpbEZIiP)=" \
"%c%c%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d, type=", \
- (unsigned long) MAGIC_SENTRY_ID(E), (E)->name, \
+ (unsigned long)MAGIC_SENTRY_ID(E), (E)->name, \
MAGIC_SENTRY_PARENT(E), (unsigned) (E)->address, \
MAGIC_STATE_REGION_C(E), MAGIC_STATE_LIBSPEC_C(E), \
MAGIC_STATE_FLAG(E,MAGIC_STATE_DIRTY), \
struct _magic_dsentry *dsentry_buff);
PUBLIC struct _magic_sentry *magic_sentry_lookup_by_addr(void *addr,
struct _magic_dsentry *dsentry_buff);
-PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name(char *parent_name,
- char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff);
+PUBLIC struct _magic_sentry *
+ magic_sentry_lookup_by_name(const char *parent_name, const char *name,
+ _magic_id_t site_id, struct _magic_dsentry *dsentry_buff);
PUBLIC struct _magic_sentry *magic_sentry_lookup_by_range(void *addr,
struct _magic_dsentry *dsentry_buff);
PUBLIC struct _magic_sentry *magic_sentry_lookup_by_min_off_by_n(void *addr,
int flags, long *min_n_ptr, struct _magic_dsentry *dsentry_buff);
-PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(char *string);
+PUBLIC struct _magic_sentry *
+ magic_sentry_lookup_by_string(const char *string);
/* Lookup index functions. */
PUBLIC void magic_sentry_rl_build_index(void *buff, size_t buff_size);
PUBLIC void magic_sentry_hash_build(void *buff, size_t buff_size);
PUBLIC void magic_sentry_hash_destroy(void);
PUBLIC size_t magic_sentry_hash_estimate_buff_size(int sentries_num);
-PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name_hash(char *parent_name,
- char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff);
+PUBLIC struct _magic_sentry *
+ magic_sentry_lookup_by_name_hash(const char *parent_name,
+ const char *name, _magic_id_t site_id,
+ struct _magic_dsentry *dsentry_buff);
PUBLIC void *magic_sentry_hash_alloc(size_t size);
PUBLIC void magic_sentry_hash_dealloc(void *object, size_t size);
PUBLIC struct _magic_sentry_list *magic_sentry_list_lookup_by_name_hash(
- char *parent_name, char *name, _magic_id_t site_id,
+ const char *parent_name, const char *name, _magic_id_t site_id,
struct _magic_dsentry *dsentry_buff);
/* Magic state entry functions. */
PUBLIC int magic_check_sentry(struct _magic_sentry *entry);
-PUBLIC int magic_check_sentries();
+PUBLIC int magic_check_sentries(void);
PUBLIC void magic_print_sentry(struct _magic_sentry* entry);
PUBLIC void magic_print_sentry_abs_name(struct _magic_sentry *sentry);
-PUBLIC void magic_print_sentries();
-PUBLIC void magic_print_nonstr_sentries();
-PUBLIC void magic_print_str_sentries();
+PUBLIC void magic_print_sentries(void);
+PUBLIC void magic_print_nonstr_sentries(void);
+PUBLIC void magic_print_str_sentries(void);
PUBLIC long magic_sentry_get_off_by_n(struct _magic_sentry* sentry,
void *addr, int flags);
/* Magic state type struct. */
struct _magic_type {
_magic_id_t id;
- char *name;
- char **names;
+ const char *name;
+ const char **names;
unsigned num_names;
- char *type_str;
+ const char *type_str;
unsigned size;
unsigned num_child_types;
struct _magic_type **contained_types;
struct _magic_type **compatible_types;
- char **member_names;
+ const char **member_names;
unsigned *member_offsets;
void *value_set;
unsigned type_id;
int flags;
unsigned bit_width;
- void *ext;
+ const void *ext;
};
/* Magic state entry struct. */
struct _magic_sentry {
_magic_id_t id;
- char *name;
+ const char *name;
struct _magic_type *type;
int flags;
void *address;
/* Magic state function struct. */
struct _magic_function {
_magic_id_t id;
- char *name;
+ const char *name;
struct _magic_type *type;
int flags;
void *address;
/* Magic dynamic function struct. */
struct _magic_dfunction {
unsigned long magic_number;
- char *parent_name;
+ const char *parent_name;
struct _magic_function function;
struct _magic_dfunction *prev;
struct _magic_dfunction *next;
/* Magic dynamic state index struct. */
struct _magic_dsindex {
struct _magic_type *type;
- char *name;
- char *parent_name;
+ const char *name;
+ const char *parent_name;
int flags;
};
struct _magic_dsentry {
unsigned long magic_number;
- char *parent_name;
+ const char *parent_name;
char name_ext_buff[MAGIC_DSENTRY_EXT_NAME_BUFF_SIZE];
struct _magic_sentry sentry;
struct _magic_type type;
#define MAGIC_MAX_MEMPOOLS 1024
#define MAGIC_MAX_MEMPOOL_NAME_LEN 32
#define MAGIC_MEMPOOL_NAME_PREFIX "_magic_mempool_"
-EXTERN char *const MAGIC_MEMPOOL_NAME_UNKNOWN;
-EXTERN char *const MAGIC_MEMPOOL_NAME_DETACHED;
+EXTERN const char *const MAGIC_MEMPOOL_NAME_UNKNOWN;
+EXTERN const char *const MAGIC_MEMPOOL_NAME_DETACHED;
struct _magic_mpdesc {
int is_alive;
PUBLIC void st_cb_map_from_parent_union_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
PUBLIC void st_cb_map_child_union_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
PUBLIC void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
+PUBLIC void st_cb_map_child_nonaggr_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
PUBLIC void st_cb_map_child_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
PUBLIC void st_cb_map_child_primitive_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
PUBLIC void st_cb_map_child_ptr_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping);
#define ST_CB_PRINT st_cb_print
-#define ST_TYPE_NAME_KEY(TYPE) ((char *) (TYPE)->ext)
+#define ST_TYPE_NAME_KEY(TYPE) ((const char *) (TYPE)->ext)
#define ST_TYPE_NAME_MATCH(REGISTERED_TYPE_NAME_KEY, KEY) \
(REGISTERED_TYPE_NAME_KEY == KEY)
PRIVATE int transfer_metadata_sentries(st_init_info_t *info,
struct _magic_vars_t *cached_magic_vars,
struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts,
- int *max_buff_sz);
+ size_t *max_buff_sz);
PRIVATE int transfer_metadata_sentry_members(st_init_info_t *info,
struct _magic_sentry *sentry);
PRIVATE int md_transfer_str(st_init_info_t *info, char **str_pt);
#define MD_TRANSFER_STR(INFO, STR_PT) \
do { \
- if (md_transfer_str(INFO, STR_PT)) { \
+ if (md_transfer_str(INFO, __UNCONST(STR_PT))) { \
printf("%s, line %d. md_transfer_str(): ERROR transferring.\n", \
__FILE__, __LINE__); \
return EGENERIC; \
DEFINE_DECL_CALLBACK(int, copy_state_region, (void *state_info_opaque, uint32_t address, size_t size, uint32_t dst_address));
DEFINE_DECL_CALLBACK(void *, alloc_contig, (size_t len, int flags, uint32_t *phys));
DEFINE_DECL_CALLBACK(int, free_contig, (void *ptr, size_t length));
-DEFINE_DECL_CALLBACK(char *, debug_header, (void));
+DEFINE_DECL_CALLBACK(const char *, debug_header, (void));
/* Default callback values. */
#define ST_CB_OS_PANIC_EMPTY NULL
#define ST_SPECIAL_H
/* Public functions for special types and regions. */
-PUBLIC void st_register_typename_key(char *key);
-PUBLIC void st_register_typename_keys(char **keys);
+PUBLIC void st_register_typename_key(const char *key);
+PUBLIC void st_register_typename_keys(const char **keys);
PUBLIC int st_add_special_mmapped_region(void *address, size_t size,
const char* name);
PUBLIC int st_del_special_mmapped_region_by_addr(void *address);
__X(function_hash_buff), __X(function_hash_head)
/* Public utility functions. */
-PUBLIC int st_strcmp_wildcard(char *with_wildcard, char *without_wildcard);
-PUBLIC void st_cb_print(int level, char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info);
+PUBLIC int st_strcmp_wildcard(const char *with_wildcard, const char *without_wildcard);
+PUBLIC void st_cb_print(int level, const char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info);
PUBLIC void st_map_str_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
PUBLIC void st_map_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
PUBLIC void st_lookup_sentry_pair(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr);
PUBLIC int st_transfer_metadata_dsentries(st_init_info_t *info,
struct _magic_vars_t *cached_magic_vars,
struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts,
- int *max_buff_sz, int *dsentries_num);
+ size_t *max_buff_sz, int *dsentries_num);
/* Public functions for state transfer. */
PUBLIC int st_state_transfer(st_init_info_t *info);
PUBLIC void st_set_status_by_state_flags(int status_flags, int status_op, int match_state_flags, int skip_state_flags);
PUBLIC int st_set_status_by_function_ids(int status_flags, int status_op, unsigned long *ids);
PUBLIC int st_set_status_by_sentry_ids(int status_flags, int status_op, unsigned long *ids);
-PUBLIC int st_set_status_by_names(int status_flags, int status_op, char **parent_names, char **names, _magic_id_t *dsentry_site_ids);
+PUBLIC int st_set_status_by_names(int status_flags, int status_op, const char **parent_names, const char **names, _magic_id_t *dsentry_site_ids);
PUBLIC int st_set_status_by_local_addrs(int status_flags, int status_op, void **addrs);
PUBLIC void st_set_status_by_sentry(int status_flags, int status_op, void *cached_sentry);
PUBLIC void st_set_status_by_function(int status_flags, int status_op, void *cached_function);
PUBLIC int st_set_status_by_function_id(int status_flags, int status_op, unsigned long id);
PUBLIC int st_set_status_by_sentry_id(int status_flags, int status_op, unsigned long id);
-PUBLIC int st_set_status_by_name(int status_flags, int status_op, char *parent_name, char *name, _magic_id_t dsentry_site_id);
+PUBLIC int st_set_status_by_name(int status_flags, int status_op, const char *parent_name, const char *name, _magic_id_t dsentry_site_id);
PUBLIC int st_set_status_by_local_addr(int status_flags, int status_op, void *addr);
PUBLIC int st_pair_by_function_ids(unsigned long *cached_ids, unsigned long *local_ids, int status_flags, int status_op);
#define ST_CHECK_INIT() assert(st_init_done && "st_init() should be called first!")
-#define ST_SENTRY_IS_CACHED(E) (MAGIC_SENTRY_ID(E) >= 1 && MAGIC_SENTRY_ID(E) <= st_cached_magic_vars.sentries_num && st_cached_magic_vars.sentries[MAGIC_SENTRY_ID(E)-1].address == (E)->address)
+#define ST_SENTRY_IS_CACHED(E) (MAGIC_SENTRY_ID(E) >= 1 && (int)MAGIC_SENTRY_ID(E) <= st_cached_magic_vars.sentries_num && st_cached_magic_vars.sentries[MAGIC_SENTRY_ID(E)-1].address == (E)->address)
#define ST_GET_CACHED_COUNTERPART(CE,T,CT,LE) do { \
- int i = (CE)->id - 1; \
- assert(i >= 0 && i < st_counterparts.T##_size); \
- LE = st_counterparts.CT[i].counterpart; \
+ int _i = (CE)->id - 1; \
+ assert(_i >= 0 && _i < st_counterparts.T##_size); \
+ LE = st_counterparts.CT[_i].counterpart; \
} while(0)
#define ST_SET_CACHED_COUNTERPART(CE,T,CT,LE) do { \
- int i = (CE)->id - 1; \
- assert(i >= 0 && i < st_counterparts.T##_size); \
- st_counterparts.CT[i].counterpart = LE; \
+ int _i = (CE)->id - 1; \
+ assert(_i >= 0 && _i < st_counterparts.T##_size); \
+ st_counterparts.CT[_i].counterpart = LE; \
} while(0)
#define ST_HAS_CACHED_COUNTERPART(CE,CT) (st_counterparts.CT[(CE)->id - 1].counterpart != NULL)
/* Magic default stubs. */
PUBLIC struct _magic_type magic_default_type = {
- 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_OPAQUE, 0, 0
+ 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_OPAQUE, 0, 0, NULL
};
PUBLIC struct _magic_dsentry magic_default_dsentry = {
"", /* parent_name */
{ 0 }, /* name_ext_buff */
{ 0, "", NULL, MAGIC_STATE_DYNAMIC, NULL, NULL }, /* sentry */
- { 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_ARRAY, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC, 0 }, /* type */
+ { 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_ARRAY, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC, 0, NULL }, /* type */
{ NULL }, /* type_array */
#if MAGIC_DSENTRY_ALLOW_PREV
NULL, /* prev */
};
PUBLIC struct _magic_type magic_default_ret_addr_type = {
- 0, "", NULL, 0, "", sizeof(void*), 1, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_POINTER, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC|MAGIC_TYPE_INT_CAST|MAGIC_TYPE_STRICT_VALUE_SET, 0
+ 0, "", NULL, 0, "", sizeof(void*), 1, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_POINTER, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC|MAGIC_TYPE_INT_CAST|MAGIC_TYPE_STRICT_VALUE_SET, 0, NULL
};
/* Magic code reentrant flag. */
/*===========================================================================*
* magic_assert_failed *
*===========================================================================*/
-PUBLIC void magic_assert_failed(const char *assertion, const char *file,
+PUBLIC void __dead magic_assert_failed(const char *assertion, const char *file,
const char *function, const int line)
{
_magic_printf("Assertion '%s' failed in file %s, function %s(), line %d, pid %d\n",
static struct _magic_type _magic_void_array_type_buff;
static struct _magic_type *_magic_void_array_type_contained_types[1];
static struct _magic_type _magic_ptrint_type_buff;
- static char* _magic_ptrint_type_name = "ptrint";
+ static const char* _magic_ptrint_type_name = "ptrint";
static char _magic_ptrint_type_str_buff[8];
static struct _magic_type _magic_ptrint_array_type_buff;
static struct _magic_type *_magic_ptrint_array_type_contained_types[1];
/*===========================================================================*
* magic_data_init *
*===========================================================================*/
-MAGIC_FUNC void magic_data_init()
+MAGIC_FUNC void magic_data_init(void)
{
MAGIC_FUNC_BODY();
}
/*===========================================================================*
* magic_dsindex_lookup_by_name *
*===========================================================================*/
-PUBLIC struct _magic_dsindex* magic_dsindex_lookup_by_name(char *parent_name,
- char *name)
+PUBLIC struct _magic_dsindex*
+magic_dsindex_lookup_by_name(const char *parent_name, const char *name)
{
int i;
struct _magic_dsindex* index = NULL;
/* O(1) ID lookup for functions. */
#if MAGIC_LOOKUP_FUNCTION
- if(id <= _magic_functions_num) {
+ if((int)id <= _magic_functions_num) {
return &_magic_functions[id - 1];
}
#endif
/*===========================================================================*
* magic_function_lookup_by_name *
*===========================================================================*/
-PUBLIC struct _magic_function* magic_function_lookup_by_name(char *parent_name, char *name)
+PUBLIC struct _magic_function*
+magic_function_lookup_by_name(const char *parent_name, const char *name)
{
int i;
struct _magic_function* entry = NULL;
/*===========================================================================*
* magic_type_lookup_by_name *
*===========================================================================*/
-PUBLIC struct _magic_type* magic_type_lookup_by_name(char *name)
+PUBLIC struct _magic_type* magic_type_lookup_by_name(const char *name)
{
- int i, j;
+ int i;
+ unsigned int j;
struct _magic_type* entry = NULL;
/* Scan all the entries and return the one matching the provided name. */
*===========================================================================*/
PUBLIC void magic_type_names_print(const struct _magic_type* type)
{
- int i;
+ unsigned int i;
for(i=0;i<type->num_names;i++) {
_magic_printf("%s%s", (i==0 ? "" : "|"), type->names[i]);
return FALSE;
}
if(type->num_names > 1) {
- for(i=0; i<type->num_names; i++){
+ for(i=0; (unsigned int)i<type->num_names; i++){
if(strcmp(type->names[i], other_type->names[i])) {
return FALSE;
}
if(type->type_id == MAGIC_TYPE_STRUCT) {
if(flags & MAGIC_TYPE_COMPARE_MEMBER_NAMES) {
- for(i=0; i<type->num_child_types; i++){
+ for(i=0; (unsigned int)i<type->num_child_types; i++){
if(strcmp(type->member_names[i], other_type->member_names[i])) {
return FALSE;
}
}
}
if(flags & MAGIC_TYPE_COMPARE_MEMBER_OFFSETS) {
- for(i=0; i<type->num_child_types; i++){
+ for(i=0; (unsigned int)i<type->num_child_types; i++){
if(type->member_offsets[i] != other_type->member_offsets[i]) {
return FALSE;
}
}
if(flags & MAGIC_SIZE_TYPE_NAMES) {
size += sizeof(type->num_names) + sizeof(type->names) + sizeof(*(type->names))*(type->num_names);
- for(i=0;i<type->num_names;i++) {
+ for(i=0;(unsigned int)i<type->num_names;i++) {
size += strlen(type->names[i])+1;
}
}
int selement_num = 0, sel_analyzed_num = 0;
void* args_array[7];
args_array[0] = (void*) &flags;
- args_array[1] = (void*) &cb;
+ args_array[1] = (void*) __UNCONST(&cb);
args_array[2] = (void*) cb_args;
args_array[3] = (void*) sentry;
args_array[4] = (void*) sentry_stats;
_magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats)
{
const struct _magic_type* ptr_type = selement->type;
- int i, ret = 0;
+ unsigned int i;
+ int ret = 0;
int trg_flags;
const struct _magic_type *trg_type;
_magic_trg_stats_t trg_stats;
#include <magic_analysis.h>
#include <st/state_transfer.h>
-char* sef_sf_typename_keys[] = { "dsi_u", NULL };
+const char* sef_sf_typename_keys[] = { "dsi_u", NULL };
#define dsi_u_idx 0
/*===========================================================================*
/*===========================================================================*
* sef_cb_sf_transfer_typename *
*===========================================================================*/
-int sef_cb_sf_transfer_typename(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) {
+static int sef_cb_sf_transfer_typename(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) {
const char *typename_key = ST_TYPE_NAME_KEY(selement->type);
if(ST_TYPE_NAME_MATCH(sef_sf_typename_keys[dsi_u_idx],typename_key))
{
#ifdef __MINIX
/* FIXME: due to the current linker command line ordering, parts of lib(min)c
- * that are used exclusively by libmagic end up not being instrumented, which
+ * that are used exclusively by libmagicrt end up not being instrumented, which
* then causes problems transferring pointers such as _ctype_tab_ and
* _tolower_tab_. As a temporary workaround, we redefine the macros that use
* those pointers. This code is currently never triggered so it is not
int scantable_ok = 0;
/* table of function names */
-char *functable[] = {
+const char *functable[] = {
"acos", "asin", "atan", "cos", "cosh", "exp", "ln", "log",
"sin", "sinh", "sqr", "sqrt", "tan", "tanh", NULL
};
int same_str(const char *a, const char *b);
int same_str_len(const char *a, const char *b, int len);
-void init_scantable();
+void init_scantable(void);
int tokenize(struct memh *mh, char **string, struct tok **listptr);
int scan_number(char **stringptr, struct val *valptr);
int precedence(struct tok *t);
/**** TOKENIZATION ***/
-void init_scantable() {
+void init_scantable(void) {
int i;
if (scantable_ok) return;
tok->funcid = 0;
/* look for matching function */
for (i = 0; functable[i]; i++) {
- char *fname = functable[i];
- if (same_str_len(name, fname, len) && strlen(fname) == len) {
+ const char *fname = functable[i];
+ if (same_str_len(name, fname, len) && strlen(fname) == (size_t)len) {
tok->funcid = i+1;
break;
}
}
}
-void prt_stk(struct tok *stk, int depth) {
- do { prt_tok(&stk[depth]); } while (depth-- > 0);
- printf("\n");
-}
-
void prt_lst(struct tok *t) {
for (; t; t=t->next) prt_tok(t);
printf("\n");
}
-/* variables dumper */
-void dump_vars(struct vartable *vt) {
- struct var *v;
- if (!vt) printf("no vars\n");
- else for (v=vt->first; v; v=v->next) {
- if (v->val.type == T_INT)
- printf("'%s'=%ld ", v->name, v->val.ival);
- else
- printf("'%s'=%g ", v->name, v->val.rval);
- }
- printf("\n");
-}
#else
void prt_tok(struct tok *t) {}
-void prt_stk(struct tok *stk, int depth) {}
void prt_lst(struct tok *t) {}
-void dump_vars(struct vartable *vt) {}
#endif
PUBLIC THREAD_LOCAL short magic_mempool_mgmt_active_level = 0;
PUBLIC THREAD_LOCAL short magic_mempool_ids[MAGIC_MEMPOOL_MAX_FUNC_RECURSIONS];
-char* const MAGIC_MEMPOOL_NAME_UNKNOWN = "_magic_mempool_unknown#";
-char* const MAGIC_MEMPOOL_NAME_DETACHED = "_magic_mempool_detached#";
+const char* const MAGIC_MEMPOOL_NAME_UNKNOWN = "_magic_mempool_unknown#";
+const char* const MAGIC_MEMPOOL_NAME_DETACHED = "_magic_mempool_detached#";
__attribute__((weak)) int magic_mempool_allow_reset = 1;
__attribute__((weak)) int magic_mempool_allow_reuse = 1;
/*===========================================================================*
* magic_mempool_alloc_id *
*===========================================================================*/
-MAGIC_MACRO_FUNC short magic_mempool_alloc_id()
+MAGIC_MACRO_FUNC short magic_mempool_alloc_id(void)
{
short i, id = -1;
/*===========================================================================*
* magic_mempool_reset *
*===========================================================================*/
-MAGIC_MACRO_FUNC void magic_mempool_reset(char* mempool_name, int reset_name)
+MAGIC_MACRO_FUNC void magic_mempool_reset(const char* mempool_name, int reset_name)
{
struct _magic_dsentry *prev_dsentry, *dsentry, *block_dsentry;
struct _magic_sentry* sentry;
if (sentry->name == mempool_name) {
block_dsentry = MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry);
if (block_dsentry != NULL) {
- struct _magic_dsentry *tmp_block_dsentry = MAGIC_CAS(&MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry), block_dsentry, NULL);
+ struct _magic_dsentry *tmp_block_dsentry =
+ MAGIC_PCAS(&MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry), block_dsentry, NULL);
assert(tmp_block_dsentry == block_dsentry && "New blocks have been allocated from a reseted mempool!");
}
if (reset_name) {
- char *tmp_name = MAGIC_CAS(&sentry->name, mempool_name, MAGIC_MEMPOOL_NAME_UNKNOWN);
+ const char *tmp_name =
+ MAGIC_PCAS(&sentry->name, mempool_name, MAGIC_MEMPOOL_NAME_UNKNOWN);
assert(tmp_name == mempool_name && "The name of the mempool has changed while being reseted!");
}
MAGIC_MEM_DEBUG_RESET((char*)dsentry);
/*===========================================================================*
* magic_mempool_dsentry_set_name *
*===========================================================================*/
-MAGIC_MACRO_FUNC void magic_mempool_dsentry_set_name(struct _magic_dsentry* dsentry, char* name)
+MAGIC_MACRO_FUNC void magic_mempool_dsentry_set_name(struct _magic_dsentry* dsentry,
+ const char* name)
{
- char *old_name, *ret;
+ const char *old_name, *ret;
if ((name == MAGIC_MEMPOOL_NAME_UNKNOWN) || (name == MAGIC_MEMPOOL_NAME_DETACHED)) {
do {
/*===========================================================================*
* magic_mempool_dsentry_update *
*===========================================================================*/
-MAGIC_MACRO_FUNC void magic_mempool_dsentry_update(struct _magic_dsentry* dsentry, char* name)
+MAGIC_MACRO_FUNC void magic_mempool_dsentry_update(struct _magic_dsentry* dsentry,
+ const char* name)
{
struct _magic_sentry* sentry = MAGIC_DSENTRY_TO_SENTRY(dsentry);
struct _magic_dsentry* next_mempool_dsentry;
*===========================================================================*/
PUBLIC int magic_create_dsentry(struct _magic_dsentry *dsentry,
void *data_ptr, struct _magic_type *type, size_t size, int flags,
- char *name, char *parent_name)
+ const char *name, const char *parent_name)
{
/* This function does not require any dsentry locking. */
struct _magic_sentry *sentry = MAGIC_DSENTRY_TO_SENTRY(dsentry);
*===========================================================================*/
PUBLIC struct _magic_obdsentry* magic_create_obdsentry(void *data_ptr,
struct _magic_type *type, size_t size, int flags,
- const char *name, char *parent_name)
+ const char *name, const char *parent_name)
{
struct _magic_obdsentry *obdsentry = NULL;
int i, ret;
*===========================================================================*/
PUBLIC void magic_stack_dsentries_create(
struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries,
- /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, char* function_name, char* name, */ ...)
+ /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, const char* function_name, const char* name, */ ...)
{
int i;
struct _magic_dsentry *dsentry;
struct _magic_type *type;
void* data_ptr;
- char* function_name;
- char* name;
+ const char* function_name;
+ const char* name;
char *min_data_ptr = NULL, *max_data_ptr = NULL;
va_list va;
dsentry = va_arg(va, struct _magic_dsentry *);
type = va_arg(va, struct _magic_type *);
data_ptr = va_arg(va, void *);
- function_name = va_arg(va, char *);
- name = va_arg(va, char *);
+ function_name = va_arg(va, const char *);
+ name = va_arg(va, const char *);
if (i == num_dsentries - 1) {
/* Return address. */
int *value_set = (void*) type;
*===========================================================================*/
PUBLIC int magic_create_dfunction(struct _magic_dfunction *dfunction,
void *data_ptr, struct _magic_type *type, int flags,
- char *name, char *parent_name)
+ const char *name, const char *parent_name)
{
struct _magic_function *function = MAGIC_DFUNCTION_TO_FUNCTION(dfunction);
alloc_length = length + (length % page_size == 0 ? 0 : page_size-(length % page_size));
data_ptr = vm_map_cacheblock(dev, dev_offset, ino, ino_offset, flags, length);
if (data_ptr != MAP_FAILED) {
- ptr = mmap(data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- MAGIC_MEM_PRINTF("vm_map_cacheblock: ptr = mmap(start, length, prot, flags, fd, offset) <-> 0x%08x = mmap(0x%08x, %d, 0x%08x, 0x%08x, %d, %d)\n", (unsigned) ptr, data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- assert(ptr == data_ptr-page_size); /* Ensured by VM. */
+ ptr = mmap((char *)data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ MAGIC_MEM_PRINTF("vm_map_cacheblock: ptr = mmap(start, length, prot, flags, fd, offset) <-> 0x%08x = mmap(0x%08x, %d, 0x%08x, 0x%08x, %d, %d)\n", (unsigned) ptr, (char *)data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ assert(ptr == (char *)data_ptr-page_size); /* Ensured by VM. */
aligned_ptr = ptr;
ptr = ((char*)ptr) + page_size - MAGIC_SIZE_TO_REAL(0);
}
{
int i,j;
void *start_address, *end_address;
- void* linker_vars[] = { MAGIC_LINKER_VAR_NAMES };
+ const char* linker_vars[] = { MAGIC_LINKER_VAR_NAMES };
/* Init sentry and data range. */
MAGIC_RANGE_INIT(magic_data_range);
token_buff[len] = '\0';
if (token_start == name) {
struct _magic_sentry *sentry;
- char *sentry_parent_name = "", *sentry_name = NULL;
+ const char *sentry_parent_name = "", *sentry_name = NULL;
char *delim = NULL;
_magic_id_t dsentry_site_id = MAGIC_DSENTRY_SITE_ID_NULL;
if (!(delim = strchr(token_buff, MAGIC_DSENTRY_ABS_NAME_SEP[0]))) {
case MAGIC_TYPE_STRUCT:
case MAGIC_TYPE_UNION:
- for(i=0;i<parent_type->num_child_types;i++) {
+ for(i=0; (unsigned int)i<parent_type->num_child_types;i++) {
if(!strcmp(parent_type->member_names[i], name)) {
child_num = i;
break;
}
}
- if(i == parent_type->num_child_types) {
+ if((unsigned int)i == parent_type->num_child_types) {
return NULL;
}
break;
/* O(1) ID lookup for sentries. */
#if MAGIC_LOOKUP_SENTRY
- if (id <= _magic_sentries_num) {
+ if ((int)id <= _magic_sentries_num) {
return &_magic_sentries[id - 1];
}
#endif
/*===========================================================================*
* magic_sentry_lookup_by_name *
*===========================================================================*/
-PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name(char *parent_name,
- char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff)
+PUBLIC struct _magic_sentry *
+ magic_sentry_lookup_by_name(const char *parent_name, const char *name,
+ _magic_id_t site_id, struct _magic_dsentry *dsentry_buff)
{
int i;
struct _magic_sentry *entry = NULL;
/*===========================================================================*
* magic_sentry_lookup_by_string *
*===========================================================================*/
-PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(char *string)
+PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(const char *string)
{
int i;
struct _magic_sentry *entry = NULL;
* magic_sentry_lookup_by_name_hash *
*===========================================================================*/
PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name_hash(
- char *parent_name, char *name, _magic_id_t site_id,
+ const char *parent_name, const char *name, _magic_id_t site_id,
struct _magic_dsentry *dsentry_buff)
{
/*
* magic_sentry_list_lookup_by_name_hash *
*===========================================================================*/
PUBLIC struct _magic_sentry_list *magic_sentry_list_lookup_by_name_hash(
- char *parent_name, char *name, _magic_id_t site_id,
+ const char *parent_name, const char *name, _magic_id_t site_id,
struct _magic_dsentry *dsentry_buff)
{
/*
#define DO_SKIP_INVARIANTS_VIOLATIONS 0
PRIVATE st_alloc_pages *st_alloc_pages_current = NULL;
-PRIVATE int st_alloc_buff_available = 0;
+PRIVATE size_t st_alloc_buff_available = 0;
PRIVATE char *st_alloc_buff_pt = NULL;
PRIVATE char *st_pre_allocated_page_pt = NULL;
PRIVATE struct _magic_dsentry *st_dsentry_buff = NULL;
/* Typedef registration and lookup */
-int st_strcmp_wildcard(char *with_wildcard, char *without_wildcard)
+int st_strcmp_wildcard(const char *with_wildcard, const char *without_wildcard)
{
/* Note: this implementation only supports basic regexes with a '*'
* at the beginning or the end of the string.
*/
- char *star = strchr(with_wildcard, '*');
+ const char *star = strchr(with_wildcard, '*');
if (star) {
if (star == with_wildcard) {
size_t len = strlen(with_wildcard+1);
size_t len_without_wildcard = strlen(without_wildcard);
- char *match_without_wildcard = without_wildcard+
+ const char *match_without_wildcard = without_wildcard+
len_without_wildcard-len;
if (match_without_wildcard < without_wildcard) {
return -1;
return strcmp(with_wildcard, without_wildcard);
}
-char *st_typename_noxfers[] = { ST_TYPENAME_NO_TRANSFER_NAMES, NULL };
-char *st_typename_ixfers[] = { ST_TYPENAME_IDENTITY_TRANSFER_NAMES, NULL };
-char *st_typename_cixfers[] = { ST_TYPENAME_CIDENTITY_TRANSFER_NAMES, NULL };
-char *st_typename_pxfers[] = { ST_TYPENAME_PTR_TRANSFER_NAMES, NULL };
-char *st_typename_sxfers[] = { ST_TYPENAME_STRUCT_TRANSFER_NAMES, NULL };
-char *st_sentryname_ixfers[] = { ST_SENTRYNAME_IDENTITY_TRANSFER_NAMES, NULL };
-char *st_sentryname_cixfers[] = { ST_SENTRYNAME_CIDENTITY_TRANSFER_NAMES, NULL};
-char *st_sentryname_pxfers[] = { ST_SENTRYNAME_PTR_TRANSFER_NAMES, NULL };
+const char *st_typename_noxfers[] = { ST_TYPENAME_NO_TRANSFER_NAMES, NULL };
+const char *st_typename_ixfers[] = { ST_TYPENAME_IDENTITY_TRANSFER_NAMES, NULL };
+const char *st_typename_cixfers[] = { ST_TYPENAME_CIDENTITY_TRANSFER_NAMES, NULL };
+const char *st_typename_pxfers[] = { ST_TYPENAME_PTR_TRANSFER_NAMES, NULL };
+const char *st_typename_sxfers[] = { ST_TYPENAME_STRUCT_TRANSFER_NAMES, NULL };
+const char *st_sentryname_ixfers[] = { ST_SENTRYNAME_IDENTITY_TRANSFER_NAMES, NULL };
+const char *st_sentryname_cixfers[] = { ST_SENTRYNAME_CIDENTITY_TRANSFER_NAMES, NULL};
+const char *st_sentryname_pxfers[] = { ST_SENTRYNAME_PTR_TRANSFER_NAMES, NULL };
/* Exclude stack references in addition to the default sentry names from state transfer. */
-char *st_sentryname_noxfers[] = {
+const char *st_sentryname_noxfers[] = {
ST_SENTRYNAME_NO_TRANSFER_NAMES,
#define __X(R) #R /* Stringify the symbol names. */
ST_STACK_REFS_INT_LIST,
#endif
#undef __X
NULL };
-char *st_sentryname_noxfers_mem[] = { ST_SENTRYNAME_NO_TRANSFER_MEM_NAMES, NULL };
+const char *st_sentryname_noxfers_mem[] = { ST_SENTRYNAME_NO_TRANSFER_MEM_NAMES, NULL };
/* Exclude the data segments of certain libs from state transfer. */
-char *st_dsentry_lib_noxfer[] = {
+const char *st_dsentry_lib_noxfer[] = {
#ifdef ST_DSENTRYLIB_NO_TRANSFER_NAMES
ST_DSENTRYLIB_NO_TRANSFER_NAMES,
#endif
NULL };
-char *st_typename_key_registrations[MAX_NUM_TYPENAMES];
+const char *st_typename_key_registrations[MAX_NUM_TYPENAMES];
-int is_typename(char *search_key, struct _magic_type *type)
+static int is_typename(const char *search_key, struct _magic_type *type)
{
- int i;
+ unsigned int i;
/* We can't use a cached lookup result */
if (!st_strcmp_wildcard(search_key, type->name)) {
/* The name matches */
return FALSE;
}
-PUBLIC void st_register_typename_key(char *key)
+PUBLIC void st_register_typename_key(const char *key)
{
int i, is_registered = FALSE;
for(i = 0 ; i < MAX_NUM_TYPENAMES ; i++) {
assert(is_registered && "Error, number of typename registrations > MAX_NUM_TYPENAMES.\n");
}
-PUBLIC void st_register_typename_keys(char **keys)
+PUBLIC void st_register_typename_keys(const char **keys)
{
int i = 0;
while (keys[i] != NULL) {
PRIVATE void set_typename_key(struct _magic_type *type)
{
- char **registration = st_typename_key_registrations;
+ const char **registration = st_typename_key_registrations;
while (*registration != NULL) {
if (is_typename(*registration, type)) {
}
}
-PUBLIC void register_typenames()
+PRIVATE void register_typenames(void)
{
int i;
}
-PRIVATE INLINE void register_typenames_and_callbacks()
+PRIVATE INLINE void register_typenames_and_callbacks(void)
{
static int st_is_registered = FALSE;
}
-PUBLIC int st_type_name_match_any(char **registered_type_name_keys,
- char *key)
+PRIVATE int st_type_name_match_any(const char **registered_type_name_keys,
+ const char *key)
{
int i = 0;
while (registered_type_name_keys[i] != NULL) {
return FALSE;
}
-PUBLIC int st_sentry_name_match_any(char **sentry_wildcard_names,
- char *name)
+PRIVATE int st_sentry_name_match_any(const char **sentry_wildcard_names,
+ const char *name)
{
int i = 0;
while (sentry_wildcard_names[i] != NULL) {
return FALSE;
}
-PUBLIC int st_dsentry_parent_name_match_any(char **wildcard_names,
- char *name)
+PRIVATE int st_dsentry_parent_name_match_any(const char **wildcard_names,
+ const char *name)
{
int i = 0;
while (wildcard_names[i] != NULL) {
}
/* Utilities. */
-PUBLIC void st_cb_print(int level, char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info)
+PUBLIC void st_cb_print(int level, const char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info)
{
if (ST_CB_PRINT_LEVEL(level)) {
_magic_printf("[%s] %s. Current state element:\n",
else if(trg_extf_flags & ST_ON_PTRXFER_SET_DEFAULT) {
ST_CB_PRINT(ST_CB_DBG, "ptr lookup results in forcefully setting ptr to default value", selement, sel_analyzed, sel_stats, cb_info);
if (trg_flags & MAGIC_STATE_STRING) {
- *((char**)local_selement_address) = "";
+ *((char**)local_selement_address) = __UNCONST("");
}
else {
*local_selement_address = NULL;
PUBLIC int st_cb_transfer_sentry_default(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info)
{
- char *sentry_name = selement->sentry->name;
+ const char *sentry_name = selement->sentry->name;
#if ST_ASSUME_RAW_COPY_BEFORE_TRANSFER
if (MAGIC_STATE_FLAGS(selement->sentry, MAGIC_STATE_DYNAMIC)) {
PUBLIC int st_cb_transfer_typename_default(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info)
{
- char *typename_key = ST_TYPE_NAME_KEY(selement->type);
+ const char *typename_key = ST_TYPE_NAME_KEY(selement->type);
if (ST_TYPE_NAME_MATCH_ANY(st_typename_ixfers, typename_key)) {
return transfer_identity_sel_cb(selement, sel_analyzed, sel_stats, cb_info);
}
local_sel_analyzed->u.ptr.num_trg_types = 1;
}
else {
- int i;
+ unsigned int i;
void *address = NULL;
local_sel_analyzed->u.ptr.num_trg_types = 0;
for (i = cached_sel_analyzed->u.ptr.first_legal_trg_type ; i < cached_sel_analyzed->u.ptr.num_trg_types ; i++) {
PUBLIC void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping)
{
- int i;
- char *cached_member_name;
+ unsigned int i;
+ const char *cached_member_name;
/* Match struct/unions with struct/unions. */
assert(cached_selement->parent_type->type_id == MAGIC_TYPE_STRUCT || cached_selement->parent_type->type_id == MAGIC_TYPE_UNION);
if (local_selement->parent_type->type_id != MAGIC_TYPE_STRUCT && local_selement->parent_type->type_id != MAGIC_TYPE_UNION) {
PUBLIC void st_cb_map_child_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping)
{
- int i, j;
+ unsigned int i, j;
const struct _magic_type *cached_type = cached_selement->type;
const struct _magic_type *local_type = local_selement->type;
assert(cached_type->type_id == MAGIC_TYPE_STRUCT || cached_type->type_id == MAGIC_TYPE_UNION);
return OK;
}
+#if APPARENTLY_UNUSED
PUBLIC void st_set_policies(int policies)
{
st_policies = policies;
}
+#endif
#if MAGIC_LOOKUP_SENTRY_ALLOW_RANGE_INDEX
PRIVATE void st_init_rl_index(st_init_info_t *info,
#define __X(x) offsetof(struct _magic_vars_t, x)
size_t offset_list[] = { ST_MAGIC_VARS_PTR_CLEAR_LIST };
#undef __X
- int i;
+ unsigned int i;
for (i = 0 ; i < sizeof(offset_list) / sizeof(size_t) ; i++)
*((void **)(((char *)magic_vars) + offset_list[i])) = NULL;
PUBLIC int st_init(st_init_info_t *info)
{
- int r, max_buff_sz = 0, dsentries_num;
+ size_t max_buff_sz = 0;
+ int r, dsentries_num;
int allow_unpaired_types = TRUE;
if (st_init_done) {
return OK;
else {
int i;
for(i = 0 ; i < st_cached_magic_vars.sentries_num ; i++) {
- struct _magic_sentry *sentry = &st_cached_magic_vars.sentries[i];
+ sentry = &st_cached_magic_vars.sentries[i];
if (MAGIC_SENTRY_IS_STRING(sentry) && !strcmp(st_lookup_str_local_data(sentry), (char*)local_sentry->address)) {
cached_sentry = sentry;
break;
assert((cached_function == NULL) ^ (local_function == NULL));
if (cached_function) {
- if (cached_function->id - 1 >= st_counterparts.functions_size) {
+ if ((int)cached_function->id - 1 >= st_counterparts.functions_size) {
/*
* Try to check if this is a function
* from an external shared object.
PUBLIC int st_sentry_equals(struct _magic_sentry *cached_sentry, struct _magic_sentry *local_sentry)
{
- char *cached_parent_name = "", *local_parent_name = "";
+ const char *cached_parent_name = "", *local_parent_name = "";
int cached_flags = MAGIC_STATE_FLAGS_TO_NONEXTF(cached_sentry->flags) & (~MAGIC_STATE_ADDR_NOT_TAKEN);
int local_flags = MAGIC_STATE_FLAGS_TO_NONEXTF(local_sentry->flags) & (~MAGIC_STATE_ADDR_NOT_TAKEN);
if (cached_flags != local_flags) {
}
PUBLIC int st_set_status_by_names(int status_flags, int status_op,
- char **parent_names, char **names, _magic_id_t *dsentry_site_ids)
+ const char **parent_names, const char **names,
+ _magic_id_t *dsentry_site_ids)
{
int r, i = 0;
while (names[i] != NULL) {
}
PUBLIC int st_set_status_by_name(int status_flags, int status_op,
- char *parent_name, char *name, _magic_id_t dsentry_site_id)
+ const char *parent_name, const char *name, _magic_id_t dsentry_site_id)
{
struct _magic_sentry *cached_sentry = NULL;
struct _magic_function *cached_function = NULL;
PUBLIC int st_set_status_by_local_addr(int status_flags, int status_op,
void *addr)
{
- char *parent_name, *name;
+ const char *parent_name, *name;
_magic_id_t dsentry_site_id = MAGIC_DSENTRY_SITE_ID_NULL;
struct _magic_sentry *sentry = NULL;
struct _magic_function *function = NULL;
if (type->names != NULL && type->num_names > 0) {
/* transfer array of name pointers */
MD_TRANSFER(info, type->names, (void **)&type->names, type->num_names * sizeof(char *));
- for (i = 0 ; i < type->num_names ; i++) {
+ for (i = 0 ; (unsigned int)i < type->num_names ; i++) {
/* transfer individual name */
MD_TRANSFER_STR(info, &type->names[i]);
}
PRIVATE int transfer_metadata_sentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars
, struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts
- , int *max_buff_sz)
+ , size_t *max_buff_sz)
{
int i;
}
PUBLIC int st_transfer_metadata_dsentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars
- , struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, int *max_buff_sz, int *dsentries_num)
+ , struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, size_t *max_buff_sz, int *dsentries_num)
{
struct _magic_dsentry **dsentry_ptr;
{
struct _magic_dsentry *local_dsentry = NULL;
struct _magic_sentry *cached_sentry = NULL;
- char *name, *parent_name;
+ const char *name, *parent_name;
struct _magic_type *type;
int region;
size_t size;
MAGIC_DSODESC_LOCK();
MAGIC_SODESC_ITER(_magic_first_sodesc, sodesc,
if (!strcmp(cached_dsentry->parent_name, sodesc->lib.name)) {
- parent_name = (char *)sodesc->lib.name;
+ parent_name = (const char *)sodesc->lib.name;
found_parent_name = 1;
break;
}
if (!found_parent_name) {
MAGIC_DSODESC_ITER(_magic_first_dsodesc, dsodesc,
if (!strcmp(cached_dsentry->parent_name, dsodesc->lib.name)) {
- parent_name = (char *)dsodesc->lib.name;
+ parent_name = (const char *)dsodesc->lib.name;
found_parent_name = 1;
break;
}
#include <st/state_transfer.h>
#include <st/special.h>
-void *_magic_real_alloc_contig(size_t len, int flags, uint32_t *phys);
-int _magic_real_free_contig(void *addr, size_t len);
-
-
-static char* _magic_generic_debug_header(void)
+static const char* _magic_generic_debug_header(void)
{
- return (char*) "[DEBUG]";
-}
-
-/*===========================================================================*
- * _magic_state_transfer *
- *===========================================================================*/
-int _magic_state_transfer(sef_init_info_t *info)
-{
- st_init_info_t st_info;
- /* Convert SEF flags into ST flags. */
- st_info.flags = 0;
- if (info->flags & SEF_LU_ASR)
- st_info.flags |= ST_LU_ASR;
- if (info->flags & SEF_LU_NOMMAP)
- st_info.flags |= ST_LU_NOMMAP;
- st_info.init_buff_start = info->init_buff_start;
- st_info.init_buff_cleanup_start = info->init_buff_cleanup_start;
- st_info.init_buff_len = info->init_buff_len;
- /* Transmit sef_init_info opaquely to the state transfer framework. */
- st_info.info_opaque = (void *) (info);
- /* Add the OS callbacks. */
- st_info.st_cbs_os.panic = &(panic); /* panic() callback. */
- st_info.st_cbs_os.old_state_table_lookup = &(sef_old_state_table_lookup_opaque); /* old_state_table_lookup() callback. */
- st_info.st_cbs_os.copy_state_region = &(sef_copy_state_region_opaque); /* copy_state_region() callback. */
- st_info.st_cbs_os.alloc_contig = &(_magic_real_alloc_contig); /* alloc_contig() callback. */
- st_info.st_cbs_os.free_contig = &(_magic_real_free_contig); /* free_contig() callback. */
- st_info.st_cbs_os.debug_header = &(_magic_generic_debug_header); /* debug_header() callback. */
- return st_state_transfer(&st_info);
+ return "[DEBUG]";
}
/*===========================================================================*
{
return magic_real_munmap(addr, length);
}
+
+/*===========================================================================*
+ * _magic_state_transfer *
+ *===========================================================================*/
+int _magic_state_transfer(sef_init_info_t *info)
+{
+ st_init_info_t st_info;
+ /* Convert SEF flags into ST flags. */
+ st_info.flags = 0;
+ if (info->flags & SEF_LU_ASR)
+ st_info.flags |= ST_LU_ASR;
+ if (info->flags & SEF_LU_NOMMAP)
+ st_info.flags |= ST_LU_NOMMAP;
+ st_info.init_buff_start = info->init_buff_start;
+ st_info.init_buff_cleanup_start = info->init_buff_cleanup_start;
+ st_info.init_buff_len = info->init_buff_len;
+ /* Transmit sef_init_info opaquely to the state transfer framework. */
+ st_info.info_opaque = (void *) (info);
+ /* Add the OS callbacks. */
+ st_info.st_cbs_os.panic = &(panic); /* panic() callback. */
+ st_info.st_cbs_os.old_state_table_lookup = &(sef_old_state_table_lookup_opaque); /* old_state_table_lookup() callback. */
+ st_info.st_cbs_os.copy_state_region = &(sef_copy_state_region_opaque); /* copy_state_region() callback. */
+ st_info.st_cbs_os.alloc_contig = &(_magic_real_alloc_contig); /* alloc_contig() callback. */
+ st_info.st_cbs_os.free_contig = &(_magic_real_free_contig); /* free_contig() callback. */
+ st_info.st_cbs_os.debug_header = &(_magic_generic_debug_header); /* debug_header() callback. */
+ return st_state_transfer(&st_info);
+}
+
+
echo "TOOLDIR=\"${MINIX_TOOLS_DIR}/bin\"" >> ${MINIX_LLVM_DIR}/common.inc
fi
-STATIC_DIR="${MINIX_LLVM_DIR}/static"
-
-if [ ! -f ${STATIC_DIR}/Makefile.common.inc ]; then
- echo "# This file was automatically generated by configure.llvm" > ${STATIC_DIR}/Makefile.common.inc
- echo "_MINIX_ARCH=${ARCH}" >> ${STATIC_DIR}/Makefile.common.inc
- echo "_MINIX_ROOT=${MINIX_ROOT_1}" >> ${STATIC_DIR}/Makefile.common.inc
- echo "_MINIX_TOOLS_DIR=${MINIX_TOOLS_DIR}" >> ${STATIC_DIR}/Makefile.common.inc
-fi
-
. ${MINIX_LLVM_DIR}/minix.inc
# Set default values for essential variables
: ${JOBS=1}
: ${GEN_GOLD_PLUGIN="yes"}
: ${REBUILD_MINIX="yes"}
-: ${GEN_STATIC_MAGIC="yes"}
########################
# Generate Gold Plugin
########################
# Build Minix
########################
-export BUILDVARS=$(echo "${BUILDVARS} -V MKBITCODE=yes"| sed -e 's,-V MKMAGIC=yes,-V DBG=-g -V STRIPFLAG=-s -V CPPFLAGS=-D_MINIX_MAGIC=1,')
+export BUILDVARS=$(echo "${BUILDVARS} -V MKBITCODE=yes"| sed -e 's,-V MKMAGIC=yes,-V MKMAGIC=yes -V DBG=-g -V STRIPFLAG=-s -V CPPFLAGS=-D_MINIX_MAGIC=1,')
if [ "${REBUILD_MINIX}" == "yes" ]; then
echo "Building Minix: NO"
fi
-if [ "${GEN_STATIC_MAGIC}" == "yes" ]; then
- echo "Building static magic library..."
- cd ${STATIC_DIR}/magic
- make install || EXITCODE=1
- cd ${MYPWD}
- if [ "$EXITCODE" != "0" ]; then
- echo "Error: Failed building static magic library."
- exit $EXITCODE
- else
- echo "Completed building static magic library."
- fi
-else
- echo "Building static magic library: NO"
-fi
-
exit $EXITCODE
+++ /dev/null
-#ifndef _MAGIC_RCU_H
-#define _MAGIC_RCU_H
-
-void magic_rcu_quiescent_begin();
-void magic_rcu_quiescent_end();
-void magic_rcu_quiescent_state();
-void magic_rcu_quiescent_state_start();
-void magic_rcu_quiescent_state_end();
-
-void magic_rcu_init();
-void magic_synchronize_rcu();
-
-void magic_rcu_read_lock();
-void magic_rcu_read_unlock();
-
-#define magic_rcu_has_atomic_quiescent_state() magic_rcu_has_atomic_qs
-extern int magic_rcu_has_atomic_qs;
-
-#endif /* _MAGIC_RCU_H */
local LIBS=""
for a in $*
do
- LIBS="$LIBS `find $INSTALL_DIR -maxdepth 1 -name ${a}\*.bcc | xargs`"
+ LIBS="$LIBS `find $INSTALL_DIR -maxdepth 2 -name ${a}\*.bcc | xargs`"
done
echo $LIBS
}
function find_static_libs()
{
- local stat_libs_llvmapps=
local stat_libs_minix=
- local install_dir_save=
- stat_libs_llvmapps=`build_llvm_libs $*`
-
- install_dir_save=${INSTALL_DIR}
-
- INSTALL_DIR=${MINIX_LLVM_BIN_DIR}
stat_libs_minix=`build_llvm_libs $*`
- INSTALL_DIR=${install_dir_save}
-
- echo "${stat_libs_llvmapps} ${stat_libs_minix}"
+ echo "${stat_libs_minix}"
}
#Make sure we are running from the right directory
. ${MINIX_LLVM_DIR}/minix.inc
+INSTALL_DIR=${DESTDIR}/minix/lib
+
echo ".so and .bcc binaries of LLVM passes set to be picked up from:"
echo " ${INSTALL_DIR}"
-echo " and"
-echo " ${MINIX_LLVM_BIN_DIR}"
echo
# Picking up the selected modules
+++ /dev/null
-# THIS FILE IS AN EDITED VERSION OF A FILE GENERATED BY LLVM-APPS
-
-###########################################################
-# llvm-apps settings for Minix binary instrumentation
-###########################################################
-_MINIX_LLVM_DIR=$(_MINIX_ROOT)/minix/llvm
-_MINIX_OBJ_DIR=$(_MINIX_ROOT)/../obj.$(_MINIX_ARCH)
-_MINIX_OBJ_LLVM_DIR=$(_MINIX_ROOT)/../obj_llvm.$(_MINIX_ARCH)
-_MINIX_SYSROOT=$(_MINIX_OBJ_DIR)/destdir.$(_MINIX_ARCH)
-
-###########################################################
-# Main configuration (override in common.overrides.*inc to match your settings)
-###########################################################
-HAVE_LLVM=1
-LLVMBASEDIR=$(_MINIX_LLVM_DIR)
-LLVMPREFIX=$(_MINIX_OBJ_LLVM_DIR)/Release+Asserts
-LLVM_TWOSTEP_LINKING_WITH_GOLD=0
-LLVM_TWOSTEP_LINKING_WITH_GOLD_USES_LLC=0
-LLVM_OUTPUT_TRG_DIR=
-LLVM_CAP_ALL=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE,CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_DAC_READ_SEARCH,CAP_FOWNER,CAP_FSETID,CAP_IPC_LOCK,CAP_IPC_OWNER,CAP_KILL,CAP_LEASE,CAP_LINUX_IMMUTABLE,CAP_MAC_ADMIN,CAP_MAC_OVERRIDE,CAP_MKNOD,CAP_NET_ADMIN,CAP_NET_BIND_SERVICE,CAP_NET_BROADCAST,CAP_NET_RAW,CAP_SETGID,CAP_SETFCAP,CAP_SETPCAP,CAP_SETUID,CAP_SYS_ADMIN,CAP_SYS_BOOT,CAP_SYS_CHROOT,CAP_SYS_MODULE,CAP_SYS_NICE,CAP_SYS_PACCT,CAP_SYS_PTRACE,CAP_SYS_RAWIO,CAP_SYS_RESOURCE,CAP_SYS_TIME,CAP_SYS_TTY_CONFIG,CAP_SYSLOG,CAP_SYS_MODULE
-###########################################################
-
-###########################################################
-# Common variables
-###########################################################
-ABS_ROOT=$(LLVMBASEDIR)
-
-PERF_PATH=/usr/bin/perf
-LLVMDIR=$(ABS_ROOT)
-LLVMINC=$(LLVMDIR)/include
-LLVMLIB=$(LLVMDIR)/lib
-INSTALL_DIR=$(ABS_ROOT)/bin
-
-LLVMSECTIONIFY_SO=$(INSTALL_DIR)/sectionify.so
-LLVMAOPIFY_SO=$(INSTALL_DIR)/aopify.so
-LLVMMAGIC_ST_IN_LIBST=0
-
-CC=clang
-CXX=clang++
-CFLAGS=-fasynchronous-unwind-tables -g -I$(LLVMINC)
-###########################################################
-
-###########################################################
-# LLVM gold plugin support (see README.llvm for details)
-#
-# Note: LLVMGOLD_PREFIX below should point to a valid LLVM 2.9 (+LLVMGOLD_CC=llvm-gcc) [or LLVM >= 3.0 (+LLVMGOLD_CC=clang)] installation with gold plugin support (binutils >=2.22)
-###########################################################
-LLVMGOLD_HAS_LTO_DISABLE_OPT=1
-LLVMGOLD_PREFIX=$(LLVMPREFIX)
-LLVMGOLD_PLUGIN=$(_MINIX_LLVM_DIR)/bin/LLVMgold.so
-
-LLVMGOLD_CC=$(_MINIX_TOOLS_DIR)/bin/i586-elf32-minix-clang -flto
-LLVMGOLD_CXX=$(_MINIX_TOOLS_DIR)/bin/i586-elf32-minix-clang++ -flto
-LLVMGOLD_AR=ar --plugin $(LLVMGOLD_PLUGIN)
-LLVMGOLD_RANLIB=$(LLVMGOLD_AR) -s
-
-LLVMGOLD_AR_FLAGS=--plugin $(LLVMGOLD_PLUGIN) -cru
-LLVMGOLD_CFLAGS=-fasynchronous-unwind-tables -g -D_MINIX -D_POSIX_SOURCE -D_SYSTEM -Wno-long-long --sysroot=$(_MINIX_SYSROOT) -I$(LLVMINC) -I$(_MINIX_OBJ_LLVM_DIR)/include/llvm -I$(_MINIX_ROOT)/external/bsd/llvm/dist/llvm/include -I$(_MINIX_OBJ_LLVM_DIR)/include -I$(_MINIX_SYSROOT)/usr/include
-LLVMGOLD_LINK=-Wl,--plugin -Wl,$(LLVMGOLD_PLUGIN)
-LLVMGOLD_LINKFLAGS=-Wl,-plugin-opt=-disable-fp-elim -Wl,-plugin-opt=save-temps
-LLVMGOLD_LINKCOMMONFLAGS=-L$(_MINIX_OBJ_DIR)/destdir.$(_MINIX_ARCH)/usr/lib -rdynamic
-LLVMGOLD_LIBS=
-LLVMGOLD_LDFLAGS=$(LLVMGOLD_LINK) $(LLVMGOLD_LINKFLAGS) $(LLVMGOLD_LINKCOMMONFLAGS) $(LLVMGOLD_LIBS)
-LLVMGOLD_OPTFLAGS=-disable-internalize -mem2reg -std-compile-opts
-LLVMGOLD_LLCFLAGS=--disable-fp-elim
-LLVMGOLD_TSLINK_PARTIALFLAGS=-Wl,-r -nostdlib
-LLVMGOLD_TSLINK_FINALFLAGS=-B$(LLVMGOLD_PREFIX)/bfd_bin
-LLVMGOLD_OPTIMIZED=1
-
-###########################################################
-
-BUILD_LLVMAPPS_FOR_MINIX=yes
-GEN_GOLD_PLUGIN=yes
-REBUILD_MINIX=yes
-ARCH_NAME=x86
-ARCH_BITS=32
+++ /dev/null
-#Makefile for creating the magic static library
-
-MODULE = magic
-OBJS = magic.o magic_analysis.o magic_asr.o magic_eval_lib.o magic_eval.o magic_mem.o magic_range.o magic_splay_tree.o magic_sentry.o magic_selement.o
-HEADERS = $(wildcard $(LLVMINC)/*.h) $(wildcard $(LLVMINC)/st/*.h)
-
-USE_SECTIONIFY=YES
-SECTIONIFY_NO_OVERRIDE=yes
-SECTIONIFY_DATA_SECTION_MAP=^_____magic_instr_.*/magic_instr_data,.*/magic_data
-SECTIONIFY_FUNCTION_SECTION_MAP=.*/magic_functions
-
-OBJS += minix/magic_util.o minix/magic_ds.o
-HEADERS += $(wildcard minix/*.h)
-
-OBJS+=magic_st.bcc
-
-include Makefile.inc
-
-CFLAGS += -I$(_MINIX_ROOT)/minix/servers
-
-# XXX: there is essential code in assert() statements, so force asserts on..
-CFLAGS += -UNDEBUG
-
-magic_st.bcc:
- make -f Makefile.magic_st $@
-
-magic_st.o:
- make -f Makefile.magic_st $@
-
+++ /dev/null
-
-include ../Makefile.common.inc
-include ../Makefile.settings
-
-MODULE_NAME=$(MODULE).bcc
-
-CFLAGS += $(CXXFLAGS) -Wall -g -Wno-long-long
-CFLAGS += -D__MINIX -D_MINIX_SYSTEM
-
-LLVM_VERSION=$(shell $(LLVMPREFIX)/bin/llvm-config --version | cut -d"." -f1,2 | sed "s/[^0-9]//g")
-
-HAVE_NOCONSTRUCTOR_PRIORITY = $(shell expr $(LLVM_VERSION) \>= 30)
-ifeq ($(HAVE_NOCONSTRUCTOR_PRIORITY),0)
-CFLAGS += -DHAVE_NOCONSTRUCTOR_PRIORITY=1
-endif
-
-ifeq ($(USE_SECTIONIFY),YES)
-LOPT_FLAGS+=-load=$(LLVMSECTIONIFY_SO) -sectionify -sectionify-no-override -sectionify-data-section-map=$(SECTIONIFY_DATA_SECTION_MAP) -sectionify-function-section-map=$(SECTIONIFY_FUNCTION_SECTION_MAP)
-ifeq (SECTIONIFY_NO_OVERRIDE,YES)
-LOPT_FLAGS+=-sectionify-no-override
-endif
-endif
-
-V?=0
-ifneq ($V,0)
-QUIET=
-ECHO:=@\#
-QMAKE=VERBOSE=1 make
-else
-QUIET= @
-ECHO= echo
-QMAKE=make -s
-endif
-
-$(MODULE_NAME): $(OBJS) $(HEADERS) $(COMMON_BCCS)
- $(QUIET) $(ECHO) " [GOLD_LINK] $@.o"
- $(QUIET) $(LLVMGOLD_CC) $(CFLAGS) $(LLVMGOLD_CFLAGS) $(LLVMGOLD_LDFLAGS) -shared -o $@.o $(OBJS) $(COMMON_BCCS)
- $(QUIET) $(ECHO) " [OPT] $@"
- $(QUIET) $(LLVMPREFIX)/bin/opt $(LOPT_FLAGS) -o $@ $@.o.bc
-
-all: $(MODULE_NAME)
-
-%.o: %.c $(HEADERS)
- $(QUIET) $(ECHO) " [GOLD_CC] $<"
- $(QUIET) $(LLVMGOLD_CC) $(CFLAGS) $(LLVMGOLD_CFLAGS) $(INCLUDES) $(INCLUDES_$<) -c -o $@ $<
-
-install: $(INSTALL_DIR)/$(MODULE_NAME)
-
-$(INSTALL_DIR)/$(MODULE_NAME): $(MODULE_NAME)
- install -c -D -m 744 $? $@
-
-clean: $(EXTRA_CLEAN)
- $(QUIET) $(ECHO) " [RM] *.BCC *.bcc *.bc *.BCL *.BCL.sh *.bcl $(OBJS) *.s $(COMMON_BCCS)"
- $(QUIET) rm -f *.BCC *.bcc *.bc *.BCL *.BCL.sh *.bcl *.o $(OBJS) *.s $(COMMON_BCCS)
-
-distclean: clean
- $(QUIET) $(ECHO) " [RM] $(INSTALL_DIR)/$(MODULE_NAME)"
- $(QUIET) rm -f $(INSTALL_DIR)/$(MODULE_NAME)
+++ /dev/null
-
-MODULE = magic_st
-
-OBJS = magic_st.o
-
-USE_SECTIONIFY=YES
-SECTIONIFY_DATA_SECTION_MAP=.*/magic_data_st
-SECTIONIFY_FUNCTION_SECTION_MAP=.*/magic_functions_st
-
-include Makefile.inc
-
-Wl,-plugin-opt=-disable-opt
SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so
+# dcvmoole: the following construction is a hack for libmagicrt. For reasons
+# not entirely under our control, clang refuses to take .bc objects even when
+# using the gold linker, saying that LLVM IR code cannot be linked. In order
+# to sidestep this, libmagicrt uses the name "foo.bc.o" instead of "foo.bc" to
+# link the its LLVM IR objects. As all libmagicrt modules use the sectionify
+# pass below, and this step needs temporary files, we give the temporary files
+# the .o suffix (while anything would do!), and allow the libmagicrt makefile
+# to override the rename to the real file name to perform a copy instead. As
+# a result, libmagicrt ends up with both the .bc and .bc.o objects, and it can
+# pass the latter set to clang, bypassing clang's overly strict checks.
+SECTIONIFYMV?=mv -f
.S.bc: ${.TARGET:.bc=.o}
rm -f ${.TARGET}
.c.bc:
${_MKTARGET_COMPILE}
${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
- if [ -n '${SECTIONIFY.${.IMPSRC:T}}' ]; then \
- ${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}} -o ${.TARGET}.tmp ${.TARGET} && mv -f ${.TARGET}.tmp ${.TARGET}; \
+ if [ -n '${SECTIONIFY.${.IMPSRC:T}:U${SECTIONIFY}}' ]; then \
+ ${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}:U${SECTIONIFY}} -o ${.TARGET}.o ${.TARGET} && ${SECTIONIFYMV} ${.TARGET}.o ${.TARGET}; \
fi
.cc.bc .cxx.bc .cpp.bc:
_YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
.if ${USE_BITCODE:Uno} == "yes"
+.if defined(LIB)
_LIBS+=${_LIB_bc.a}
+.endif
.endif # ${USE_BITCODE:Uno} == "yes"
.NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
#MINIX-specific vars
_MKVARS.no+= \
- MKIMAGEONLY MKSMALL MKBITCODE MKSRC
+ MKIMAGEONLY MKSMALL MKBITCODE MKMAGIC MKSRC
.if !empty(MACHINE_ARCH:Mearm*)
_MKVARS.no+= \
MKWATCHDOG MKACPI MKAPIC MKDEBUGREG MKINSTALLBOOT MKPCI
MKLIVEUPDATE:= no
.endif
+# MINIX: MKMAGIC implies MKBITCODE
+.if ${MKMAGIC} == "yes"
+MKBITCODE:= yes
+.endif
+
.if !empty(MACHINE_ARCH:Mearm*)
_NEEDS_LIBCXX.${MACHINE_ARCH}= yes
.endif
#MINIX-specific vars
.for var in \
USE_WATCHDOG USE_ACPI USE_APIC USE_DEBUGREG USE_SYSDEBUG \
- USE_LIVEUPDATE USE_PCI USE_BITCODE
+ USE_LIVEUPDATE USE_PCI USE_BITCODE USE_MAGIC
.if (${${var:S/USE_/MK/}} == "no")
${var}:= no
.else