diff --git a/newlib/libc/posix/collate.c b/newlib/libc/posix/collate.c index a2f62c978f..8e84895bac 100644 --- a/newlib/libc/posix/collate.c +++ b/newlib/libc/posix/collate.c @@ -58,8 +58,9 @@ struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE]; void __collate_err(int ex, const char *f); int -__collate_load_tables(encoding) - char *encoding; +__collate_load_tables( + char *encoding +) { char buf[PATH_MAX]; FILE *fp; @@ -113,8 +114,9 @@ __collate_load_tables(encoding) } u_char * -__collate_substitute(s) - const u_char *s; +__collate_substitute( + const u_char *s +) { int dest_len, len, nlen; int delta = strlen((const char *) s); @@ -143,9 +145,12 @@ __collate_substitute(s) } void -__collate_lookup(t, len, prim, sec) - const u_char *t; - int *len, *prim, *sec; +__collate_lookup( + const u_char *t, + int *len, + int *prim, + int *sec +) { struct __collate_st_chain_pri *p2; @@ -165,8 +170,7 @@ __collate_lookup(t, len, prim, sec) } u_char * -__collate_strdup(s) - u_char *s; +__collate_strdup(u_char *s) { u_char *t = (u_char *) strdup((const char *) s); diff --git a/newlib/libc/posix/collcmp.c b/newlib/libc/posix/collcmp.c index 7770897619..675c4d80ae 100644 --- a/newlib/libc/posix/collcmp.c +++ b/newlib/libc/posix/collcmp.c @@ -40,8 +40,10 @@ * "[a-z]"-type ranges with national characters. */ -int __collate_range_cmp (c1, c2) - int c1, c2; +int __collate_range_cmp ( + int c1, + int c2 +) { static char s1[2], s2[2]; int ret; diff --git a/newlib/libc/posix/engine.c b/newlib/libc/posix/engine.c index c80834a0c2..cda7afa897 100644 --- a/newlib/libc/posix/engine.c +++ b/newlib/libc/posix/engine.c @@ -135,12 +135,13 @@ static char *pchar(int ch); == size_t nmatch, regmatch_t pmatch[], int eflags); */ static int /* 0 success, REG_NOMATCH failure */ -matcher(g, string, nmatch, pmatch, eflags) -struct re_guts *g; -char *string; -size_t nmatch; -regmatch_t pmatch[]; -int eflags; +matcher( + struct re_guts *g, + char *string, + size_t nmatch, + regmatch_t pmatch[], + int eflags +) { char *endp; int i; @@ -346,12 +347,13 @@ int eflags; == char *stop, sopno startst, sopno stopst); */ static char * /* == stop (success) always */ -dissect(m, start, stop, startst, stopst) -struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; +dissect( + struct match *m, + char *start, + char *stop, + sopno startst, + sopno stopst +) { int i; sopno ss; /* start sop of current subRE */ @@ -539,13 +541,14 @@ sopno stopst; == char *stop, sopno startst, sopno stopst, sopno lev); */ static char * /* == stop (success) or NULL (failure) */ -backref(m, start, stop, startst, stopst, lev) -struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; -sopno lev; /* PLUS nesting level */ +backref( + struct match *m, + char *start, + char *stop, + sopno startst, + sopno stopst, + sopno lev /* PLUS nesting level */ +) { int i; sopno ss; /* start sop of current subRE */ @@ -744,12 +747,13 @@ sopno lev; /* PLUS nesting level */ == char *stop, sopno startst, sopno stopst); */ static char * /* where tentative match ended, or NULL */ -fast(m, start, stop, startst, stopst) -struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; +fast( + struct match *m, + char *start, + char *stop, + sopno startst, + sopno stopst +) { states st = m->st; states fresh = m->fresh; @@ -835,12 +839,13 @@ sopno stopst; == char *stop, sopno startst, sopno stopst); */ static char * /* where it ended */ -slow(m, start, stop, startst, stopst) -struct match *m; -char *start; -char *stop; -sopno startst; -sopno stopst; +slow( + struct match *m, + char *start, + char *stop, + sopno startst, + sopno stopst +) { states st = m->st; states empty = m->empty; @@ -931,13 +936,14 @@ sopno stopst; == #define NNONCHAR (CODEMAX-CHAR_MAX) */ static states -step(g, start, stop, bef, ch, aft) -struct re_guts *g; -sopno start; /* start state within strip */ -sopno stop; /* state after stop state within strip */ -states bef; /* states reachable before */ -int ch; /* character or NONCHAR code */ -states aft; /* states already known reachable after */ +step( + struct re_guts *g, + sopno start, /* start state within strip */ + sopno stop, /* state after stop state within strip */ + states bef, /* states reachable before */ + int ch, /* character or NONCHAR code */ + states aft /* states already known reachable after */ +) { cset *cs; sop s; diff --git a/newlib/libc/posix/fnmatch.c b/newlib/libc/posix/fnmatch.c index 1a679ab85e..1f062a54cf 100644 --- a/newlib/libc/posix/fnmatch.c +++ b/newlib/libc/posix/fnmatch.c @@ -163,11 +163,12 @@ fnmatch(pattern, string, flags) } static int -rangematch(pattern, test, flags, newp) - const char *pattern; - char test; - int flags; - char **newp; +rangematch( + const char *pattern, + char test, + int flags, + char **newp +) { int negate, ok; char c, c2; diff --git a/newlib/libc/posix/regcomp.c b/newlib/libc/posix/regcomp.c index c789746755..c839809468 100644 --- a/newlib/libc/posix/regcomp.c +++ b/newlib/libc/posix/regcomp.c @@ -303,9 +303,10 @@ int cflags; == static void p_ere(struct parse *p, int stop); */ static void -p_ere(p, stop) -struct parse *p; -int stop; /* character this ERE should end at */ +p_ere( + struct parse *p, + int stop /* character this ERE should end at */ +) { char c; sopno prevback = 0; @@ -349,8 +350,7 @@ int stop; /* character this ERE should end at */ == static void p_ere_exp(struct parse *p); */ static void -p_ere_exp(p) -struct parse *p; +p_ere_exp(struct parse *p) { char c; sopno pos; @@ -498,8 +498,7 @@ struct parse *p; == static void p_str(struct parse *p); */ static void -p_str(p) -struct parse *p; +p_str(struct parse *p) { (void)REQUIRE(MORE(), REG_EMPTY); while (MORE()) @@ -519,10 +518,11 @@ struct parse *p; * The amount of lookahead needed to avoid this kludge is excessive. */ static void -p_bre(p, end1, end2) -struct parse *p; -int end1; /* first terminating character */ -int end2; /* second terminating character */ +p_bre( + struct parse *p, + int end1, /* first terminating character */ + int end2 /* second terminating character */ +) { sopno start = HERE(); int first = 1; /* first subexpression? */ @@ -552,9 +552,10 @@ int end2; /* second terminating character */ == static int p_simp_re(struct parse *p, int starordinary); */ static int /* was the simple RE an unbackslashed $? */ -p_simp_re(p, starordinary) -struct parse *p; -int starordinary; /* is a leading * an ordinary character? */ +p_simp_re( + struct parse *p, + int starordinary /* is a leading * an ordinary character? */ +) { int c; int count; @@ -670,8 +671,7 @@ int starordinary; /* is a leading * an ordinary character? */ == static int p_count(struct parse *p); */ static int /* the value */ -p_count(p) -struct parse *p; +p_count(struct parse *p) { int count = 0; int ndigits = 0; @@ -693,8 +693,7 @@ struct parse *p; * no set operations are done. */ static void -p_bracket(p) -struct parse *p; +p_bracket(struct parse *p) { cset *cs = allocset(p); int invert = 0; @@ -767,9 +766,10 @@ struct parse *p; == static void p_b_term(struct parse *p, cset *cs); */ static void -p_b_term(p, cs) -struct parse *p; -cset *cs; +p_b_term( + struct parse *p, + cset *cs +) { char c; char start, finish; @@ -846,9 +846,10 @@ cset *cs; == static void p_b_cclass(struct parse *p, cset *cs); */ static void -p_b_cclass(p, cs) -struct parse *p; -cset *cs; +p_b_cclass( + struct parse *p, + cset *cs +) { int c; char *sp = p->next; @@ -942,9 +943,10 @@ cset *cs; * This implementation is incomplete. xxx */ static void -p_b_eclass(p, cs) -struct parse *p; -cset *cs; +p_b_eclass( + struct parse *p, + cset *cs +) { char c; @@ -957,8 +959,7 @@ cset *cs; == static char p_b_symbol(struct parse *p); */ static char /* value of symbol */ -p_b_symbol(p) -struct parse *p; +p_b_symbol(struct parse *p) { char value; @@ -977,9 +978,10 @@ struct parse *p; == static char p_b_coll_elem(struct parse *p, int endc); */ static char /* value of collating element */ -p_b_coll_elem(p, endc) -struct parse *p; -int endc; /* name ended by endc,']' */ +p_b_coll_elem( + struct parse *p, + int endc /* name ended by endc,']' */ +) { char *sp = p->next; struct cname *cp; @@ -1006,8 +1008,9 @@ int endc; /* name ended by endc,']' */ == static char othercase(int ch); */ static char /* if no counterpart, return ch */ -othercase(ch) -int ch; +othercase( + int ch +) { ch = (uch)ch; assert(isalpha(ch)); @@ -1026,9 +1029,10 @@ int ch; * Boy, is this implementation ever a kludge... */ static void -bothcases(p, ch) -struct parse *p; -int ch; +bothcases( + struct parse *p, + int ch +) { char *oldnext = p->next; char *oldend = p->end; @@ -1052,9 +1056,10 @@ int ch; == static void ordinary(struct parse *p, int ch); */ static void -ordinary(p, ch) -struct parse *p; -int ch; +ordinary( + struct parse *p, + int ch +) { cat_t *cap = p->g->categories; @@ -1074,8 +1079,9 @@ int ch; * Boy, is this implementation ever a kludge... */ static void -nonnewline(p) -struct parse *p; +nonnewline( + struct parse *p +) { char *oldnext = p->next; char *oldend = p->end; @@ -1098,11 +1104,12 @@ struct parse *p; == static void repeat(struct parse *p, sopno start, int from, int to); */ static void -repeat(p, start, from, to) -struct parse *p; -sopno start; /* operand from here to end of strip */ -int from; /* repeated from this number */ -int to; /* to this number of times (maybe INFINITY) */ +repeat( + struct parse *p, + sopno start, /* operand from here to end of strip */ + int from, /* repeated from this number */ + int to /* to this number of times (maybe INFINITY) */ +) { sopno finish = HERE(); # define N 2 @@ -1170,9 +1177,10 @@ int to; /* to this number of times (maybe INFINITY) */ == static int seterr(struct parse *p, int e); */ static int /* useless but makes type checking happy */ -seterr(p, e) -struct parse *p; -int e; +seterr( + struct parse *p, + int e +) { if (p->error == 0) /* keep earliest error condition */ p->error = e; @@ -1186,8 +1194,7 @@ int e; == static cset *allocset(struct parse *p); */ static cset * -allocset(p) -struct parse *p; +allocset(struct parse *p) { int no = p->g->ncsets++; size_t nc; @@ -1241,9 +1248,10 @@ struct parse *p; == static void freeset(struct parse *p, cset *cs); */ static void -freeset(p, cs) -struct parse *p; -cset *cs; +freeset( + struct parse *p, + cset *cs +) { int i; cset *top = &p->g->sets[p->g->ncsets]; @@ -1266,9 +1274,10 @@ cset *cs; * the same value! */ static int /* set number */ -freezeset(p, cs) -struct parse *p; -cset *cs; +freezeset( + struct parse *p, + cset *cs +) { short h = cs->hash; int i; @@ -1300,9 +1309,10 @@ cset *cs; == static int firstch(struct parse *p, cset *cs); */ static int /* character; there is no "none" value */ -firstch(p, cs) -struct parse *p; -cset *cs; +firstch( + struct parse *p, + cset *cs +) { int i; size_t css = (size_t)p->g->csetsize; @@ -1319,9 +1329,10 @@ cset *cs; == static int nch(struct parse *p, cset *cs); */ static int -nch(p, cs) -struct parse *p; -cset *cs; +nch( + struct parse *p, + cset *cs +) { int i; size_t css = (size_t)p->g->csetsize; @@ -1428,9 +1439,10 @@ char *cp; * is deferred. */ static void -mcinvert(p, cs) -struct parse *p; -cset *cs; +mcinvert( + struct parse *p, + cset *cs +) { assert(cs->multis == NULL); /* xxx */ } @@ -1443,9 +1455,10 @@ cset *cs; * is deferred. */ static void -mccase(p, cs) -struct parse *p; -cset *cs; +mccase( + struct parse *p, + cset *cs +) { assert(cs->multis == NULL); /* xxx */ } @@ -1455,9 +1468,10 @@ cset *cs; == static int isinsets(struct re_guts *g, int c); */ static int /* predicate */ -isinsets(g, c) -struct re_guts *g; -int c; +isinsets( + struct re_guts *g, + int c +) { uch *col; int i; @@ -1475,10 +1489,11 @@ int c; == static int samesets(struct re_guts *g, int c1, int c2); */ static int /* predicate */ -samesets(g, c1, c2) -struct re_guts *g; -int c1; -int c2; +samesets( + struct re_guts *g, + int c1, + int c2 +) { uch *col; int i; @@ -1497,9 +1512,10 @@ int c2; == static void categorize(struct parse *p, struct re_guts *g); */ static void -categorize(p, g) -struct parse *p; -struct re_guts *g; +categorize( + struct parse *p, + struct re_guts *g +) { cat_t *cats = g->categories; int c; @@ -1525,10 +1541,11 @@ struct re_guts *g; == static sopno dupl(struct parse *p, sopno start, sopno finish); */ static sopno /* start of duplicate */ -dupl(p, start, finish) -struct parse *p; -sopno start; /* from here */ -sopno finish; /* to this less one */ +dupl( + struct parse *p, + sopno start, /* from here */ + sopno finish /* to this less one */ +) { sopno ret = HERE(); sopno len = finish - start; @@ -1553,10 +1570,11 @@ sopno finish; /* to this less one */ * some changes to the data structures. Maybe later. */ static void -doemit(p, op, opnd) -struct parse *p; -sop op; -size_t opnd; +doemit( + struct parse *p, + sop op, + size_t opnd +) { /* avoid making error situations worse */ if (p->error != 0) @@ -1579,11 +1597,12 @@ size_t opnd; == static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); */ static void -doinsert(p, op, opnd, pos) -struct parse *p; -sop op; -size_t opnd; -sopno pos; +doinsert( + struct parse *p, + sop op, + size_t opnd, + sopno pos +) { sopno sn; sop s; @@ -1619,10 +1638,11 @@ sopno pos; == static void dofwd(struct parse *p, sopno pos, sop value); */ static void -dofwd(p, pos, value) -struct parse *p; -sopno pos; -sop value; +dofwd( + struct parse *p, + sopno pos, + sop value +) { /* avoid making error situations worse */ if (p->error != 0) @@ -1637,9 +1657,10 @@ sop value; == static void enlarge(struct parse *p, sopno size); */ static void -enlarge(p, size) -struct parse *p; -sopno size; +enlarge( + struct parse *p, + sopno size +) { sop *sp; @@ -1660,9 +1681,10 @@ sopno size; == static void stripsnug(struct parse *p, struct re_guts *g); */ static void -stripsnug(p, g) -struct parse *p; -struct re_guts *g; +stripsnug( + struct parse *p, + struct re_guts *g +) { g->nstates = p->slen; g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); @@ -1683,9 +1705,10 @@ struct re_guts *g; * Note that must and mlen got initialized during setup. */ static void -findmust(p, g) -struct parse *p; -struct re_guts *g; +findmust( + struct parse *p, + struct re_guts *g +) { sop *scan; sop *start = NULL; @@ -1852,10 +1875,11 @@ struct re_guts *g; * re paths. */ static int -altoffset(scan, offset, mccs) -sop *scan; -int offset; -int mccs; +altoffset( + sop *scan, + int offset, + int mccs +) { int largest; int try; @@ -1932,9 +1956,10 @@ int mccs; * the value of the character from the text that was mismatched. */ static void -computejumps(p, g) -struct parse *p; -struct re_guts *g; +computejumps( + struct parse *p, + struct re_guts *g +) { int ch; int mindex; @@ -1978,9 +2003,10 @@ struct re_guts *g; * the search algorithm works. */ static void -computematchjumps(p, g) -struct parse *p; -struct re_guts *g; +computematchjumps( + struct parse *p, + struct re_guts *g +) { int mindex; /* General "must" iterator */ int suffix; /* Keeps track of matching suffix */ @@ -2056,9 +2082,10 @@ struct re_guts *g; == static sopno pluscount(struct parse *p, struct re_guts *g); */ static sopno /* nesting depth */ -pluscount(p, g) -struct parse *p; -struct re_guts *g; +pluscount( + struct parse *p, + struct re_guts *g +) { sop *scan; sop s; diff --git a/newlib/libc/posix/regerror.c b/newlib/libc/posix/regerror.c index a48d37c729..1b07b636c7 100644 --- a/newlib/libc/posix/regerror.c +++ b/newlib/libc/posix/regerror.c @@ -160,9 +160,10 @@ size_t errbuf_size; == static char *regatoi(const regex_t *preg, char *localbuf); */ static char * -regatoi(preg, localbuf) -const regex_t *preg; -char *localbuf; +regatoi( + const regex_t *preg, + char *localbuf +) { struct rerr *r; diff --git a/newlib/libc/search/hash.c b/newlib/libc/search/hash.c index 33ff275d94..f242337f5b 100644 --- a/newlib/libc/search/hash.c +++ b/newlib/libc/search/hash.c @@ -276,8 +276,9 @@ __hash_open (const char *file, } static int -hash_close(dbp) - DB *dbp; +hash_close( + DB *dbp +) { HTAB *hashp; int retval; @@ -292,8 +293,9 @@ hash_close(dbp) } static int -hash_fd(dbp) - const DB *dbp; +hash_fd( + const DB *dbp +) { HTAB *hashp; @@ -310,10 +312,11 @@ hash_fd(dbp) /************************** LOCAL CREATION ROUTINES **********************/ static HTAB * -init_hash(hashp, file, info) - HTAB *hashp; - const char *file; - const HASHINFO *info; +init_hash( + HTAB *hashp, + const char *file, + const HASHINFO *info +) { #ifdef __USE_INTERNAL_STAT64 struct stat64 statbuf; @@ -385,9 +388,10 @@ init_hash(hashp, file, info) * Returns 0 on No Error */ static int -init_htab(hashp, nelem) - HTAB *hashp; - int nelem; +init_htab( + HTAB *hashp, + int nelem +) { int nbuckets, nsegs; int l2; @@ -431,8 +435,9 @@ init_htab(hashp, nelem) * structure, freeing all allocated space. */ static int -hdestroy(hashp) - HTAB *hashp; +hdestroy( + HTAB *hashp +) { int i, save_errno; @@ -491,9 +496,10 @@ hdestroy(hashp) * -1 ERROR */ static int -hash_sync(dbp, flags) - const DB *dbp; - u_int flags; +hash_sync( + const DB *dbp, + u_int flags +) { HTAB *hashp; @@ -520,8 +526,9 @@ hash_sync(dbp, flags) * -1 indicates that errno should be set */ static int -flush_meta(hashp) - HTAB *hashp; +flush_meta( + HTAB *hashp +) { HASHHDR *whdrp; #if (BYTE_ORDER == LITTLE_ENDIAN) @@ -568,11 +575,12 @@ flush_meta(hashp) * -1 to indicate an internal ERROR (i.e. out of memory, etc) */ static int -hash_get(dbp, key, data, flag) - const DB *dbp; - const DBT *key; - DBT *data; - u_int flag; +hash_get( + const DB *dbp, + const DBT *key, + DBT *data, + u_int flag +) { HTAB *hashp; @@ -585,11 +593,12 @@ hash_get(dbp, key, data, flag) } static int -hash_put(dbp, key, data, flag) - const DB *dbp; - DBT *key; - const DBT *data; - u_int flag; +hash_put( + const DB *dbp, + DBT *key, + const DBT *data, + u_int flag +) { HTAB *hashp; @@ -608,10 +617,11 @@ hash_put(dbp, key, data, flag) } static int -hash_delete(dbp, key, flag) - const DB *dbp; - const DBT *key; - u_int flag; /* Ignored */ +hash_delete( + const DB *dbp, + const DBT *key, + u_int flag /* Ignored */ +) { HTAB *hashp; @@ -631,10 +641,12 @@ hash_delete(dbp, key, flag) * Assume that hashp has been set in wrapper routine. */ static int -hash_access(hashp, action, key, val) - HTAB *hashp; - ACTION action; - DBT *key, *val; +hash_access( + HTAB *hashp, + ACTION action, + DBT *key, + DBT *val +) { BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; @@ -760,10 +772,12 @@ hash_access(hashp, action, key, val) } static int -hash_seq(dbp, key, data, flag) - const DB *dbp; - DBT *key, *data; - u_int flag; +hash_seq( + const DB *dbp, + DBT *key, + DBT *data, + u_int flag +) { __uint32_t bucket; BUFHEAD *bufp; @@ -850,8 +864,9 @@ hash_seq(dbp, key, data, flag) * -1 ==> Error */ extern int -__expand_table(hashp) - HTAB *hashp; +__expand_table( + HTAB *hashp +) { __uint32_t old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; @@ -905,9 +920,11 @@ __expand_table(hashp) * fails, then this routine can go away. */ static void * -hash_realloc(p_ptr, oldsize, newsize) - SEGMENT **p_ptr; - int oldsize, newsize; +hash_realloc( + SEGMENT **p_ptr, + int oldsize, + int newsize +) { void *p; @@ -921,10 +938,11 @@ hash_realloc(p_ptr, oldsize, newsize) } extern __uint32_t -__call_hash(hashp, k, len) - HTAB *hashp; - char *k; - int len; +__call_hash( + HTAB *hashp, + char *k, + int len +) { int n, bucket; @@ -941,9 +959,10 @@ __call_hash(hashp, k, len) * Returns 0 on success */ static int -alloc_segs(hashp, nsegs) - HTAB *hashp; - int nsegs; +alloc_segs( + HTAB *hashp, + int nsegs +) { int i; SEGMENT store; @@ -975,8 +994,10 @@ alloc_segs(hashp, nsegs) * Hashp->hdr needs to be byteswapped. */ static void -swap_header_copy(srcp, destp) - HASHHDR *srcp, *destp; +swap_header_copy( + HASHHDR *srcp, + HASHHDR *destp +) { int i; @@ -1004,8 +1025,9 @@ swap_header_copy(srcp, destp) } static void -swap_header(hashp) - HTAB *hashp; +swap_header( + HTAB *hashp +) { HASHHDR *hdrp; int i; diff --git a/newlib/libc/search/hash_bigkey.c b/newlib/libc/search/hash_bigkey.c index e110e46945..29a14502a7 100644 --- a/newlib/libc/search/hash_bigkey.c +++ b/newlib/libc/search/hash_bigkey.c @@ -83,10 +83,12 @@ static int collect_data(HTAB *, BUFHEAD *, int, int); *-1 ==> ERROR */ extern int -__big_insert(hashp, bufp, key, val) - HTAB *hashp; - BUFHEAD *bufp; - const DBT *key, *val; +__big_insert( + HTAB *hashp, + BUFHEAD *bufp, + const DBT *key, + const DBT *val +) { __uint16_t *p; int key_size, n, val_size; @@ -183,9 +185,10 @@ __big_insert(hashp, bufp, key, val) *-1 => ERROR */ extern int -__big_delete(hashp, bufp) - HTAB *hashp; - BUFHEAD *bufp; +__big_delete( + HTAB *hashp, + BUFHEAD *bufp +) { BUFHEAD *last_bfp, *rbufp; __uint16_t *bp, pageno; @@ -262,12 +265,13 @@ __big_delete(hashp, bufp) * -3 error */ extern int -__find_bigpair(hashp, bufp, ndx, key, size) - HTAB *hashp; - BUFHEAD *bufp; - int ndx; - char *key; - int size; +__find_bigpair( + HTAB *hashp, + BUFHEAD *bufp, + int ndx, + char *key, + int size +) { __uint16_t *bp; char *p; @@ -314,9 +318,10 @@ __find_bigpair(hashp, bufp, ndx, key, size) * bucket) */ extern __uint16_t -__find_last_page(hashp, bpp) - HTAB *hashp; - BUFHEAD **bpp; +__find_last_page( + HTAB *hashp, + BUFHEAD **bpp +) { BUFHEAD *bufp; __uint16_t *bp, pageno; @@ -355,12 +360,13 @@ __find_last_page(hashp, bpp) * index (index should always be 1). */ extern int -__big_return(hashp, bufp, ndx, val, set_current) - HTAB *hashp; - BUFHEAD *bufp; - int ndx; - DBT *val; - int set_current; +__big_return( + HTAB *hashp, + BUFHEAD *bufp, + int ndx, + DBT *val, + int set_current +) { BUFHEAD *save_p; __uint16_t *bp, len, off, save_addr; @@ -446,10 +452,12 @@ __big_return(hashp, bufp, ndx, val, set_current) * allocate a buffer and copy the data as you recurse up. */ static int -collect_data(hashp, bufp, len, set) - HTAB *hashp; - BUFHEAD *bufp; - int len, set; +collect_data( + HTAB *hashp, + BUFHEAD *bufp, + int len, + int set +) { __uint16_t *bp; char *p; @@ -502,11 +510,13 @@ collect_data(hashp, bufp, len, set) * Fill in the key and data for this big pair. */ extern int -__big_keydata(hashp, bufp, key, val, set) - HTAB *hashp; - BUFHEAD *bufp; - DBT *key, *val; - int set; +__big_keydata( + HTAB *hashp, + BUFHEAD *bufp, + DBT *key, + DBT *val, + int set +) { key->size = collect_key(hashp, bufp, 0, val, set); if (key->size == -1) @@ -520,12 +530,13 @@ __big_keydata(hashp, bufp, key, val, set) * collect the data, allocate a buffer and copy the key as you recurse up. */ static int -collect_key(hashp, bufp, len, val, set) - HTAB *hashp; - BUFHEAD *bufp; - int len; - DBT *val; - int set; +collect_key( + HTAB *hashp, + BUFHEAD *bufp, + int len, + DBT *val, + int set +) { BUFHEAD *xbp; char *p; @@ -565,15 +576,16 @@ collect_key(hashp, bufp, len, val, set) * -1 => error */ extern int -__big_split(hashp, op, np, big_keyp, addr, obucket, ret) - HTAB *hashp; - BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */ - BUFHEAD *np; /* Pointer to new bucket page */ +__big_split( + HTAB *hashp, + BUFHEAD *op, /* Pointer to where to put keys that go in old bucket */ + BUFHEAD *np, /* Pointer to new bucket page */ /* Pointer to first page containing the big key/data */ - BUFHEAD *big_keyp; - int addr; /* Address of big_keyp */ - __uint32_t obucket;/* Old Bucket */ - SPLIT_RETURN *ret; + BUFHEAD *big_keyp, + int addr, /* Address of big_keyp */ + __uint32_t obucket,/* Old Bucket */ + SPLIT_RETURN *ret +) { BUFHEAD *tmpp; __uint16_t *tp; diff --git a/newlib/libc/search/hash_buf.c b/newlib/libc/search/hash_buf.c index 2b921681a7..7f8e90b679 100644 --- a/newlib/libc/search/hash_buf.c +++ b/newlib/libc/search/hash_buf.c @@ -107,11 +107,12 @@ static BUFHEAD *newbuf(HTAB *, __uint32_t, BUFHEAD *); * address you are seeking. */ extern BUFHEAD * -__get_buf(hashp, addr, prev_bp, newpage) - HTAB *hashp; - __uint32_t addr; - BUFHEAD *prev_bp; - int newpage; /* If prev_bp set, indicates a new overflow page. */ +__get_buf( + HTAB *hashp, + __uint32_t addr, + BUFHEAD *prev_bp, + int newpage /* If prev_bp set, indicates a new overflow page. */ +) { BUFHEAD *bp; __uint32_t is_disk_mask; @@ -162,10 +163,11 @@ __get_buf(hashp, addr, prev_bp, newpage) * If newbuf finds an error (returning NULL), it also sets errno. */ static BUFHEAD * -newbuf(hashp, addr, prev_bp) - HTAB *hashp; - __uint32_t addr; - BUFHEAD *prev_bp; +newbuf( + HTAB *hashp, + __uint32_t addr, + BUFHEAD *prev_bp +) { BUFHEAD *bp; /* The buffer we're going to use */ BUFHEAD *xbp; /* Temp pointer */ @@ -292,9 +294,10 @@ newbuf(hashp, addr, prev_bp) } extern void -__buf_init(hashp, nbytes) - HTAB *hashp; - int nbytes; +__buf_init( + HTAB *hashp, + int nbytes +) { BUFHEAD *bfp; int npages; @@ -317,9 +320,11 @@ __buf_init(hashp, nbytes) } extern int -__buf_free(hashp, do_free, to_disk) - HTAB *hashp; - int do_free, to_disk; +__buf_free( + HTAB *hashp, + int do_free, + int to_disk +) { BUFHEAD *bp; @@ -348,9 +353,10 @@ __buf_free(hashp, do_free, to_disk) } extern void -__reclaim_buf(hashp, bp) - HTAB *hashp; - BUFHEAD *bp; +__reclaim_buf( + HTAB *hashp, + BUFHEAD *bp +) { bp->ovfl = 0; bp->addr = 0; diff --git a/newlib/libc/search/hash_func.c b/newlib/libc/search/hash_func.c index 30263d0f63..ad8dd666d6 100644 --- a/newlib/libc/search/hash_func.c +++ b/newlib/libc/search/hash_func.c @@ -167,9 +167,10 @@ hash3(keyarg, len) /* Hash function from Chris Torek. */ static __uint32_t -hash4(keyarg, len) - const void *keyarg; - size_t len; +hash4( + const void *keyarg, + size_t len +) { const u_char *key; size_t loop; diff --git a/newlib/libc/search/hash_log2.c b/newlib/libc/search/hash_log2.c index 622c228474..0bc766af55 100644 --- a/newlib/libc/search/hash_log2.c +++ b/newlib/libc/search/hash_log2.c @@ -40,8 +40,9 @@ static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; #include "db_local.h" __uint32_t -__log2(num) - __uint32_t num; +__log2( + __uint32_t num +) { __uint32_t i, limit; diff --git a/newlib/libc/search/hash_page.c b/newlib/libc/search/hash_page.c index 9d15b0cb70..c073f49dfc 100644 --- a/newlib/libc/search/hash_page.c +++ b/newlib/libc/search/hash_page.c @@ -91,9 +91,11 @@ static int ugly_split * stuff on. */ static void -putpair(p, key, val) - char *p; - const DBT *key, *val; +putpair( + char *p, + const DBT *key, + const DBT *val +) { __uint16_t *bp, n, off; @@ -123,10 +125,11 @@ putpair(p, key, val) * -1 error */ extern int -__delpair(hashp, bufp, ndx) - HTAB *hashp; - BUFHEAD *bufp; - int ndx; +__delpair( + HTAB *hashp, + BUFHEAD *bufp, + int ndx +) { __uint16_t *bp, newoff; int n; @@ -176,9 +179,11 @@ __delpair(hashp, bufp, ndx) * -1 ==> Error */ extern int -__split_page(hashp, obucket, nbucket) - HTAB *hashp; - __uint32_t obucket, nbucket; +__split_page( + HTAB *hashp, + __uint32_t obucket, + __uint32_t nbucket +) { BUFHEAD *new_bufp, *old_bufp; __uint16_t *ino; @@ -272,12 +277,14 @@ __split_page(hashp, obucket, nbucket) * -1 ==> failure */ static int -ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) - HTAB *hashp; - __uint32_t obucket; /* Same as __split_page. */ - BUFHEAD *old_bufp, *new_bufp; - int copyto; /* First byte on page which contains key/data values. */ - int moved; /* Number of pairs moved to new page. */ +ugly_split( + HTAB *hashp, + __uint32_t obucket, /* Same as __split_page. */ + BUFHEAD *old_bufp, + BUFHEAD *new_bufp, + int copyto, /* First byte on page which contains key/data values. */ + int moved /* Number of pairs moved to new page. */ +) { BUFHEAD *bufp; /* Buffer header for ino */ __uint16_t *ino; /* Page keys come off of */ @@ -393,10 +400,12 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) * 1 ==> failure */ extern int -__addel(hashp, bufp, key, val) - HTAB *hashp; - BUFHEAD *bufp; - const DBT *key, *val; +__addel( + HTAB *hashp, + BUFHEAD *bufp, + const DBT *key, + const DBT *val +) { __uint16_t *bp, *sop; int do_expand; @@ -460,9 +469,10 @@ __addel(hashp, bufp, key, val) * NULL on error */ extern BUFHEAD * -__add_ovflpage(hashp, bufp) - HTAB *hashp; - BUFHEAD *bufp; +__add_ovflpage( + HTAB *hashp, + BUFHEAD *bufp +) { __uint16_t *sp; __uint16_t ndx, ovfl_num; @@ -513,11 +523,14 @@ __add_ovflpage(hashp, bufp) * -1 indicates FAILURE */ extern int -__get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) - HTAB *hashp; - char *p; - __uint32_t bucket; - int is_bucket, is_disk, is_bitmap; +__get_page( + HTAB *hashp, + char *p, + __uint32_t bucket, + int is_bucket, + int is_disk, + int is_bitmap +) { int fd, page, size; int rsize; @@ -573,11 +586,13 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) * -1 ==>failure */ extern int -__put_page(hashp, p, bucket, is_bucket, is_bitmap) - HTAB *hashp; - char *p; - __uint32_t bucket; - int is_bucket, is_bitmap; +__put_page( + HTAB *hashp, + char *p, + __uint32_t bucket, + int is_bucket, + int is_bitmap +) { int fd, page, size; int wsize; @@ -622,9 +637,12 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) * once they are read in. */ extern int -__ibitmap(hashp, pnum, nbits, ndx) - HTAB *hashp; - int pnum, nbits, ndx; +__ibitmap( + HTAB *hashp, + int pnum, + int nbits, + int ndx +) { __uint32_t *ip; int clearbytes, clearints; @@ -645,8 +663,9 @@ __ibitmap(hashp, pnum, nbits, ndx) } static __uint32_t -first_free(map) - __uint32_t map; +first_free( + __uint32_t map +) { __uint32_t i, mask; @@ -660,8 +679,9 @@ first_free(map) } static __uint16_t -overflow_page(hashp) - HTAB *hashp; +overflow_page( + HTAB *hashp +) { __uint32_t *freep = NULL; int max_free, offset, splitnum; @@ -808,9 +828,10 @@ overflow_page(hashp) * Mark this overflow page as free. */ extern void -__free_ovflpage(hashp, obufp) - HTAB *hashp; - BUFHEAD *obufp; +__free_ovflpage( + HTAB *hashp, + BUFHEAD *obufp +) { __uint16_t addr; __uint32_t *freep; @@ -854,8 +875,9 @@ __free_ovflpage(hashp, obufp) * -1 failure */ static int -open_temp(hashp) - HTAB *hashp; +open_temp( + HTAB *hashp +) { sigset_t set, oset; static char namestr[] = "_hashXXXXXX"; @@ -878,9 +900,11 @@ open_temp(hashp) * an overflow pair, so we need to shift things. */ static void -squeeze_key(sp, key, val) - __uint16_t *sp; - const DBT *key, *val; +squeeze_key( + __uint16_t *sp, + const DBT *key, + const DBT *val +) { char *p; __uint16_t free_space, n, off, pageno; @@ -905,9 +929,10 @@ squeeze_key(sp, key, val) } static __uint32_t * -fetch_bitmap(hashp, ndx) - HTAB *hashp; - int ndx; +fetch_bitmap( + HTAB *hashp, + int ndx +) { if (ndx >= hashp->nmaps) return (NULL); diff --git a/newlib/libc/search/tdestroy.c b/newlib/libc/search/tdestroy.c index 04c6b70520..23c4b0e70f 100644 --- a/newlib/libc/search/tdestroy.c +++ b/newlib/libc/search/tdestroy.c @@ -26,9 +26,10 @@ __RCSID("$NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $"); /* Walk the nodes of a tree */ static void -trecurse(root, free_action) - node_t *root; /* Root of the tree to be walked */ - void (*free_action)(void *); +trecurse( + node_t *root, /* Root of the tree to be walked */ + void (*free_action)(void *) +) { if (root->llink != NULL) trecurse(root->llink, free_action); diff --git a/newlib/libc/search/twalk.c b/newlib/libc/search/twalk.c index 02ef52242f..7aec6e4dd2 100644 --- a/newlib/libc/search/twalk.c +++ b/newlib/libc/search/twalk.c @@ -28,10 +28,11 @@ static void trecurse(const node_t *, /* Walk the nodes of a tree */ static void -trecurse(root, action, level) - const node_t *root; /* Root of the tree to be walked */ - void (*action)(const void *, VISIT, int); - int level; +trecurse( + const node_t *root, /* Root of the tree to be walked */ + void (*action)(const void *, VISIT, int), + int level +) { if (root->llink == NULL && root->rlink == NULL) diff --git a/newlib/libm/common/s_nextafter.c b/newlib/libm/common/s_nextafter.c index 9453a0a001..356c79f3de 100644 --- a/newlib/libm/common/s_nextafter.c +++ b/newlib/libm/common/s_nextafter.c @@ -70,7 +70,7 @@ PORTABILITY if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */ ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */ return x+y; - if(x==y) return x; /* x=y, return x */ + if(x==y) return y; /* x=y, return y */ if((ix|lx)==0) { /* x == 0 */ INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */ y = x*x; diff --git a/newlib/libm/common/sf_nextafter.c b/newlib/libm/common/sf_nextafter.c index cea4da58dd..cdc7c663df 100644 --- a/newlib/libm/common/sf_nextafter.c +++ b/newlib/libm/common/sf_nextafter.c @@ -32,7 +32,7 @@ if(FLT_UWORD_IS_NAN(ix) || FLT_UWORD_IS_NAN(iy)) return x+y; - if(x==y) return x; /* x=y, return x */ + if(x==y) return y; /* x=y, return y */ if(FLT_UWORD_IS_ZERO(ix)) { /* x == 0 */ SET_FLOAT_WORD(x,(hy&0x80000000)|FLT_UWORD_MIN); y = x*x; diff --git a/newlib/libm/math/ef_pow.c b/newlib/libm/math/ef_pow.c index 07b225f8cb..8cf58dbb54 100644 --- a/newlib/libm/math/ef_pow.c +++ b/newlib/libm/math/ef_pow.c @@ -50,8 +50,8 @@ lg2_h = 6.93145752e-01, /* 0x3f317200 */ lg2_l = 1.42860654e-06, /* 0x35bfbe8c */ ovt = 4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */ cp = 9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */ -cp_h = 9.6179199219e-01, /* 0x3f763800 =head of cp */ -cp_l = 4.7017383622e-06, /* 0x369dc3a0 =tail of cp_h */ +cp_h = 9.6191406250e-01f, /* 0x3f764000 =12b of cp */ +cp_l = -1.1736857402e-04f, /* 0xb8f623c6 =tail of cp_h */ ivln2 = 1.4426950216e+00, /* 0x3fb8aa3b =1/ln2 */ ivln2_h = 1.4426879883e+00, /* 0x3fb8aa00 =16b 1/ln2*/ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ @@ -173,7 +173,8 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ GET_FLOAT_WORD(is,s_h); SET_FLOAT_WORD(s_h,is&0xfffff000); /* t_h=ax+bp[k] High */ - SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21)); + is = ((ix >> 1) & 0xfffff000U) | 0x20000000; + SET_FLOAT_WORD(t_h, is + 0x00400000 + (k << 21)); t_l = ax - (t_h-bp[k]); s_l = v*((u-s_h*t_h)-s_h*t_l); /* compute log(ax) */ @@ -241,7 +242,7 @@ ivln2_l = 7.0526075433e-06; /* 0x36eca570 =1/ln2 tail*/ } t = p_l+p_h; GET_FLOAT_WORD(is,t); - SET_FLOAT_WORD(t,is&0xfffff000); + SET_FLOAT_WORD(t,is&0xffff8000); u = t*lg2_h; v = (p_l-(t-p_h))*lg2+t*lg2_l; z = u+v; diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index f6b62552ed..469052a98a 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -1420,7 +1420,7 @@ api_fatal_debug () /* Attempt to carefully handle SIGCONT when we are stopped. */ void -_cygtls::handle_SIGCONT () +_cygtls::handle_SIGCONT (threadlist_t * &tl_entry) { if (NOTSTATE (myself, PID_STOPPED)) return; @@ -1435,7 +1435,11 @@ _cygtls::handle_SIGCONT () while (1) if (sig) /* Assume that it's ok to just test sig outside of a lock since setup_handler does it this way. */ - yield (); /* Attempt to schedule another thread. */ + { + cygheap->unlock_tls (tl_entry); + yield (); /* Attempt to schedule another thread. */ + tl_entry = cygheap->find_tls (_main_tls); + } else if (sigsent) break; /* SIGCONT has been recognized by other thread */ else @@ -1445,10 +1449,10 @@ _cygtls::handle_SIGCONT () sigsent = true; } /* Clear pending stop signals */ - sig_clear (SIGSTOP); - sig_clear (SIGTSTP); - sig_clear (SIGTTIN); - sig_clear (SIGTTOU); + sig_clear (SIGSTOP, false); + sig_clear (SIGTSTP, false); + sig_clear (SIGTTIN, false); + sig_clear (SIGTTOU, false); } int @@ -1477,7 +1481,7 @@ sigpacket::process () if (si.si_signo == SIGCONT) { tl_entry = cygheap->find_tls (_main_tls); - _main_tls->handle_SIGCONT (); + _main_tls->handle_SIGCONT (tl_entry); cygheap->unlock_tls (tl_entry); } @@ -1528,11 +1532,14 @@ sigpacket::process () if ((HANDLE) *tls) tls->signal_debugger (si); - if (issig_wait) + tls->lock (); + if (issig_wait && tls->sigwait_mask != 0) { tls->sigwait_mask = 0; + tls->unlock (); goto dosig; } + tls->unlock (); if (handler == SIG_IGN) { @@ -1546,14 +1553,14 @@ sigpacket::process () goto exit_sig; if (si.si_signo == SIGSTOP) { - sig_clear (SIGCONT); + sig_clear (SIGCONT, false); goto stop; } /* Clear pending SIGCONT on stop signals */ if (si.si_signo == SIGTSTP || si.si_signo == SIGTTIN || si.si_signo == SIGTTOU) - sig_clear (SIGCONT); + sig_clear (SIGCONT, false); if (handler == (void *) SIG_DFL) { diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc index dc43cd9f59..2651e49a62 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -60,6 +60,10 @@ const unsigned fhandler_console::MAX_WRITE_CHARS = 16384; fhandler_console::console_state NO_COPY *fhandler_console::shared_console_info[MAX_CONS_DEV + 1]; +static bool NO_COPY inside_pcon_checked = false; +static bool NO_COPY inside_pcon = false; +static int NO_COPY parent_pty; + bool NO_COPY fhandler_console::invisible_console; /* con_ra is shared in the same process. @@ -71,37 +75,33 @@ static struct fhandler_base::rabuf_t con_ra; static wchar_t last_char; DWORD -fhandler_console::attach_console (pid_t owner, bool *err) +fhandler_console::attach_console (DWORD owner, bool *err) { DWORD resume_pid = (DWORD) -1; - pinfo p (owner); - if (p) + if (!process_alive (owner)) + return resume_pid; + DWORD attached = + get_console_process_id (owner, true, false, false); + if (!attached) { - DWORD attached = - fhandler_pty_common::get_console_process_id (p->dwProcessId, - true, false, false); - if (!attached) + resume_pid = + get_console_process_id (GetCurrentProcessId (), false, false, false); + FreeConsole (); + BOOL r = AttachConsole (owner); + if (!r) { - resume_pid = - fhandler_pty_common::get_console_process_id (myself->dwProcessId, - false, false, false); - FreeConsole (); - BOOL r = AttachConsole (p->dwProcessId); - if (!r) - { - if (resume_pid) - AttachConsole (resume_pid); - if (err) - *err = true; - return (DWORD) -1; - } + if (resume_pid) + AttachConsole (resume_pid); + if (err) + *err = true; + return (DWORD) -1; } } return resume_pid; } void -fhandler_console::detach_console (DWORD resume_pid, pid_t owner) +fhandler_console::detach_console (DWORD resume_pid, DWORD owner) { if (resume_pid == (DWORD) -1) return; @@ -110,11 +110,11 @@ fhandler_console::detach_console (DWORD resume_pid, pid_t owner) FreeConsole (); AttachConsole (resume_pid); } - else if (myself->pid != owner) + else if (GetCurrentProcessId () != owner) FreeConsole (); } -pid_t +DWORD fhandler_console::get_owner () { return con.owner; @@ -133,14 +133,14 @@ static class write_pending_buffer { empty (); } - inline void put (HANDLE output_handle, pid_t owner, char x) + inline void put (HANDLE output_handle, DWORD owner, char x) { if (ixput == WPBUF_LEN) send (output_handle, owner); buf[ixput++] = x; } inline void empty () { ixput = 0u; } - inline void send (HANDLE output_handle, pid_t owner) + inline void send (HANDLE output_handle, DWORD owner) { if (!output_handle) { @@ -395,7 +395,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp) } }; termios &ti = ttyp->ti; - while (con.owner == myself->pid) + while (con.owner == GetCurrentProcessId ()) { DWORD total_read, n, i; @@ -709,7 +709,7 @@ fhandler_console::set_unit () unit = device::minor (cs->tty_min_state.ntty); shared_console_info[unit] = cs; if (created) - con.owner = myself->pid; + con.owner = GetCurrentProcessId (); } } } @@ -917,10 +917,10 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p) /* conmode can be tty::restore when non-cygwin app is exec'ed from login shell. */ tty::cons_mode conmode = - (con.owner == myself->pid) ? tty::restore : tty::cygwin; + (con.owner == GetCurrentProcessId ()) ? tty::restore : tty::cygwin; set_output_mode (conmode, ti, p); set_input_mode (conmode, ti, p); - set_disable_master_thread (con.owner == myself->pid); + set_disable_master_thread (con.owner == GetCurrentProcessId ()); } /* Return the tty structure associated with a given tty number. If the @@ -1033,7 +1033,7 @@ fhandler_console::set_cursor_maybe () /* Workaround for a bug of windows xterm compatible mode. */ /* The horizontal tab positions are broken after resize. */ void -fhandler_console::fix_tab_position (HANDLE h, pid_t owner) +fhandler_console::fix_tab_position (HANDLE h, DWORD owner) { /* Re-setting ENABLE_VIRTUAL_TERMINAL_PROCESSING fixes the tab position. */ @@ -1773,13 +1773,8 @@ fhandler_console::open (int flags, mode_t) setup_io_mutex (); acquire_output_mutex (mutex_timeout); - do - { - pinfo p (con.owner); - if (!p) - con.owner = myself->pid; - } - while (false); + if (!process_alive (con.owner)) + con.owner = GetCurrentProcessId (); /* Open the input handle as handle_ */ bool err = false; @@ -1843,7 +1838,7 @@ fhandler_console::open (int flags, mode_t) set_open_status (); - if (myself->pid == con.owner && wincap.has_con_24bit_colors ()) + if (GetCurrentProcessId () == con.owner && wincap.has_con_24bit_colors ()) { bool is_legacy = false; DWORD dwMode; @@ -1874,7 +1869,7 @@ fhandler_console::open (int flags, mode_t) debug_printf ("opened conin$ %p, conout$ %p", get_handle (), get_output_handle ()); - if (myself->pid == con.owner) + if (GetCurrentProcessId () == con.owner) { if (GetModuleHandle ("ConEmuHk64.dll")) hook_conemu_cygwin_connector (); @@ -1894,12 +1889,68 @@ fhandler_console::open (int flags, mode_t) return 1; } +void +fhandler_console::setup_pcon_hand_over () +{ + /* Prepare for pcon hand over */ + if (!inside_pcon_checked) + for (int i = 0; i < NTTYS; i++) + { + if (!cygwin_shared->tty[i]->pcon_activated) + continue; + DWORD owner = cygwin_shared->tty[i]->nat_pipe_owner_pid; + if (get_console_process_id (owner, true, false, false, false)) + { + inside_pcon = true; + atexit (fhandler_console::pcon_hand_over_proc); + parent_pty = i; + break; + } + } + inside_pcon_checked = true; +} + +void +fhandler_console::pcon_hand_over_proc (void) +{ + if (!inside_pcon) + return; + tty *ttyp = cygwin_shared->tty[parent_pty]; + char buf[MAX_PATH]; + shared_name (buf, PIPE_SW_MUTEX, parent_pty); + HANDLE mtx = OpenMutex (MAXIMUM_ALLOWED, FALSE, buf); + WaitForSingleObject (mtx, INFINITE); + ReleaseMutex (mtx); + DWORD res = WaitForSingleObject (mtx, INFINITE); + if (res == WAIT_OBJECT_0 || res == WAIT_ABANDONED) + { + DWORD owner = ttyp->nat_pipe_owner_pid; + if (owner == GetCurrentProcessId () + || owner == (myself->exec_dwProcessId ?: myself->dwProcessId)) + fhandler_pty_slave::close_pseudoconsole (ttyp, 0); + } + else + system_printf("Acquiring pcon_ho_mutex failed."); + /* Do not release the mutex. + Hold onto the mutex until this process completes. */ +} + bool fhandler_console::open_setup (int flags) { set_flags ((flags & ~O_TEXT) | O_BINARY); if (myself->set_ctty (this, flags) && !myself->cygstarted) - init_console_handler (true); + { + init_console_handler (true); + setup_pcon_hand_over (); + + /* Initialize handle_set */ + handle_set.input_handle = get_handle (); + handle_set.output_handle = get_output_handle (); + handle_set.input_mutex = input_mutex; + handle_set.output_mutex = output_mutex; + handle_set.unit = unit; + } return fhandler_base::open_setup (flags); } @@ -1925,16 +1976,16 @@ fhandler_console::close () acquire_output_mutex (mutex_timeout); - if (shared_console_info[unit]) + if (shared_console_info[unit] && !myself->cygstarted + && (dev_t) myself->ctty == get_device ()) { /* Restore console mode if this is the last closure. */ OBJECT_BASIC_INFORMATION obi; NTSTATUS status; status = NtQueryObject (get_handle (), ObjectBasicInformation, &obi, sizeof obi, NULL); - if ((NT_SUCCESS (status) && obi.HandleCount == 1 - && (dev_t) myself->ctty == get_device ()) - || myself->pid == con.owner) + if (NT_SUCCESS (status) + && obi.HandleCount == (con.owner == GetCurrentProcessId () ? 2 : 3)) { /* Cleaning-up console mode for cygwin apps. */ set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set); @@ -1943,7 +1994,7 @@ fhandler_console::close () } } - if (shared_console_info[unit] && con.owner == myself->pid) + if (shared_console_info[unit] && con.owner == GetCurrentProcessId ()) { if (master_thread_started) { @@ -1952,7 +2003,7 @@ fhandler_console::close () thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); if (thread_sync_event) { - con.owner = MAX_PID + 1; + con.owner = (DWORD) -1; WaitForSingleObject (thread_sync_event, INFINITE); CloseHandle (thread_sync_event); } @@ -3441,7 +3492,7 @@ enum_proc (const LOGFONTW *lf, const TEXTMETRICW *tm, } static void -check_font (HANDLE hdl, pid_t owner) +check_font (HANDLE hdl, DWORD owner) { CONSOLE_FONT_INFOEX cfi; LOGFONTW lf; @@ -4327,6 +4378,7 @@ fhandler_console::fixup_after_fork_exec (bool execing) cygheap->ctty = NULL; return; } + setup_pcon_hand_over (); if (!execing) return; diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/disk_file.cc index 5359e13e89..70b7765dc0 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -1810,6 +1810,9 @@ fhandler_disk_file::prw_open (bool write, void *aio) return -1; } + /* prw_handle is invalid after fork. */ + need_fork_fixup (true); + /* record prw_handle's asyncness for subsequent pread/pwrite operations */ prw_handle_isasync = !!aio; return 0; diff --git a/winsup/cygwin/fhandler/fifo.cc b/winsup/cygwin/fhandler/fifo.cc index efea508ae5..ee49ce695e 100644 --- a/winsup/cygwin/fhandler/fifo.cc +++ b/winsup/cygwin/fhandler/fifo.cc @@ -669,7 +669,7 @@ fhandler_fifo::create_shmem (bool only_open) { HANDLE sect; OBJECT_ATTRIBUTES attr; - NTSTATUS status; + NTSTATUS status = STATUS_SUCCESS; LARGE_INTEGER size = { .QuadPart = sizeof (fifo_shmem_t) }; SIZE_T viewsize = sizeof (fifo_shmem_t); PVOID addr = NULL; diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc index 8077082ee1..7244fa4cd5 100644 --- a/winsup/cygwin/fhandler/pipe.cc +++ b/winsup/cygwin/fhandler/pipe.cc @@ -580,7 +580,7 @@ fhandler_pipe_fifo::raw_write (const void *ptr, size_t len) else if (avail >= PIPE_BUF) len1 = avail & ~(PIPE_BUF - 1); else - len1 = 1 << (31 - __builtin_clzl (avail)); + len1 = 1 << (63 - __builtin_clzl (avail)); short_write_once = true; } if (isclosed ()) /* A signal handler might have closed the fd. */ diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc index 12a0ab377c..eb51c6d392 100644 --- a/winsup/cygwin/fhandler/pty.cc +++ b/winsup/cygwin/fhandler/pty.cc @@ -74,58 +74,6 @@ void release_attach_mutex (void) ReleaseMutex (attach_mutex); } -inline static bool process_alive (DWORD pid); - -/* This functions looks for a process which attached to the same console - with current process and is matched to given conditions: - match: If true, return given pid if the process pid attaches to the - same console, otherwise, return 0. If false, return pid except - for given pid. - cygwin: return only process's pid which has cygwin pid. - stub_only: return only stub process's pid of non-cygwin process. */ -DWORD -fhandler_pty_common::get_console_process_id (DWORD pid, bool match, - bool cygwin, bool stub_only, - bool nat) -{ - tmp_pathbuf tp; - DWORD *list = (DWORD *) tp.c_get (); - const DWORD buf_size = NT_MAX_PATH / sizeof (DWORD); - - DWORD num = GetConsoleProcessList (list, buf_size); - if (num == 0 || num > buf_size) - return 0; - - DWORD res_pri = 0, res = 0; - /* Last one is the oldest. */ - /* https://github.com/microsoft/terminal/issues/95 */ - for (int i = (int) num - 1; i >= 0; i--) - if ((match && list[i] == pid) || (!match && list[i] != pid)) - { - if (!cygwin) - { - res_pri = list[i]; - break; - } - else - { - pinfo p (cygwin_pid (list[i])); - if (nat && !!p && !ISSTATE(p, PID_NOTCYGWIN)) - continue; - if (!!p && p->exec_dwProcessId) - { - res_pri = stub_only ? p->exec_dwProcessId : list[i]; - break; - } - if (!p && !res && process_alive (list[i]) && stub_only) - res = list[i]; - if (!!p && !res && !stub_only) - res = list[i]; - } - } - return res_pri ?: res; -} - static bool isHybrid; /* Set true if the active pipe is set to nat pipe owned by myself even though the current process is a cygwin process. */ @@ -1116,28 +1064,11 @@ fhandler_pty_slave::set_switch_to_nat_pipe (void) } } -inline static bool -process_alive (DWORD pid) -{ - /* This function is very similar to _pinfo::alive(), however, this - can be used for non-cygwin process which is started from non-cygwin - shell. In addition, this checks exit code as well. */ - if (pid == 0) - return false; - HANDLE h = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); - if (h == NULL) - return false; - DWORD exit_code; - BOOL r = GetExitCodeProcess (h, &exit_code); - CloseHandle (h); - if (r && exit_code == STILL_ACTIVE) - return true; - return false; -} - inline static bool nat_pipe_owner_self (DWORD pid) { + if (pid == GetCurrentProcessId ()) + return true; return (pid == (myself->exec_dwProcessId ?: myself->dwProcessId)); } @@ -3557,11 +3488,16 @@ fhandler_pty_slave::get_winpid_to_hand_over (tty *ttyp, { /* Search another native process which attaches to the same console */ DWORD current_pid = myself->exec_dwProcessId ?: myself->dwProcessId; + if (ttyp->nat_pipe_owner_pid == GetCurrentProcessId ()) + current_pid = GetCurrentProcessId (); switch_to = get_console_process_id (current_pid, false, true, true, true); if (!switch_to) switch_to = get_console_process_id (current_pid, false, true, false, true); + if (!switch_to) + switch_to = get_console_process_id (current_pid, + false, false, false, false); } return switch_to; } @@ -3589,13 +3525,13 @@ fhandler_pty_slave::hand_over_only (tty *ttyp, DWORD force_switch_to) void fhandler_pty_slave::close_pseudoconsole (tty *ttyp, DWORD force_switch_to) { - DWORD switch_to = get_winpid_to_hand_over (ttyp, force_switch_to); acquire_attach_mutex (mutex_timeout); ttyp->previous_code_page = GetConsoleCP (); ttyp->previous_output_code_page = GetConsoleOutputCP (); release_attach_mutex (); if (nat_pipe_owner_self (ttyp->nat_pipe_owner_pid)) { /* I am owner of the nat pipe. */ + DWORD switch_to = get_winpid_to_hand_over (ttyp, force_switch_to); if (switch_to) { /* Change pseudo console owner to another process (switch_to). */ diff --git a/winsup/cygwin/fhandler/termios.cc b/winsup/cygwin/fhandler/termios.cc index d106955dcc..3cbdf7fca0 100644 --- a/winsup/cygwin/fhandler/termios.cc +++ b/winsup/cygwin/fhandler/termios.cc @@ -20,6 +20,7 @@ details. */ #include "cygheap.h" #include "child_info.h" #include "ntdll.h" +#include "tls_pbuf.h" /* Wait time for some treminal mutexes. This is set to 0 when the process calls CreateProcess() with DEBUG_PROCESS flag, because @@ -827,3 +828,90 @@ fhandler_termios::spawn_worker::close_handle_set () if (cons_need_cleanup) fhandler_console::close_handle_set (&cons_handle_set); } + +void +fhandler_termios::atexit_func () +{ + fhandler_console::pcon_hand_over_proc (); +} + +bool +fhandler_termios::process_alive (DWORD pid) +{ + /* This function is very similar to _pinfo::alive(), however, this + can be used for non-cygwin process which is started from non-cygwin + shell. In addition, this checks exit code as well. */ + if (pid == 0) + return false; + HANDLE h = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); + if (h == NULL) + return false; + DWORD exit_code; + BOOL r = GetExitCodeProcess (h, &exit_code); + CloseHandle (h); + if (r && exit_code == STILL_ACTIVE) + return true; + return false; +} + +/* This functions looks for a process which attached to the same console + with current process and is matched to given conditions: + match: If true, return given pid if the process pid attaches to the + same console, otherwise, return 0. If false, return pid except + for given pid. + cygwin: return only process's pid which has cygwin pid. + stub_only: return only stub process's pid of non-cygwin process. */ +DWORD +fhandler_termios::get_console_process_id (DWORD pid, bool match, + bool cygwin, bool stub_only, + bool nat) +{ + tmp_pathbuf tp; + DWORD *list = (DWORD *) tp.c_get (); + const DWORD buf_size = NT_MAX_PATH / sizeof (DWORD); + + DWORD buf_size1 = 1; + DWORD num; + /* The buffer of too large size does not seem to be expected by new condrv. + https://github.com/microsoft/terminal/issues/18264#issuecomment-2515448548 + Use the minimum buffer size in the loop. */ + while ((num = GetConsoleProcessList (list, buf_size1)) > buf_size1) + { + if (num > buf_size) + return 0; + buf_size1 = num; + } + if (num == 0) + return 0; + + DWORD res_pri = 0, res = 0; + /* Last one is the oldest. */ + /* https://github.com/microsoft/terminal/issues/95 */ + for (int i = (int) num - 1; i >= 0; i--) + if ((match && list[i] == pid) || (!match && list[i] != pid)) + { + if (!process_alive (list[i])) + continue; + if (!cygwin) + { + res_pri = list[i]; + break; + } + else + { + pinfo p (cygwin_pid (list[i])); + if (nat && !!p && !ISSTATE(p, PID_NOTCYGWIN)) + continue; + if (!!p && p->exec_dwProcessId) + { + res_pri = stub_only ? p->exec_dwProcessId : list[i]; + break; + } + if (!p && !res && stub_only) + res = list[i]; + if (!!p && !res && !stub_only) + res = list[i]; + } + } + return res_pri ?: res; +} diff --git a/winsup/cygwin/flock.cc b/winsup/cygwin/flock.cc index 0f1efa01d4..b41cba5c70 100644 --- a/winsup/cygwin/flock.cc +++ b/winsup/cygwin/flock.cc @@ -297,6 +297,7 @@ class inode_t HANDLE i_dir; HANDLE i_mtx; uint32_t i_cnt; /* # of threads referencing this instance. */ + uint32_t i_lock_cnt; /* # of locks for this file */ public: inode_t (dev_t dev, ino_t ino); @@ -321,6 +322,8 @@ class inode_t void unlock_and_remove_if_unused (); lockf_t *get_all_locks_list (); + uint32_t get_lock_count () /* needs get_all_locks_list() */ + { return i_lock_cnt; } bool del_my_locks (long long id, HANDLE fhdl); }; @@ -503,7 +506,8 @@ inode_t::get (dev_t dev, ino_t ino, bool create_if_missing, bool lock) } inode_t::inode_t (dev_t dev, ino_t ino) -: i_lockf (NULL), i_all_lf (NULL), i_dev (dev), i_ino (ino), i_cnt (0L) +: i_lockf (NULL), i_all_lf (NULL), i_dev (dev), i_ino (ino), i_cnt (0L), + i_lock_cnt (0) { HANDLE parent_dir; WCHAR name[48]; @@ -610,17 +614,16 @@ inode_t::get_all_locks_list () dbi->ObjectName.Buffer[LOCK_OBJ_NAME_LEN] = L'\0'; if (!newlock.from_obj_name (this, &i_all_lf, dbi->ObjectName.Buffer)) continue; - if (lock - i_all_lf >= MAX_LOCKF_CNT) - { - system_printf ("Warning, can't handle more than %d locks per file.", - MAX_LOCKF_CNT); - break; - } + /* This should not be happen. The number of locks is limitted + in lf_setlock() and lf_clearlock() so that it does not + exceed MAX_LOCKF_CNT. */ + assert (lock - i_all_lf < MAX_LOCKF_CNT); if (lock > i_all_lf) lock[-1].lf_next = lock; new (lock++) lockf_t (newlock); } } + i_lock_cnt = lock - i_all_lf; /* If no lock has been found, return NULL. */ if (lock == i_all_lf) return NULL; @@ -1190,6 +1193,12 @@ fhandler_base::lock (int a_op, struct flock *fl) return -1; } +/* The total number of locks shall not exceed MAX_LOCKF_CNT. + If once it exceeds, lf_fildoverlap() cannot work correctly. + Therefore, lf_setlock() and lf_clearlock() control the + total number of locks not to exceed MAX_LOCKF_CNT. When + they detect that the operation will cause excess, they + return ENOCLK. */ /* * Set a byte-range lock. */ @@ -1346,14 +1355,31 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) * * Handle any locks that overlap. */ + node->get_all_locks_list (); /* Update lock count */ + uint32_t lock_cnt = node->get_lock_count (); + /* lf_clearlock() sometimes increases the number of locks. Without + this room, the unlocking will never succeed in some situation. */ + const uint32_t room_for_clearlock = 2; + const int incr[] = {1, 1, 2, 2, 3, 2}; + int decr = 0; + prev = head; block = *head; needtolink = 1; for (;;) { ovcase = lf_findoverlap (block, lock, SELF, &prev, &overlap); + /* Estimate the maximum increase in number of the locks that + can occur here. If this possibly exceeds the MAX_LOCKF_CNT, + return ENOLCK. */ if (ovcase) - block = overlap->lf_next; + { + block = overlap->lf_next; + HANDLE ov_obj = overlap->lf_obj; + decr = (ov_obj && get_obj_handle_count (ov_obj) == 1) ? 1 : 0; + } + if (needtolink) + lock_cnt += incr[ovcase] - decr; /* * Six cases: * 0) no overlap @@ -1368,6 +1394,8 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) case 0: /* no overlap */ if (needtolink) { + if (lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; *prev = lock; lock->lf_next = overlap; lock->create_lock_obj (); @@ -1380,12 +1408,18 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) * able to acquire it. * Cygwin: Always wake lock. */ + if (lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; + /* Do not create a lock here. It should be done after all + overlaps have been removed. */ lf_wakelock (overlap, fhdl); - overlap->lf_type = lock->lf_type; - overlap->create_lock_obj (); - lock->lf_next = *clean; - *clean = lock; - break; + *prev = overlap->lf_next; + overlap->lf_next = *clean; + *clean = overlap; + /* We may have multiple versions (lf_ver) having same lock range. + Therefore, we need to find overlap repeatedly. (originally, + just 'break' here. */ + continue; case 2: /* overlap contains lock */ /* @@ -1397,6 +1431,11 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) *clean = lock; break; } + if (overlap->lf_start < lock->lf_start + && overlap->lf_end > lock->lf_end) + lock_cnt++; + if (lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; if (overlap->lf_start == lock->lf_start) { *prev = lock; @@ -1413,6 +1452,8 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) break; case 3: /* lock contains overlap */ + if (needtolink && lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; /* * If downgrading lock, others may be able to * acquire it, otherwise take the list. @@ -1440,6 +1481,8 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) /* * Add lock after overlap on the list. */ + if (lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; lock->lf_next = overlap->lf_next; overlap->lf_next = lock; overlap->lf_end = lock->lf_start - 1; @@ -1454,13 +1497,16 @@ lf_setlock (lockf_t *lock, inode_t *node, lockf_t **clean, HANDLE fhdl) /* * Add the new lock before overlap. */ - if (needtolink) { + if (needtolink) + { + if (lock_cnt > MAX_LOCKF_CNT - room_for_clearlock) + return ENOLCK; *prev = lock; lock->lf_next = overlap; - } + lock->create_lock_obj (); + } overlap->lf_start = lock->lf_end + 1; lf_wakelock (overlap, fhdl); - lock->create_lock_obj (); overlap->create_lock_obj (); break; } @@ -1485,9 +1531,34 @@ lf_clearlock (lockf_t *unlock, lockf_t **clean, HANDLE fhdl) if (lf == NOLOCKF) return 0; + + inode_t *node = lf->lf_inode; + tmp_pathbuf tp; + node->i_all_lf = (lockf_t *) tp.w_get (); + node->get_all_locks_list (); /* Update lock count */ + uint32_t lock_cnt = node->get_lock_count (); + bool first_loop = true; + prev = head; while ((ovcase = lf_findoverlap (lf, unlock, SELF, &prev, &overlap))) { + /* Estimate the maximum increase in number of the locks that + can occur here. If this possibly exceeds the MAX_LOCKF_CNT, + return ENOLCK. */ + HANDLE ov_obj = overlap->lf_obj; + if (first_loop) + { + const int incr[] = {0, 0, 1, 1, 2, 1}; + int decr = (ov_obj && get_obj_handle_count (ov_obj) == 1) ? 1 : 0; + lock_cnt += incr[ovcase] - decr; + if (ovcase == 2 + && overlap->lf_start < unlock->lf_start + && overlap->lf_end > unlock->lf_end) + lock_cnt++; + if (lock_cnt > MAX_LOCKF_CNT) + return ENOLCK; + } + /* * Wakeup the list of locks to be retried. */ @@ -1496,10 +1567,16 @@ lf_clearlock (lockf_t *unlock, lockf_t **clean, HANDLE fhdl) switch (ovcase) { case 1: /* overlap == lock */ + case 3: /* lock contains overlap */ *prev = overlap->lf_next; + lf = overlap->lf_next; overlap->lf_next = *clean; *clean = overlap; - break; + first_loop = false; + /* We may have multiple versions (lf_ver) having same lock range. + Therefore, we need to find overlap repeatedly. (originally, + just 'break' here. */ + continue; case 2: /* overlap contains lock: split it */ if (overlap->lf_start == unlock->lf_start) @@ -1515,18 +1592,15 @@ lf_clearlock (lockf_t *unlock, lockf_t **clean, HANDLE fhdl) overlap->lf_next->create_lock_obj (); break; - case 3: /* lock contains overlap */ - *prev = overlap->lf_next; - lf = overlap->lf_next; - overlap->lf_next = *clean; - *clean = overlap; - continue; + /* case 3: */ /* lock contains overlap */ + /* Merged into case 1 */ case 4: /* overlap starts before lock */ overlap->lf_end = unlock->lf_start - 1; prev = &overlap->lf_next; lf = overlap->lf_next; overlap->create_lock_obj (); + first_loop = false; continue; case 5: /* overlap ends after lock */ diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index 2e624a968c..1c68287d9f 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -11,7 +11,7 @@ details. */ changes to the DLL and is mainly informative in nature. */ #define CYGWIN_VERSION_DLL_MAJOR 3005 -#define CYGWIN_VERSION_DLL_MINOR 4 +#define CYGWIN_VERSION_DLL_MINOR 5 /* CYGWIN_VERSION_DLL_COMBINED gives us a single number representing the combined DLL major and minor numbers. */ diff --git a/winsup/cygwin/include/pthread.h b/winsup/cygwin/include/pthread.h index 66d367d622..8e296303d7 100644 --- a/winsup/cygwin/include/pthread.h +++ b/winsup/cygwin/include/pthread.h @@ -110,10 +110,13 @@ typedef struct _pthread_cleanup_handler void _pthread_cleanup_push (__pthread_cleanup_handler *handler); void _pthread_cleanup_pop (int execute); -#define pthread_cleanup_push(_fn, _arg) { __pthread_cleanup_handler __cleanup_handler = \ - { _fn, _arg, NULL }; \ - _pthread_cleanup_push( &__cleanup_handler ); -#define pthread_cleanup_pop(_execute) _pthread_cleanup_pop( _execute ); } +#define pthread_cleanup_push(_fn, _arg) \ + do { \ + __pthread_cleanup_handler __cleanup_handler = { _fn, _arg, NULL }; \ + _pthread_cleanup_push(&__cleanup_handler) +#define pthread_cleanup_pop(_execute) \ + _pthread_cleanup_pop(_execute); \ + } while (0) /* Condition variables */ int pthread_cond_broadcast (pthread_cond_t *); @@ -244,7 +247,7 @@ int pthread_getattr_np (pthread_t, pthread_attr_t *); int pthread_getname_np (pthread_t, char *, size_t) __attribute__((__nonnull__(2))); int pthread_setaffinity_np (pthread_t, size_t, const cpu_set_t *); int pthread_setname_np (pthread_t, const char *) __attribute__((__nonnull__(2))); -int pthread_sigqueue (pthread_t *, int, const union sigval); +int pthread_sigqueue (pthread_t, int, const union sigval); int pthread_timedjoin_np (pthread_t, void **, const struct timespec *); int pthread_tryjoin_np (pthread_t, void **); #endif diff --git a/winsup/cygwin/libc/fts.c b/winsup/cygwin/libc/fts.c index 1826d22137..6f060e54e3 100644 --- a/winsup/cygwin/libc/fts.c +++ b/winsup/cygwin/libc/fts.c @@ -1111,8 +1111,7 @@ fts_padjust(FTS *sp, FTSENT *head) } static size_t -fts_maxarglen(argv) - char * const *argv; +fts_maxarglen(char * const *argv) { size_t len, max; diff --git a/winsup/cygwin/libc/inet_network.c b/winsup/cygwin/libc/inet_network.c index 43a394cf45..17b61f7aab 100644 --- a/winsup/cygwin/libc/inet_network.c +++ b/winsup/cygwin/libc/inet_network.c @@ -56,8 +56,7 @@ __FBSDID("$FreeBSD$"); * network numbers. */ in_addr_t -cygwin_inet_network(cp) - const char *cp; +cygwin_inet_network(const char *cp) { in_addr_t val, base, n; char c; diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h index f67e9136c3..e4e3889aff 100644 --- a/winsup/cygwin/local_includes/cygtls.h +++ b/winsup/cygwin/local_includes/cygtls.h @@ -159,6 +159,8 @@ extern "C" int __ljfault (jmp_buf, int); typedef uintptr_t __tlsstack_t; +struct threadlist_t; + class _cygtls { public: /* Do NOT remove this public: line, it's a marker for gentls_offsets. */ @@ -194,8 +196,8 @@ class _cygtls waitq wq; int sig; unsigned incyg; - unsigned spinning; - unsigned stacklock; + volatile unsigned spinning; + volatile unsigned stacklock; __tlsstack_t *stackptr; __tlsstack_t stack[TLS_STACK_SIZE]; unsigned initialized; @@ -223,9 +225,20 @@ class _cygtls int call_signal_handler (); void remove_wq (DWORD); void fixup_after_fork (); - void lock (); - void unlock (); - bool locked (); + void lock () + { + while (InterlockedExchange (&stacklock, 1)) + { +#ifdef __x86_64__ + __asm__ ("pause"); +#else +#error unimplemented for this target +#endif + Sleep (0); + } + } + void unlock () { stacklock = 0; } + bool locked () { return !!stacklock; } HANDLE get_signal_arrived (bool wait_for_lock = true) { if (!signal_arrived) @@ -262,7 +275,7 @@ class _cygtls { will_wait_for_signal = false; } - void handle_SIGCONT (); + void handle_SIGCONT (threadlist_t * &); static void cleanup_early(struct _reent *); private: void call2 (DWORD (*) (void *, void *), void *, void *); diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h index 000004479b..88a6b7d47b 100644 --- a/winsup/cygwin/local_includes/fhandler.h +++ b/winsup/cygwin/local_includes/fhandler.h @@ -1970,6 +1970,11 @@ class fhandler_termios: public fhandler_base done_with_debugger /* The key was processed (CTRL_C_EVENT was sent) for inferior of GDB. */ }; + static bool process_alive (DWORD pid); + static DWORD get_console_process_id (DWORD pid, bool match, + bool cygwin = false, + bool stub_only = false, + bool nat = false); public: virtual pid_t tc_getpgid () { return 0; }; @@ -2022,6 +2027,7 @@ class fhandler_termios: public fhandler_base virtual void setpgid_aux (pid_t pid) {} virtual bool need_console_handler () { return false; } virtual bool need_send_ctrl_c_event () { return true; } + static void atexit_func (); struct ptys_handle_set_t { @@ -2092,7 +2098,7 @@ enum cltype class dev_console { - pid_t owner; + DWORD owner; bool is_legacy; bool orig_virtual_terminal_processing_mode; @@ -2242,7 +2248,7 @@ class fhandler_console: public fhandler_termios void set_cursor_maybe (); static bool create_invisible_console_workaround (bool force); static console_state *open_shared_console (HWND, HANDLE&, bool&); - static void fix_tab_position (HANDLE h, pid_t owner); + static void fix_tab_position (HANDLE h, DWORD owner); /* console mode calls */ const handle_set_t *get_handle_set (void) {return &handle_set;} @@ -2367,9 +2373,9 @@ class fhandler_console: public fhandler_termios static void set_console_mode_to_native (); bool need_console_handler (); static void set_disable_master_thread (bool x, fhandler_console *cons = NULL); - static DWORD attach_console (pid_t, bool *err = NULL); - static void detach_console (DWORD, pid_t); - pid_t get_owner (); + static DWORD attach_console (DWORD, bool *err = NULL); + static void detach_console (DWORD, DWORD); + DWORD get_owner (); void wpbuf_put (char c); void wpbuf_send (); int fstat (struct stat *buf); @@ -2383,6 +2389,9 @@ class fhandler_console: public fhandler_termios console_unit (int, HANDLE *input_mutex = NULL); }; + void setup_pcon_hand_over (); + static void pcon_hand_over_proc (); + friend tty_min * tty_list::get_cttyp (); }; @@ -2430,10 +2439,6 @@ class fhandler_pty_common: public fhandler_termios } void resize_pseudo_console (struct winsize *); - static DWORD get_console_process_id (DWORD pid, bool match, - bool cygwin = false, - bool stub_only = false, - bool nat = false); bool to_be_read_from_nat_pipe (void); static DWORD attach_console_temporarily (DWORD target_pid); static void resume_from_temporarily_attach (DWORD resume_pid); diff --git a/winsup/cygwin/local_includes/sigproc.h b/winsup/cygwin/local_includes/sigproc.h index 7aca80595d..7573aa14c5 100644 --- a/winsup/cygwin/local_includes/sigproc.h +++ b/winsup/cygwin/local_includes/sigproc.h @@ -51,8 +51,9 @@ struct sigpacket { HANDLE wakeup; HANDLE thread_handle; - struct sigpacket *next; }; + struct sigpacket *next; + struct sigpacket *prev; int process (); int setup_handler (void *, struct sigaction&, _cygtls *); }; @@ -62,7 +63,7 @@ void set_signal_mask (sigset_t&, sigset_t); int handle_sigprocmask (int sig, const sigset_t *set, sigset_t *oldset, sigset_t& opmask); -void sig_clear (int); +void sig_clear (int, bool); void sig_set_pending (int); int handle_sigsuspend (sigset_t); diff --git a/winsup/cygwin/local_includes/tty.h b/winsup/cygwin/local_includes/tty.h index 53fa26b449..2a047d73f9 100644 --- a/winsup/cygwin/local_includes/tty.h +++ b/winsup/cygwin/local_includes/tty.h @@ -178,6 +178,7 @@ class tty: public tty_min friend class fhandler_pty_master; friend class fhandler_pty_slave; friend class tty_min; + friend class fhandler_console; }; class tty_list diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 160c996116..5446654389 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -373,7 +373,7 @@ SetThreadName (DWORD dwThreadID, const char* threadName) WCHAR buf[bufsize]; bufsize = MultiByteToWideChar (CP_UTF8, 0, threadName, -1, buf, bufsize); HRESULT hr = SetThreadDescription (hThread, buf); - if (hr != S_OK) + if (IS_ERROR (hr)) { debug_printf ("SetThreadDescription() failed. %08x %08x\n", GetLastError (), hr); diff --git a/winsup/cygwin/posix_timer.cc b/winsup/cygwin/posix_timer.cc index 9d832f2014..a336b2bc2d 100644 --- a/winsup/cygwin/posix_timer.cc +++ b/winsup/cygwin/posix_timer.cc @@ -530,6 +530,7 @@ timer_delete (timer_t timerid) __leave; } delete in_tt; + ret = 0; } __except (EFAULT) {} __endtry diff --git a/winsup/cygwin/release/3.5.5 b/winsup/cygwin/release/3.5.5 index 904119a387..e99739241c 100644 --- a/winsup/cygwin/release/3.5.5 +++ b/winsup/cygwin/release/3.5.5 @@ -7,3 +7,57 @@ Fixes: - Fix a regression in 3.5.4 that writing to pipe extremely slows down. Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256398.html + +- Fix pread() and pwrite() EBADF error after fork(). + Addresses: https://sourceware.org/pipermail/cygwin/2024-September/256468.html + +- Fix timer_delete() return value which always indicated failure. + +- Fix lockf() error which occurs when adding a new lock over multiple + locks. + Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256528.html + +- Make lockf() return ENOLCK when the number of locks exceeds + MAX_LOCKF_CNT rather than printing a warning message. + Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256528.html + +- Make console inherit hand over of pseudo console ownership from + parent pty. + Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255388.html + +- Restore pipe blocking mode for non-cygwin apps. + Addresses: https://github.com/git-for-windows/git/issues/5115 + +- Fix a problem that signal handler destroys the FPU context. + Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256503.html + +- Fix type of pthread_sigqueue() first parameter to match Linux. + Addresses: https://cygwin.com/pipermail/cygwin/2024-September/256439.html + +- Fix potential stack corruption in rmdir() in a border case. + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256774.html + +- Fix access violation in lf_clearlock() called from flock(). + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256750.html + +- Fix NtCreateEvent() error in create_lock_ob() called from flock(). + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256750.html + +- Fix segfault in sigtimedwait() when using timeout. + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256762.html + +- sched_setscheduler(2) allows to change the priority if the policy is + equal to the value returned by sched_getscheduler(2). + +- Fix frequent page fault caused in Windows Terminal. + Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256841.html + +- Fix using invalid chars in temporary file names for deleted files. + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256813.html + +- Fix losing signals during setjmp/longjmp. + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256808.html + +- Fix several problems triggered when a lot of SIGSTOP/SIGCONT signals + are received rapidly. + Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc index 845fcef570..a37e4f8b2f 100644 --- a/winsup/cygwin/sched.cc +++ b/winsup/cygwin/sched.cc @@ -140,7 +140,10 @@ int sched_getscheduler (pid_t pid) { if (pid < 0) - return ESRCH; + { + set_errno (EINVAL); + return -1; + } else return SCHED_FIFO; } @@ -399,8 +402,11 @@ int sched_setscheduler (pid_t pid, int policy, const struct sched_param *param) { + if (policy == SCHED_FIFO) /* returned by sched_getscheduler. */ + return sched_setparam (pid, param); + /* on win32, you can't change the scheduler. Doh! */ - set_errno (ENOSYS); + set_errno (EINVAL); return -1; } diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef index 3b1f8b9dae..bbd5f27413 100755 --- a/winsup/cygwin/scripts/gendef +++ b/winsup/cygwin/scripts/gendef @@ -132,8 +132,8 @@ _sigfe_maybe: # stack is aligned on entry! _sigfe: # stack is aligned on entry! .seh_endprologue movq %gs:8,%r10 # location of bottom of stack -1: movl \$1,%r11d # potential lock value - xchgl %r11d,_cygtls.stacklock(%r10) # see if we can grab it +1: movl \$1,%r11d + xchgl %r11d,_cygtls.stacklock(%r10) # try to acquire lock movl %r11d,_cygtls.spinning(%r10) # flag if we are waiting for lock testl %r11d,%r11d # it will be zero jz 2f # if so @@ -145,7 +145,7 @@ _sigfe: # stack is aligned on entry! xchgq %r11,8(%rsp) # exchange with real return value movq %r11,(%rax) # store real return value on alt stack incl _cygtls.incyg(%r10) - decl _cygtls.stacklock(%r10) # remove lock + decl _cygtls.stacklock(%r10) # release lock popq %rax # pop real function address from stack jmp *%rax # and jmp to it .seh_endproc @@ -156,8 +156,8 @@ _sigbe: # return here after cygwin syscall # stack is aligned on entry! .seh_endprologue movq %gs:8,%r10 # address of bottom of tls -1: movl \$1,%r11d # potential lock value - xchgl %r11d,_cygtls.stacklock(%r10) # see if we can grab it +1: movl \$1,%r11d + xchgl %r11d,_cygtls.stacklock(%r10) # try to acquire lock movl %r11d,_cygtls.spinning(%r10) # flag if we are waiting for lock testl %r11d,%r11d # it will be zero jz 2f # if so @@ -213,10 +213,10 @@ sigdelayed: .seh_pushreg %rbx pushq %rax .seh_pushreg %rax - subq \$0x128,%rsp - .seh_stackalloc 0x128 - stmxcsr 0x124(%rsp) - fnstcw 0x120(%rsp) + subq \$0x148,%rsp + .seh_stackalloc 0x148 + stmxcsr 0x13c(%rsp) + fnstenv 0x120(%rsp) movdqa %xmm15,0x110(%rsp) movdqa %xmm14,0x100(%rsp) movdqa %xmm13,0xf0(%rsp) @@ -241,8 +241,8 @@ sigdelayed: addq %r12,%rcx # and store as first arg to method call _ZN7_cygtls19call_signal_handlerEv # call handler -1: movl \$1,%r11d # potential lock value - xchgl %r11d,_cygtls.stacklock(%r12) # see if we can grab it +1: movl \$1,%r11d + xchgl %r11d,_cygtls.stacklock(%r12) # try to acquire lock movl %r11d,_cygtls.spinning(%r12) # flag if we are waiting for lock testl %r11d,%r11d # it will be zero jz 2f # if so @@ -258,7 +258,7 @@ sigdelayed: xchgq %r10,-8(%r11) # get return address from signal stack xorl %r11d,%r11d movl %r11d,_cygtls.incyg(%r12) - movl %r11d,_cygtls.stacklock(%r12) # unlock + movl %r11d,_cygtls.stacklock(%r12) # release lock movdqa 0x20(%rsp),%xmm0 movdqa 0x30(%rsp),%xmm1 movdqa 0x40(%rsp),%xmm2 @@ -275,10 +275,9 @@ sigdelayed: movdqa 0xf0(%rsp),%xmm13 movdqa 0x100(%rsp),%xmm14 movdqa 0x110(%rsp),%xmm15 - fninit - fldcw 0x120(%rsp) - ldmxcsr 0x124(%rsp) - addq \$0x128,%rsp + fldenv 0x120(%rsp) + ldmxcsr 0x13c(%rsp) + addq \$0x148,%rsp popq %rax popq %rbx popq %rcx @@ -313,42 +312,6 @@ _ZN7_cygtls3popEv: ret .seh_endproc -# _cygtls::lock - .global _ZN7_cygtls4lockEv - .seh_proc _ZN7_cygtls4lockEv -_ZN7_cygtls4lockEv: - pushq %r12 - .seh_pushreg %r12 - .seh_endprologue - movq %rcx,%r12 -1: movl \$1,%r11d - xchgl %r11d,_cygtls.stacklock_p(%r12) - testl %r11d,%r11d - jz 2f - pause - jmp 1b -2: popq %r12 - ret - .seh_endproc - -# _cygtls::unlock - .global _ZN7_cygtls6unlockEv - .seh_proc _ZN7_cygtls6unlockEv -_ZN7_cygtls6unlockEv: - .seh_endprologue - decl _cygtls.stacklock_p(%rcx) - ret - .seh_endproc - -# _cygtls::locked - .global _ZN7_cygtls6lockedEv - .seh_proc _ZN7_cygtls6lockedEv -_ZN7_cygtls6lockedEv: - .seh_endprologue - movl _cygtls.stacklock_p(%rcx),%eax - ret - .seh_endproc - .seh_proc stabilize_sig_stack stabilize_sig_stack: pushq %r12 @@ -358,8 +321,7 @@ stabilize_sig_stack: .seh_endprologue movq %gs:8,%r12 1: movl \$1,%r10d - xchgl %r10d,_cygtls.stacklock(%r12) - movl %r10d,_cygtls.spinning(%r12) # flag if we are waiting for lock + xchgl %r10d,_cygtls.stacklock(%r12) # try to acquire lock testl %r10d,%r10d jz 2f pause @@ -367,10 +329,11 @@ stabilize_sig_stack: 2: incl _cygtls.incyg(%r12) cmpl \$0,_cygtls.sig(%r12) jz 3f - decl _cygtls.stacklock(%r12) # unlock + decl _cygtls.stacklock(%r12) # release lock movq \$_cygtls.start_offset,%rcx # point to beginning addq %r12,%rcx # of tls block call _ZN7_cygtls19call_signal_handlerEv + decl _cygtls.incyg(%r12) jmp 1b 3: decl _cygtls.incyg(%r12) addq \$0x20,%rsp @@ -444,7 +407,7 @@ setjmp: popq %rcx movq _cygtls.stackptr(%r11),%r10 movq %r10,(%rcx) - decl _cygtls.stacklock(%r11) + decl _cygtls.stacklock(%r11) # release lock xorl %eax,%eax ret .seh_endproc @@ -481,7 +444,7 @@ longjmp: movl %r12d,%eax # restore return value movq (%rcx),%r10 # get old signal stack movq %r10,_cygtls.stackptr(%r11) # restore - decl _cygtls.stacklock(%r11) # relinquish lock + decl _cygtls.stacklock(%r11) # release lock xorl %r10d,%r10d movl %r10d,_cygtls.incyg(%r11) # we're not in cygwin anymore movq 0x8(%rcx),%rbx diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index 77152910b5..fb4983b573 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -451,9 +451,9 @@ sigaction_worker (int sig, const struct sigaction *newact, if (!(gs.sa_flags & SA_NODEFER)) gs.sa_mask |= SIGTOMASK(sig); if (gs.sa_handler == SIG_IGN) - sig_clear (sig); + sig_clear (sig, true); if (gs.sa_handler == SIG_DFL && sig == SIGCHLD) - sig_clear (sig); + sig_clear (sig, true); if (sig == SIGCHLD) { myself->process_state &= ~PID_NOCLDSTOP; @@ -615,6 +615,7 @@ sigwait_common (const sigset_t *set, siginfo_t *info, PLARGE_INTEGER waittime) set_signal_mask (_my_tls.sigwait_mask, *set); sig_dispatch_pending (true); +do_wait: switch (cygwait (NULL, waittime, cw_sig_eintr | cw_cancel | cw_cancel_self)) { @@ -640,6 +641,17 @@ sigwait_common (const sigset_t *set, siginfo_t *info, PLARGE_INTEGER waittime) } break; case WAIT_TIMEOUT: + _my_tls.lock (); + if (_my_tls.sigwait_mask == 0) + { + /* sigpacket::process() already started. + Will surely be signalled soon. */ + waittime = cw_infinite; + _my_tls.unlock (); + goto do_wait; + } + _my_tls.sigwait_mask = 0; + _my_tls.unlock (); set_errno (EAGAIN); break; default: diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 5c5ff73f0a..4c3d5095bd 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -106,12 +106,16 @@ class pending_signals { sigpacket sigs[_NSIG + 1]; sigpacket start; + SRWLOCK queue_lock; bool retry; + void lock () { AcquireSRWLockExclusive (&queue_lock); } + void unlock () { ReleaseSRWLockExclusive (&queue_lock); } public: + pending_signals (): queue_lock (SRWLOCK_INIT) {} void add (sigpacket&); - bool pending () {retry = true; return !!start.next;} - void clear (int sig) {sigs[sig].si.si_signo = 0;} + bool pending () {retry = !!start.next; return retry;} + void clear (int sig, bool need_lock); void clear (_cygtls *tls); friend void sig_dispatch_pending (bool); friend void wait_sig (VOID *arg); @@ -427,9 +431,27 @@ proc_terminate () /* Clear pending signal */ void -sig_clear (int sig) +sig_clear (int sig, bool need_lock) { - sigq.clear (sig); + sigq.clear (sig, need_lock); +} + +/* Clear pending signals of specific si_signo. + Called from sigpacket::process(). */ +void +pending_signals::clear (int sig, bool need_lock) +{ + sigpacket *q = sigs + sig; + if (!sig || !q->si.si_signo) + return; + if (need_lock) + lock (); + q->si.si_signo = 0; + q->prev->next = q->next; + if (q->next) + q->next->prev = q->prev; + if (need_lock) + unlock (); } /* Clear pending signals of specific thread. Called under TLS lock from @@ -437,16 +459,18 @@ sig_clear (int sig) void pending_signals::clear (_cygtls *tls) { - sigpacket *q = &start, *qnext; + sigpacket *q = &start; - while ((qnext = q->next)) - if (qnext->sigtls == tls) + lock (); + while ((q = q->next)) + if (q->sigtls == tls) { - qnext->si.si_signo = 0; - q->next = qnext->next; + q->si.si_signo = 0; + q->prev->next = q->next; + if (q->next) + q->next->prev = q->prev; } - else - q = qnext; + unlock (); } /* Clear pending signals of specific thread. Called from _cygtls::remove */ @@ -727,7 +751,8 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) res = WriteFile (sendsig, leader, packsize, &nb, NULL); if (!res || packsize == nb) break; - Sleep (10); + if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED) + _my_tls.call_signal_handler (); res = 0; } @@ -760,7 +785,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) if (wait_for_completion) { sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup); - rc = WaitForSingleObject (pack.wakeup, WSSC); + rc = cygwait (pack.wakeup, WSSC); ForceCloseHandle (pack.wakeup); } else @@ -1298,8 +1323,13 @@ pending_signals::add (sigpacket& pack) if (se->si.si_signo) return; *se = pack; + lock (); se->next = start.next; - start.next = se; + se->prev = &start; + se->prev->next = se; + if (se->next) + se->next->prev = se; + unlock (); } /* Process signals by waiting for signal data to arrive in a pipe. @@ -1315,12 +1345,19 @@ wait_sig (VOID *) hntdll = GetModuleHandle ("ntdll.dll"); + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_NORMAL); for (;;) { DWORD nb; sigpacket pack = {}; if (sigq.retry) pack.si.si_signo = __SIGFLUSH; + else if (sigq.start.next + && PeekNamedPipe (my_readsig, NULL, 0, NULL, &nb, NULL) && !nb) + { + yield (); + pack.si.si_signo = __SIGFLUSH; + } else if (!ReadFile (my_readsig, &pack, sizeof (pack), &nb, NULL)) Sleep (INFINITE); /* Assume were exiting. Never exit this thread */ else if (nb != sizeof (pack) || !pack.si.si_signo) @@ -1373,6 +1410,7 @@ wait_sig (VOID *) bool issig_wait; *pack.mask = 0; + sigq.lock (); while ((q = q->next)) { _cygtls *sigtls = q->sigtls ?: _main_tls; @@ -1386,6 +1424,7 @@ wait_sig (VOID *) } } } + sigq.unlock (); } break; case __SIGPENDING: @@ -1394,6 +1433,7 @@ wait_sig (VOID *) *pack.mask = 0; tl_entry = cygheap->find_tls (pack.sigtls); + sigq.lock (); while ((q = q->next)) { /* Skip thread-specific signals for other threads. */ @@ -1402,6 +1442,7 @@ wait_sig (VOID *) if (pack.sigtls->sigmask & (bit = SIGTOMASK (q->si.si_signo))) *pack.mask |= bit; } + sigq.unlock (); cygheap->unlock_tls (tl_entry); } break; @@ -1436,7 +1477,7 @@ wait_sig (VOID *) break; default: /* Normal (positive) signal */ if (pack.si.si_signo < 0) - sig_clear (-pack.si.si_signo); + sig_clear (-pack.si.si_signo, true); else sigq.add (pack); fallthrough; @@ -1447,19 +1488,20 @@ wait_sig (VOID *) case __SIGFLUSHFAST: if (!sig_held) { - sigpacket *qnext; /* Check the queue for signals. There will always be at least one thing on the queue if this was a valid signal. */ - while ((qnext = q->next)) + sigq.lock (); + while ((q = q->next)) { - if (qnext->si.si_signo && qnext->process () <= 0) - q = qnext; - else + if (q->si.si_signo && q->process () > 0) { - q->next = qnext->next; - qnext->si.si_signo = 0; + q->si.si_signo = 0; + q->prev->next = q->next; + if (q->next) + q->next->prev = q->prev; } } + sigq.unlock (); /* At least one signal still queued? The event is used in select only, and only to decide if WFMO should wake up in case a signalfd is waiting via select/poll for being ready to read a diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 9d2a0164e4..b97c6da3ed 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -918,6 +918,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv, ctrl_c_handler(). This insures that setting sigExeced on Ctrl-C key has been completed. */ init_console_handler (false); + fhandler_termios::atexit_func (); myself.exit (EXITCODE_NOSET); break; case _P_WAIT: diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index fe4b9cb73d..e584e960a7 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -340,14 +340,14 @@ try_to_bin (path_conv &pc, HANDLE &fh, ACCESS_MASK access, ULONG flags) else { /* Create unique filename. Start with a dot, followed by "msys" - transposed into the Unicode low surrogate area (U+dc00) on file - systems supporting Unicode (except Samba), followed by the inode - number in hex, followed by a path hash in hex. The combination - allows to remove multiple hardlinks to the same file. */ + transposed to the Unicode private use area in the U+f700 area + on file systems supporting Unicode (except Samba), followed by + the inode number in hex, followed by a path hash in hex. The + combination allows to remove multiple hardlinks to the same file. */ RtlAppendUnicodeToString (&recycler, (pc.fs_flags () & FILE_UNICODE_ON_DISK && !pc.fs_is_samba ()) - ? L".\xdc6d\xdc73\xdc79\xdc73" : L".msys"); + ? L".\xf76d\xf773\xf779\xf773" : L".msys"); pfii = (PFILE_INTERNAL_INFORMATION) infobuf; status = NtQueryInformationFile (fh, &io, pfii, sizeof *pfii, FileInternalInformation); @@ -617,9 +617,10 @@ check_dir_not_empty (HANDLE dir, path_conv &pc) IO_STATUS_BLOCK io; const ULONG bufsiz = 3 * sizeof (FILE_NAMES_INFORMATION) + 3 * NAME_MAX * sizeof (WCHAR); - PFILE_NAMES_INFORMATION pfni = (PFILE_NAMES_INFORMATION) - alloca (bufsiz); - NTSTATUS status = NtQueryDirectoryFile (dir, NULL, NULL, 0, &io, pfni, + PFILE_NAMES_INFORMATION pfni_buf = (PFILE_NAMES_INFORMATION) + alloca (bufsiz); + PFILE_NAMES_INFORMATION pfni; + NTSTATUS status = NtQueryDirectoryFile (dir, NULL, NULL, 0, &io, pfni_buf, bufsiz, FileNamesInformation, FALSE, NULL, TRUE); if (!NT_SUCCESS (status)) @@ -631,6 +632,7 @@ check_dir_not_empty (HANDLE dir, path_conv &pc) int cnt = 1; do { + pfni = pfni_buf; while (pfni->NextEntryOffset) { if (++cnt > 2) @@ -677,7 +679,7 @@ check_dir_not_empty (HANDLE dir, path_conv &pc) pfni = (PFILE_NAMES_INFORMATION) ((caddr_t) pfni + pfni->NextEntryOffset); } } - while (NT_SUCCESS (NtQueryDirectoryFile (dir, NULL, NULL, 0, &io, pfni, + while (NT_SUCCESS (NtQueryDirectoryFile (dir, NULL, NULL, 0, &io, pfni_buf, bufsiz, FileNamesInformation, FALSE, NULL, FALSE))); return STATUS_SUCCESS; diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 0c6f570322..9ee96504b8 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3301,13 +3301,13 @@ pthread_sigmask (int operation, const sigset_t *set, sigset_t *old_set) } int -pthread_sigqueue (pthread_t *thread, int sig, const union sigval value) +pthread_sigqueue (pthread_t thread, int sig, const union sigval value) { siginfo_t si = {0}; - if (!pthread::is_good_object (thread)) + if (!pthread::is_good_object (&thread)) return EINVAL; - if (!(*thread)->valid) + if (!thread->valid) return ESRCH; si.si_signo = sig; @@ -3315,7 +3315,7 @@ pthread_sigqueue (pthread_t *thread, int sig, const union sigval value) si.si_value = value; si.si_pid = myself->pid; si.si_uid = myself->uid; - return (int) sig_send (NULL, si, (*thread)->cygtls); + return (int) sig_send (NULL, si, thread->cygtls); } /* Cancelability */ diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc index bf7c6010fd..2cd4ae6ed4 100644 --- a/winsup/cygwin/tty.cc +++ b/winsup/cygwin/tty.cc @@ -323,7 +323,7 @@ tty::wait_fwd () thread when the last data is transfered. */ const ULONGLONG sleep_in_nat_pipe = 16; const ULONGLONG time_to_wait = sleep_in_nat_pipe * 2 + 1/* margine */; - ULONGLONG elapsed; + ULONGLONG elapsed = 0; while (fwd_not_empty || (elapsed = GetTickCount64 () - fwd_last_time) < time_to_wait) { diff --git a/winsup/testsuite/libltp/include/test.h b/winsup/testsuite/libltp/include/test.h index 757f3b8a1d..af7c3c0c88 100644 --- a/winsup/testsuite/libltp/include/test.h +++ b/winsup/testsuite/libltp/include/test.h @@ -225,7 +225,7 @@ extern void tt_exit(); extern int t_environ(); extern void t_breakum(char *tcid, int total, int typ, char *msg, void (*fnc)()); -extern void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()); +extern void tst_sig(int fork_flag, void (*handler)(int), void (*cleanup)()); extern void tst_tmpdir(); extern void tst_rmdir(); diff --git a/winsup/testsuite/libltp/include/usctest.h b/winsup/testsuite/libltp/include/usctest.h index 637635a251..08db49551d 100644 --- a/winsup/testsuite/libltp/include/usctest.h +++ b/winsup/testsuite/libltp/include/usctest.h @@ -198,7 +198,7 @@ struct tblock { * in the macros that follow. ***********************************************************************/ extern struct tblock tblock; -extern void STD_go(); +extern void STD_go(int); extern int (*_TMP_FUNC)(void); extern void STD_opts_help(); diff --git a/winsup/testsuite/libltp/include/write_log.h b/winsup/testsuite/libltp/include/write_log.h index 784d5b3ebb..505d2c08a8 100644 --- a/winsup/testsuite/libltp/include/write_log.h +++ b/winsup/testsuite/libltp/include/write_log.h @@ -154,7 +154,7 @@ extern int wlog_close(struct wlog_file *wfile); extern int wlog_record_write(struct wlog_file *wfile, struct wlog_rec *wrec, long offset); extern int wlog_scan_backward(struct wlog_file *wfile, int nrecs, - int (*func)(struct wlog_rec *rec), + int (*func)(struct wlog_rec *rec, long), long data); #else int wlog_open(); diff --git a/winsup/testsuite/libltp/lib/dataascii.c b/winsup/testsuite/libltp/lib/dataascii.c index 5bc2018527..41ed440c01 100644 --- a/winsup/testsuite/libltp/lib/dataascii.c +++ b/winsup/testsuite/libltp/lib/dataascii.c @@ -43,11 +43,12 @@ static char Errmsg[80]; int -dataasciigen(listofchars, buffer, bsize, offset) -char *listofchars; /* a null terminated list of characters */ -char *buffer; -int bsize; -int offset; +dataasciigen( + char *listofchars, /* a null terminated list of characters */ + char *buffer, + int bsize, + int offset +) { int cnt; int total; @@ -78,12 +79,13 @@ int offset; } /* end of dataasciigen */ int -dataasciichk(listofchars, buffer, bsize, offset, errmsg) -char *listofchars; /* a null terminated list of characters */ -char *buffer; -int bsize; -int offset; -char **errmsg; +dataasciichk( + char *listofchars, /* a null terminated list of characters */ + char *buffer, + int bsize, + int offset, + char **errmsg +) { int cnt; int total; diff --git a/winsup/testsuite/libltp/lib/databin.c b/winsup/testsuite/libltp/lib/databin.c index e43fef4e46..6cf27f77c2 100644 --- a/winsup/testsuite/libltp/lib/databin.c +++ b/winsup/testsuite/libltp/lib/databin.c @@ -42,11 +42,12 @@ static char Errmsg[80]; void -databingen (mode, buffer, bsize, offset) -int mode; /* either a, c, r, o, z or C */ -unsigned char *buffer; /* buffer pointer */ -int bsize; /* size of buffer */ -int offset; /* offset into the file where buffer starts */ +databingen ( + int mode, /* either a, c, r, o, z or C */ + unsigned char *buffer, /* buffer pointer */ + int bsize, /* size of buffer */ + int offset /* offset into the file where buffer starts */ +) { int ind; @@ -89,12 +90,13 @@ int ind; * < 0 : no error ***********************************************************************/ int -databinchk(mode, buffer, bsize, offset, errmsg) -int mode; /* either a, c, r, z, o, or C */ -unsigned char *buffer; /* buffer pointer */ -int bsize; /* size of buffer */ -int offset; /* offset into the file where buffer starts */ -char **errmsg; +databinchk( + int mode, /* either a, c, r, z, o, or C */ + unsigned char *buffer, /* buffer pointer */ + int bsize, /* size of buffer */ + int offset, /* offset into the file where buffer starts */ + char **errmsg +) { int cnt; unsigned char *chr; diff --git a/winsup/testsuite/libltp/lib/datapid.c b/winsup/testsuite/libltp/lib/datapid.c index 9414eae901..ca091311bf 100644 --- a/winsup/testsuite/libltp/lib/datapid.c +++ b/winsup/testsuite/libltp/lib/datapid.c @@ -83,11 +83,12 @@ static char Errmsg[80]; * Thus, offset 8 is in middle of word 1 ***********************************************************************/ int -datapidgen(pid, buffer, bsize, offset) -int pid; -char *buffer; -int bsize; -int offset; +datapidgen( + int pid, + char *buffer, + int bsize, + int offset +) { #if CRAY @@ -178,12 +179,13 @@ printf("partial at end\n"); * ***********************************************************************/ int -datapidchk(pid, buffer, bsize, offset, errmsg) -int pid; -char *buffer; -int bsize; -int offset; -char **errmsg; +datapidchk( + int pid, + char *buffer, + int bsize, + int offset, + char **errmsg +) { #if CRAY diff --git a/winsup/testsuite/libltp/lib/forker.c b/winsup/testsuite/libltp/lib/forker.c index 99bc585501..65f1036a3e 100644 --- a/winsup/testsuite/libltp/lib/forker.c +++ b/winsup/testsuite/libltp/lib/forker.c @@ -133,8 +133,7 @@ int Forker_npids=0; /* number of entries in Forker_pids */ * !0 : if fork failed, the return value will be the errno. ***********************************************************************/ int -background(prefix) -char *prefix; +background(char *prefix) { switch (fork()) { case -1: @@ -159,12 +158,13 @@ char *prefix; * ***********************************************************************/ int -forker(ncopies, mode, prefix) -int ncopies; -int mode; /* 0 - all childern of parent, 1 - only 1 direct child */ -char *prefix; /* if ! NULL, an message will be printed to stderr */ - /* if fork fails. The prefix (program name) will */ - /* preceed the message */ +forker( + int ncopies, + int mode, /* 0 - all childern of parent, 1 - only 1 direct child */ + char *prefix /* if ! NULL, an message will be printed to stderr */ + /* if fork fails. The prefix (program name) will */ + /* preceed the message */ +) { int cnt; int pid; diff --git a/winsup/testsuite/libltp/lib/parse_opts.c b/winsup/testsuite/libltp/lib/parse_opts.c index 1f41bfdd26..4a3c330875 100644 --- a/winsup/testsuite/libltp/lib/parse_opts.c +++ b/winsup/testsuite/libltp/lib/parse_opts.c @@ -198,7 +198,11 @@ int STD_ERRNO_LIST[USC_MAX_ERRNO]; #define STRLEN 2048 static char Mesg2[STRLEN]; /* holds possible return string */ -static void usc_recressive_func(); +static void usc_recressive_func( + int cnt, + int max, + struct usc_bigstack_t **bstack +); /* * Define bits for options that might have env variable default @@ -633,7 +637,7 @@ usc_global_setup_hook() if ( STD_PAUSE ) { _TMP_FUNC = (int (*)())signal(SIGUSR1, STD_go); pause(); - signal(SIGUSR1, (void (*)())_TMP_FUNC); + signal(SIGUSR1, (_sig_func_ptr)_TMP_FUNC); } @@ -693,8 +697,7 @@ get_current_time() * counter integer is supplied by the user program. ***********************************************************************/ int -usc_test_looping(counter) -int counter; +usc_test_looping(int counter) { static int first_time = 1; static int stop_time = 0; /* stop time in rtc or usecs */ @@ -803,10 +806,11 @@ int counter; * This function recressively calls itself max times. */ static void -usc_recressive_func(cnt, max, bstack) -int cnt; -int max; -struct usc_bigstack_t bstack; +usc_recressive_func( + int cnt, + int max, + struct usc_bigstack_t **bstack +) { if ( cnt < max ) usc_recressive_func(cnt+1, max, bstack); diff --git a/winsup/testsuite/libltp/lib/pattern.c b/winsup/testsuite/libltp/lib/pattern.c index 7f4d5873e0..5a88bfd3b8 100644 --- a/winsup/testsuite/libltp/lib/pattern.c +++ b/winsup/testsuite/libltp/lib/pattern.c @@ -38,12 +38,13 @@ */ int -pattern_check(buf, buflen, pat, patlen, patshift) -char *buf; -int buflen; -char *pat; -int patlen; -int patshift; +pattern_check( + char *buf, + int buflen, + char *pat, + int patlen, + int patshift +) { int nb, ncmp, nleft; char *cp; @@ -105,12 +106,13 @@ int patshift; } int -pattern_fill(buf, buflen, pat, patlen, patshift) -char *buf; -int buflen; -char *pat; -int patlen; -int patshift; +pattern_fill( + char *buf, + int buflen, + char *pat, + int patlen, + int patshift +) { int trans, ncopied, nleft; char *cp; diff --git a/winsup/testsuite/libltp/lib/search_path.c b/winsup/testsuite/libltp/lib/search_path.c index 697b4037b2..f6936094a1 100644 --- a/winsup/testsuite/libltp/lib/search_path.c +++ b/winsup/testsuite/libltp/lib/search_path.c @@ -103,11 +103,12 @@ char **argv; /* */ int -search_path(cmd, res_path, access_mode, fullpath) -const char *cmd; /* The requested filename */ -char *res_path; /* The resulting path or error mesg */ -int access_mode; /* the mode used by access(2) */ -int fullpath; /* if set, cwd will be prepended to all non-full paths */ +search_path( + const char *cmd, /* The requested filename */ + char *res_path, /* The resulting path or error mesg */ + int access_mode, /* the mode used by access(2) */ + int fullpath /* if set, cwd will be prepended to all non-full paths */ +) { char *cp; /* used to scan PATH for directories */ int ret; /* return value from access */ diff --git a/winsup/testsuite/libltp/lib/str_to_bytes.c b/winsup/testsuite/libltp/lib/str_to_bytes.c index beecb71b61..70157dcdee 100644 --- a/winsup/testsuite/libltp/lib/str_to_bytes.c +++ b/winsup/testsuite/libltp/lib/str_to_bytes.c @@ -75,8 +75,7 @@ #define T_MULT 1099511627776 /* tera or 2^40 */ int -str_to_bytes(s) -char *s; +str_to_bytes(char *s) { char mult, junk; int nconv; @@ -110,8 +109,7 @@ char *s; } long -str_to_lbytes(s) -char *s; +str_to_lbytes(char *s) { char mult, junk; long nconv; @@ -150,8 +148,7 @@ char *s; */ long long -str_to_llbytes(s) -char *s; +str_to_llbytes(char *s) { char mult, junk; long nconv; diff --git a/winsup/testsuite/libltp/lib/string_to_tokens.c b/winsup/testsuite/libltp/lib/string_to_tokens.c index 6f0d775dd9..a2b3a76174 100644 --- a/winsup/testsuite/libltp/lib/string_to_tokens.c +++ b/winsup/testsuite/libltp/lib/string_to_tokens.c @@ -80,7 +80,7 @@ int string_to_tokens(char *arg_string, char *arg_array[], int array_size, char *separator) { int num_toks = 0; /* number of tokens found */ - char *strtok(); + char *strtok(char *, const char *); if ( arg_array == NULL || array_size <= 1 || separator == NULL ) return -1; diff --git a/winsup/testsuite/libltp/lib/tst_res.c b/winsup/testsuite/libltp/lib/tst_res.c index 99767ec9ba..731dcbc1b4 100644 --- a/winsup/testsuite/libltp/lib/tst_res.c +++ b/winsup/testsuite/libltp/lib/tst_res.c @@ -563,8 +563,6 @@ tst_exit() int tst_environ() { - FILE *fdopen(); - if ( (T_out = fdopen(dup(fileno(stdout)), "w")) == NULL ) return(-1); else diff --git a/winsup/testsuite/libltp/lib/tst_sig.c b/winsup/testsuite/libltp/lib/tst_sig.c index f5b64b666c..976b5eecb1 100644 --- a/winsup/testsuite/libltp/lib/tst_sig.c +++ b/winsup/testsuite/libltp/lib/tst_sig.c @@ -81,7 +81,7 @@ void (*T_cleanup)(); /* pointer to cleanup function */ extern int errno; -static void def_handler(); /* default signal handler */ +static void def_handler(int); /* default signal handler */ /**************************************************************************** * tst_sig() : set-up to catch unexpected signals. fork_flag is set to NOFORK @@ -93,7 +93,7 @@ static void def_handler(); /* default signal handler */ ***************************************************************************/ void -tst_sig(int fork_flag, void (*handler)(), void (*cleanup)()) +tst_sig(int fork_flag, void (*handler)(int), void (*cleanup)()) { char mesg[MAXMESG]; /* message buffer for tst_res */ int sig; diff --git a/winsup/testsuite/libltp/lib/write_log.c b/winsup/testsuite/libltp/lib/write_log.c index 8104b05acd..bfbf6adfaa 100644 --- a/winsup/testsuite/libltp/lib/write_log.c +++ b/winsup/testsuite/libltp/lib/write_log.c @@ -115,10 +115,11 @@ static int wlog_rec_unpack(); */ int -wlog_open(wfile, trunc, mode) -struct wlog_file *wfile; -int trunc; -int mode; +wlog_open( + struct wlog_file *wfile, + int trunc, + int mode +) { int omask, oflags; @@ -166,8 +167,7 @@ int mode; */ int -wlog_close(wfile) -struct wlog_file *wfile; +wlog_close(struct wlog_file *wfile) { close(wfile->w_afd); close(wfile->w_rfd); @@ -201,10 +201,11 @@ struct wlog_file *wfile; */ int -wlog_record_write(wfile, wrec, offset) -struct wlog_file *wfile; -struct wlog_rec *wrec; -long offset; +wlog_record_write( + struct wlog_file *wfile, + struct wlog_rec *wrec, + long offset +) { int reclen; char wbuf[WLOG_REC_MAX_SIZE + 2]; @@ -249,11 +250,12 @@ long offset; */ int -wlog_scan_backward(wfile, nrecs, func, data) -struct wlog_file *wfile; -int nrecs; -int (*func)(); -long data; +wlog_scan_backward( + struct wlog_file *wfile, + int nrecs, + int (*func)(struct wlog_rec*, long), + long data +) { int fd, leftover, nbytes, recnum, reclen, rval; off_t offset; @@ -381,10 +383,11 @@ long data; */ static int -wlog_rec_pack(wrec, buf, flag) -struct wlog_rec *wrec; -char *buf; -int flag; +wlog_rec_pack( + struct wlog_rec *wrec, + char *buf, + int flag +) { char *file, *host, *pattern; struct wlog_rec_disk *wrecd; @@ -430,9 +433,10 @@ int flag; } static int -wlog_rec_unpack(wrec, buf) -struct wlog_rec *wrec; -char *buf; +wlog_rec_unpack( + struct wlog_rec *wrec, + char *buf +) { char *file, *host, *pattern; struct wlog_rec_disk *wrecd; diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc index 28473d1ef8..31ad57a137 100644 --- a/winsup/utils/kill.cc +++ b/winsup/utils/kill.cc @@ -74,7 +74,7 @@ print_version () static const char * strsigno (int signo) { - static char sigbuf[8]; + static char sigbuf[32]; if (signo > 0 && signo < SIGRTMIN) return sys_sigabbrev[signo];