From: Michael Wallner Date: Thu, 22 Oct 2015 19:56:44 +0000 (+0200) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=277d56eeb14cb124042362cb9d5f6e387487748c;p=m6w6%2Fext-psi flush --- diff --git a/src/libffi.c b/src/libffi.c index 4963fc5..2c68fbf 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -10,6 +10,9 @@ # endif # if HAVE_SYS_MMAN_H # include +# ifndef MAP_ANONYMOUS +# define MAP_ANONYMOUS MAP_ANON +# endif # endif #endif diff --git a/src/parser.h b/src/parser.h index fe3ff8e..8df41ea 100644 --- a/src/parser.h +++ b/src/parser.h @@ -25,6 +25,7 @@ typedef struct decl_type { char *name; token_t type; struct decl_type *real; + struct decl_struct *strct; } decl_type; static inline decl_type *init_decl_type(token_t type, char *name) { @@ -248,6 +249,54 @@ static inline void free_decls(decls *decls) { free(decls); } +typedef struct decl_struct_layout { + size_t pos; + size_t len; +} decl_struct_layout; + +typedef struct decl_struct { + char *name; + decl_args *args; + decl_struct_layout *layout; +} decl_struct; + +static inline decl_struct *init_decl_struct(char *name, decl_args *args) { + decl_struct *s = calloc(1, sizeof(*s)); + s->name = strdup(name); + s->args = args; + return s; +} + +static inline void free_decl_struct(decl_struct *s) { + free_decl_args(s->args); + free(s->name); + free(s); +} + +typedef struct decl_structs { + size_t count; + decl_struct **list; +} decl_structs; + +static inline decl_structs *add_decl_struct(decl_structs *ss, decl_struct *s) { + if (!ss) { + ss = calloc(1, sizeof(*ss)); + } + ss->list = realloc(ss->list, ++ss->count * sizeof(*ss->list)); + ss->list[ss->count-1] = s; + return ss; +} + +static inline void free_decl_structs(decl_structs *ss) { + size_t i; + + for (i = 0; i < ss->count; ++i) { + free_decl_struct(ss->list[i]); + } + free(ss->list); + free(ss); +} + typedef union impl_val { unsigned char bval; char cval; @@ -775,6 +824,7 @@ typedef void (*psi_error_cb)(int type, const char *msg, ...); #define PSI_DATA_MEMBERS \ constants *consts; \ decl_typedefs *defs; \ + decl_structs *structs; \ decls *decls; \ impls *impls; \ char *lib; \ @@ -796,6 +846,9 @@ static inline void PSI_DataDtor(PSI_Data *data) { if (data->defs) { free_decl_typedefs(data->defs); } + if (data->structs) { + free_decl_structs(data->structs); + } if (data->decls) { free_decls(data->decls); } diff --git a/src/parser_proc.h b/src/parser_proc.h index 492a681..bdc0b45 100644 --- a/src/parser_proc.h +++ b/src/parser_proc.h @@ -2,37 +2,37 @@ #define PSI_T_LIB 2 #define PSI_T_QUOTED_STRING 3 #define PSI_T_EOS 4 -#define PSI_T_BOOL 5 -#define PSI_T_INT 6 -#define PSI_T_FLOAT 7 -#define PSI_T_STRING 8 -#define PSI_T_CONST 9 -#define PSI_T_NSNAME 10 -#define PSI_T_EQUALS 11 -#define PSI_T_TYPEDEF 12 -#define PSI_T_NAME 13 -#define PSI_T_LPAREN 14 -#define PSI_T_RPAREN 15 -#define PSI_T_LBRACKET 16 -#define PSI_T_NUMBER 17 -#define PSI_T_RBRACKET 18 -#define PSI_T_DIGITS 19 -#define PSI_T_COMMA 20 -#define PSI_T_VOID 21 -#define PSI_T_CHAR 22 -#define PSI_T_SHORT 23 -#define PSI_T_LONG 24 -#define PSI_T_DOUBLE 25 -#define PSI_T_SINT8 26 -#define PSI_T_UINT8 27 -#define PSI_T_SINT16 28 -#define PSI_T_UINT16 29 -#define PSI_T_SINT32 30 -#define PSI_T_UINT32 31 -#define PSI_T_SINT64 32 -#define PSI_T_UINT64 33 -#define PSI_T_LBRACE 34 -#define PSI_T_RBRACE 35 +#define PSI_T_STRUCT 5 +#define PSI_T_NAME 6 +#define PSI_T_LBRACE 7 +#define PSI_T_RBRACE 8 +#define PSI_T_BOOL 9 +#define PSI_T_INT 10 +#define PSI_T_FLOAT 11 +#define PSI_T_STRING 12 +#define PSI_T_CONST 13 +#define PSI_T_NSNAME 14 +#define PSI_T_EQUALS 15 +#define PSI_T_TYPEDEF 16 +#define PSI_T_LPAREN 17 +#define PSI_T_RPAREN 18 +#define PSI_T_LBRACKET 19 +#define PSI_T_NUMBER 20 +#define PSI_T_RBRACKET 21 +#define PSI_T_COMMA 22 +#define PSI_T_VOID 23 +#define PSI_T_CHAR 24 +#define PSI_T_SHORT 25 +#define PSI_T_LONG 26 +#define PSI_T_DOUBLE 27 +#define PSI_T_SINT8 28 +#define PSI_T_UINT8 29 +#define PSI_T_SINT16 30 +#define PSI_T_UINT16 31 +#define PSI_T_SINT32 32 +#define PSI_T_UINT32 33 +#define PSI_T_SINT64 34 +#define PSI_T_UINT64 35 #define PSI_T_FUNCTION 36 #define PSI_T_COLON 37 #define PSI_T_REFERENCE 38 diff --git a/src/parser_proc.y b/src/parser_proc.y index fb7f53b..d368914 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -46,6 +46,14 @@ block ::= decl_typedef(def). { block ::= constant(constant). { P->consts = add_constant(P->consts, constant); } +block ::= decl_struct(strct). { + P->structs = add_decl_struct(P->structs, strct); +} + +%type decl_struct {decl_struct*} +decl_struct(strct) ::= STRUCT NAME(N) LBRACE struct_args(args) RBRACE. { + strct = init_decl_struct(N->text, args); +} %type const_type {const_type*} const_type(type_) ::= BOOL(T). { @@ -71,10 +79,16 @@ constant(constant) ::= CONST const_type(type) NSNAME(T) EQUALS impl_def_val(val) } %type decl_typedef {decl_typedef*} -decl_typedef(def) ::= TYPEDEF NAME(ALIAS) decl_type(type) EOS. { +decl_typedef(def) ::= TYPEDEF decl_type(type) NAME(ALIAS) EOS. { def = init_decl_typedef(ALIAS->text, type); free(ALIAS); } +decl_typedef(def) ::= TYPEDEF STRUCT(S) NAME(N) NAME(ALIAS) EOS. { + def = init_decl_typedef(ALIAS->text, init_decl_type(S->type, N->text)); + free(ALIAS); + free(S); + free(N); +} %type decl {decl*} decl(decl) ::= decl_abi(abi) decl_arg(func) LPAREN decl_args(args) RPAREN EOS. { @@ -101,7 +115,7 @@ decl_var(var) ::= NAME(T) LBRACKET NUMBER(D) RBRACKET. { free(T); free(D); } -decl_var(var) ::= pointers(p) NAME(T) LBRACKET DIGITS(D) RBRACKET. { +decl_var(var) ::= pointers(p) NAME(T) LBRACKET NUMBER(D) RBRACKET. { var = init_decl_var(T->text, p+1, atol(D->text)); free(T); free(D); @@ -128,6 +142,13 @@ decl_args(args) ::= decl_arg(arg). { decl_args(args) ::= decl_args(args_) COMMA decl_arg(arg). { args = add_decl_arg(args_, arg); } +%type struct_args {decl_args*} +struct_args(args) ::= decl_arg(arg) EOS. { + args = init_decl_args(arg); +} +struct_args(args) ::= struct_args(args_) decl_arg(arg) EOS. { + args = add_decl_arg(args_, arg); +} %type decl_type {decl_type*} decl_type(type_) ::= VOID(T). { diff --git a/src/validator.c b/src/validator.c index 6bfd4e4..44ea4ab 100644 --- a/src/validator.c +++ b/src/validator.c @@ -117,7 +117,7 @@ static inline int validate_decl_func(PSI_Validator *V, decl *decl, decl_arg *fun return 0; } - decl->dlptr = dlsym(V->dlopened, func->var->name); + decl->dlptr = dlsym(V->dlopened ?: RTLD_NEXT, func->var->name); if (!decl->dlptr) { V->error(PSI_WARNING, "Failed to located symbol '%s': %s", func->var->name, dlerror());