container_of() gcc macro

A colleague of mine approached me a few days ago with the following question – “What does container_of() do?”. He linked to the following file in the Linux kernel (we do embedded development at work),

 * container_of - cast a member of a structure out to the containing structure
 * @ptr:    the pointer to the member.
 * @type:   the type of the container struct this is embedded in.
 * @member: the name of the member within the struct.
#define container_of(ptr, type, member) ({          \
    const typeof(((type *)0)->member)*__mptr = (ptr);    \
             (type *)((char *)__mptr - offsetof(type, member)); })

At first glance, I wondered what kind of function was I looking at? It soon became clear that it wasn’t a function at all, but a macro. One of those compiler directives the kernel developers enjoy using.

Continue reading


Flashing a new kernel and ROM on an Xperia Arc

While there are a plenty of tutorials on how to flash a new kernel/ROM onto my phone available on the XDA developers forum, fact of the matter is that I don’t visit very often. The result is that every few months when I feel like ‘upgrading’ my phone, I have to read/search through a mountain of posts to get the information I need. Being the lazy kind of individual, I’ve decided to make my own notes on how to do the upgrade. For anyone reading this, please note: these instructions are for an unlocked Xperia Arc (international release).
Continue reading

disabling the android lock screen & welcome message

I build android systems from source often enough these days.; usually to test some new feature or the other. One of the first things one can do with a new android system is tap the ‘OK’ button on the “Welcome to android” tutorial that comes up. After doing this for the umpteenth time, I had enough! And that silly lock screen too! There had to be a way to statically disable these annoyances in source code, and I was going to find it!

Fortunately, it wasn’t as difficult as I thought it would be.

Continue reading