# endif
# if HAVE_SYS_MMAN_H
# include <sys/mman.h>
+# ifndef MAP_ANONYMOUS
+# define MAP_ANONYMOUS MAP_ANON
+# endif
# endif
#endif
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) {
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;
#define PSI_DATA_MEMBERS \
constants *consts; \
decl_typedefs *defs; \
+ decl_structs *structs; \
decls *decls; \
impls *impls; \
char *lib; \
if (data->defs) {
free_decl_typedefs(data->defs);
}
+ if (data->structs) {
+ free_decl_structs(data->structs);
+ }
if (data->decls) {
free_decls(data->decls);
}
#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
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). {
}
%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. {
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);
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). {
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());