Browsed by
Category: Programming

Module to cause linux kernel panic

Module to cause linux kernel panic

In doing some robustness testing, I needed to crash my Linux VM intentionally to see if the rest of the system survived. I was thinking of writing a kernel module that just did something silly like dereference null or divide by zero, but turns out you can do it much easier than that. Just call panic.

#define __NO_VERSION__
#include <linux/version.h>

int init_module(void)
    panic(" insert lame excuse here");
    return 0;

Build with gcc -I/usr/src/linux/include -D__KERNEL__ -DMODULE -o panic.o -c panic.c
Here's a good link about building kernel modules without full kernel source.

When you run: insmod panic.o 
Bang - your system will kernel panic and crash.
Credit to Paul's Journal
“Hello World” OpenGL on Linux

“Hello World” OpenGL on Linux

Writing the OpenGL context creation plumbing on Linux isn’t 100% intuitive. It’s always good to have a handy getting started guide. With developers increasingly using engines such as Unity, the number of people writing directly to OpenGL is shrinking – and so are some of the online resources to get over this initial step. I decided to collect a few links and copy critical sample code here for when I need to whip something up quickly.


Some links to good ‘hello world’ Linux GL samples:


Taken from:

Below is a minimal example of creating an RGBA-format X window that’s compatible with OpenGL using GLX 1.3 commands. The window is cleared to yellow when the program runs. The program does minimal error checking; all return values should be checked.

#include < stdio.h >
#include < stdlib.h >
#include < GL/gl.h >
#include < GL/glx.h >

