Changeset a35b458 in mainline for kernel/generic/src/lib


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
kernel/generic/src/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/lib/elf.c

    r3061bc1 ra35b458  
    8080            (header->e_ident[EI_MAG3] != ELFMAG3))
    8181                return EE_INVALID;
    82        
     82
    8383        /* Identify ELF compatibility */
    8484        if ((header->e_ident[EI_DATA] != ELF_DATA_ENCODING) ||
     
    8888            (header->e_ident[EI_CLASS] != ELF_CLASS))
    8989                return EE_INCOMPATIBLE;
    90        
     90
    9191        if (header->e_phentsize != sizeof(elf_segment_header_t))
    9292                return EE_INCOMPATIBLE;
    93        
     93
    9494        if (header->e_shentsize != sizeof(elf_section_header_t))
    9595                return EE_INCOMPATIBLE;
    96        
     96
    9797        /* Check if the object type is supported. */
    9898        if (header->e_type != ET_EXEC)
    9999                return EE_UNSUPPORTED;
    100        
     100
    101101        /* Check if the ELF image starts on a page boundary */
    102102        if (ALIGN_UP((uintptr_t) header, PAGE_SIZE) != (uintptr_t) header)
    103103                return EE_UNSUPPORTED;
    104        
     104
    105105        /* Walk through all segment headers and process them. */
    106106        elf_half i;
     
    109109                    &((elf_segment_header_t *)(((uint8_t *) header) +
    110110                    header->e_phoff))[i];
    111                
     111
    112112                int rc = segment_header(seghdr, header, as, flags);
    113113                if (rc != EE_OK)
    114114                        return rc;
    115115        }
    116        
     116
    117117        /* Inspect all section headers and process them. */
    118118        for (i = 0; i < header->e_shnum; i++) {
     
    120120                    &((elf_section_header_t *)(((uint8_t *) header) +
    121121                    header->e_shoff))[i];
    122                
     122
    123123                int rc = section_header(sechdr, header, as);
    124124                if (rc != EE_OK)
    125125                        return rc;
    126126        }
    127        
     127
    128128        return EE_OK;
    129129}
     
    139139{
    140140        assert(rc < sizeof(error_codes) / sizeof(char *));
    141        
     141
    142142        return error_codes[rc];
    143143}
     
    199199        backend_data.elf = elf;
    200200        backend_data.segment = entry;
    201        
     201
    202202        if (entry->p_align > 1) {
    203203                if ((entry->p_offset % entry->p_align) !=
     
    205205                        return EE_INVALID;
    206206        }
    207        
     207
    208208        unsigned int flags = 0;
    209        
     209
    210210        if (entry->p_flags & PF_X)
    211211                flags |= AS_AREA_EXEC;
    212        
     212
    213213        if (entry->p_flags & PF_W)
    214214                flags |= AS_AREA_WRITE;
    215        
     215
    216216        if (entry->p_flags & PF_R)
    217217                flags |= AS_AREA_READ;
    218        
     218
    219219        flags |= AS_AREA_CACHEABLE;
    220        
     220
    221221        /*
    222222         * Align vaddr down, inserting a little "gap" at the beginning.
     
    226226        uintptr_t base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE);
    227227        size_t mem_sz = entry->p_memsz + (entry->p_vaddr - base);
    228        
     228
    229229        as_area_t *area = as_area_create(as, flags, mem_sz,
    230230            AS_AREA_ATTR_NONE, &elf_backend, &backend_data, &base, 0);
    231231        if (!area)
    232232                return EE_MEMORY;
    233        
     233
    234234        /*
    235235         * The segment will be mapped on demand by elf_page_fault().
    236236         *
    237237         */
    238        
     238
    239239        return EE_OK;
    240240}
     
    266266                break;
    267267        }
    268        
     268
    269269        return EE_OK;
    270270}
  • kernel/generic/src/lib/gsort.c

    r3061bc1 ra35b458  
    7575{
    7676        size_t i = 0;
    77        
     77
    7878        while (i < cnt) {
    7979                if ((i != 0) &&
     
    109109        uint8_t ibuf_slot[IBUF_SIZE];
    110110        void *slot;
    111        
     111
    112112        if (elem_size > IBUF_SIZE) {
    113113                slot = (void *) malloc(elem_size, 0);
     
    116116        } else
    117117                slot = (void *) ibuf_slot;
    118        
     118
    119119        _gsort(data, cnt, elem_size, cmp, arg, slot);
    120        
     120
    121121        if (elem_size > IBUF_SIZE)
    122122                free(slot);
    123        
     123
    124124        return true;
    125125}
  • kernel/generic/src/lib/halt.c

    r3061bc1 ra35b458  
    5555#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
    5656        bool rundebugger = false;
    57        
     57
    5858        if (!atomic_get(&haltstate)) {
    5959                atomic_set(&haltstate, 1);
     
    6363        atomic_set(&haltstate, 1);
    6464#endif
    65        
     65
    6666        interrupts_disable();
    67        
     67
    6868#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
    6969        if ((rundebugger) && (kconsole_check_poll()))
    7070                kconsole("panic", "\nLast resort kernel console ready.\n", false);
    7171#endif
    72        
     72
    7373        if (CPU)
    7474                log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
    7575        else
    7676                log(LF_OTHER, LVL_NOTE, "cpu: halted");
    77        
     77
    7878        cpu_halt();
    7979}
  • kernel/generic/src/lib/mem.c

    r3061bc1 ra35b458  
    7272        size_t i;
    7373        uint16_t *ptr = (uint16_t *) dst;
    74        
     74
    7575        for (i = 0; i < cnt; i++)
    7676                ptr[i] = val;
     
    9494        if (src == dst)
    9595                return dst;
    96        
     96
    9797        /* Non-overlapping? */
    9898        if ((dst >= src + cnt) || (src >= dst + cnt))
    9999                return memcpy(dst, src, cnt);
    100        
     100
    101101        uint8_t *dp;
    102102        const uint8_t *sp;
    103        
     103
    104104        /* Which direction? */
    105105        if (src > dst) {
     
    107107                dp = dst;
    108108                sp = src;
    109                
     109
    110110                while (cnt-- != 0)
    111111                        *dp++ = *sp++;
     
    114114                dp = dst + (cnt - 1);
    115115                sp = src + (cnt - 1);
    116                
     116
    117117                while (cnt-- != 0)
    118118                        *dp-- = *sp--;
    119119        }
    120        
     120
    121121        return dst;
    122122}
  • kernel/generic/src/lib/memfnc.c

    r3061bc1 ra35b458  
    5757{
    5858        uint8_t *dp = (uint8_t *) dst;
    59        
     59
    6060        while (cnt-- != 0)
    6161                *dp++ = val;
    62        
     62
    6363        return dst;
    6464}
     
    8080        uint8_t *dp = (uint8_t *) dst;
    8181        const uint8_t *sp = (uint8_t *) src;
    82        
     82
    8383        while (cnt-- != 0)
    8484                *dp++ = *sp++;
    85        
     85
    8686        return dst;
    8787}
  • kernel/generic/src/lib/ra.c

    r3061bc1 ra35b458  
    304304                        succ->flags |= RA_SEGMENT_FREE;
    305305                }
    306                
    307        
     306
     307
    308308                /* Put unneeded parts back. */
    309309                if (pred) {
  • kernel/generic/src/lib/rd.c

    r3061bc1 ra35b458  
    5858        uintptr_t base = (uintptr_t) data;
    5959        assert((base % FRAME_SIZE) == 0);
    60        
     60
    6161        rd_parea.pbase = base;
    6262        rd_parea.frames = SIZE2FRAMES(size);
     
    6464        rd_parea.mapped = false;
    6565        ddi_parea_register(&rd_parea);
    66        
     66
    6767        sysinfo_set_item_val("rd", NULL, true);
    6868        sysinfo_set_item_val("rd.size", NULL, size);
    6969        sysinfo_set_item_val("rd.address.physical", NULL, (sysarg_t) base);
    70        
     70
    7171        log(LF_OTHER, LVL_NOTE, "RAM disk at %p (size %zu bytes)", (void *) base,
    7272            size);
  • kernel/generic/src/lib/str.c

    r3061bc1 ra35b458  
    151151        if (*offset + 1 > size)
    152152                return 0;
    153        
     153
    154154        /* First byte read from string */
    155155        uint8_t b0 = (uint8_t) str[(*offset)++];
    156        
     156
    157157        /* Determine code length */
    158        
     158
    159159        unsigned int b0_bits;  /* Data bits in first byte */
    160160        unsigned int cbytes;   /* Number of continuation bytes */
    161        
     161
    162162        if ((b0 & 0x80) == 0) {
    163163                /* 0xxxxxxx (Plain ASCII) */
     
    180180                return U_SPECIAL;
    181181        }
    182        
     182
    183183        if (*offset + cbytes > size)
    184184                return U_SPECIAL;
    185        
     185
    186186        wchar_t ch = b0 & LO_MASK_8(b0_bits);
    187        
     187
    188188        /* Decode continuation bytes */
    189189        while (cbytes > 0) {
    190190                uint8_t b = (uint8_t) str[(*offset)++];
    191                
     191
    192192                /* Must be 10xxxxxx */
    193193                if ((b & 0xc0) != 0x80)
    194194                        return U_SPECIAL;
    195                
     195
    196196                /* Shift data bits to ch */
    197197                ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
    198198                cbytes--;
    199199        }
    200        
     200
    201201        return ch;
    202202}
     
    221221        if (*offset >= size)
    222222                return EOVERFLOW;
    223        
     223
    224224        if (!chr_check(ch))
    225225                return EINVAL;
    226        
     226
    227227        /* Unsigned version of ch (bit operations should only be done
    228228           on unsigned types). */
    229229        uint32_t cc = (uint32_t) ch;
    230        
     230
    231231        /* Determine how many continuation bytes are needed */
    232        
     232
    233233        unsigned int b0_bits;  /* Data bits in first byte */
    234234        unsigned int cbytes;   /* Number of continuation bytes */
    235        
     235
    236236        if ((cc & ~LO_MASK_32(7)) == 0) {
    237237                b0_bits = 7;
     
    250250                return EINVAL;
    251251        }
    252        
     252
    253253        /* Check for available space in buffer */
    254254        if (*offset + cbytes >= size)
    255255                return EOVERFLOW;
    256        
     256
    257257        /* Encode continuation bytes */
    258258        unsigned int i;
     
    261261                cc = cc >> CONT_BITS;
    262262        }
    263        
     263
    264264        /* Encode first byte */
    265265        str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
    266        
     266
    267267        /* Advance offset */
    268268        *offset += cbytes + 1;
    269        
     269
    270270        return EOK;
    271271}
     
    284284{
    285285        size_t size = 0;
    286        
     286
    287287        while (*str++ != 0)
    288288                size++;
    289        
     289
    290290        return size;
    291291}
     
    323323        size_t len = 0;
    324324        size_t offset = 0;
    325        
     325
    326326        while (len < max_len) {
    327327                if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
    328328                        break;
    329                
     329
    330330                len++;
    331331        }
    332        
     332
    333333        return offset;
    334334}
     
    363363        size_t len = 0;
    364364        size_t offset = 0;
    365        
     365
    366366        while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
    367367                len++;
    368        
     368
    369369        return len;
    370370}
     
    380380{
    381381        size_t len = 0;
    382        
     382
    383383        while (*wstr++ != 0)
    384384                len++;
    385        
     385
    386386        return len;
    387387}
     
    399399        size_t len = 0;
    400400        size_t offset = 0;
    401        
     401
    402402        while (str_decode(str, &offset, size) != 0)
    403403                len++;
    404        
     404
    405405        return len;
    406406}
     
    419419        size_t limit = ALIGN_DOWN(size, sizeof(wchar_t));
    420420        size_t offset = 0;
    421        
     421
    422422        while ((offset < limit) && (*str++ != 0)) {
    423423                len++;
    424424                offset += sizeof(wchar_t);
    425425        }
    426        
     426
    427427        return len;
    428428}
     
    437437        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    438438                return true;
    439        
     439
    440440        return false;
    441441}
     
    450450        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    451451                return true;
    452        
     452
    453453        return false;
    454454}
     
    476476        wchar_t c1 = 0;
    477477        wchar_t c2 = 0;
    478        
     478
    479479        size_t off1 = 0;
    480480        size_t off2 = 0;
     
    486486                if (c1 < c2)
    487487                        return -1;
    488                
     488
    489489                if (c1 > c2)
    490490                        return 1;
     
    523523        wchar_t c1 = 0;
    524524        wchar_t c2 = 0;
    525        
     525
    526526        size_t off1 = 0;
    527527        size_t off2 = 0;
    528        
     528
    529529        size_t len = 0;
    530530
     
    569569        assert(size > 0);
    570570        assert(src != NULL);
    571        
     571
    572572        size_t src_off = 0;
    573573        size_t dest_off = 0;
    574        
     574
    575575        wchar_t ch;
    576576        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
     
    578578                        break;
    579579        }
    580        
     580
    581581        dest[dest_off] = '\0';
    582582}
     
    602602        /* There must be space for a null terminator in the buffer. */
    603603        assert(size > 0);
    604        
     604
    605605        size_t src_off = 0;
    606606        size_t dest_off = 0;
    607        
     607
    608608        wchar_t ch;
    609609        while ((ch = str_decode(src, &src_off, n)) != 0) {
     
    611611                        break;
    612612        }
    613        
     613
    614614        dest[dest_off] = '\0';
    615615}
     
    636636        char *dest = malloc(size, 0);
    637637        assert(dest);
    638        
     638
    639639        str_cpy(dest, size, src);
    640640        return dest;
     
    666666        if (size > n)
    667667                size = n;
    668        
     668
    669669        char *dest = malloc(size + 1, 0);
    670670        assert(dest);
    671        
     671
    672672        str_ncpy(dest, size + 1, src, size);
    673673        return dest;
     
    695695        src_idx = 0;
    696696        dest_off = 0;
    697        
     697
    698698        while ((ch = src[src_idx++]) != 0) {
    699699                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
     
    717717        size_t off = 0;
    718718        size_t last = 0;
    719        
     719
    720720        while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
    721721                if (acc == ch)
     
    723723                last = off;
    724724        }
    725        
     725
    726726        return NULL;
    727727}
     
    744744{
    745745        size_t len = wstr_length(str);
    746        
     746
    747747        if ((pos > len) || (pos + 1 > max_pos))
    748748                return false;
    749        
     749
    750750        size_t i;
    751751        for (i = len; i + 1 > pos; i--)
    752752                str[i + 1] = str[i];
    753        
     753
    754754        str[pos] = ch;
    755        
     755
    756756        return true;
    757757}
     
    772772{
    773773        size_t len = wstr_length(str);
    774        
     774
    775775        if (pos >= len)
    776776                return false;
    777        
     777
    778778        size_t i;
    779779        for (i = pos + 1; i <= len; i++)
    780780                str[i - 1] = str[i];
    781        
     781
    782782        return true;
    783783}
     
    800800        assert(neg != NULL);
    801801        assert(result != NULL);
    802        
     802
    803803        *neg = false;
    804804        const char *str = nptr;
    805        
     805
    806806        /* Ignore leading whitespace */
    807807        while (isspace(*str))
    808808                str++;
    809        
     809
    810810        if (*str == '-') {
    811811                *neg = true;
     
    813813        } else if (*str == '+')
    814814                str++;
    815        
     815
    816816        if (base == 0) {
    817817                /* Decode base if not specified */
    818818                base = 10;
    819                
     819
    820820                if (*str == '0') {
    821821                        base = 8;
    822822                        str++;
    823                        
     823
    824824                        switch (*str) {
    825825                        case 'b':
     
    856856                }
    857857        }
    858        
     858
    859859        *result = 0;
    860860        const char *startstr = str;
    861        
     861
    862862        while (*str != 0) {
    863863                unsigned int digit;
    864                
     864
    865865                if ((*str >= 'a') && (*str <= 'z'))
    866866                        digit = *str - 'a' + 10;
     
    871871                else
    872872                        break;
    873                
     873
    874874                if (digit >= base)
    875875                        break;
    876                
     876
    877877                uint64_t prev = *result;
    878878                *result = (*result) * base + digit;
    879                
     879
    880880                if (*result < prev) {
    881881                        /* Overflow */
     
    883883                        return EOVERFLOW;
    884884                }
    885                
     885
    886886                str++;
    887887        }
    888        
     888
    889889        if (str == startstr) {
    890890                /*
     
    894894                str = nptr;
    895895        }
    896        
     896
    897897        *endptr = (char *) str;
    898        
     898
    899899        if (str == nptr)
    900900                return EINVAL;
    901        
     901
    902902        return EOK;
    903903}
     
    919919{
    920920        assert(result != NULL);
    921        
     921
    922922        bool neg;
    923923        char *lendptr;
    924924        errno_t ret = str_uint(nptr, &lendptr, base, &neg, result);
    925        
     925
    926926        if (endptr != NULL)
    927927                *endptr = (char *) lendptr;
    928        
     928
    929929        if (ret != EOK)
    930930                return ret;
    931        
     931
    932932        /* Do not allow negative values */
    933933        if (neg)
    934934                return EINVAL;
    935        
     935
    936936        /* Check whether we are at the end of
    937937           the string in strict mode */
    938938        if ((strict) && (*lendptr != 0))
    939939                return EINVAL;
    940        
     940
    941941        return EOK;
    942942}
Note: See TracChangeset for help on using the changeset viewer.