libfoundation: Synchronise MLC changes to 'develop' branch.

The libfoundation changes from the MLC branch are needed for ongoing LC8 development, but unfortunately they were too tangled in with other changes to be able to be extracted.

This commit imports all of the changes in a single "squashed" commit in order to get things synchronised.  Ongoing libfoundation development should take place on this branch.