int singleBufferAttributess[] = {
    GLX_RED_SIZE,      1,   /* Request a single buffered color buffer */
    GLX_GREEN_SIZE,    1,   /* with the maximum number of color bits  */
    GLX_BLUE_SIZE,     1,   /* for each component                     */

int doubleBufferAttributes[] = {
    GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
    GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
    GLX_GREEN_SIZE,    1, 
    GLX_BLUE_SIZE,     1,

static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
    return (event->type == MapNotify) && (event->xmap.window == (Window) arg);
int main( int argc, char *argv[] )
    Display              *dpy;
    Window                xWin;
    XEvent                event;
    XVisualInfo          *vInfo;
    XSetWindowAttributes  swa;
    GLXFBConfig          *fbConfigs;
    GLXContext            context;
    GLXWindow             glxWin;
    int                   swaMask;
    int                   numReturned;
    int                   swapFlag = True;

    /* Open a connection to the X server */
    dpy = XOpenDisplay( NULL );
    if ( dpy == NULL ) {
        printf( "Unable to open a connection to the X servern" );
        exit( EXIT_FAILURE );

    /* Request a suitable framebuffer configuration - try for a double 
    ** buffered configuration first */
    fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                   doubleBufferAttributes, &numReturned );

    if ( fbConfigs == NULL ) {  /* no double buffered configs available */
      fbConfigs = glXChooseFBConfig( dpy, DefaultScreen(dpy),
                                     singleBufferAttributess, &numReturned );
      swapFlag = False;

    /* Create an X colormap and window with a visual matching the first
    ** returned framebuffer config */
    vInfo = glXGetVisualFromFBConfig( dpy, fbConfigs[0] );

    swa.border_pixel = 0;
    swa.event_mask = StructureNotifyMask;
    swa.colormap = XCreateColormap( dpy, RootWindow(dpy, vInfo->screen),
                                    vInfo->visual, AllocNone );

    swaMask = CWBorderPixel | CWColormap | CWEventMask;

    xWin = XCreateWindow( dpy, RootWindow(dpy, vInfo->screen), 0, 0, 256, 256,
                          0, vInfo->depth, InputOutput, vInfo->visual,
                          swaMask, &swa );

    /* Create a GLX context for OpenGL rendering */
    context = glXCreateNewContext( dpy, fbConfigs[0], GLX_RGBA_TYPE,
				 NULL, True );

    /* Create a GLX window to associate the frame buffer configuration
    ** with the created X window */
    glxWin = glXCreateWindow( dpy, fbConfigs[0], xWin, NULL );
    /* Map the window to the screen, and wait for it to appear */
    XMapWindow( dpy, xWin );
    XIfEvent( dpy, &event, WaitForNotify, (XPointer) xWin );

    /* Bind the GLX context to the Window */
    glXMakeContextCurrent( dpy, glxWin, glxWin, context );

    /* OpenGL rendering ... */
    glClearColor( 1.0, 1.0, 0.0, 1.0 );
    glClear( GL_COLOR_BUFFER_BIT );

    if ( swapFlag )
        glXSwapBuffers( dpy, glxWin );

    sleep( 10 );
    exit( EXIT_SUCCESS );


The value of ESP was not properly saved across a function call…

The value of ESP was not properly saved across a function call…

Windows can trigger this error, but sometimes it’s not easy to figure out what’s going on.

I recently got this error when trying to use the OpenGL ES ANGLE library on Windows 10. When compiling against the ANGLE library, the error came when trying to call into the ANGLE and used eglGetProcAddress().

eglGetProcAddress() returns function pointers for important GL extensions, so I couldn’t just ignore it or work around it.

In looking around, the obvious first step is to make sure you’re defining the function pointers correctly, but that turns out not to be my problem.

In looking at this article, I realized I probably had a mismatch of compiler and linker settings. The Visual Studio projects (VS2008) that came with ANGLE required a certain set of compiler and linker flags that were not standard. I had migrated the Visual Studio projects to VS2015, so that also added an element of uncertainty. I simply opened both project settings up next to each other and compared the settings for the ANGLE library build and the final project and found a few mismatches. I change a number of them to be the same, and things worked great.

Check the linking AND compiling flags for not only your project, but the project files that generate the libraries you’re linking against. Differences in compiler settings can cause this error.

Practice your coding skills

Practice your coding skills

For those of us that work in the industry, one of the difficult parts about working in high tech is constantly keeping on top of all the new developments and technology.

One of the things I’ve noticed after you get a lot of years of work under your belt is that you naturally start specializing into certain areas. These specializations are good in themselves, but often they utilize only slivers of the original breadth of computer science, algorithms, and data structures. If one is not careful, you can lose that breadth that is essential to your adaptability.

LeetCode is a great website with literally hundreds of coding problems that can help you brush up on your algorithms, data structures, and coding skills.  Give it a whirl!

‘Audibilization’ of sorting algorithms

‘Audibilization’ of sorting algorithms

Visualization and “audibilization” of 15 Sorting Algorithms in 6 Minutes.
Sorts random shuffles of integers, with both speed and the number of items adapted to each algorithm’s complexity.
The algorithms are: selection sort, insertion sort, quick sort, merge sort, heap sort, radix sort (LSD), radix sort (MSD), std::sort (intro sort), std::stable_sort (adaptive merge sort), shell sort, bubble sort, cocktail shaker sort, gnome sort, bitonic sort and bogo sort (30 seconds of it).

Google more information via the “Sound of Sorting”.

CMake with compilers that need custom parameters

CMake with compilers that need custom parameters

When using CMake on non-GCC/non-Microsoft compilers – you often run into interesting problems. Especially true for embedded devices/cross-compilers.

One thing that can bite you is the fact that CMake requires the compiler to pass a ‘smoke’ test. Unfortunately, if there are required parameters for your compiler, the smoke test part will fail.

There are a few ways to solve this, the ‘recommended’ way seems to be via the CMAKE_FORCE_C_COMPILER/CMAKE_FORCE_CXX_COMPILER flags. This allows you to tell CMake what the compiler is and pass the smoke test.

CMAKE_FORCE_C_COMPILER(/usr/mycc/cxint86 GNU)
CMAKE_FORCE_CXX_COMPILER(/usr/mycc/cxxint86 GNU)

Here are the docs for more information

Siggraph 2015 paper – Dynamic Skin Microgeometry

Siggraph 2015 paper – Dynamic Skin Microgeometry

Generating photo-realistic faces has long been a holy grail for rendering. It’s the combination of a number of difficult problems – eyes, skin, hair, etc. These guys demonstrate a simple, innovative new technique for mimicking the complex skin structures that occur when a character makes different faces. They simulate these ‘micro-structures’ by using anisotrophic bluring/sharpening of facial textures. Good for both realtime and off-line techniques.

Machine Learning and you

Machine Learning and you

Recently I took the Coursera Machine Learning course from Stanford and got to implement a lot of these kinds of algorithms (HIGHLY recommend the course).  This guy took it a step or two further and added some clever visualizations and additional training tricks.  Very good work – especially considering it was done by a seaming amateur implementer.

It’s fascinating how we can now write small neural nets like this and very quickly train our computers to do work not only as good as us, but in growing numbers of cases, better than the BEST humans in the world could do.  The implications are staggering…and somewhat disconcerting.  What happens when we have enough compute and enough data that our racks of machine learning systems can do all the analysis and optimization of every facet of our society?  What does that leave us to do, and how does our economic system work when many of these thinking jobs go away?

While this has been argued all the way back to the industrial revolution, there is some growing work by more respected people that we are turning a tipping point (  Or more interestingly, do we go through another era much like the industrial revolution in which broad swaths of the population become cogs in a bigger machine until we re-adjust.  Much food for thought and social rumination…