1

On Tanenbaum's operating systems design and implementation, p.154 says the bitmap has a bit for each of the NR_SYS_PROCS(32).

And at the end of minix/kernel/table.c, there is a check to make sure the number of processes in the boot image is not greater than the ipc mask:

/* verify that the first chunk of the ipc mask has enough bits to accommodate the processes
* in the image. */

extern int dummy[(BITCHUNK_BITS > NR_BOOT_PROCS - 1) ? 1 : -1];

I was looking into the size of BITCHUNK_BITS, thinking it would equal 32, but it equals 16, as defined in /minix/kernal/const.h

#define BITCHUNK_BITS (sizeof(bitchunk_t) * CHAR_BIT)

where bitchunk_t is unsigned short and CHART_BIT is 8.

Why make sure the number of processes in the boot images is less than 16 rather than 32 when it is possible to add more user processes to the boot image?

Kevin
  • 97
  • 9

1 Answers1

1

It is just a dirty trick to generate a compile-time error when some constants have the wrong values.

If they have okay values, the boolean expression BITCHUNK_BITS > NR_BOOT_PROCS - 1 will evaluate to 1 and the program will attempt to declare a dummy array with size 1. Everything is ok and the array will never be used.

If they have bad values, the boolean expression BITCHUNK_BITS > NR_BOOT_PROCS - 1 will evaluate to 0 and the program will attempt to declare a dummy array with size -1 on purpose. Which is illegal in C so the program will never compile.

In modern C, you don't use such dirty tricks, but instead

_Static_assert( BITCHUNK_BITS > (NR_BOOT_PROCS - 1), "BITCHUNK_BITS too small" );
Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Hmm, as a 0-entry array is also illegal, I wonder why they did not just use `dummy[BITCHUNK_BITS > NR_BOOT_PROCS - 1]`. – too honest for this site Nov 27 '15 at 12:42
  • @Olaf Probably because some compilers have evil non-standard settings, like for example `gcc -std=gnu90` which allows zero-size arrays. (It does so to enable the old "struct hack" trick. GNU invented this in the 90s as a work-around to make the "struct hack" safe, before flexible array members were introduced in C99) – Lundin Nov 27 '15 at 12:46
  • Hmm, I thought that was just valid for arrays in `struct` (exactly to provide a flex array member). Maybe I'll check if it is true for global arrays, too (where it makes no sense as such an array cannot be extended at run-time). Ok, I checked. This really is a weired thing which also allowed initialiser-defined arrays. – too honest for this site Nov 27 '15 at 12:50
  • Thanks for the modern equivalent of the dummy function. But as a specific question to minix, why would it check to make sure there are less than 16 bits rather than 32? – Kevin Nov 27 '15 at 12:51