Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / minix / endpoint.h @ 14

History | View | Annotate | Download (3.04 KB)

1

    
2
#ifndef _MINIX_ENDPOINT_H
3
#define _MINIX_ENDPOINT_H 1
4

    
5
#include <minix/sys_config.h>
6
#include <minix/com.h>
7
#include <limits.h>
8
#include <minix/type.h>
9

    
10
/*
11
 * Endpoints are split into two parts: a process slot and a generation number.
12
 *
13
 * The process slot number identifies the slot in various process tables.
14
 * It is positive or zero for user processes, and negative for kernel tasks.
15
 * Constants dictate that with the current endpoint layout, the maximum range
16
 * of process slot numbers is [-MAX_NR_TASKS,MAX_NR_PROCS>.  The used part of
17
 * the range is currently [-NR_TASKS,NR_PROCS> -- these two constants may be
18
 * changed within the maximum range without changing the endpoint layout.
19
 *
20
 * The generation number is a per-slot number that gets increased by one every
21
 * time a slot is reused for a new process.  The generation number minimizes
22
 * the chance that the endpoint of a dead process can (accidentially) be used
23
 * to communicate with a different, live process.  Preventing such accidents
24
 * is essential for proper system service restartability support.
25
 *
26
 * The split between the two parts of the endpoint is such that when the
27
 * generation number is zero, the endpoint number equals the process slot
28
 * number, even for negative task numbers.  This is required for the endpoint
29
 * numbers hardcoded in <minix/com.h>, and it makes endpoint numbers easy to
30
 * read in general.
31
 *
32
 * There are three special endpoint numbers: ANY, NONE, and SELF.  These
33
 * numbers are used to identify "any process", "no process at all", and
34
 * "own process", respectively.  They fall outside the normal range of
35
 * process slot numbers, and are always of generation zero.
36
 */
37

    
38
/*
39
 * The following constant defines the split between the two parts of the
40
 * endpoint numbers.  It can be adjusted to allow for either more processes
41
 * or more per-process generation numbers.  Changing it will change the
42
 * endpoint number layout, and thus break binary compatibility with existing
43
 * processes.
44
 */
45
#define _ENDPOINT_GENERATION_SHIFT        15
46

    
47
/* Derived constants. */
48
#define _ENDPOINT_GENERATION_SIZE        (1 << _ENDPOINT_GENERATION_SHIFT)
49
/* INT_MAX is used here to prevent signedness issues with the macros below. */
50
#define _ENDPOINT_MAX_GENERATION        (INT_MAX/_ENDPOINT_GENERATION_SIZE-1)
51
#define _ENDPOINT_SLOT_TOP        (_ENDPOINT_GENERATION_SIZE-MAX_NR_TASKS)
52

    
53
/* The special endpoint numbers, and the resulting maximum slot number. */
54
#define ANY                ((endpoint_t) (_ENDPOINT_SLOT_TOP - 1))
55
#define NONE                ((endpoint_t) (_ENDPOINT_SLOT_TOP - 2))
56
#define SELF                ((endpoint_t) (_ENDPOINT_SLOT_TOP - 3))
57
#define MAX_NR_PROCS                      (_ENDPOINT_SLOT_TOP - 3)        /* (int)SELF */
58

    
59
/* Sanity check. */
60
#if NR_PROCS > MAX_NR_PROCS
61
#error "NR_PROCS exceeds MAX_NR_PROCS, increase _ENDPOINT_GENERATION_SHIFT"
62
#endif
63

    
64
/* Generation + Process slot number <-> endpoint. */
65
#define _ENDPOINT(g, p) \
66
        ((endpoint_t)(((g) << _ENDPOINT_GENERATION_SHIFT) + (p)))
67
#define _ENDPOINT_G(e) (((e)+MAX_NR_TASKS) >> _ENDPOINT_GENERATION_SHIFT)
68
#define _ENDPOINT_P(e) \
69
        ((((e)+MAX_NR_TASKS) & (_ENDPOINT_GENERATION_SIZE - 1)) - MAX_NR_TASKS)
70

    
71
#endif