From: yu.dongliang <18588496441@163.com> Date: Wed, 26 Aug 2026 16:20:54 +0000 (+0800) Subject: 1, support of musl libc, Now all .h of C89 ok, X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=8f8e161a2d953bf675fc35b14f80fe02b0ee5892;p=scf.git 1, support of musl libc, Now all .h of C89 ok, 2, support 'volatile'. --- diff --git a/core/scf_ast.c b/core/scf_ast.c index 2bf5a93..ebaa6ae 100644 --- a/core/scf_ast.c +++ b/core/scf_ast.c @@ -666,8 +666,8 @@ int scf_function_signature(scf_ast_t* ast, scf_function_t* f, scf_vector_t* argv fname = op->signature; } - if (!argv) - argv = f->argv; + if (!argv && f->member_flag) + argv = f->argv; if (f->signature) { scf_string_free(f->signature); diff --git a/core/scf_ast.h b/core/scf_ast.h index c749ace..ea412b3 100644 --- a/core/scf_ast.h +++ b/core/scf_ast.h @@ -85,4 +85,12 @@ int scf_function_signature2(scf_string_t** ps, scf_ast_t* ast, scf_type_t* t, co int scf_ast_add_const_str(scf_ast_t* ast, scf_node_t* parent, scf_lex_word_t* w); int scf_ast_add_const_var(scf_ast_t* ast, scf_node_t* parent, int type, const uint64_t u64); +static inline int scf_anon_rename(scf_string_t* name, int line, int pos, void* obj) +{ + char buf[256]; + int n = snprintf(buf, sizeof(buf) - 1, "%d_%d_%lx", line, pos, (uintptr_t)obj); + + return scf_string_cat_cstr_len(name, buf, n); +} + #endif diff --git a/core/scf_basic_block.c b/core/scf_basic_block.c index 0fc2e60..b229f16 100644 --- a/core/scf_basic_block.c +++ b/core/scf_basic_block.c @@ -1330,7 +1330,8 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) continue; if (scf_vector_find(bb->entry_dn_aliases, dn) - || dn->var->tmp_flag) + || dn->var->tmp_flag + || dn->var->volatile_flag) ret = scf_vector_add_unique(bb->dn_reloads, dn); else ret = scf_vector_add_unique(bb->dn_loads, dn); @@ -1348,7 +1349,8 @@ int scf_basic_block_loads_saves(scf_basic_block_t* bb, scf_list_t* bb_list_head) } if (scf_vector_find(bb->exit_dn_aliases, dn) - || dn->var->tmp_flag) + || dn->var->tmp_flag + || dn->var->volatile_flag) ret = scf_vector_add_unique(bb->dn_resaves, dn); else ret = scf_vector_add_unique(bb->dn_saves, dn); diff --git a/core/scf_lex_word.h b/core/scf_lex_word.h index eb0b9d9..8d00360 100644 --- a/core/scf_lex_word.h +++ b/core/scf_lex_word.h @@ -191,6 +191,7 @@ enum scf_lex_words SCF_LEX_WORD_KEY_STATIC, // static SCF_LEX_WORD_KEY_EXTERN, // extern SCF_LEX_WORD_KEY_INLINE, // inline + SCF_LEX_WORD_KEY_VOLATILE, // volatile // for co-routine SCF_LEX_WORD_KEY_ASYNC, // async diff --git a/core/scf_optimizer_group.c b/core/scf_optimizer_group.c index e44b376..a91636f 100644 --- a/core/scf_optimizer_group.c +++ b/core/scf_optimizer_group.c @@ -76,6 +76,11 @@ int _optimize_peep_hole(scf_bb_group_t* bbg, scf_basic_block_t* bb) for (i = 0; i < bb->dn_reloads->size; ) { dn = bb->dn_reloads->data[i]; + if (dn->var->volatile_flag) { + i++; + continue; + } + for (j = 0; j < bb->prevs->size; j++) { bb_prev = bb->prevs->data[j]; diff --git a/core/scf_variable.h b/core/scf_variable.h index c908bac..0981309 100644 --- a/core/scf_variable.h +++ b/core/scf_variable.h @@ -62,6 +62,7 @@ struct scf_variable_s { uint32_t extern_flag :1; uint32_t extra_flag :1; uint32_t typedef_flag:1; + uint32_t volatile_flag:1; uint32_t tmp_flag :1; uint32_t local_flag :1; diff --git a/examples/hello.c b/examples/hello.c index 6dd7ef7..a75b378 100644 --- a/examples/hello.c +++ b/examples/hello.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -13,6 +12,9 @@ #include #include #include +#include + +#include // stdint.h as C99, not C89 / ANSI. int main() { diff --git a/examples/signal.c b/examples/signal.c new file mode 100644 index 0000000..2e4b4bf --- /dev/null +++ b/examples/signal.c @@ -0,0 +1,20 @@ +#include +#include + +void sig_int(int sig) +{ + printf("signal: %d\n", sig); +} + +void sleep(long); + +int main() +{ + signal(SIGINT, sig_int); + + sleep(5); + + sleep(1); + printf("signal ok\n"); + return 0; +} diff --git a/examples/volatile.c b/examples/volatile.c new file mode 100644 index 0000000..4fbc2ae --- /dev/null +++ b/examples/volatile.c @@ -0,0 +1,9 @@ +int printf(const char* fmt, ...); + +int main() +{ + volatile int i = 1; + + printf("i: %d\n", i); + return 0; +} diff --git a/lex/scf_lex.c b/lex/scf_lex.c index 2647478..d3eac48 100644 --- a/lex/scf_lex.c +++ b/lex/scf_lex.c @@ -93,6 +93,7 @@ static scf_key_word_t key_words[] = {SCF_CSTR("static"), SCF_LEX_WORD_KEY_STATIC}, {SCF_CSTR("extern"), SCF_LEX_WORD_KEY_EXTERN}, {SCF_CSTR("inline"), SCF_LEX_WORD_KEY_INLINE}, + {SCF_CSTR("volatile"), SCF_LEX_WORD_KEY_VOLATILE}, {SCF_CSTR("async"), SCF_LEX_WORD_KEY_ASYNC}, {SCF_CSTR("await"), SCF_LEX_WORD_KEY_AWAIT}, diff --git a/native/scf_instruction.h b/native/scf_instruction.h index 8fd1716..3bab7d0 100644 --- a/native/scf_instruction.h +++ b/native/scf_instruction.h @@ -75,6 +75,8 @@ struct scf_instruction_s int flag; // asm jcc back or front int nb_used; + + uint8_t volatile_flag:1; }; struct scf_rela_s diff --git a/native/x64/scf_x64_inst.c b/native/x64/scf_x64_inst.c index c9b0f16..c0c3b10 100644 --- a/native/x64/scf_x64_inst.c +++ b/native/x64/scf_x64_inst.c @@ -1803,16 +1803,9 @@ static int _x64_inst_reload_handler(scf_native_t* ctx, scf_3ac_code_t* c) scf_x64_context_t* x64 = ctx->priv; scf_function_t* f = x64->f; + scf_instruction_t* inst; scf_3ac_operand_t* dst = c->dsts->data[0]; scf_dag_node_t* dn = dst->dag_node; - scf_dag_node_t* dn2 = NULL; - - int ret; - int i; - - if (dn->color < 0) - return 0; - assert(dn->color > 0); if (!c->instructions) { c->instructions = scf_vector_alloc(); @@ -1820,23 +1813,20 @@ static int _x64_inst_reload_handler(scf_native_t* ctx, scf_3ac_code_t* c) return -ENOMEM; } - r = x64_find_register_color(dn->color); + assert(0 != dn->color); - ret = x64_overflow_reg2(r, dn, c, f); - if (ret < 0) { - scf_loge("\n"); - return ret; - } + int i = c->instructions->size; dn->loaded = 0; - ret = x64_load_reg(r, dn, c, f); - if (ret < 0) - return ret; - ret = scf_vector_add_unique(r->dag_nodes, dn); - if (ret < 0) { - scf_loge("\n"); - return ret; + X64_SELECT_REG_CHECK(&r, dn, c, f, 1); + + if (dn->var->volatile_flag) { + + for ( ; i < c->instructions->size; i++) { + inst = c->instructions->data[i]; + inst->volatile_flag = 1; + } } return 0; @@ -1871,7 +1861,23 @@ static int _x64_inst_save_handler(scf_native_t* ctx, scf_3ac_code_t* c) return -ENOMEM; } - return x64_save_var(dn, c, f); + scf_instruction_t* inst; + + int i = c->instructions->size; + + int ret = x64_save_var(dn, c, f); + if (ret < 0) + return ret; + + if (dn->var->volatile_flag) { + + for ( ; i < c->instructions->size; i++) { + inst = c->instructions->data[i]; + inst->volatile_flag = 1; + } + } + + return ret; } #define X64_INST_BINARY_ASSIGN(name, op) \ diff --git a/native/x64/scf_x64_optimize.c b/native/x64/scf_x64_optimize.c index 0753af8..b7cc421 100644 --- a/native/x64/scf_x64_optimize.c +++ b/native/x64/scf_x64_optimize.c @@ -286,11 +286,14 @@ static int _x64_peephole_function(scf_vector_t* save_insts, scf_function_t* f, i && x64_reg_is_retval(inst->dst.base)) continue; - assert(0 == scf_vector_del(c->instructions, inst)); - assert(0 == scf_vector_del(save_insts, inst)); + if (!inst->volatile_flag) { - free(inst); - inst = NULL; + assert(0 == scf_vector_del(c->instructions, inst)); + assert(0 == scf_vector_del(save_insts, inst)); + + free(inst); + inst = NULL; + } } int n_locals = 0; diff --git a/native/x64/scf_x64_peephole.c b/native/x64/scf_x64_peephole.c index 9f09af6..832ea1f 100644 --- a/native/x64/scf_x64_peephole.c +++ b/native/x64/scf_x64_peephole.c @@ -5,6 +5,9 @@ static int __x64_peep_mov_by_lea(scf_instruction_t* mov, scf_instruction_t* lea) { + if (mov->volatile_flag) + return 0; + scf_instruction_t* inst; if (lea->src.index) @@ -33,6 +36,9 @@ static int __x64_peep_mov_by_lea(scf_instruction_t* mov, scf_instruction_t* lea) static int __x64_peep_src_was_mem(scf_instruction_t* inst, scf_inst_data_t* src) { + if (inst->volatile_flag) + return 0; + scf_instruction_t* tmp; scf_x64_OpCode_t* OpCode; @@ -76,6 +82,9 @@ static int __x64_peep_src_was_mem(scf_instruction_t* inst, scf_inst_data_t* src) static int __x64_peep_dst_was_mem(scf_instruction_t* inst, scf_inst_data_t* dst) { + if (inst->volatile_flag) + return 0; + scf_instruction_t* tmp; if (inst->src.imm_size > 0) @@ -100,6 +109,9 @@ static int __x64_peep_dst_was_mem(scf_instruction_t* inst, scf_inst_data_t* dst) static int __x64_peep_mov_to_mem(scf_instruction_t* mov, scf_inst_data_t* src) { + if (mov->volatile_flag) + return 0; + scf_instruction_t* inst; if (!mov->dst.index) @@ -215,11 +227,14 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, if (scf_inst_data_same(&std->src, &inst->src)) { - assert(0 == scf_vector_del(inst->c->instructions, inst)); + if (!inst->volatile_flag) { + assert(0 == scf_vector_del(inst->c->instructions, inst)); - free(inst); - inst = NULL; - return X64_PEEPHOLE_DEL; + free(inst); + inst = NULL; + return X64_PEEPHOLE_DEL; + } + return 0; } assert(0 == scf_vector_del(peep_insts, std)); @@ -227,11 +242,13 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, if (std->nb_used > 0) continue; - assert(0 == scf_vector_del(std->c->instructions, std)); - assert(0 == scf_vector_del(save_insts, std)); + if (!std->volatile_flag) { + assert(0 == scf_vector_del(std->c->instructions, std)); + assert(0 == scf_vector_del(save_insts, std)); - free(std); - std = NULL; + free(std); + std = NULL; + } continue; } else if (scf_inst_data_same(&std->src, &inst->src)) { @@ -247,11 +264,14 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, if (scf_inst_data_same(&std->src, &inst->dst)) { - assert(0 == scf_vector_del(inst->c->instructions, inst)); + if (!inst->volatile_flag) { + assert(0 == scf_vector_del(inst->c->instructions, inst)); - free(inst); - inst = NULL; - return X64_PEEPHOLE_DEL; + free(inst); + inst = NULL; + return X64_PEEPHOLE_DEL; + } + return 0; } if (inst->src.mem_flag) { diff --git a/parse/scf_dfa_function.c b/parse/scf_dfa_function.c index b6b2b42..3ec88b5 100644 --- a/parse/scf_dfa_function.c +++ b/parse/scf_dfa_function.c @@ -157,8 +157,8 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) if (d->pf_pointers > 0) { t = NULL; - int ret; - int pf_pointers = d->pf_pointers; + int ret; + int pf_pointers = d->pf_pointers; d->pf_pointers = 0; @@ -171,9 +171,18 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) if (!v_pf) return -ENOMEM; - v_pf->local_flag = local_flag; - v_pf->global_flag = global_flag; - v_pf->member_flag = member_flag; + if (name == id->type_w) { + ret = scf_anon_rename(v_pf->w->text, lp->line, lp->pos, v_pf); + if (ret < 0) { + scf_variable_free(v_pf); + return ret; + } + } + + v_pf->local_flag = local_flag; + v_pf->global_flag = global_flag; + v_pf->member_flag = member_flag; + v_pf->volatile_flag = id0->volatile_flag; } else v_pf = d->current_var; @@ -199,6 +208,8 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) return ret; fd->v_pf = v_pf; + + member_flag = 0; } f = scf_function_alloc(name); @@ -206,11 +217,22 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) return SCF_DFA_ERROR; f->member_flag = member_flag; - if (id && d->current_identities->size > 1) { - scf_stack_pop(d->current_identities); - free(id); + if (id) { + if (name == id->type_w) { + int ret = scf_anon_rename(f->node.w->text, lp->line, lp->pos, f); + if (ret < 0) { + scf_function_free(f); + return ret; + } + } + + if (d->current_identities->size > 1) { + scf_stack_pop(d->current_identities); + free(id); + } + + id = NULL; } - id = NULL; scf_logi("s->size: %d, function: %s(), line: %d, member_flag: %d\n", s->size, f->node.w->text->data, f->node.w->line, f->member_flag); @@ -223,6 +245,8 @@ int _function_add_function(scf_dfa_t* dfa, dfa_data_t* d, scf_lex_word_t* lp) if (v_pf) { v_pf->static_flag = f->static_flag; v_pf->func_ptr = f; + + scf_logi("s->size: %d, pf: (*%s)(), line: %d\n", s->size, v_pf->w->text->data, v_pf->w->line); } scf_scope_push_function(ast->current_block->scope, f); @@ -328,6 +352,8 @@ int _function_add_arg(scf_dfa_t* dfa, dfa_data_t* d) if (!arg) return SCF_DFA_ERROR; + arg->volatile_flag = t->volatile_flag; + scf_scope_push_var(fd->f->scope, arg); } else arg = d->current_var; @@ -434,7 +460,7 @@ static int _function_action_pf_rp(scf_dfa_t* dfa, scf_vector_t* words, void* dat d->pf_lps = 0; if (id && id->identity) - scf_logw("pf: %s(), nb_pointers: %d\n", id->identity->text->data, d->pf_pointers); + scf_logw("pf: (*%s)(), nb_pointers: %d\n", id->identity->text->data, d->pf_pointers); } else { // SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "function_pf_rp"), SCF_DFA_HOOK_PRE); } @@ -514,14 +540,30 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) if (b->node.type >= SCF_STRUCT) { - if (!b->node.class_flag) { + if (!b->node.class_flag && !b->node.union_flag) { scf_loge("only class has member function\n"); + + scf_function_free(f); + f = NULL; return SCF_DFA_ERROR; } assert(b->scope); - if (!strcmp(f->node.w->text->data, "__init")) { + if (!f->member_flag) { + fprev = scf_scope_find_function(b->scope, f->node.w->text->data); + + if (fprev && !scf_function_same(fprev, f)) { + + scf_loge("repeated declare function '%s', first in line: %d, second in line: %d, function overloading only can do in class\n", + f->node.w->text->data, fprev->node.w->line, f->node.w->line); + + scf_function_free(f); + f = NULL; + return SCF_DFA_ERROR; + } + + } else if (!strcmp(f->node.w->text->data, "__init")) { fprev = scf_scope_find_same_function(b->scope, f); @@ -532,10 +574,16 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) if (fprev && !scf_function_same(fprev, f)) { scf_loge("function '%s' can't be overloaded, repeated declare first in line: %d, second in line: %d\n", f->node.w->text->data, fprev->node.w->line, f->node.w->line); + + scf_function_free(f); + f = NULL; return SCF_DFA_ERROR; } } else { scf_loge("class member function must be '__init()' or '__release()', file: %s, line: %d\n", f->node.w->file->data, f->node.w->line); + + scf_function_free(f); + f = NULL; return SCF_DFA_ERROR; } } else { @@ -560,6 +608,9 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_loge("repeated declare function '%s', first in line: %d, second in line: %d, function overloading only can do in class\n", f->node.w->text->data, fprev->node.w->line, f->node.w->line); + + scf_function_free(f); + f = NULL; return SCF_DFA_ERROR; } } @@ -585,6 +636,8 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) } scf_function_free(f); + f = NULL; + fd->f = fprev; } else { @@ -596,6 +649,9 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) f->node.w->text->data, fprev->node.w->line, f->node.w->line); dfa->ops->push_word(dfa, w); + + scf_function_free(f); + f = NULL; return SCF_DFA_ERROR; } @@ -606,6 +662,7 @@ static int _function_action_rp(scf_dfa_t* dfa, scf_vector_t* words, void* data) scf_node_add_child((scf_node_t*)b, (scf_node_t*)f); } + f = NULL; if (s->size <= 1) SCF_DFA_PUSH_HOOK(scf_dfa_find_node(dfa, "function_end"), SCF_DFA_HOOK_END); diff --git a/parse/scf_dfa_identity.c b/parse/scf_dfa_identity.c index 371f523..1c461b9 100644 --- a/parse/scf_dfa_identity.c +++ b/parse/scf_dfa_identity.c @@ -44,12 +44,14 @@ static int _identity_action_identity(scf_dfa_t* dfa, scf_vector_t* words, void* return SCF_DFA_ERROR; } - id->identity = w; - id->const_flag = d->const_flag; - id->extern_flag = d->extern_flag; - - d->const_flag = 0; - d->extern_flag = 0; + id->identity = w; + id->const_flag = d->const_flag; + id->extern_flag = d->extern_flag; + id->volatile_flag = d->volatile_flag; + + d->const_flag = 0; + d->extern_flag = 0; + d->volatile_flag = 0; return SCF_DFA_NEXT_WORD; } diff --git a/parse/scf_dfa_type.c b/parse/scf_dfa_type.c index 8523c58..0e1672f 100644 --- a/parse/scf_dfa_type.c +++ b/parse/scf_dfa_type.c @@ -182,6 +182,15 @@ static int _type_action_inline(scf_dfa_t* dfa, scf_vector_t* words, void* data) return SCF_DFA_NEXT_WORD; } +static int _type_action_volatile(scf_dfa_t* dfa, scf_vector_t* words, void* data) +{ + dfa_data_t* d = data; + + d->volatile_flag = 1; + + return SCF_DFA_NEXT_WORD; +} + static int _type_action_base_type(scf_dfa_t* dfa, scf_vector_t* words, void* data) { scf_parse_t* parse = dfa->priv; @@ -206,19 +215,21 @@ static int _type_action_base_type(scf_dfa_t* dfa, scf_vector_t* words, void* dat return SCF_DFA_ERROR; } - id->type_w = w; + id->type_w = w; - id->const_flag = d->const_flag; - id->static_flag = d->static_flag; - id->extern_flag = d->extern_flag; - id->inline_flag = d->inline_flag; - id->typedef_flag = d->typedef_flag; + id->const_flag = d->const_flag; + id->static_flag = d->static_flag; + id->extern_flag = d->extern_flag; + id->inline_flag = d->inline_flag; + id->typedef_flag = d->typedef_flag; + id->volatile_flag = d->volatile_flag; d->const_flag = 0; d->static_flag = 0; d->extern_flag = 0; d->inline_flag = 0; d->typedef_flag = 0; + d->volatile_flag = 0; if (_base_type_filter(dfa, words, s) < 0) return SCF_DFA_ERROR; @@ -453,6 +464,7 @@ static int _dfa_init_module_type(scf_dfa_t* dfa) SCF_DFA_MODULE_NODE(dfa, type, _static, scf_dfa_is_static, _type_action_static); SCF_DFA_MODULE_NODE(dfa, type, _extern, scf_dfa_is_extern, _type_action_extern); SCF_DFA_MODULE_NODE(dfa, type, _inline, scf_dfa_is_inline, _type_action_inline); + SCF_DFA_MODULE_NODE(dfa, type, _volatile, scf_dfa_is_volatile, _type_action_volatile); SCF_DFA_MODULE_NODE(dfa, type, _const, scf_dfa_is_const, _type_action_const); SCF_DFA_MODULE_NODE(dfa, type, vconst, scf_dfa_is_const, _type_action_const); @@ -475,6 +487,7 @@ static int _dfa_init_syntax_type(scf_dfa_t* dfa) SCF_DFA_GET_MODULE_NODE(dfa, type, _static, _static); SCF_DFA_GET_MODULE_NODE(dfa, type, _extern, _extern); SCF_DFA_GET_MODULE_NODE(dfa, type, _inline, _inline); + SCF_DFA_GET_MODULE_NODE(dfa, type, _volatile, _volatile); SCF_DFA_GET_MODULE_NODE(dfa, type, _const, _const); SCF_DFA_GET_MODULE_NODE(dfa, type, vconst, vconst); @@ -496,17 +509,21 @@ static int _dfa_init_syntax_type(scf_dfa_t* dfa) scf_dfa_node_add_child(entry, _static); scf_dfa_node_add_child(entry, _extern); scf_dfa_node_add_child(entry, _const); + scf_dfa_node_add_child(entry, _volatile); scf_dfa_node_add_child(entry, _inline); scf_dfa_node_add_child(entry, _struct); scf_dfa_node_add_child(entry, base_type); scf_dfa_node_add_child(entry, type_name); + // typedef scf_dfa_node_add_child(_typedef, _const); + scf_dfa_node_add_child(_typedef, _volatile); scf_dfa_node_add_child(_typedef, _struct); scf_dfa_node_add_child(_typedef, base_type); scf_dfa_node_add_child(_typedef, type_name); + // for types scf_dfa_node_add_child(_static, _struct); scf_dfa_node_add_child(_static, base_type); scf_dfa_node_add_child(_static, type_name); @@ -519,14 +536,38 @@ static int _dfa_init_syntax_type(scf_dfa_t* dfa) scf_dfa_node_add_child(_const, base_type); scf_dfa_node_add_child(_const, type_name); + scf_dfa_node_add_child(_volatile, _struct); + scf_dfa_node_add_child(_volatile, base_type); + scf_dfa_node_add_child(_volatile, type_name); + scf_dfa_node_add_child(_inline, _struct); scf_dfa_node_add_child(_inline, base_type); scf_dfa_node_add_child(_inline, type_name); + // static scf_dfa_node_add_child(_static, _inline); scf_dfa_node_add_child(_static, _const); + scf_dfa_node_add_child(_static, _volatile); + + scf_dfa_node_add_child(_inline, _static); + scf_dfa_node_add_child(_const, _static); + scf_dfa_node_add_child(_volatile, _static); + + // extern scf_dfa_node_add_child(_extern, _const); + scf_dfa_node_add_child(_extern, _volatile); + scf_dfa_node_add_child(_const, _extern); + scf_dfa_node_add_child(_volatile, _extern); + + // inline scf_dfa_node_add_child(_inline, _const); + scf_dfa_node_add_child(_inline, _volatile); + scf_dfa_node_add_child(_const, _inline); + scf_dfa_node_add_child(_volatile, _inline); + + // const & volatile + scf_dfa_node_add_child(_const, _volatile); + scf_dfa_node_add_child(_volatile, _const); // for long long, long int, long double, short int, ... scf_dfa_node_add_child(base_type, base_type); diff --git a/parse/scf_dfa_util.h b/parse/scf_dfa_util.h index 5e56969..749e08f 100644 --- a/parse/scf_dfa_util.h +++ b/parse/scf_dfa_util.h @@ -214,6 +214,13 @@ static inline int scf_dfa_is_inline(scf_dfa_t* dfa, void* word) return SCF_LEX_WORD_KEY_INLINE == w->type; } +static inline int scf_dfa_is_volatile(scf_dfa_t* dfa, void* word) +{ + scf_lex_word_t* w = word; + + return SCF_LEX_WORD_KEY_VOLATILE == w->type; +} + static inline int scf_dfa_is_va_start(scf_dfa_t* dfa, void* word) { scf_lex_word_t* w = word; diff --git a/parse/scf_dfa_var.c b/parse/scf_dfa_var.c index 2ed0120..4e03af9 100644 --- a/parse/scf_dfa_var.c +++ b/parse/scf_dfa_var.c @@ -163,13 +163,14 @@ static int _var_add_var(scf_dfa_t* dfa, dfa_data_t* d) if (!v) return SCF_DFA_ERROR; - v->local_flag = local_flag; - v->global_flag = global_flag; - v->member_flag = member_flag; + v->local_flag = local_flag; + v->global_flag = global_flag; + v->member_flag = member_flag; - v->static_flag = id0->static_flag; - v->extern_flag = id0->extern_flag; - v->typedef_flag = id0->typedef_flag; + v->static_flag = id0->static_flag; + v->extern_flag = id0->extern_flag; + v->typedef_flag = id0->typedef_flag; + v->volatile_flag = id0->volatile_flag; if (id0->type_def) { int i; @@ -185,27 +186,28 @@ static int _var_add_var(scf_dfa_t* dfa, dfa_data_t* d) } #if 1 - scf_logi("typedef_flag: %u, type: %d, nb_pointers: %d, nb_dimentions: %d", - v->typedef_flag, v->type, v->nb_pointers, v->nb_dimentions); + scf_logi("typedef_flag: %u, v: %p, type: %d, nb_pointers: %d, nb_dimentions: %d", + v->typedef_flag, v, v->type, v->nb_pointers, v->nb_dimentions); if (v->w) printf(", var: '%s', line:%d, pos:%d", v->w->text->data, v->w->line, v->w->pos); else printf(", var: 'anonymous', line:%d, pos:%d", id0->type_w->line, id0->type_w->pos); - printf(", local: %d, global: %d, member: %d, extern: %d, static: %d\n\n", + printf(", local: %d, global: %d, member: %d, extern: %d, static: %d, volatile: %d\n\n", v->local_flag, v->global_flag, v->member_flag, - v->extern_flag, v->static_flag); + v->extern_flag, v->static_flag, v->volatile_flag); #endif scf_scope_push_var(ast->current_block->scope, v); - d->current_var = v; - d->current_var_w = w; - id0->nb_pointers = 0; - id0->const_flag = 0; - id0->static_flag = 0; - id0->extern_flag = 0; + d->current_var = v; + d->current_var_w = w; + id0->nb_pointers = 0; + id0->const_flag = 0; + id0->static_flag = 0; + id0->extern_flag = 0; + id0->volatile_flag = 0; if (d->current_identities->size >= 2) { @@ -344,6 +346,8 @@ static int _var_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data) if (d->expr_local_flag > 0 && _var_init_expr(dfa, d, words, 0) < 0) return SCF_DFA_ERROR; + d->current_var = NULL; + return SCF_DFA_SWITCH_TO; } @@ -400,6 +404,8 @@ static int _var_action_semicolon(scf_dfa_t* dfa, scf_vector_t* words, void* data if (b->nb_nodes > 0) b->nodes[b->nb_nodes - 1]->semi_flag = 1; + d->current_var = NULL; + return SCF_DFA_OK; } diff --git a/parse/scf_operator_handler_const.c b/parse/scf_operator_handler_const.c index f5f9d49..f38d239 100644 --- a/parse/scf_operator_handler_const.c +++ b/parse/scf_operator_handler_const.c @@ -663,14 +663,6 @@ static int _scf_op_const_sizeof(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes return -1; } -static int _scf_const_rename(scf_variable_t* v) -{ - char buf[256]; - int n = snprintf(buf, sizeof(buf) - 1, "c%d_%d_%lx", v->w->line, v->w->pos, (uintptr_t)v); - - return scf_string_cat_cstr_len(v->w->text, buf, n); -} - static int _scf_op_const_unary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) { assert(1 == nb_nodes); @@ -708,7 +700,7 @@ static int _scf_op_const_unary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, parent->type = r->type; parent->var = r; - return _scf_const_rename(r); + return scf_anon_rename(r->w->text, r->w->line, r->w->pos, r); } else { scf_loge("type %d not support\n", v0->type); return -1; @@ -772,7 +764,7 @@ static int _scf_op_const_binary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes parent->type = r->type; parent->var = r; - return _scf_const_rename(r); + return scf_anon_rename(r->w->text, r->w->line, r->w->pos, r); } return 0; diff --git a/parse/scf_operator_handler_expr.c b/parse/scf_operator_handler_expr.c index 4606422..15c4f24 100644 --- a/parse/scf_operator_handler_expr.c +++ b/parse/scf_operator_handler_expr.c @@ -69,7 +69,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void* scf_operator_handler_pt h = scf_find_expr_operator_handler(node->op->type); if (!h) { - scf_loge("\n"); + scf_loge("node->op->type: %d, SCF_OP_Q_MASK: %d, SCF_OP_COLON: %d\n", node->op->type, SCF_OP_Q_MASK, SCF_OP_COLON); goto _error; } @@ -270,6 +270,54 @@ static int _scf_op_expr_logic_not(scf_ast_t* ast, scf_node_t** nodes, int nb_nod return _scf_op_expr_unary(ast, nodes, nb_nodes, data); } +static int _scf_op_expr_colon(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) +{ + assert(2 == nb_nodes); + + return 0; +} + +static int _scf_op_expr_q_mask(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) +{ + assert(2 == nb_nodes); + + scf_handler_data_t* d = data; + + scf_variable_t* v0 = _scf_operand_get(nodes[0]); + scf_node_t* colon = nodes[1]; + scf_node_t* q_mask = colon ->parent; + scf_node_t* parent = q_mask->parent; + + assert(v0); + + if (scf_variable_const_integer(v0)) { + int i; + int j; + + for (i = 0; i < parent->nb_nodes; i++) { + if (q_mask == parent->nodes[i]) + break; + } + assert(i < parent->nb_nodes); + + j = !scf_zero_extend(v0->data.u64, v0->size); + + scf_logd("v0->data.u64: %ld, j: %d\n", v0->data.u64, j); + + colon ->nodes[j]->parent = parent; + parent->nodes[i] = colon->nodes[j]; + colon ->nodes[j] = NULL; + + scf_node_free(q_mask); + q_mask = NULL; + } else { + scf_loge("v0 type %d not support\n", v0->type); + return -1; + } + + return 0; +} + static int _scf_op_expr_binary(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data) { assert(2 == nb_nodes); @@ -696,6 +744,9 @@ scf_operator_handler_pt expr_operator_handlers[SCF_N_OPS] = [SCF_OP_LOGIC_AND ] = _scf_op_expr_logic_and, [SCF_OP_LOGIC_OR ] = _scf_op_expr_logic_or, + [SCF_OP_Q_MASK ] = _scf_op_expr_q_mask, + [SCF_OP_COLON ] = _scf_op_expr_colon, + [SCF_OP_ASSIGN ] = _scf_op_expr_assign, }; @@ -734,6 +785,11 @@ int scf_expr_calculate(scf_ast_t* ast, scf_expr_t* e, scf_variable_t** pret) if (ret < 0) return ret; + if (SCF_OP_EXPR == e->type) { + assert(e->nodes && 1 == e->nb_nodes); + node = e->nodes[0]; + } + if (SCF_OP_EXPR == node->type) { node = node->nodes[0]; diff --git a/parse/scf_parse.h b/parse/scf_parse.h index 24bcee9..92b5897 100644 --- a/parse/scf_parse.h +++ b/parse/scf_parse.h @@ -65,6 +65,7 @@ typedef struct { uint32_t static_flag :1; uint32_t inline_flag :1; uint32_t typedef_flag:1; + uint32_t volatile_flag:1; } dfa_identity_t; @@ -104,6 +105,7 @@ struct dfa_data_s { scf_node_t* current_va_copy; scf_node_t* current_va_end; + uint32_t volatile_flag:1; uint32_t typedef_flag:1; uint32_t const_flag :1; uint32_t extern_flag:1; diff --git a/sysroot/include/bits/signal.h b/sysroot/include/bits/signal.h new file mode 100644 index 0000000..c99317d --- /dev/null +++ b/sysroot/include/bits/signal.h @@ -0,0 +1,153 @@ +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 +#endif + +#ifdef _GNU_SOURCE +enum { REG_R8 = 0 }; +#define REG_R8 REG_R8 +enum { REG_R9 = 1 }; +#define REG_R9 REG_R9 +enum { REG_R10 = 2 }; +#define REG_R10 REG_R10 +enum { REG_R11 = 3 }; +#define REG_R11 REG_R11 +enum { REG_R12 = 4 }; +#define REG_R12 REG_R12 +enum { REG_R13 = 5 }; +#define REG_R13 REG_R13 +enum { REG_R14 = 6 }; +#define REG_R14 REG_R14 +enum { REG_R15 = 7 }; +#define REG_R15 REG_R15 +enum { REG_RDI = 8 }; +#define REG_RDI REG_RDI +enum { REG_RSI = 9 }; +#define REG_RSI REG_RSI +enum { REG_RBP = 10 }; +#define REG_RBP REG_RBP +enum { REG_RBX = 11 }; +#define REG_RBX REG_RBX +enum { REG_RDX = 12 }; +#define REG_RDX REG_RDX +enum { REG_RAX = 13 }; +#define REG_RAX REG_RAX +enum { REG_RCX = 14 }; +#define REG_RCX REG_RCX +enum { REG_RSP = 15 }; +#define REG_RSP REG_RSP +enum { REG_RIP = 16 }; +#define REG_RIP REG_RIP +enum { REG_EFL = 17 }; +#define REG_EFL REG_EFL +enum { REG_CSGSFS = 18 }; +#define REG_CSGSFS REG_CSGSFS +enum { REG_ERR = 19 }; +#define REG_ERR REG_ERR +enum { REG_TRAPNO = 20 }; +#define REG_TRAPNO REG_TRAPNO +enum { REG_OLDMASK = 21 }; +#define REG_OLDMASK REG_OLDMASK +enum { REG_CR2 = 22 }; +#define REG_CR2 REG_CR2 +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +typedef long long greg_t, gregset_t[23]; +typedef struct _fpstate { + unsigned short cwd, swd, ftw, fop; + unsigned long long rip, rdp; + unsigned mxcsr, mxcr_mask; + struct { + unsigned short significand[4], exponent, padding[3]; + } _st[8]; + struct { + unsigned element[4]; + } _xmm[16]; + unsigned padding[24]; +} *fpregset_t; +struct sigcontext { + unsigned long r8, r9, r10, r11, r12, r13, r14, r15; + unsigned long rdi, rsi, rbp, rbx, rdx, rax, rcx, rsp, rip, eflags; + unsigned short cs, gs, fs, __pad0; + unsigned long err, trapno, oldmask, cr2; + struct _fpstate *fpstate; + unsigned long __reserved1[8]; +}; +typedef struct { + gregset_t gregs; + fpregset_t fpregs; + unsigned long long __reserved1[8]; +} mcontext_t; +#else +typedef struct { + unsigned long __space[32]; +} mcontext_t; +#endif + +struct sigaltstack { + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef struct __ucontext { + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; + unsigned long __fpregs_mem[64]; +} ucontext_t; + +#define SA_NOCLDSTOP 1 +#define SA_NOCLDWAIT 2 +#define SA_SIGINFO 4 +#define SA_ONSTACK 0x08000000 +#define SA_RESTART 0x10000000 +#define SA_NODEFER 0x40000000 +#define SA_RESETHAND 0x80000000 +#define SA_RESTORER 0x04000000 + +#endif + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT SIGABRT +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL 29 +#define SIGPWR 30 +#define SIGSYS 31 +#define SIGUNUSED SIGSYS + +#define _NSIG 65 + diff --git a/sysroot/include/signal.h b/sysroot/include/signal.h new file mode 100644 index 0000000..1a49727 --- /dev/null +++ b/sysroot/include/signal.h @@ -0,0 +1,307 @@ +#ifndef _SIGNAL_H +#define _SIGNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) + +#ifdef _GNU_SOURCE +#define __ucontext ucontext +#endif + +#define __NEED_size_t +#define __NEED_pid_t +#define __NEED_uid_t +#define __NEED_struct_timespec +#define __NEED_pthread_t +#define __NEED_pthread_attr_t +#define __NEED_time_t +#define __NEED_clock_t +#define __NEED_sigset_t + +#include + +#define SIG_BLOCK 0 +#define SIG_UNBLOCK 1 +#define SIG_SETMASK 2 + +#define SI_ASYNCNL (-60) +#define SI_TKILL (-6) +#define SI_SIGIO (-5) +#define SI_ASYNCIO (-4) +#define SI_MESGQ (-3) +#define SI_TIMER (-2) +#define SI_QUEUE (-1) +#define SI_USER 0 +#define SI_KERNEL 128 + +typedef struct sigaltstack stack_t; + +#endif + +#include + +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) + +#define SIG_HOLD ((void (*)(int)) 2) + +#define FPE_INTDIV 1 +#define FPE_INTOVF 2 +#define FPE_FLTDIV 3 +#define FPE_FLTOVF 4 +#define FPE_FLTUND 5 +#define FPE_FLTRES 6 +#define FPE_FLTINV 7 +#define FPE_FLTSUB 8 + +#define ILL_ILLOPC 1 +#define ILL_ILLOPN 2 +#define ILL_ILLADR 3 +#define ILL_ILLTRP 4 +#define ILL_PRVOPC 5 +#define ILL_PRVREG 6 +#define ILL_COPROC 7 +#define ILL_BADSTK 8 + +#define SEGV_MAPERR 1 +#define SEGV_ACCERR 2 +#define SEGV_BNDERR 3 +#define SEGV_PKUERR 4 +#define SEGV_MTEAERR 8 +#define SEGV_MTESERR 9 + +#define BUS_ADRALN 1 +#define BUS_ADRERR 2 +#define BUS_OBJERR 3 +#define BUS_MCEERR_AR 4 +#define BUS_MCEERR_AO 5 + +#define CLD_EXITED 1 +#define CLD_KILLED 2 +#define CLD_DUMPED 3 +#define CLD_TRAPPED 4 +#define CLD_STOPPED 5 +#define CLD_CONTINUED 6 + +union sigval { + int sival_int; + void *sival_ptr; +}; + +typedef struct { +#ifdef __SI_SWAP_ERRNO_CODE + int si_signo, si_code, si_errno; +#else + int si_signo, si_errno, si_code; +#endif + union { + char __pad[128 - 2*sizeof(int) - sizeof(long)]; + struct { + union { + struct { + pid_t si_pid; + uid_t si_uid; + } __piduid; + struct { + int si_timerid; + int si_overrun; + } __timer; + } __first; + union { + union sigval si_value; + struct { + int si_status; + clock_t si_utime, si_stime; + } __sigchld; + } __second; + } __si_common; + struct { + void *si_addr; + short si_addr_lsb; + union { + struct { + void *si_lower; + void *si_upper; + } __addr_bnd; + unsigned si_pkey; + } __first; + } __sigfault; + struct { + long si_band; + int si_fd; + } __sigpoll; + struct { + void *si_call_addr; + int si_syscall; + unsigned si_arch; + } __sigsys; + } __si_fields; +} siginfo_t; +#define si_pid __si_fields.__si_common.__first.__piduid.si_pid +#define si_uid __si_fields.__si_common.__first.__piduid.si_uid +#define si_status __si_fields.__si_common.__second.__sigchld.si_status +#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime +#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime +#define si_value __si_fields.__si_common.__second.si_value +#define si_addr __si_fields.__sigfault.si_addr +#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb +#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower +#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper +#define si_pkey __si_fields.__sigfault.__first.si_pkey +#define si_band __si_fields.__sigpoll.si_band +#define si_fd __si_fields.__sigpoll.si_fd +#define si_timerid __si_fields.__si_common.__first.__timer.si_timerid +#define si_overrun __si_fields.__si_common.__first.__timer.si_overrun +#define si_ptr si_value.sival_ptr +#define si_int si_value.sival_int +#define si_call_addr __si_fields.__sigsys.si_call_addr +#define si_syscall __si_fields.__sigsys.si_syscall +#define si_arch __si_fields.__sigsys.si_arch + +struct sigaction { + union { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + } __sa_handler; + sigset_t sa_mask; + int sa_flags; + void (*sa_restorer)(void); +}; +#define sa_handler __sa_handler.sa_handler +#define sa_sigaction __sa_handler.sa_sigaction + +#define SA_UNSUPPORTED 0x00000400 +#define SA_EXPOSE_TAGBITS 0x00000800 + +struct sigevent { + union sigval sigev_value; + int sigev_signo; + int sigev_notify; + union { + char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; + pid_t sigev_notify_thread_id; + struct { + void (*sigev_notify_function)(union sigval); + pthread_attr_t *sigev_notify_attributes; + } __sev_thread; + } __sev_fields; +}; + +#define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id +#define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function +#define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes + +#define SIGEV_SIGNAL 0 +#define SIGEV_NONE 1 +#define SIGEV_THREAD 2 +#define SIGEV_THREAD_ID 4 + +int __libc_current_sigrtmin(void); +int __libc_current_sigrtmax(void); + +#define SIGRTMIN (__libc_current_sigrtmin()) +#define SIGRTMAX (__libc_current_sigrtmax()) + +int kill(pid_t, int); + +int sigemptyset(sigset_t *); +int sigfillset(sigset_t *); +int sigaddset(sigset_t *, int); +int sigdelset(sigset_t *, int); +int sigismember(const sigset_t *, int); + +int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); +int sigsuspend(const sigset_t *); +int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); +int sigpending(sigset_t *); +int sigwait(const sigset_t *__restrict, int *__restrict); +int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); +int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); +int sigqueue(pid_t, int, union sigval); + +int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); +int pthread_kill(pthread_t, int); + +void psiginfo(const siginfo_t *, const char *); +void psignal(int, const char *); + +#endif + +#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +typedef void (*sighandler_t)(int); + +int killpg(pid_t, int); +int sigaltstack(const stack_t *__restrict, stack_t *__restrict); +int sighold(int); +int sigignore(int); +int siginterrupt(int, int); +int sigpause(int); +int sigrelse(int); +//void (*sigset(int, void (*)(int)))(int); +sighandler_t sigset(int, sighandler_t); // use this as read easy. +#define TRAP_BRKPT 1 +#define TRAP_TRACE 2 +#define TRAP_BRANCH 3 +#define TRAP_HWBKPT 4 +#define TRAP_UNK 5 +#define POLL_IN 1 +#define POLL_OUT 2 +#define POLL_MSG 3 +#define POLL_ERR 4 +#define POLL_PRI 5 +#define POLL_HUP 6 +#define SS_ONSTACK 1 +#define SS_DISABLE 2 +#define SS_AUTODISARM (1U << 31) +#define SS_FLAG_BITS SS_AUTODISARM +#endif + +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) +#define NSIG _NSIG +typedef void (*sig_t)(int); + +#define SYS_SECCOMP 1 +#define SYS_USER_DISPATCH 2 +#endif + +#ifdef _GNU_SOURCE +void (*bsd_signal(int, void (*)(int)))(int); +int sigisemptyset(const sigset_t *); +int sigorset (sigset_t *, const sigset_t *, const sigset_t *); +int sigandset(sigset_t *, const sigset_t *, const sigset_t *); + +#define SA_NOMASK SA_NODEFER +#define SA_ONESHOT SA_RESETHAND +#endif + +#define SIG_ERR ((void (*)(int))-1) +#define SIG_DFL ((void (*)(int)) 0) +#define SIG_IGN ((void (*)(int)) 1) + +typedef int sig_atomic_t; + +sighandler_t signal(int, sighandler_t); // use this as read easy. +//void (*signal(int, void (*)(int)))(int); +int raise(int); + +#if _REDIR_TIME64 +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ + || defined(_BSD_SOURCE) +__REDIR(sigtimedwait, __sigtimedwait_time64); +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif