Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is MISRA-C applicable to Linux applications

I understand that MISRA-C standards are intended for embedded firmware. When embedded Linux is your product platform, can/should your embedded applications be developed to be MISRA-C compliant? Has anyone ever considered such an exercise?

My general sense is that you must first understand all the 'rules' and then apply them in your design/coding phase. There may be instances like system calls (pthread_create) and void* that need to be forced into compliance - producing ugly looking code.

like image 937
Andrew W. Avatar asked Apr 29 '15 18:04

Andrew W.


People also ask

Is MISRA C still used?

MISRA C guidelines, which originally targeted only the automotive industry, are now widely accepted and used in other industries such as aerospace and defense, industrial automation, and medical devices. Most engineering organizations originally applied MISRA C and C++ standards to their hand-written C and C++ code.

What is the use of MISRA C?

MISRA C is a set of software development guidelines for the C programming language developed by The MISRA Consortium. Its aims are to facilitate code safety, security, portability and reliability in the context of embedded systems, specifically those systems programmed in ISO C / C90 / C99.

What is the latest version of MISRA C?

The current version, MISRA C: 2012 (sometimes written as MISRA C 2012 or MISRA C2012), has evolved over several years, and Amendment 2 to MISRA C: 2012 was published in 2020. Amendment 3 is projected to be released in 2022. For the C++ programming language, the current MISRA standard is MISRA C++ 2008.

What is the latest MISRA standard?

Today MISRA C is the de facto standard for developing software in C where safety, security and code quality are important. Future developments of MISRA C will continue to extend support for newer versions of the language, and additional language features.


2 Answers

While MISRA-C was originally created as a standard just for automotive and safety-critical applications, this is no longer true. Nowadays MISRA-C is more of a general standard that can be used for any C programs where bugs, crashes and portability issues are not desired.

You need to ask yourself why you are using MISRA-C. Is it because you wish to use it as a coding standard to get rid of bugs, or because the application is of a mission-critical nature?

For the Linux case, the main issue will be if you'll just have your own code MISRA compliant, or if you will demand that this is true for all libraries included as well. And there is just no way you'll make the Linux kernel + libraries MISRA compliant, you'd have to rewrite Linux from scratch.

This makes Linux unsuitable for mission-critical software. But if your program is not of a mission-critical nature, you should be able to use Linux. You might have to write a number of standing deviations from MISRA-C in advance, for things that you can tell will cause problems.

like image 152
Lundin Avatar answered Oct 18 '22 09:10

Lundin


In a word: No.

MISRA does provide some good guidelines, but you'd be better off just cherry picking rules to which you want to adhere (assuming you have automated checking in your build / static analysis).

Skimming through MISRA-2004 stuff, here are some problem areas.

Having all your libraries be MISRA compliant is, in itself, MISRA rule.

Rules on goto, continue and break, function returns, and pointer arithmetic are violated in literally billions of lines of both kernel and userspace code, so good luck getting your libraries (or kernel) under compliance.

Pointer casting rules will be impossible to follow if using sockets, among other common APIs.

MISRA-2004 11.2 Conversions shall not be performed between a pointer to object and any type other than an integral type, another pointer to object type or a pointer to void.

2004-20.x sections ban <errno.h>, <stdio.h>, <time.h> and <signal.h>. Banning signals and error checking promotes BAD Linux programming if you're writing long-running, robust services.

And no dynamic memory allocation is a rule in there somewhere.

I know MISRA has rules that allow you to violate rules if you document them (is this true for required or just advisory???), but you'll document soooo many exceptions that it's really sort of pointless.

All that said, if you have a customer insisting on MISRA compliance (which is the only reason I've ever seen it used), you could probably document all your rule violations and make some hand-wavy attempt to call yourself MISRA compliant. So there might be a business case for pretending to be MISRA compliant on Linux, but I see little to no technical advantage in it.

I'm afraid if you want to be truly compliant AND need a heavyweight/full-featured OS you're better off forking out the dough for QNX, GHS Integrity, VxWorks, etc.

like image 4
Brian McFarland Avatar answered Oct 18 '22 07:10

Brian McFarland