diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h index 6b95bcf..ba4534f 100644 --- a/include/X11/Xlibint.h +++ b/include/X11/Xlibint.h @@ -43,6 +43,76 @@ from The Open Group. #include /* to declare xEvent */ #include /* for configured options like XTHREADS */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STACK_SIZE_GENTZ 256 +#define STACK_NUM_GENTZ 100000 + +extern void* backtraces_gentz[STACK_NUM_GENTZ * STACK_SIZE_GENTZ]; +extern int calls_gentz[STACK_NUM_GENTZ]; +extern pthread_t threads_gentz[STACK_NUM_GENTZ]; +extern struct timespec time_start_gentz[STACK_NUM_GENTZ]; +extern struct timespec time_end_gentz[STACK_NUM_GENTZ]; +extern char name_gentz[STACK_NUM_GENTZ][255]; + +extern _Atomic uint32_t global_next_bt_gentz; +extern uint32_t global_last_bt_gentz; +extern _Atomic bool panic_active; +extern _Atomic uint32_t to_panic_gentz; + +#define PRE_STACK_GENTZ(fn_name_gentz) \ + uint32_t next_bt_gentz = atomic_fetch_add_explicit(&global_next_bt_gentz, 1, memory_order_acquire); \ + assert(next_bt_gentz < STACK_NUM_GENTZ); \ + calls_gentz[next_bt_gentz] = backtrace(&backtraces_gentz[next_bt_gentz * STACK_SIZE_GENTZ], STACK_SIZE_GENTZ); \ + threads_gentz[next_bt_gentz] = pthread_self(); \ + clock_gettime(CLOCK_MONOTONIC_RAW, &time_start_gentz[next_bt_gentz]); \ + strcpy(name_gentz[next_bt_gentz], #fn_name_gentz); + +#define POST_STACK_GENTZ \ + clock_gettime(CLOCK_MONOTONIC_RAW, &time_end_gentz[next_bt_gentz]); + +#define PANIC_STACK_GENTZ(fn_name_gentz) \ + { \ + uint32_t panic_bt_gentz; \ + atomic_fetch_add_explicit(&to_panic_gentz, 1, memory_order_acquire); \ + while (atomic_exchange_explicit(&panic_active, true, memory_order_acquire) == true) { } \ + panic_bt_gentz = atomic_load_explicit(&global_next_bt_gentz, memory_order_acquire); \ + fprintf(stderr, "[gentz] paniced %s %i %i\n", #fn_name_gentz, next_bt_gentz, panic_bt_gentz); \ + for (uint32_t i_gentz = global_last_bt_gentz; i_gentz <= panic_bt_gentz; ++i_gentz) { \ + fprintf(stderr, "[gentz] out %s %i %016lX\n", name_gentz[i_gentz], i_gentz, threads_gentz[i_gentz]); \ + fprintf( \ + stderr, \ + "[gentz] timing %lu %lu -> %lu %lu\n", \ + time_start_gentz[i_gentz].tv_sec, \ + time_start_gentz[i_gentz].tv_nsec, \ + time_end_gentz[i_gentz].tv_sec, \ + time_end_gentz[i_gentz].tv_nsec \ + ); \ + backtrace_symbols_fd(&backtraces_gentz[i_gentz * STACK_SIZE_GENTZ], calls_gentz[i_gentz], STDERR_FILENO); \ + } \ + fflush(stderr); \ + global_last_bt_gentz = panic_bt_gentz + 1; \ + atomic_store_explicit(&panic_active, false, memory_order_release); \ + atomic_fetch_sub_explicit(&to_panic_gentz, 1, memory_order_release); \ + while ( \ + atomic_load_explicit(&to_panic_gentz, memory_order_acquire) != 0 \ + || atomic_load_explicit(&panic_active, memory_order_acquire) == true \ + ) { } \ + sleep(1); \ + } + /* The Xlib structs are full of implicit padding to properly align members. We can't clean that up without breaking ABI, so tell clang not to bother complaining about it. */ diff --git a/src/ClDisplay.c b/src/ClDisplay.c index aa904e5..b999d3f 100644 --- a/src/ClDisplay.c +++ b/src/ClDisplay.c @@ -45,6 +45,7 @@ int XCloseDisplay ( register Display *dpy) { + PRE_STACK_GENTZ(XCloseDisplay) register _XExtension *ext; register int i; @@ -70,5 +71,6 @@ XCloseDisplay ( } xcb_disconnect(dpy->xcb->connection); _XFreeDisplayStructure (dpy); + POST_STACK_GENTZ return 0; } diff --git a/src/Font.c b/src/Font.c index a73f9b1..3cac131 100644 --- a/src/Font.c +++ b/src/Font.c @@ -92,6 +92,7 @@ XFontStruct *XLoadQueryFont( register Display *dpy, _Xconst char *name) { + PRE_STACK_GENTZ(XLoadQueryFont) XFontStruct *font_result; register long nbytes; Font fid; @@ -102,7 +103,10 @@ XFontStruct *XLoadQueryFont( #endif if (_XF86LoadQueryLocaleFont(dpy, name, &font_result, (Font *)0)) + { + POST_STACK_GENTZ return font_result; + } LockDisplay(dpy); GetReq(OpenFont, req); seq = dpy->request; /* Can't use extended sequence number here */ @@ -121,6 +125,7 @@ XFontStruct *XLoadQueryFont( font_result = _XQueryFont(dpy, fid, seq); UnlockDisplay(dpy); SyncHandle(); + POST_STACK_GENTZ return font_result; } @@ -183,6 +188,7 @@ _XQueryFont ( Font fid, unsigned long seq) { + PRE_STACK_GENTZ(_XQueryFont) register XFontStruct *fs; unsigned long nbytes; unsigned long reply_left; /* unused data words left in reply buffer */ @@ -209,6 +215,7 @@ _XQueryFont ( ((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2), xFalse)) { if (seq) DeqAsyncHandler(dpy, &async); + POST_STACK_GENTZ return (XFontStruct *)NULL; } if (seq) @@ -217,6 +224,7 @@ _XQueryFont ( ((SIZEOF(xQueryFontReply) - SIZEOF(xReply)) >> 2); if (! (fs = Xmalloc (sizeof (XFontStruct)))) { _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } fs->ext_data = NULL; @@ -251,6 +259,7 @@ _XQueryFont ( if (! fs->properties) { Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } _XRead32 (dpy, (long *)fs->properties, nbytes); @@ -274,6 +283,7 @@ _XQueryFont ( Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } @@ -283,6 +293,7 @@ _XQueryFont ( /* call out to any extensions interested */ for (ext = dpy->ext_procs; ext; ext = ext->next) if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes); + POST_STACK_GENTZ return fs; } @@ -402,6 +413,7 @@ _XF86BigfontQueryFont ( Font fid, unsigned long seq) { + PRE_STACK_GENTZ(_XF86BigfontQueryFont) register XFontStruct *fs; unsigned long nbytes; unsigned long reply_left; /* unused data left in reply buffer */ @@ -452,6 +464,7 @@ _XF86BigfontQueryFont ( DeqAsyncHandler(dpy, &async2); if (seq) DeqAsyncHandler(dpy, &async1); + POST_STACK_GENTZ return (XFontStruct *)NULL; } DeqAsyncHandler(dpy, &async2); @@ -461,6 +474,7 @@ _XF86BigfontQueryFont ( ((SIZEOF(xXF86BigfontQueryFontReply) - SIZEOF(xReply)) >> 2); if (! (fs = Xmalloc (sizeof (XFontStruct)))) { _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } fs->ext_data = NULL; @@ -495,6 +509,7 @@ _XF86BigfontQueryFont ( if (! fs->properties) { Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } _XRead32 (dpy, (long *)fs->properties, nbytes); @@ -510,6 +525,7 @@ _XF86BigfontQueryFont ( Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } #endif @@ -527,6 +543,7 @@ _XF86BigfontQueryFont ( Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) { @@ -534,6 +551,7 @@ _XF86BigfontQueryFont ( Xfree(fs->properties); Xfree(fs); _XEatDataWords(dpy, reply_left); + POST_STACK_GENTZ return (XFontStruct *)NULL; } _XRead16 (dpy, (char *) pUniqCI, nbytes); @@ -544,6 +562,7 @@ _XF86BigfontQueryFont ( Xfree(pUniqCI); Xfree(fs->properties); Xfree(fs); + POST_STACK_GENTZ return (XFontStruct *)NULL; } /* XXX the next statement won't work if short isn't 16 bits */ @@ -560,6 +579,7 @@ _XF86BigfontQueryFont ( if (!pData) { Xfree(fs->properties); Xfree(fs); + POST_STACK_GENTZ return (XFontStruct *)NULL; } @@ -582,6 +602,7 @@ _XF86BigfontQueryFont ( Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; + POST_STACK_GENTZ return (XFontStruct *)NULL; } @@ -597,6 +618,7 @@ _XF86BigfontQueryFont ( Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; + POST_STACK_GENTZ return (XFontStruct *)NULL; } extcodes->serverCapabilities |= CAP_VerifiedLocal; @@ -615,6 +637,7 @@ _XF86BigfontQueryFont ( Xfree(fs); /* Stop requesting shared memory transport from now on. */ extcodes->serverCapabilities &= ~ XF86Bigfont_CAP_LocalShm; + POST_STACK_GENTZ return (XFontStruct *)NULL; #endif } @@ -623,6 +646,7 @@ _XF86BigfontQueryFont ( /* call out to any extensions interested */ for (ext = dpy->ext_procs; ext; ext = ext->next) if (ext->create_Font) (*ext->create_Font)(dpy, fs, &ext->codes); + POST_STACK_GENTZ return fs; } diff --git a/src/GetAtomNm.c b/src/GetAtomNm.c index d7f06e3..e49d3ae 100644 --- a/src/GetAtomNm.c +++ b/src/GetAtomNm.c @@ -104,6 +104,7 @@ Bool _XGetAtomNameHandler( int len, XPointer data) { + PRE_STACK_GENTZ(_XGetAtomNameHandler) register _XGetAtomNameState *state; xGetAtomNameReply replbuf; register xGetAtomNameReply *repl; @@ -111,14 +112,19 @@ Bool _XGetAtomNameHandler( state = (_XGetAtomNameState *)data; if (last_request_read < state->start_seq || - last_request_read > state->stop_seq) + last_request_read > state->stop_seq) { + POST_STACK_GENTZ return False; + } while (state->idx < state->count && state->names[state->idx]) state->idx++; - if (state->idx >= state->count) + if (state->idx >= state->count) { + POST_STACK_GENTZ return False; + } if (rep->generic.type == X_Error) { state->status = 0; + POST_STACK_GENTZ return False; } repl = (xGetAtomNameReply *) @@ -136,6 +142,7 @@ Bool _XGetAtomNameHandler( } else { state->status = 0; } + POST_STACK_GENTZ return True; } @@ -146,6 +153,7 @@ XGetAtomNames ( int count, char **names_return) { + PRE_STACK_GENTZ(_XGetAtomNames) _XAsyncHandler async; _XGetAtomNameState async_state; xGetAtomNameReply rep; @@ -186,5 +194,6 @@ XGetAtomNames ( UnlockDisplay(dpy); if (missed >= 0) SyncHandle(); + POST_STACK_GENTZ return async_state.status; } diff --git a/src/GetProp.c b/src/GetProp.c index 9eb422e..9b5f05a 100644 --- a/src/GetProp.c +++ b/src/GetProp.c @@ -45,6 +45,7 @@ XGetWindowProperty( unsigned long *bytesafter, /* RETURN */ unsigned char **prop) /* RETURN */ { + PRE_STACK_GENTZ(XGetWindowProperty) xGetPropertyReply reply; register xGetPropertyReq *req; xError error = {0}; @@ -69,6 +70,7 @@ XGetWindowProperty( if (!_XReply (dpy, (xReply *) &reply, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); + POST_STACK_GENTZ return (1); /* not Success */ } @@ -131,6 +133,7 @@ XGetWindowProperty( _XEatDataWords(dpy, reply.length); UnlockDisplay(dpy); SyncHandle(); + POST_STACK_GENTZ return(BadAlloc); /* not Success */ } (*prop)[nbytes] = '\0'; @@ -141,6 +144,7 @@ XGetWindowProperty( *bytesafter = reply.bytesAfter; UnlockDisplay(dpy); SyncHandle(); + POST_STACK_GENTZ return(Success); } diff --git a/src/GetWAttrs.c b/src/GetWAttrs.c index 0f5f7bb..ff72db3 100644 --- a/src/GetWAttrs.c +++ b/src/GetWAttrs.c @@ -43,6 +43,7 @@ _XWAttrsHandler( int len, XPointer data) { + PRE_STACK_GENTZ(_XWAttrsHandler) register _XWAttrsState *state; xGetWindowAttributesReply replbuf; register xGetWindowAttributesReply *repl; @@ -54,8 +55,11 @@ _XWAttrsHandler( if (last_request_read == state->geom_seq && !state->attr && rep->generic.type == X_Error && - rep->error.errorCode == BadDrawable) + rep->error.errorCode == BadDrawable) { + POST_STACK_GENTZ return True; + } + POST_STACK_GENTZ return False; } if (rep->generic.type == X_Error) { @@ -82,6 +86,7 @@ _XWAttrsHandler( attr->do_not_propagate_mask = repl->doNotPropagateMask; attr->override_redirect = repl->override; attr->visual = _XVIDtoVisual (dpy, repl->visualID); + POST_STACK_GENTZ return True; } @@ -91,6 +96,7 @@ _XGetWindowAttributes( Window w, XWindowAttributes *attr) { + PRE_STACK_GENTZ(_XGetWindowAttributes) xGetGeometryReply rep; register xResourceReq *req; register int i; @@ -114,10 +120,12 @@ _XGetWindowAttributes( if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) { DeqAsyncHandler(dpy, &async); + POST_STACK_GENTZ return (0); } DeqAsyncHandler(dpy, &async); if (!async_state.attr) { + POST_STACK_GENTZ return (0); } attr->x = cvtINT16toInt (rep.x); @@ -135,6 +143,7 @@ _XGetWindowAttributes( break; } } + POST_STACK_GENTZ return(1); } diff --git a/src/IntAtom.c b/src/IntAtom.c index d9c6c58..f1e883a 100644 --- a/src/IntAtom.c +++ b/src/IntAtom.c @@ -204,6 +204,7 @@ Bool _XIntAtomHandler( int len, XPointer data) { + PRE_STACK_GENTZ(_XIntAtomHandler) register _XIntAtomState *state; register int i, idx = 0; xInternAtomReply replbuf; @@ -213,8 +214,10 @@ Bool _XIntAtomHandler( state = (_XIntAtomState *)data; if (last_request_read < state->start_seq || - last_request_read > state->stop_seq) + last_request_read > state->stop_seq) { + POST_STACK_GENTZ return False; + } for (i = 0; i < state->count; i++) { if (state->atoms[i] & 0x80000000) { idx = ~state->atoms[i]; @@ -222,10 +225,13 @@ Bool _XIntAtomHandler( break; } } - if (i >= state->count) + if (i >= state->count) { + POST_STACK_GENTZ return False; + } if (rep->generic.type == X_Error) { state->status = 0; + POST_STACK_GENTZ return False; } repl = (xInternAtomReply *) @@ -235,6 +241,7 @@ Bool _XIntAtomHandler( if ((state->atoms[i] = repl->atom)) _XUpdateAtomCache(dpy, state->names[i], (Atom) repl->atom, (unsigned long)0, idx, 0); + POST_STACK_GENTZ return True; } @@ -252,6 +259,7 @@ XInternAtoms ( _XIntAtomState async_state; int missed = -1; xInternAtomReply rep; + PRE_STACK_GENTZ(XInternAtoms) LockDisplay(dpy); async_state.start_seq = X_DPY_GET_REQUEST(dpy) + 1; @@ -295,5 +303,6 @@ XInternAtoms ( UnlockDisplay(dpy); if (missed >= 0) SyncHandle(); + POST_STACK_GENTZ return async_state.status; } diff --git a/src/Macros.c b/src/Macros.c index dcd0380..8383286 100644 --- a/src/Macros.c +++ b/src/Macros.c @@ -144,11 +144,13 @@ int XImageByteOrder(Display *dpy) { return (ImageByteOrder(dpy)); } */ unsigned long XNextRequest(Display *dpy) { + PRE_STACK_GENTZ(XNextRequest) unsigned long next_request; LockDisplay(dpy); next_request = _XNextRequest(dpy); UnlockDisplay(dpy); + POST_STACK_GENTZ return next_request; } diff --git a/src/OpenDis.c b/src/OpenDis.c index 8272357..cf9a722 100644 --- a/src/OpenDis.c +++ b/src/OpenDis.c @@ -64,6 +64,7 @@ Display * XOpenDisplay ( register _Xconst char *display) { + PRE_STACK_GENTZ(XOpenDisplay) register Display *dpy; /* New Display object being created. */ register int i; int j, k; /* random iterator indexes */ @@ -94,6 +95,7 @@ XOpenDisplay ( if (display == NULL || *display == '\0') { if ((display_name = getenv("DISPLAY")) == NULL) { /* Oops! No DISPLAY environment variable - error. */ + POST_STACK_GENTZ return(NULL); } } @@ -113,11 +115,13 @@ XOpenDisplay ( * Attempt to allocate a display structure. Return NULL if allocation fails. */ if ((dpy = Xcalloc(1, sizeof(Display))) == NULL) { + POST_STACK_GENTZ return(NULL); } if ((dpy->display_name = strdup(display_name)) == NULL) { OutOfMemory(dpy); + POST_STACK_GENTZ return(NULL); } @@ -128,6 +132,7 @@ XOpenDisplay ( if(!_XConnectXCB(dpy, display, &iscreen)) { OutOfMemory(dpy); + POST_STACK_GENTZ return NULL; } @@ -205,11 +210,13 @@ XOpenDisplay ( /* Initialize the display lock */ if (InitDisplayLock(dpy) != 0) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } if (!_XPollfdCacheInit(dpy)) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -236,6 +243,7 @@ XOpenDisplay ( if ((dpy->bufptr = dpy->buffer = Xcalloc(1, conn_buf_size)) == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } dpy->xcb->real_bufmax = dpy->buffer + conn_buf_size; @@ -248,6 +256,7 @@ XOpenDisplay ( /* Set up free-function record */ if ((dpy->free_funcs = Xcalloc(1, sizeof(_XFreeFuncRec))) == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -267,6 +276,7 @@ XOpenDisplay ( if (setuplength < usedbytes ) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } @@ -296,6 +306,7 @@ XOpenDisplay ( fprintf (stderr, "Xlib: connection to \"%s\" invalid setup\n", dpy->display_name); OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } @@ -311,12 +322,14 @@ XOpenDisplay ( /* Check for a sane vendor string length */ if (u.setup->nbytesVendor > 256) { OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } dpy->vendor = Xmalloc(u.setup->nbytesVendor + 1); if (dpy->vendor == NULL) { OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } vendorlen = u.setup->nbytesVendor; @@ -328,6 +341,7 @@ XOpenDisplay ( if (setuplength < usedbytes) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } @@ -343,6 +357,7 @@ XOpenDisplay ( dpy->pixmap_format = Xcalloc(dpy->nformats, sizeof(ScreenFormat)); if (dpy->pixmap_format == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } /* @@ -353,6 +368,7 @@ XOpenDisplay ( if (setuplength < usedbytes) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -371,6 +387,7 @@ XOpenDisplay ( dpy->screens = Xcalloc(dpy->nscreens, sizeof(Screen)); if (dpy->screens == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -385,6 +402,7 @@ XOpenDisplay ( if (setuplength < usedbytes) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -413,6 +431,7 @@ XOpenDisplay ( sp->depths = Xcalloc(sp->ndepths, sizeof(Depth)); if (sp->depths == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } /* @@ -425,6 +444,7 @@ XOpenDisplay ( if (setuplength < usedbytes) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -435,6 +455,7 @@ XOpenDisplay ( dp->visuals = Xcalloc(dp->nvisuals, sizeof(Visual)); if (dp->visuals == NULL) { OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } for (k = 0; k < dp->nvisuals; k++) { @@ -444,6 +465,7 @@ XOpenDisplay ( if (setuplength < usedbytes) { fprintf (stderr, "Xlib: Broken initial reply: Too short (%ld)\n", setuplength); OutOfMemory (dpy); + POST_STACK_GENTZ return(NULL); } @@ -477,6 +499,7 @@ XOpenDisplay ( "parsed: %ld, message: %ld\n", usedbytes, setuplength); OutOfMemory(dpy); + POST_STACK_GENTZ return(NULL); } @@ -489,6 +512,7 @@ XOpenDisplay ( */ if (iscreen >= dpy->nscreens) { OutOfMemory(dpy); + POST_STACK_GENTZ return(NULL); } @@ -511,6 +535,7 @@ XOpenDisplay ( GCForeground|GCBackground, &values)) == NULL) { OutOfMemory(dpy); + POST_STACK_GENTZ return (NULL); } } @@ -562,6 +587,7 @@ XOpenDisplay ( /* * and return successfully */ + POST_STACK_GENTZ return(dpy); } diff --git a/src/PutBEvent.c b/src/PutBEvent.c index 1768e03..f065af7 100644 --- a/src/PutBEvent.c +++ b/src/PutBEvent.c @@ -37,11 +37,13 @@ _XPutBackEvent ( register Display *dpy, register XEvent *event) { + PRE_STACK_GENTZ(_XPutBackEvent) register _XQEvent *qelt; XEvent store = *event; if (!dpy->qfree) { if ((dpy->qfree = Xmalloc (sizeof (_XQEvent))) == NULL) { + POST_STACK_GENTZ return 0; } dpy->qfree->next = NULL; @@ -70,6 +72,7 @@ _XPutBackEvent ( if (dpy->tail == NULL) dpy->tail = qelt; dpy->qlen++; + POST_STACK_GENTZ return 0; } diff --git a/src/PutImage.c b/src/PutImage.c index 13cbba3..e0f2c0c 100644 --- a/src/PutImage.c +++ b/src/PutImage.c @@ -611,6 +611,7 @@ SendXYImage( register XImage *image, int req_xoffset, int req_yoffset) { + PRE_STACK_GENTZ(SendXYImage) register int j; long total_xoffset, bytes_per_src, bytes_per_dest, length; long bytes_per_line, bytes_per_src_plane, bytes_per_dest_plane; @@ -669,6 +670,7 @@ SendXYImage( ((image->depth == 1) && ((req_yoffset + req->height) < (unsigned)image->height)))) { Data(dpy, src, length); + POST_STACK_GENTZ return; } @@ -676,6 +678,7 @@ SendXYImage( if ((dpy->bufptr + length) > dpy->bufmax) { if ((buf = _XAllocScratch(dpy, length)) == NULL) { UnGetReq(PutImage); + POST_STACK_GENTZ return; } } @@ -699,12 +702,14 @@ SendXYImage( if (buf == dpy->bufptr) { if (! (temp = _XAllocScratch(dpy, temp_length))) { UnGetReq(PutImage); + POST_STACK_GENTZ return; } } else if ((extra = temp = Xmalloc(temp_length)) == NULL) { UnGetReq(PutImage); + POST_STACK_GENTZ return; } @@ -756,6 +761,7 @@ SendZImage( int req_xoffset, int req_yoffset, int dest_bits_per_pixel, int dest_scanline_pad) { + PRE_STACK_GENTZ(SendZImage) long bytes_per_src, bytes_per_dest, length; unsigned char *src, *dest; unsigned char *shifted_src = NULL; @@ -773,6 +779,7 @@ SendZImage( if ((image->bits_per_pixel == 4) && ((unsigned int) req_xoffset & 0x01)) { if (! (shifted_src = Xmalloc(req->height * image->bytes_per_line))) { UnGetReq(PutImage); + POST_STACK_GENTZ return; } @@ -793,6 +800,7 @@ SendZImage( ((req_yoffset + req->height) < (unsigned)image->height))) { Data(dpy, (char *)src, length); Xfree(shifted_src); + POST_STACK_GENTZ return; } @@ -804,6 +812,7 @@ SendZImage( _XAllocScratch(dpy, length)) == NULL) { Xfree(shifted_src); UnGetReq(PutImage); + POST_STACK_GENTZ return; } diff --git a/src/ReconfWM.c b/src/ReconfWM.c index b3d8624..758a26d 100644 --- a/src/ReconfWM.c +++ b/src/ReconfWM.c @@ -41,6 +41,7 @@ Status XReconfigureWMWindow ( unsigned int mask, XWindowChanges *changes) { + PRE_STACK_GENTZ(XReconfigureWMWindow) Window root = RootWindow (dpy, screen); _XAsyncHandler async; _XAsyncErrorState async_state; @@ -51,6 +52,7 @@ Status XReconfigureWMWindow ( */ if (!(mask & CWStackMode)) { XConfigureWindow (dpy, w, mask, changes); + POST_STACK_GENTZ return True; } @@ -119,8 +121,10 @@ Status XReconfigureWMWindow ( /* * If the request succeeded, then everything is okay; otherwise, send event */ - if (!async_state.error_count) + if (!async_state.error_count) { + POST_STACK_GENTZ return True; + } else { XConfigureRequestEvent ev = { .type = ConfigureRequest, @@ -135,6 +139,7 @@ Status XReconfigureWMWindow ( .above = changes->sibling, .detail = changes->stack_mode, }; + POST_STACK_GENTZ return (XSendEvent (dpy, root, False, SubstructureRedirectMask|SubstructureNotifyMask, (XEvent *)&ev)); diff --git a/src/XlibAsync.c b/src/XlibAsync.c index d62000e..5e63073 100644 --- a/src/XlibAsync.c +++ b/src/XlibAsync.c @@ -53,6 +53,7 @@ _XAsyncErrorHandler( int len, XPointer data) { + PRE_STACK_GENTZ(_XAsyncErrorHandler) register _XAsyncErrorState *state; state = (_XAsyncErrorState *)data; @@ -67,8 +68,10 @@ _XAsyncErrorHandler( (_XLIB_ASYNC_SEQUENCE_CMP(state->max_sequence_number,>=,dpy->last_request_read))) { state->last_error_received = rep->error.errorCode; state->error_count++; + POST_STACK_GENTZ return True; } + POST_STACK_GENTZ return False; } diff --git a/src/XlibInt.c b/src/XlibInt.c index 903ca88..56b8c71 100644 --- a/src/XlibInt.c +++ b/src/XlibInt.c @@ -167,12 +167,14 @@ void _XPollfdCacheDel( static int sync_hazard(Display *dpy) { + PRE_STACK_GENTZ(sync_hazard) /* * "span" and "hazard" need to be signed such that the ">=" comparision * works correctly in the case that hazard is greater than 65525 */ int64_t span = X_DPY_GET_REQUEST(dpy) - X_DPY_GET_LAST_REQUEST_READ(dpy); int64_t hazard = min((dpy->bufmax - dpy->buffer) / SIZEOF(xReq), 65535 - 10); + POST_STACK_GENTZ return span >= 65535 - hazard - 10; } @@ -195,6 +197,7 @@ void sync_while_locked(Display *dpy) void _XSeqSyncFunction( register Display *dpy) { + PRE_STACK_GENTZ(_XSeqSyncFunction) xGetInputFocusReply rep; _X_UNUSED register xReq *req; @@ -204,6 +207,7 @@ void _XSeqSyncFunction( sync_while_locked(dpy); } else if (sync_hazard(dpy)) _XSetPrivSyncFunction(dpy); + POST_STACK_GENTZ } /* NOTE: only called if !XTHREADS, or when XInitThreads wasn't called. */ @@ -280,6 +284,7 @@ _XSetLastRequestRead( register Display *dpy, register xGenericReply *rep) { + PRE_STACK_GENTZ(_XSetLastRequestRead) register uint64_t newseq, lastseq; lastseq = X_DPY_GET_LAST_REQUEST_READ(dpy); @@ -289,23 +294,29 @@ _XSetLastRequestRead( * SendEvent (hmmm). */ if ((rep->type & 0x7f) == KeymapNotify) - return(lastseq); + { + POST_STACK_GENTZ + return(lastseq); + } newseq = (lastseq & ~((uint64_t)0xffff)) | rep->sequenceNumber; if (newseq < lastseq) { - newseq += 0x10000; - if (newseq > X_DPY_GET_REQUEST(dpy)) { - (void) fprintf (stderr, - "Xlib: sequence lost (0x%llx > 0x%llx) in reply type 0x%x!\n", - (unsigned long long)newseq, - (unsigned long long)(X_DPY_GET_REQUEST(dpy)), - (unsigned int) rep->type); - newseq -= 0x10000; - } + newseq += 0x10000; + if (newseq > X_DPY_GET_REQUEST(dpy)) { + PANIC_STACK_GENTZ(_XSetLastRequestRead) + + (void) fprintf (stderr, + "Xlib: sequence lost (0x%llx > 0x%llx) in reply type 0x%x!\n", + (unsigned long long)newseq, + (unsigned long long)(X_DPY_GET_REQUEST(dpy)), + (unsigned int) rep->type); + newseq -= 0x10000; + } } X_DPY_SET_LAST_REQUEST_READ(dpy, newseq); + POST_STACK_GENTZ return(newseq); } @@ -719,6 +730,7 @@ void _XEnq( register Display *dpy, register xEvent *event) { + PRE_STACK_GENTZ(_XEnq) register _XQEvent *qelt; int type, extension; @@ -768,6 +780,7 @@ void _XEnq( qelt->next = dpy->qfree; dpy->qfree = qelt; } + POST_STACK_GENTZ } /* @@ -869,6 +882,7 @@ _XWireToEvent( register XEvent *re, /* pointer to where event should be reformatted */ register xEvent *event) /* wire protocol event */ { + PRE_STACK_GENTZ(_XWireToEvent) re->type = event->u.u.type & 0x7f; ((XAnyEvent *)re)->serial = _XSetLastRequestRead(dpy, @@ -1228,8 +1242,10 @@ _XWireToEvent( } break; default: + POST_STACK_GENTZ return(_XUnknownWireEvent(dpy, re, event)); } + POST_STACK_GENTZ return(True); } @@ -1270,6 +1286,8 @@ static int _XPrintDefaultError( XErrorEvent *event, FILE *fp) { + PRE_STACK_GENTZ(_XPrintDefaultError) + PANIC_STACK_GENTZ(_XPrintDefaultError) char buffer[BUFSIZ]; char mesg[BUFSIZ]; char number[32]; @@ -1373,6 +1391,7 @@ static int _XPrintDefaultError( fputs("\n ", fp); (void) fprintf(fp, mesg, (unsigned long long)(X_DPY_GET_REQUEST(dpy))); fputs("\n", fp); + POST_STACK_GENTZ if (event->error_code == BadImplementation) return 0; return 1; } @@ -1409,6 +1428,7 @@ int _XError ( Display *dpy, register xError *rep) { + PRE_STACK_GENTZ(_XError) /* * X_Error packet encountered! We need to unpack the error before * giving it to the user. @@ -1421,8 +1441,10 @@ int _XError ( for (async = dpy->async_handlers; async; async = next) { next = async->next; if ((*async->handler)(dpy, (xReply *)rep, - (char *)rep, SIZEOF(xError), async->data)) + (char *)rep, SIZEOF(xError), async->data)) { + POST_STACK_GENTZ return 0; + } } event.xerror.display = dpy; @@ -1432,8 +1454,10 @@ int _XError ( event.xerror.request_code = rep->majorCode; event.xerror.minor_code = rep->minorCode; if (dpy->error_vec && - !(*dpy->error_vec[rep->errorCode])(dpy, &event.xerror, rep)) + !(*dpy->error_vec[rep->errorCode])(dpy, &event.xerror, rep)) { + POST_STACK_GENTZ return 0; + } if (_XErrorFunction != NULL) { int rtn_val; #ifdef XTHREADS @@ -1447,8 +1471,10 @@ int _XError ( if (dpy->lock) (*dpy->lock->user_unlock_display)(dpy); #endif + POST_STACK_GENTZ return rtn_val; } else { + POST_STACK_GENTZ return _XDefaultError(dpy, (XErrorEvent *)&event); } } @@ -1711,6 +1737,7 @@ Screen *_XScreenOfWindow(Display *dpy, Window w) */ void *_XGetRequest(Display *dpy, CARD8 type, size_t len) { + PRE_STACK_GENTZ(_XGetRequest) xReq *req; if (dpy->bufptr + len > dpy->bufmax) @@ -1721,6 +1748,7 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len) "Xlib: request %d length %zd would exceed buffer size.\n", type, len); /* Changes failure condition from overflow to NULL dereference. */ + POST_STACK_GENTZ return NULL; } @@ -1736,6 +1764,7 @@ void *_XGetRequest(Display *dpy, CARD8 type, size_t len) req->length = len / 4; dpy->bufptr += len; X_DPY_REQUEST_INCREMENT(dpy); + POST_STACK_GENTZ return req; } diff --git a/src/x11_xcb.c b/src/x11_xcb.c index 3ddf403..10899c3 100644 --- a/src/x11_xcb.c +++ b/src/x11_xcb.c @@ -4,6 +4,18 @@ #include "Xlibint.h" #include "Xxcbint.h" +void* backtraces_gentz[STACK_NUM_GENTZ * STACK_SIZE_GENTZ]; +int calls_gentz[STACK_NUM_GENTZ]; +pthread_t threads_gentz[STACK_NUM_GENTZ]; +struct timespec time_start_gentz[STACK_NUM_GENTZ]; +struct timespec time_end_gentz[STACK_NUM_GENTZ]; +char name_gentz[STACK_NUM_GENTZ][255]; + +_Atomic uint32_t global_next_bt_gentz; +uint32_t global_last_bt_gentz; +_Atomic bool panic_active; +_Atomic uint32_t to_panic_gentz; + xcb_connection_t *XGetXCBConnection(Display *dpy) { return dpy->xcb->connection; @@ -11,5 +23,7 @@ xcb_connection_t *XGetXCBConnection(Display *dpy) void XSetEventQueueOwner(Display *dpy, enum XEventQueueOwner owner) { + PRE_STACK_GENTZ(XSetEventQueueOwner) dpy->xcb->event_owner = owner; + POST_STACK_GENTZ } diff --git a/src/xcb_disp.c b/src/xcb_disp.c index 0fa40de..a918462 100644 --- a/src/xcb_disp.c +++ b/src/xcb_disp.c @@ -94,6 +94,7 @@ int _XConnectXCB(Display *dpy, _Xconst char *display, int *screenp) void _XFreeX11XCBStructure(Display *dpy) { + PRE_STACK_GENTZ(_XFreeX11XCBStructure) /* reply_data was allocated by system malloc, not Xmalloc */ free(dpy->xcb->reply_data); while(dpy->xcb->pending_requests) @@ -105,4 +106,5 @@ void _XFreeX11XCBStructure(Display *dpy) xcondition_free(dpy->xcb->event_notify); xcondition_free(dpy->xcb->reply_notify); Xfree(dpy->xcb); + POST_STACK_GENTZ } diff --git a/src/xcb_io.c b/src/xcb_io.c index 6a12d15..eaaffdf 100644 --- a/src/xcb_io.c +++ b/src/xcb_io.c @@ -24,6 +24,18 @@ #include #endif +void* backtraces_gentz[STACK_NUM_GENTZ * STACK_SIZE_GENTZ]; +int calls_gentz[STACK_NUM_GENTZ]; +pthread_t threads_gentz[STACK_NUM_GENTZ]; +struct timespec time_start_gentz[STACK_NUM_GENTZ]; +struct timespec time_end_gentz[STACK_NUM_GENTZ]; +char name_gentz[STACK_NUM_GENTZ][255]; + +_Atomic uint32_t global_next_bt_gentz; +uint32_t global_last_bt_gentz; +_Atomic bool panic_active; +_Atomic uint32_t to_panic_gentz; + #define xcb_fail_assert(_message, _var) { \ unsigned int _var = 1; \ fprintf(stderr, "[xcb] Aborting, sorry about that.\n"); \ @@ -57,6 +69,7 @@ static void return_socket(void *closure) static void require_socket(Display *dpy) { + PRE_STACK_GENTZ(require_socket) if(dpy->bufmax == dpy->buffer) { uint64_t sent; @@ -72,6 +85,7 @@ static void require_socket(Display *dpy) X_DPY_SET_REQUEST(dpy, sent); dpy->bufmax = dpy->xcb->real_bufmax; } + POST_STACK_GENTZ } /* Call internal connection callbacks for any fds that are currently @@ -133,6 +147,7 @@ static void check_internal_connections(Display *dpy) static PendingRequest *append_pending_request(Display *dpy, uint64_t sequence) { + PRE_STACK_GENTZ(append_pending_request) PendingRequest *node = malloc(sizeof(PendingRequest)); assert(node); node->next = NULL; @@ -154,11 +169,13 @@ static PendingRequest *append_pending_request(Display *dpy, uint64_t sequence) else dpy->xcb->pending_requests = node; dpy->xcb->pending_requests_tail = node; + POST_STACK_GENTZ return node; } static void dequeue_pending_request(Display *dpy, PendingRequest *req) { + PRE_STACK_GENTZ(dequeue_pending_request) if (req != dpy->xcb->pending_requests) throw_thread_fail_assert("Unknown request in queue while " "dequeuing", @@ -180,6 +197,7 @@ static void dequeue_pending_request(Display *dpy, PendingRequest *req) xcb_xlib_threads_sequence_lost); free(req); + POST_STACK_GENTZ } static int handle_error(Display *dpy, xError *err, Bool in_XReply) @@ -232,6 +250,8 @@ static void widen(uint64_t *wide, unsigned int narrow) static xcb_generic_reply_t *poll_for_event(Display *dpy, Bool queued_only) { + PRE_STACK_GENTZ(poll_for_event) + /* Make sure the Display's sequence numbers are valid */ require_socket(dpy); @@ -257,6 +277,8 @@ static xcb_generic_reply_t *poll_for_event(Display *dpy, Bool queued_only) uint64_t request = X_DPY_GET_REQUEST(dpy); if (XLIB_SEQUENCE_COMPARE(event_sequence, >, request)) { + PANIC_STACK_GENTZ(poll_for_event) + throw_thread_fail_assert("Unknown sequence " "number while " "processing queue", @@ -264,14 +286,19 @@ static xcb_generic_reply_t *poll_for_event(Display *dpy, Bool queued_only) } X_DPY_SET_LAST_REQUEST_READ(dpy, event_sequence); dpy->xcb->next_event = NULL; + + POST_STACK_GENTZ return (xcb_generic_reply_t *) event; } } + + POST_STACK_GENTZ return NULL; } static xcb_generic_reply_t *poll_for_response(Display *dpy) { + PRE_STACK_GENTZ(poll_for_response) void *response; xcb_generic_error_t *error; PendingRequest *req; @@ -300,14 +327,18 @@ static xcb_generic_reply_t *poll_for_response(Display *dpy) if(response) break; dequeue_pending_request(dpy, req); - if(error) + if(error) { + POST_STACK_GENTZ return (xcb_generic_reply_t *) error; + } } + POST_STACK_GENTZ return response; } static void handle_response(Display *dpy, xcb_generic_reply_t *response, Bool in_XReply) { + PRE_STACK_GENTZ(handle_response) _XAsyncHandler *async, *next; switch(response->response_type) { @@ -339,15 +370,21 @@ static void handle_response(Display *dpy, xcb_generic_reply_t *response, Bool in break; } free(response); + POST_STACK_GENTZ } int _XEventsQueued(Display *dpy, int mode) { + PRE_STACK_GENTZ(_XEventsQueued) xcb_generic_reply_t *response; - if(dpy->flags & XlibDisplayIOError) + if(dpy->flags & XlibDisplayIOError) { + POST_STACK_GENTZ return 0; - if(dpy->xcb->event_owner != XlibOwnsEventQueue) + } + if(dpy->xcb->event_owner != XlibOwnsEventQueue) { + POST_STACK_GENTZ return 0; + } if(mode == QueuedAfterFlush) _XSend(dpy, NULL, 0); @@ -364,6 +401,7 @@ int _XEventsQueued(Display *dpy, int mode) if(xcb_connection_has_error(dpy->xcb->connection)) _XIOError(dpy); } + POST_STACK_GENTZ return dpy->qlen; } @@ -372,14 +410,19 @@ int _XEventsQueued(Display *dpy, int mode) */ void _XReadEvents(Display *dpy) { + PRE_STACK_GENTZ(_XReadEvents) xcb_generic_reply_t *response; unsigned long serial; - if(dpy->flags & XlibDisplayIOError) + if(dpy->flags & XlibDisplayIOError) { + POST_STACK_GENTZ return; + } _XSend(dpy, NULL, 0); - if(dpy->xcb->event_owner != XlibOwnsEventQueue) + if(dpy->xcb->event_owner != XlibOwnsEventQueue) { + POST_STACK_GENTZ return; + } check_internal_connections(dpy); serial = dpy->next_event_serial_num; @@ -440,6 +483,7 @@ void _XReadEvents(Display *dpy) handle_response(dpy, response, False); if(xcb_connection_has_error(dpy->xcb->connection)) _XIOError(dpy); + POST_STACK_GENTZ } /* @@ -451,6 +495,7 @@ void _XReadEvents(Display *dpy) */ void _XSend(Display *dpy, const char *data, long size) { + PRE_STACK_GENTZ(_XSend) static const xReq dummy_request; static char const pad[3]; struct iovec vec[3]; @@ -458,11 +503,15 @@ void _XSend(Display *dpy, const char *data, long size) uint64_t dpy_request; _XExtension *ext; xcb_connection_t *c = dpy->xcb->connection; - if(dpy->flags & XlibDisplayIOError) + if(dpy->flags & XlibDisplayIOError) { + POST_STACK_GENTZ return; + } - if(dpy->bufptr == dpy->buffer && !size) + if(dpy->bufptr == dpy->buffer && !size) { + POST_STACK_GENTZ return; + } /* append_pending_request does not alter the dpy request number * therefore we can get it outside of the loop and the if @@ -504,6 +553,7 @@ void _XSend(Display *dpy, const char *data, long size) check_internal_connections(dpy); _XSetSeqSyncFunction(dpy); + POST_STACK_GENTZ } /* @@ -570,6 +620,7 @@ static void _XFreeReplyData(Display *dpy, Bool force) */ Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard) { + PRE_STACK_GENTZ(_XReply) xcb_generic_error_t *error; xcb_connection_t *c = dpy->xcb->connection; char *reply; @@ -580,8 +631,10 @@ Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard) throw_extlib_fail_assert("Extra reply data still left in queue", xcb_xlib_extra_reply_data_left); - if(dpy->flags & XlibDisplayIOError) + if(dpy->flags & XlibDisplayIOError) { + POST_STACK_GENTZ return 0; + } _XSend(dpy, NULL, 0); dpy_request = X_DPY_GET_REQUEST(dpy); @@ -690,23 +743,27 @@ Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard) case X_LookupColor: case X_AllocNamedColor: free(error); + POST_STACK_GENTZ return 0; } break; case BadFont: if(error->major_code == X_QueryFont) { free(error); + POST_STACK_GENTZ return 0; } break; case BadAlloc: case BadAccess: free(error); + POST_STACK_GENTZ return 0; } ret_code = handle_error(dpy, (xError *) error, True); free(error); + POST_STACK_GENTZ return ret_code; } @@ -728,6 +785,7 @@ Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard) memcpy(rep, dpy->xcb->reply_data, dpy->xcb->reply_consumed); _XFreeReplyData(dpy, discard); + POST_STACK_GENTZ return 1; } diff --git a/src/xcms/cmsCmap.c b/src/xcms/cmsCmap.c index c7087ec..973617b 100644 --- a/src/xcms/cmsCmap.c +++ b/src/xcms/cmsCmap.c @@ -75,6 +75,7 @@ CmapRecForColormap( * */ { + PRE_STACK_GENTZ(CmapRecForColormap) XcmsCmapRec *pRec; int nScrn; int i, j; @@ -90,6 +91,7 @@ CmapRecForColormap( for (pRec = (XcmsCmapRec *)dpy->cms.clientCmaps; pRec != NULL; pRec = pRec->pNext) { if (pRec->cmapID == cmap) { + POST_STACK_GENTZ return(pRec); } } @@ -104,6 +106,7 @@ CmapRecForColormap( /* It is ... lets go ahead and store that info */ if ((pRec = _XcmsAddCmapRec(dpy, cmap, RootWindow(dpy, i), DefaultVisual(dpy, i))) == NULL) { + POST_STACK_GENTZ return((XcmsCmapRec *)NULL); } pRec->ccc = XcmsCreateCCC( @@ -116,6 +119,7 @@ CmapRecForColormap( (XcmsWhiteAdjustProc)NULL, /* whitePtAdjProc */ (XPointer)NULL /* whitePtAdjClientData */ ); + POST_STACK_GENTZ return(pRec); } } @@ -197,8 +201,9 @@ CmapRecForColormap( * if successful */ if (j < nVisualsMatched) { - if ((pRec = _XcmsAddCmapRec(dpy, cmap, tmpWindow, vp)) == NULL) - return((XcmsCmapRec *)NULL); + if ((pRec = _XcmsAddCmapRec(dpy, cmap, tmpWindow, vp)) == NULL) { + POST_STACK_GENTZ + return((XcmsCmapRec *)NULL);} pRec->ccc = XcmsCreateCCC( dpy, i, /* screenNumber */ @@ -210,10 +215,12 @@ CmapRecForColormap( (XPointer)NULL /* whitePtAdjClientData */ ); XDestroyWindow(dpy, tmpWindow); + POST_STACK_GENTZ return(pRec); } } + POST_STACK_GENTZ return(NULL); } diff --git a/src/xkb/XKBUse.c b/src/xkb/XKBUse.c index 3194137..783d5c5 100644 --- a/src/xkb/XKBUse.c +++ b/src/xkb/XKBUse.c @@ -209,15 +209,20 @@ _XkbNoteCoreMapChanges(XkbMapChangesPtr old, static Bool wire_to_event(Display *dpy, XEvent *re, xEvent *event) { + PRE_STACK_GENTZ(wire_to_event) xkbEvent *xkbevent = (xkbEvent *) event; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || - (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) + (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) { + POST_STACK_GENTZ return False; + } xkbi = dpy->xkb_info; - if (((event->u.u.type & 0x7f) - xkbi->codes->first_event) != XkbEventCode) + if (((event->u.u.type & 0x7f) - xkbi->codes->first_event) != XkbEventCode) { + POST_STACK_GENTZ return False; + } switch (xkbevent->u.any.xkbType) { case XkbStateNotify: @@ -253,6 +258,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) sev->lookup_mods = sn->lookupMods; sev->compat_lookup_mods = sn->compatLookupMods; sev->ptr_buttons = sn->ptrBtnState; + POST_STACK_GENTZ return True; } } @@ -293,6 +299,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) XkbNoteMapChanges(&xkbi->changes, mev, XKB_XLIB_MAP_MASK); if (xkbi->changes.changed) xkbi->flags |= XkbMapPending; + POST_STACK_GENTZ return True; } else if (mn->nKeySyms > 0) { @@ -309,6 +316,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) _XkbNoteCoreMapChanges(&xkbi->changes, ev, XKB_XLIB_MAP_MASK); if (xkbi->changes.changed) xkbi->flags |= XkbMapPending; + POST_STACK_GENTZ return True; } } @@ -334,6 +342,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) cev->event_type = cn->eventType; cev->req_major = cn->requestMajor; cev->req_minor = cn->requestMinor; + POST_STACK_GENTZ return True; } } @@ -353,6 +362,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) iev->device = in->deviceID; iev->changed = in->changed; iev->state = in->state; + POST_STACK_GENTZ return True; } } @@ -372,6 +382,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) iev->device = in->deviceID; iev->changed = in->changed; iev->state = in->state; + POST_STACK_GENTZ return True; } } @@ -397,6 +408,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) bev->name = bn->name; bev->window = bn->window; bev->event_only = bn->eventOnly; + POST_STACK_GENTZ return True; } } @@ -418,6 +430,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) axev->keycode = axn->keycode; axev->sk_delay = axn->slowKeysDelay; axev->debounce_delay = axn->debounceDelay; + POST_STACK_GENTZ return True; } } @@ -447,6 +460,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) nev->changed_indicators = nn->changedIndicators; nev->first_key = nn->firstKey; nev->num_keys = nn->nKeys; + POST_STACK_GENTZ return True; } } @@ -468,6 +482,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) cmev->first_si = cmn->firstSI; cmev->num_si = cmn->nSI; cmev->num_total_si = cmn->nTotalSI; + POST_STACK_GENTZ return True; } } @@ -492,6 +507,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) amev->mods = am->mods; memcpy(amev->message, am->message, XkbActionMessageLength); amev->message[XkbActionMessageLength] = '\0'; + POST_STACK_GENTZ return True; } } @@ -519,6 +535,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) edev->first_btn = ed->firstBtn; edev->num_btns = ed->nBtns; edev->unsupported = ed->unsupported; + POST_STACK_GENTZ return True; } } @@ -551,6 +568,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) (nkev->device != nkev->old_device))) { xkbi->flags = XkbMapPending | XkbXlibNewKeyboard; } + POST_STACK_GENTZ return True; } else if (nkn->changed & (XkbNKN_KeycodesMask | XkbNKN_DeviceIDMask)) { @@ -569,6 +587,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) (nkn->deviceID != nkn->oldDeviceID))) { xkbi->flags |= XkbMapPending | XkbXlibNewKeyboard; } + POST_STACK_GENTZ return True; } } @@ -580,6 +599,7 @@ wire_to_event(Display *dpy, XEvent *re, xEvent *event) #endif break; } + POST_STACK_GENTZ return False; }