Changeset 8c193d83 in mainline


Ignore:
Timestamp:
2019-02-23T17:47:52Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Parents:
ab87db5
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-11 15:28:25)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-23 17:47:52)
Message:

Convert preprocessor macros in abi/ to C constructs

Preprocessor macros are an obsolete concept and they complicate things.
They are also completely unnecessary in most circumstances.

This commit changes untyped numeric constants into anonymous enums,
typed constants into static const variables, and function-like macros
into functions.

Files:
12 edited

Legend:

Unmodified
Added
Removed
  • abi/include/abi/cap.h

    rab87db5 r8c193d83  
    3939#include <stdint.h>
    4040
    41 #define CAP_NIL  0
     41enum {
     42        CAP_NIL = 0,
     43};
    4244
    4345typedef void *cap_handle_t;
  • abi/include/abi/ddi/arg.h

    rab87db5 r8c193d83  
    3838#include <stdint.h>
    3939
    40 #define DMAMEM_FLAGS_ANONYMOUS  0x01
     40enum {
     41        DMAMEM_FLAGS_ANONYMOUS = 0x01,
     42};
    4143
    4244/** Structure encapsulating arguments for SYS_PHYSMEM_MAP syscall. */
  • abi/include/abi/elf.h

    rab87db5 r8c193d83  
    4242 * Current ELF version
    4343 */
    44 #define EV_CURRENT  1
     44enum {
     45        EV_CURRENT = 1,
     46};
    4547
    4648/**
    4749 * ELF types
    4850 */
    49 #define ET_NONE    0       /* No type */
    50 #define ET_REL     1       /* Relocatable file */
    51 #define ET_EXEC    2       /* Executable */
    52 #define ET_DYN     3       /* Shared object */
    53 #define ET_CORE    4       /* Core */
    54 #define ET_LOPROC  0xff00  /* Processor specific */
    55 #define ET_HIPROC  0xffff  /* Processor specific */
     51enum elf_type {
     52        ET_NONE   = 0,       /* No type */
     53        ET_REL    = 1,       /* Relocatable file */
     54        ET_EXEC   = 2,       /* Executable */
     55        ET_DYN    = 3,       /* Shared object */
     56        ET_CORE   = 4,       /* Core */
     57};
     58
     59enum {
     60        ET_LOPROC = 0xff00,  /* Lowest processor specific */
     61        ET_HIPROC = 0xffff,  /* Highest processor specific */
     62};
    5663
    5764/**
    5865 * ELF machine types
    5966 */
    60 #define EM_NO           0    /* No machine */
    61 #define EM_SPARC        2    /* SPARC */
    62 #define EM_386          3    /* i386 */
    63 #define EM_MIPS         8    /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10   /* MIPS RS3000 LE */
    65 #define EM_PPC          20   /* PPC32 */
    66 #define EM_PPC64        21   /* PPC64 */
    67 #define EM_ARM          40   /* ARM */
    68 #define EM_SPARCV9      43   /* SPARC64 */
    69 #define EM_IA_64        50   /* IA-64 */
    70 #define EM_X86_64       62   /* AMD64/EMT64 */
    71 #define EM_RISCV        243  /* RISC-V */
     67enum elf_machine {
     68        EM_NO          = 0,    /* No machine */
     69        EM_SPARC       = 2,    /* SPARC */
     70        EM_386         = 3,    /* i386 */
     71        EM_MIPS        = 8,    /* MIPS RS3000 */
     72        EM_MIPS_RS3_LE = 10,   /* MIPS RS3000 LE */
     73        EM_PPC         = 20,   /* PPC32 */
     74        EM_PPC64       = 21,   /* PPC64 */
     75        EM_ARM         = 40,   /* ARM */
     76        EM_SPARCV9     = 43,   /* SPARC64 */
     77        EM_IA_64       = 50,   /* IA-64 */
     78        EM_X86_64      = 62,   /* AMD64/EMT64 */
     79        EM_RISCV       = 243,  /* RISC-V */
     80};
    7281
    7382/**
    7483 * ELF identification indexes
    7584 */
    76 #define EI_MAG0        0
    77 #define EI_MAG1        1
    78 #define EI_MAG2        2
    79 #define EI_MAG3        3
    80 #define EI_CLASS       4   /* File class */
    81 #define EI_DATA        5   /* Data encoding */
    82 #define EI_VERSION     6   /* File version */
    83 #define EI_OSABI       7
    84 #define EI_ABIVERSION  8
    85 #define EI_PAD         9   /* Start of padding bytes */
    86 #define EI_NIDENT      16  /* ELF identification table size */
     85enum {
     86        EI_MAG0       = 0,
     87        EI_MAG1       = 1,
     88        EI_MAG2       = 2,
     89        EI_MAG3       = 3,
     90        EI_CLASS      = 4,   /* File class */
     91        EI_DATA       = 5,   /* Data encoding */
     92        EI_VERSION    = 6,   /* File version */
     93        EI_OSABI      = 7,
     94        EI_ABIVERSION = 8,
     95        EI_PAD        = 9,   /* Start of padding bytes */
     96        EI_NIDENT     = 16,  /* ELF identification table size */
     97};
    8798
    8899/**
    89100 * ELF magic number
    90101 */
    91 #define ELFMAG0  0x7f
    92 #define ELFMAG1  'E'
    93 #define ELFMAG2  'L'
    94 #define ELFMAG3  'F'
     102enum {
     103        ELFMAG0 = 0x7f,
     104        ELFMAG1 = 'E',
     105        ELFMAG2 = 'L',
     106        ELFMAG3 = 'F',
     107};
    95108
    96109/**
    97110 * ELF file classes
    98111 */
    99 #define ELFCLASSNONE  0
    100 #define ELFCLASS32    1
    101 #define ELFCLASS64    2
     112enum elf_class {
     113        ELFCLASSNONE = 0,
     114        ELFCLASS32   = 1,
     115        ELFCLASS64   = 2,
     116};
    102117
    103118/**
    104119 * ELF data encoding types
    105120 */
    106 #define ELFDATANONE  0
    107 #define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
    108 #define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
     121enum elf_data_encoding {
     122        ELFDATANONE = 0,
     123        ELFDATA2LSB = 1,  /* Least significant byte first (little endian) */
     124        ELFDATA2MSB = 2,  /* Most signigicant byte first (big endian) */
     125};
    109126
    110127/**
    111128 * ELF section types
    112129 */
    113 #define SHT_NULL      0
    114 #define SHT_PROGBITS  1
    115 #define SHT_SYMTAB    2
    116 #define SHT_STRTAB    3
    117 #define SHT_RELA      4
    118 #define SHT_HASH      5
    119 #define SHT_DYNAMIC   6
    120 #define SHT_NOTE      7
    121 #define SHT_NOBITS    8
    122 #define SHT_REL       9
    123 #define SHT_SHLIB     10
    124 #define SHT_DYNSYM    11
    125 #define SHT_LOOS      0x60000000
    126 #define SHT_HIOS      0x6fffffff
    127 #define SHT_LOPROC    0x70000000
    128 #define SHT_HIPROC    0x7fffffff
    129 #define SHT_LOUSER    0x80000000
    130 #define SHT_HIUSER    0xffffffff
     130enum elf_section_type {
     131        SHT_NULL     = 0,
     132        SHT_PROGBITS = 1,
     133        SHT_SYMTAB   = 2,
     134        SHT_STRTAB   = 3,
     135        SHT_RELA     = 4,
     136        SHT_HASH     = 5,
     137        SHT_DYNAMIC  = 6,
     138        SHT_NOTE     = 7,
     139        SHT_NOBITS   = 8,
     140        SHT_REL      = 9,
     141        SHT_SHLIB    = 10,
     142        SHT_DYNSYM   = 11,
     143};
     144
     145enum {
     146        SHT_LOOS     = 0x60000000,
     147        SHT_HIOS     = 0x6fffffff,
     148        SHT_LOPROC   = 0x70000000,
     149        SHT_HIPROC   = 0x7fffffff,
     150        SHT_LOUSER   = 0x80000000,
     151        SHT_HIUSER   = 0xffffffff,
     152};
    131153
    132154/**
    133155 * ELF section flags
    134156 */
    135 #define SHF_WRITE      0x1
    136 #define SHF_ALLOC      0x2
    137 #define SHF_EXECINSTR  0x4
    138 #define SHF_TLS        0x400
    139 #define SHF_MASKPROC   0xf0000000
    140 
    141 /** Macros for decomposing elf_symbol.st_info into binging and type */
    142 #define ELF_ST_BIND(i)     ((i) >> 4)
    143 #define ELF_ST_TYPE(i)     ((i) & 0x0f)
    144 #define ELF_ST_INFO(b, t)  (((b) << 4) + ((t) & 0x0f))
     157enum {
     158        SHF_WRITE     = 0x1,
     159        SHF_ALLOC     = 0x2,
     160        SHF_EXECINSTR = 0x4,
     161        SHF_TLS       = 0x400,
     162        SHF_MASKPROC  = 0xf0000000,
     163};
     164
     165/** Functions for decomposing elf_symbol.st_info into binding and type */
     166static inline uint8_t elf_st_bind(uint8_t info)
     167{
     168        return info >> 4;
     169}
     170
     171static inline uint8_t elf_st_type(uint8_t info)
     172{
     173        return info & 0x0f;
     174}
     175
     176static inline uint8_t elf_st_info(uint8_t bind, uint8_t type)
     177{
     178        return (bind << 4) | (type & 0x0f);
     179}
    145180
    146181/**
    147182 * Symbol binding
    148183 */
    149 #define STB_LOCAL   0
    150 #define STB_GLOBAL  1
    151 #define STB_WEAK    2
    152 #define STB_LOPROC  13
    153 #define STB_HIPROC  15
     184enum elf_symbol_binding {
     185        STB_LOCAL  = 0,
     186        STB_GLOBAL = 1,
     187        STB_WEAK   = 2,
     188};
     189
     190enum {
     191        STB_LOPROC = 13,
     192        STB_HIPROC = 15,
     193};
    154194
    155195/**
    156196 * Symbol types
    157197 */
    158 #define STT_NOTYPE   0
    159 #define STT_OBJECT   1
    160 #define STT_FUNC     2
    161 #define STT_SECTION  3
    162 #define STT_FILE     4
    163 #define STT_TLS      6
    164 #define STT_LOPROC   13
    165 #define STT_HIPROC   15
     198enum elf_symbol_type {
     199        STT_NOTYPE  = 0,
     200        STT_OBJECT  = 1,
     201        STT_FUNC    = 2,
     202        STT_SECTION = 3,
     203        STT_FILE    = 4,
     204        STT_TLS     = 6,
     205};
     206
     207enum {
     208        STT_LOPROC  = 13,
     209        STT_HIPROC  = 15,
     210};
    166211
    167212/**
    168213 * Program segment types
    169214 */
    170 #define PT_NULL          0
    171 #define PT_LOAD          1
    172 #define PT_DYNAMIC       2
    173 #define PT_INTERP        3
    174 #define PT_NOTE          4
    175 #define PT_SHLIB         5
    176 #define PT_PHDR          6
    177 #define PT_TLS           7
    178 #define PT_LOOS          0x60000000
    179 #define PT_GNU_EH_FRAME  0x6474e550
    180 #define PT_GNU_STACK     0x6474e551
    181 #define PT_GNU_RELRO     0x6474e552
    182 #define PT_HIOS          0x6fffffff
    183 #define PT_LOPROC        0x70000000
    184 #define PT_HIPROC        0x7fffffff
     215enum elf_segment_type {
     216        PT_NULL         = 0,
     217        PT_LOAD         = 1,
     218        PT_DYNAMIC      = 2,
     219        PT_INTERP       = 3,
     220        PT_NOTE         = 4,
     221        PT_SHLIB        = 5,
     222        PT_PHDR         = 6,
     223        PT_TLS          = 7,
     224
     225        PT_GNU_EH_FRAME = 0x6474e550,
     226        PT_GNU_STACK    = 0x6474e551,
     227        PT_GNU_RELRO    = 0x6474e552,
     228};
     229
     230enum {
     231        PT_LOOS   = 0x60000000,
     232        PT_HIOS   = 0x6fffffff,
     233        PT_LOPROC = 0x70000000,
     234        PT_HIPROC = 0x7fffffff,
     235};
    185236
    186237/**
    187238 * Program segment attributes.
    188239 */
    189 #define PF_X  1
    190 #define PF_W  2
    191 #define PF_R  4
     240enum elf_segment_access {
     241        PF_X = 1,
     242        PF_W = 2,
     243        PF_R = 4,
     244};
    192245
    193246/**
  • abi/include/abi/ipc/interfaces.h

    rab87db5 r8c193d83  
    4040#include <abi/fourcc.h>
    4141
    42 #define IFACE_EXCHANGE_MASK  0x03
    43 #define IFACE_MOD_MASK       0x04
     42enum {
     43        IFACE_EXCHANGE_MASK = 0x03,
     44        IFACE_MOD_MASK      = 0x04,
     45};
    4446
    4547/** Interface exchange management style
  • abi/include/abi/ipc/ipc.h

    rab87db5 r8c193d83  
    4141#include <_bits/errno.h>
    4242
    43 /** Length of data being transferred with IPC call
    44  *
    45  * The uspace may not be able to utilize the full length
    46  *
    47  */
    48 #define IPC_CALL_LEN  6
     43/* Miscellaneous constants */
     44enum {
     45        /** Length of data being transferred with IPC call
     46         *
     47         * The uspace may not be able to utilize the full length
     48         *
     49         */
     50        IPC_CALL_LEN = 6,
    4951
    50 /** Maximum active async calls per phone */
    51 #define IPC_MAX_ASYNC_CALLS  64
     52        /** Maximum active async calls per phone */
     53        IPC_MAX_ASYNC_CALLS = 64,
     54
     55        /**
     56         * Maximum buffer size allowed for IPC_M_DATA_WRITE and
     57         * IPC_M_DATA_READ requests.
     58         */
     59        DATA_XFER_LIMIT = 64 * 1024,
     60};
    5261
    5362/* Flags for calls */
     63enum {
     64        /** This is answer to a call */
     65        IPC_CALL_ANSWERED       = 1 << 0,
    5466
    55 /** This is answer to a call */
    56 #define IPC_CALL_ANSWERED        (1 << 0)
     67        /** Answer will not be passed to userspace, will be discarded */
     68        IPC_CALL_DISCARD_ANSWER = 1 << 1,
    5769
    58 /** Answer will not be passed to userspace, will be discarded */
    59 #define IPC_CALL_DISCARD_ANSWER  (1 << 1)
     70        /** Call was forwarded */
     71        IPC_CALL_FORWARDED      = 1 << 2,
    6072
    61 /** Call was forwarded */
    62 #define IPC_CALL_FORWARDED       (1 << 2)
     73        /** Interrupt notification */
     74        IPC_CALL_NOTIF          = 1 << 3,
    6375
    64 /** Interrupt notification */
    65 #define IPC_CALL_NOTIF           (1 << 3)
    66 
    67 /** The call was automatically answered by the kernel due to error */
    68 #define IPC_CALL_AUTO_REPLY      (1 << 4)
    69 
    70 /**
    71  * Maximum buffer size allowed for IPC_M_DATA_WRITE and
    72  * IPC_M_DATA_READ requests.
    73  */
    74 #define DATA_XFER_LIMIT  (64 * 1024)
     76        /** The call was automatically answered by the kernel due to error */
     77        IPC_CALL_AUTO_REPLY     = 1 << 4,
     78};
    7579
    7680/* Forwarding flags. */
    77 #define IPC_FF_NONE  0
     81enum {
     82        IPC_FF_NONE = 0,
    7883
    79 /**
    80  * The call will be routed as though it was initially sent via the phone used to
    81  * forward it. This feature is intended to support the situation in which the
    82  * forwarded call needs to be handled by the same connection fibril as any other
    83  * calls that were initially sent by the forwarder to the same destination. This
    84  * flag has no imapct on routing replies.
    85  */
    86 #define IPC_FF_ROUTE_FROM_ME  (1 << 0)
     84        /**
     85         * The call will be routed as though it was initially sent via the phone
     86         * used to forward it. This feature is intended to support the situation
     87         * in which the forwarded call needs to be handled by the same
     88         * connection fibril as any other calls that were initially sent by
     89         * the forwarder to the same destination.
     90         * This flag has no imapct on routing replies.
     91         */
     92        IPC_FF_ROUTE_FROM_ME = 1 << 0,
     93};
    8794
    8895/* Data transfer flags. */
    89 #define IPC_XF_NONE  0
     96enum {
     97        IPC_XF_NONE = 0,
    9098
    91 /** Restrict the transfer size if necessary. */
    92 #define IPC_XF_RESTRICT  (1 << 0)
     99        /** Restrict the transfer size if necessary. */
     100        IPC_XF_RESTRICT = 1 << 0,
     101};
    93102
    94103/** User-defined IPC methods */
    95 #define IPC_FIRST_USER_METHOD  1024
     104enum {
     105        IPC_FIRST_USER_METHOD = 1024,
     106};
    96107
    97108typedef struct {
  • abi/include/abi/ipc/methods.h

    rab87db5 r8c193d83  
    3939
    4040/* Well known phone descriptors */
    41 #define PHONE_NS  ((cap_phone_handle_t) (CAP_NIL + 1))
     41static cap_phone_handle_t const PHONE_NS = (cap_phone_handle_t) (CAP_NIL + 1);
    4242
    4343/** Kernel IPC interfaces
    4444 *
    4545 */
    46 #define IPC_IF_KERNEL  0
     46enum {
     47        IPC_IF_KERNEL = 0,
     48};
    4749
    4850/** System-specific IPC methods
     
    5254 *
    5355 */
    54 
    5556enum {
    5657        /** This message is sent to answerbox when the phone is hung up
     
    217218
    218219/** Last system IPC method */
    219 #define IPC_M_LAST_SYSTEM  511
     220enum {
     221        IPC_M_LAST_SYSTEM = 511,
     222};
    220223
    221224#endif
  • abi/include/abi/kio.h

    rab87db5 r8c193d83  
    3737
    3838enum {
    39         KIO_UNKNOW,
     39        KIO_UNKNOWN,
    4040        KIO_WRITE,
    4141        KIO_UPDATE,
  • abi/include/abi/mm/as.h

    rab87db5 r8c193d83  
    3939
    4040/** Address space area flags. */
    41 #define AS_AREA_READ         0x01
    42 #define AS_AREA_WRITE        0x02
    43 #define AS_AREA_EXEC         0x04
    44 #define AS_AREA_CACHEABLE    0x08
    45 #define AS_AREA_GUARD        0x10
    46 #define AS_AREA_LATE_RESERVE 0x20
     41enum {
     42        AS_AREA_READ         = 0x01,
     43        AS_AREA_WRITE        = 0x02,
     44        AS_AREA_EXEC         = 0x04,
     45        AS_AREA_CACHEABLE    = 0x08,
     46        AS_AREA_GUARD        = 0x10,
     47        AS_AREA_LATE_RESERVE = 0x20,
     48};
    4749
    48 #define AS_AREA_ANY    ((void *) -1)
    49 #define AS_MAP_FAILED  ((void *) -1)
    50 
    51 #define AS_AREA_UNPAGED NULL
     50static void *const AS_AREA_ANY = (void *) -1;
     51static void *const AS_MAP_FAILED = (void *) -1;
     52static void *const AS_AREA_UNPAGED = NULL;
    5253
    5354/** Address space area info exported to uspace. */
  • abi/include/abi/synch.h

    rab87db5 r8c193d83  
    3636#define _ABI_SYNCH_H_
    3737
    38 /** Request with no timeout. */
    39 #define SYNCH_NO_TIMEOUT  0
     38enum {
     39        /** Request with no timeout. */
     40        SYNCH_NO_TIMEOUT = 0,
     41};
    4042
    41 /** No flags specified. */
    42 #define SYNCH_FLAGS_NONE           0
    43 /** Non-blocking operation request. */
    44 #define SYNCH_FLAGS_NON_BLOCKING   (1 << 0)
    45 /** Interruptible operation. */
    46 #define SYNCH_FLAGS_INTERRUPTIBLE  (1 << 1)
    47 /** Futex operation (makes sleep with timeout composable). */
    48 #define SYNCH_FLAGS_FUTEX          (1 << 2)
     43enum {
     44        /** No flags specified. */
     45        SYNCH_FLAGS_NONE          = 0,
     46        /** Non-blocking operation request. */
     47        SYNCH_FLAGS_NON_BLOCKING  = 1 << 0,
     48        /** Interruptible operation. */
     49        SYNCH_FLAGS_INTERRUPTIBLE = 1 << 1,
     50        /** Futex operation (makes sleep with timeout composable). */
     51        SYNCH_FLAGS_FUTEX         = 1 << 2,
     52};
    4953
    5054#endif
  • abi/include/abi/sysinfo.h

    rab87db5 r8c193d83  
    4242#include <stdint.h>
    4343
    44 /** Number of load components */
    45 #define LOAD_STEPS  3
     44enum {
     45        /** Number of load components */
     46        LOAD_STEPS = 3,
    4647
    47 /** Maximum name sizes */
    48 #define TASK_NAME_BUFLEN  64
    49 #define EXC_NAME_BUFLEN   20
     48        /** Maximum name sizes */
     49        TASK_NAME_BUFLEN = 64,
     50        EXC_NAME_BUFLEN  = 20,
     51};
    5052
    5153/** Item value type
  • uspace/app/taskdump/symtab.c

    rab87db5 r8c193d83  
    215215                        continue;
    216216
    217                 stype = ELF_ST_TYPE(st->sym[i].st_info);
     217                stype = elf_st_type(st->sym[i].st_info);
    218218                if (stype != STT_OBJECT && stype != STT_FUNC)
    219219                        continue;
     
    257257                        continue;
    258258
    259                 stype = ELF_ST_TYPE(st->sym[i].st_info);
     259                stype = elf_st_type(st->sym[i].st_info);
    260260                if (stype != STT_OBJECT && stype != STT_FUNC &&
    261261                    stype != STT_NOTYPE) {
  • uspace/lib/c/generic/rtld/symbol.c

    rab87db5 r8c193d83  
    262262void *symbol_get_addr(elf_symbol_t *sym, module_t *m, tcb_t *tcb)
    263263{
    264         if (ELF_ST_TYPE(sym->st_info) == STT_TLS) {
     264        if (elf_st_type(sym->st_info) == STT_TLS) {
    265265                if (tcb == NULL)
    266266                        return NULL;
Note: See TracChangeset for help on using the changeset viewer.