Operating Systems - Day 2

May 30, 2018 • Gaurav Dhingra

Patch policy:

  • Patch should have a Subject: [PATCH] Docs: Add info on supported kernels to REPORTING-BUGS.. Here clearly Docs indicate that it that the patch makes changes to the documentation section.

  • Why’s are more important than What in body of patch (aka commit message?).

  • It seems like a lot of drivers subfolder have a separate file “TODO” listing the work that needs to be done. For example, currently there is a file drivers/dma/TODO which lists a few tasks that needs to be done, here is the list of task mentioned in that file:

    • Move remaining drivers to use new slave interface
    • Remove old slave pointer machansim
    • Check other subsystems for dma drivers and merge/move to dmaengine
    • Remove dma_slave_config’s dma direction.

Include guard

Include guard is one of the topics I went through since seeing header file, it seems to be appearing at the top. Since I am also using CodeBlocks for coding in C these days, Codeblocks provides with automatic inclusion of include guard(aka macro guard) when we start a new header file.

In a C/C++ program if a function/struct/… is defined more than once, then it raises an error (one definition rule). To avoid this problem include guards are used.

#ifndef FILE_NAME_H
#define FILE_NAME_H

/* code goes here */

#endif /* end of include guard

for complete understandstanding, see this example. Though I still need to figure out why on this line drivers/staging/board/board.h#line2 we have use of __ around the file name.

static keyword in C

This stackoverflow answer suffices, actually static is used quite a lot in kernel code, which made me to have a look at its meaning.

difference between header and source file in C (also in C++)

This https://stackoverflow.com/questions/3482948/any-fundamental-difference-between-source-and-header-files-in-c

typedef in C

typedef is a reserved keyword in C. It creates an alias name for another datatype. Example (from wikipedia):

typedef int length;

Let’s see an example from linux kernel source code:

typedef unsigned char  uch;
typedef unsigned short  ush;
typedef unsigned long  ulg;

From this, it is very clear what purpose does typedef does have. But, I beilieve I saw someuse of typedef related to struct in linux kernel code but I don’t remember where, but will write about it when I come across it.

USEFUL INFO: I found this website which hosts the kernel source online https://elixir.bootlin.com/linux/latest/source, I found it to be pretty handy to use. It’s better than github’s online source code viewer I’d say.

code analysing section

Let’s see this codeblock taken from []

struct ashmem_area {
    char name[ASHMEM_FULL_NAME_LEN];
    struct list_head_unpinned_list;
    struct file *file;
    size_t size;
    unsigned long prot_mask;

Hexadecimal representation of address

Often used is the hexadecimal representation for address (saw that in lecture by Prof. Jakob Eriksson). For ex, convert 10,995 into hexadecimal value would be 2AF3. The prefix 0x is used in C (and probably also in assembly) to denote this in hexadecimal system, which would denote this value by 0x2AF3.