From 987f70c8e9b1bab87647d4ed20df79900d6c0c9e Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sat, 14 Sep 2013 15:59:51 +0200 Subject: X11 clobberable window added --- samples/X11/clobberme/Makefile | 3 + samples/X11/clobberme/clobberme.c | 171 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 samples/X11/clobberme/Makefile create mode 100644 samples/X11/clobberme/clobberme.c (limited to 'samples/X11') diff --git a/samples/X11/clobberme/Makefile b/samples/X11/clobberme/Makefile new file mode 100644 index 0000000..52dfca8 --- /dev/null +++ b/samples/X11/clobberme/Makefile @@ -0,0 +1,3 @@ +clobberme: clobberme.c Makefile + $(CC) -o clobberme -lX11 clobberme.c + diff --git a/samples/X11/clobberme/clobberme.c b/samples/X11/clobberme/clobberme.c new file mode 100644 index 0000000..ac58dc5 --- /dev/null +++ b/samples/X11/clobberme/clobberme.c @@ -0,0 +1,171 @@ +/*------------------------------------------------------------------------ + * A demonstration of a clobberable X11 window, i.e. a window that will + * assume the contents of whatever was visible above it, without clearing + * or tidying up itself. + * + * (c) 2013 by Wolfgang 'datenwolf' Draxinger + + * License agreement: This source code is provided "as is". You + * can use this source code however you want for your own personal + * use. If you give this source code to anybody else then you must + * leave this message in it. +------------------------------------------------------------------------*/ +#define _GNU_SOURCE + +#include +#include +#include +#include + +#include +#include + +#include +#include + +static void fatalError(const char *why) +{ + fprintf(stderr, "%s", why); + exit(0x666); +} + +static int Xscreen; +static Atom del_atom; +static Colormap cmap; +static Display *Xdisplay; +static Visual *Xvisual; +static Window Xroot, window_handle; +static int width, height; + +static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg) +{ + return d && e && arg && (e->type == MapNotify) && (e->xmap.window == *(Window*)arg); +} + +static void createTheWindow() +{ + XEvent event; + int x,y, attr_mask; + XSizeHints hints; + XWMHints *startup_state; + XTextProperty textprop; + XSetWindowAttributes attr = {0,}; + static char *title = "FTB's little OpenGL example - ARGB extension by WXD"; + + Xdisplay = XOpenDisplay(NULL); + if (!Xdisplay) { + fatalError("Couldn't connect to X server\n"); + } + Xscreen = DefaultScreen(Xdisplay); + Xroot = RootWindow(Xdisplay, Xscreen); + Xvisual = DefaultVisual(Xdisplay, Xscreen); + + /* Create a colormap - only needed on some X clients, eg. IRIX */ + cmap = XCreateColormap(Xdisplay, Xroot, Xvisual, AllocNone); + + attr.colormap = cmap; + attr.background_pixmap = None; + attr.border_pixmap = None; + attr.border_pixel = 0; + attr.event_mask = + StructureNotifyMask | + EnterWindowMask | + LeaveWindowMask | + ExposureMask | + ButtonPressMask | + ButtonReleaseMask | + OwnerGrabButtonMask | + KeyPressMask | + KeyReleaseMask; + + attr_mask = 0 + // | CWBackPixmap + | CWColormap + // | CWBorderPixel + | CWEventMask ; + + width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2; + height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2; + x=width/2, y=height/2; + + window_handle = XCreateWindow( Xdisplay, + Xroot, + x, y, width, height, + 0, + CopyFromParent, + InputOutput, + Xvisual, + attr_mask, &attr); + + if( !window_handle ) { + fatalError("Couldn't create the window\n"); + } + + textprop.value = (unsigned char*)title; + textprop.encoding = XA_STRING; + textprop.format = 8; + textprop.nitems = strlen(title); + + hints.x = x; + hints.y = y; + hints.width = width; + hints.height = height; + hints.flags = USPosition|USSize; + + startup_state = XAllocWMHints(); + startup_state->initial_state = NormalState; + startup_state->flags = StateHint; + + XSetWMProperties(Xdisplay, window_handle,&textprop, &textprop, + NULL, 0, + &hints, + startup_state, + NULL); + + XFree(startup_state); + + XMapWindow(Xdisplay, window_handle); + XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&window_handle); + + if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) { + XSetWMProtocols(Xdisplay, window_handle, &del_atom, 1); + } +} + +static int updateTheMessageQueue() +{ + XEvent event; + XConfigureEvent *xc; + + while (XPending(Xdisplay)) + { + XNextEvent(Xdisplay, &event); + switch (event.type) + { + case ClientMessage: + if (event.xclient.data.l[0] == del_atom) + { + return 0; + } + break; + + case ConfigureNotify: + xc = &(event.xconfigure); + width = xc->width; + height = xc->height; + break; + } + } + return 1; +} + +int main(int argc, char *argv[]) +{ + createTheWindow(); + + while (updateTheMessageQueue()) { + } + + return 0; +} + -- cgit v1.2.3 From 5ff666091056c897f04bf14619df53034801382e Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sat, 14 Sep 2013 16:05:46 +0200 Subject: X11 clobberme window title --- samples/X11/clobberme/clobberme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'samples/X11') diff --git a/samples/X11/clobberme/clobberme.c b/samples/X11/clobberme/clobberme.c index ac58dc5..3eb194a 100644 --- a/samples/X11/clobberme/clobberme.c +++ b/samples/X11/clobberme/clobberme.c @@ -50,7 +50,7 @@ static void createTheWindow() XWMHints *startup_state; XTextProperty textprop; XSetWindowAttributes attr = {0,}; - static char *title = "FTB's little OpenGL example - ARGB extension by WXD"; + static char *title = "A useless clobberable X11 window example by WXD"; Xdisplay = XOpenDisplay(NULL); if (!Xdisplay) { -- cgit v1.2.3 From adc7a12773fa9062ef74ecc33d75de046b533a34 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 15 Sep 2013 02:15:44 +0200 Subject: x11atomstuffer added --- samples/X11/x11atomstuffer/Makefile | 3 ++ samples/X11/x11atomstuffer/x11atomstuffer.c | 73 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 samples/X11/x11atomstuffer/Makefile create mode 100644 samples/X11/x11atomstuffer/x11atomstuffer.c (limited to 'samples/X11') diff --git a/samples/X11/x11atomstuffer/Makefile b/samples/X11/x11atomstuffer/Makefile new file mode 100644 index 0000000..cf1c234 --- /dev/null +++ b/samples/X11/x11atomstuffer/Makefile @@ -0,0 +1,3 @@ +x11atomstuffer: x11atomstuffer.c + $(CC) -o x11atomstuffer x11atomstuffer.c -lX11 + diff --git a/samples/X11/x11atomstuffer/x11atomstuffer.c b/samples/X11/x11atomstuffer/x11atomstuffer.c new file mode 100644 index 0000000..d2f338f --- /dev/null +++ b/samples/X11/x11atomstuffer/x11atomstuffer.c @@ -0,0 +1,73 @@ +/*------------------------------------------------------------------------ + * What happens if you stuff the X11 server with large and large amounts + * of atoms? When does it run out of memory? How is its performance + * impaired by this? This is a little program to experimenting with + * torturing the X11 server by overfeeding it with atoms. + * + * (c) 2013 datenwolf + * + * License agreement: This source code is provided "as is". You + * can use this source code however you want for your own personal + * use. If you give this source code to anybody else then you must + * leave this message in it. +------------------------------------------------------------------------*/ + +#include +#include +#include + +#include +#include + +#include +#include + +static int Xscreen; +static Display *Xdisplay; + +char const doitkey[] = "wastemyX11server"; + +int main(int argc, char *argv[]) +{ + unsigned int i; + + if( argc < 2 || strcmp(argv[1], doitkey) ) { + fprintf(stderr, +"***************** WARNING! *****************\n" +"\n" +"This program wastes serious resources of the\n" +"X11 server it is started on. Do not execute\n" +"this program on a production X11 session as\n" +"the allocated resources can not be reclaimed\n" +"without resetting or quiting the X11 server.\n" +"\n" +"To actually perform this, do the following:\n" +"\n" +"%s %s\n" +"\n" +"***************** WARNING! *****************\n", + argv[0], doitkey); + return 0; + } + + Xdisplay = XOpenDisplay(NULL); + if (!Xdisplay) { + fprintf(stderr, "Couldn't connect to X server\n"); + return -1; + } + Xscreen = DefaultScreen(Xdisplay); + + unsigned int r = getpid() ^ time(NULL); + + for(i=0; i < 0xffffffff; i++) { + char atomstr[33]; + snprintf(atomstr,32, "_wasted_0x%08x_0x%08x", r, i); + XInternAtom(Xdisplay, atomstr, False); + if( !(i % 0x00010000 ) ) { + fprintf(stderr, "%s\n", atomstr); + } + } + + return 0; +} + -- cgit v1.2.3 From edd45b2d961876fe2105a1a27fa53b7c2044ed5b Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 15 Sep 2013 02:57:12 +0200 Subject: type for counter changed to not overflow before loop conditional is reached --- samples/X11/x11atomstuffer/x11atomstuffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'samples/X11') diff --git a/samples/X11/x11atomstuffer/x11atomstuffer.c b/samples/X11/x11atomstuffer/x11atomstuffer.c index d2f338f..70ed425 100644 --- a/samples/X11/x11atomstuffer/x11atomstuffer.c +++ b/samples/X11/x11atomstuffer/x11atomstuffer.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,8 @@ char const doitkey[] = "wastemyX11server"; int main(int argc, char *argv[]) { - unsigned int i; + uint64_t i; + unsigned int r = getpid() ^ time(NULL); if( argc < 2 || strcmp(argv[1], doitkey) ) { fprintf(stderr, @@ -57,11 +59,9 @@ int main(int argc, char *argv[]) } Xscreen = DefaultScreen(Xdisplay); - unsigned int r = getpid() ^ time(NULL); - for(i=0; i < 0xffffffff; i++) { char atomstr[33]; - snprintf(atomstr,32, "_wasted_0x%08x_0x%08x", r, i); + snprintf(atomstr,32, "_wasted_0x%08x_0x%08x", r, (unsigned int)i); XInternAtom(Xdisplay, atomstr, False); if( !(i % 0x00010000 ) ) { fprintf(stderr, "%s\n", atomstr); -- cgit v1.2.3 From 270ca4e2f9f144e3d538a3d89e1141fcf7dfd689 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 15 Sep 2013 02:59:07 +0200 Subject: reworded warning message --- samples/X11/x11atomstuffer/x11atomstuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'samples/X11') diff --git a/samples/X11/x11atomstuffer/x11atomstuffer.c b/samples/X11/x11atomstuffer/x11atomstuffer.c index 70ed425..dfa86de 100644 --- a/samples/X11/x11atomstuffer/x11atomstuffer.c +++ b/samples/X11/x11atomstuffer/x11atomstuffer.c @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) "This program wastes serious resources of the\n" "X11 server it is started on. Do not execute\n" "this program on a production X11 session as\n" -"the allocated resources can not be reclaimed\n" +"the allocated atoms can not be freed/reused\n" "without resetting or quiting the X11 server.\n" "\n" "To actually perform this, do the following:\n" -- cgit v1.2.3