Changeset 4f3aa76 in mainline


Ignore:
Timestamp:
2018-11-09T22:03:24Z (6 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:
ba9a150
Parents:
b389f95
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-08 01:26:04)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-11-09 22:03:24)
Message:

Remove nfmalloc()

Location:
kernel
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/asid_fifo.c

    rb389f95 r4f3aa76  
    6565#if (!FIFO_STATIC)
    6666        fifo_create(free_asids);
     67        if (!free_asids.fifo)
     68                panic("Not enough memory to allocate ASID FIFO");
     69        // TODO: There really is no reason not to statically allocate it
     70        //       except to keep binary size low. Once kernel is a regular ELF
     71        //       binary supporting .bss section (wip as of the late 2018),
     72        //       the dynamic option should be removed.
    6773#endif
    6874
  • kernel/genarch/src/ofw/ofw_tree.c

    rb389f95 r4f3aa76  
    386386static void ofw_tree_node_sysinfo(ofw_tree_node_t *node, const char *path)
    387387{
    388         char *cur_path = (char *) nfmalloc(PATH_MAX_LEN);
     388        char *cur_path = malloc(PATH_MAX_LEN);
     389        if (!cur_path)
     390                panic("Not enough memory to process OFW tree.");
    389391
    390392        for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) {
  • kernel/generic/include/adt/fifo.h

    rb389f95 r4f3aa76  
    115115 */
    116116#define fifo_create(name) \
    117         name.fifo = nfmalloc(sizeof(*name.fifo) * name.items)
     117        name.fifo = malloc(sizeof(*name.fifo) * name.items)
    118118
    119119#endif
  • kernel/generic/include/mm/slab.h

    rb389f95 r4f3aa76  
    146146extern void free(void *);
    147147
    148 extern void *nfmalloc(size_t)
    149     __attribute__((malloc, returns_nonnull));
    150 
    151148#endif
    152149
  • kernel/generic/src/console/kconsole.c

    rb389f95 r4f3aa76  
    219219        const char *hint;
    220220        const char *help;
    221         char *output = nfmalloc(MAX_CMDLINE);
    222221        size_t hints_to_show = MAX_TAB_HINTS - 1;
    223222        size_t total_hints_shown = 0;
    224223        bool continue_showing_hints = true;
     224
     225        char *output = malloc(MAX_CMDLINE);
     226        if (!output) {
     227                // TODO: fix the function so that it does not need allocation
     228                printf("Can't complete command, out of memory.\n");
     229                return 0;
     230        }
    225231
    226232        output[0] = 0;
     
    325331}
    326332
    327 NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev)
     333NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev,
     334    char *tmp)
    328335{
    329336        printf("%s> ", prompt);
     
    332339        wchar_t *current = history[history_pos];
    333340        current[0] = 0;
    334         char *tmp = nfmalloc(STR_BOUNDS(MAX_CMDLINE));
    335341
    336342        while (true) {
     
    534540        }
    535541
    536         free(tmp);
    537542        return current;
    538543}
     
    809814                printf("Type \"exit\" to leave the console.\n");
    810815
    811         char *cmdline = nfmalloc(STR_BOUNDS(MAX_CMDLINE));
     816        char *buffer = malloc(STR_BOUNDS(MAX_CMDLINE));
     817        char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE));
     818        if (!buffer || !cmdline) {
     819                // TODO: fix the function so that it does not need allocations
     820                printf("Can't start console, out of memory.\n");
     821                free(buffer);
     822                free(cmdline);
     823                return;
     824        }
     825
    812826        while (true) {
    813                 wchar_t *tmp = clever_readline((char *) prompt, stdin);
     827                wchar_t *tmp = clever_readline((char *) prompt, stdin, buffer);
    814828                size_t len = wstr_length(tmp);
    815829                if (!len)
     
    827841                (void) cmd_info->func(cmd_info->argv);
    828842        }
     843        free(buffer);
    829844        free(cmdline);
    830845}
  • kernel/generic/src/lib/str.c

    rb389f95 r4f3aa76  
    635635{
    636636        size_t size = str_size(src) + 1;
    637         char *dest = nfmalloc(size);
    638         assert(dest);
     637        char *dest = malloc(size);
     638        if (!dest)
     639                return NULL;
    639640
    640641        str_cpy(dest, size, src);
     
    668669                size = n;
    669670
    670         char *dest = nfmalloc(size + 1);
    671         assert(dest);
     671        char *dest = malloc(size + 1);
     672        if (!dest)
     673                return NULL;
    672674
    673675        str_ncpy(dest, size + 1, src, size);
  • kernel/generic/src/mm/slab.c

    rb389f95 r4f3aa76  
    954954}
    955955
    956 static void *_malloc(size_t size, unsigned int flags)
     956void *malloc(size_t size)
    957957{
    958958        assert(_slab_initialized);
     
    964964        uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
    965965
    966         return slab_alloc(malloc_caches[idx], flags);
    967 }
    968 
    969 void *malloc(size_t size)
    970 {
    971         return _malloc(size, FRAME_ATOMIC);
    972 }
    973 
    974 /** Non-failing malloc.
    975  *  Never returns NULL, but may block forever if no memory is available.
    976  */
    977 void *nfmalloc(size_t size)
    978 {
    979         return _malloc(size, 0);
    980 }
    981 
    982 static void *_realloc(void *ptr, size_t size, unsigned int flags)
     966        return slab_alloc(malloc_caches[idx], FRAME_ATOMIC);
     967}
     968
     969void *realloc(void *ptr, size_t size)
    983970{
    984971        assert(_slab_initialized);
     
    992979                uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
    993980
    994                 new_ptr = slab_alloc(malloc_caches[idx], flags);
     981                new_ptr = slab_alloc(malloc_caches[idx], FRAME_ATOMIC);
    995982        } else
    996983                new_ptr = NULL;
     
    1007994}
    1008995
    1009 void *realloc(void *ptr, size_t size)
    1010 {
    1011         return _realloc(ptr, size, FRAME_ATOMIC);
    1012 }
    1013 
    1014996void free(void *ptr)
    1015997{
  • kernel/generic/src/sysinfo/sysinfo.c

    rb389f95 r4f3aa76  
    685685                return ret;
    686686
    687         char *path = (char *) nfmalloc(size + 1);
    688         assert(path);
     687        // TODO: Change this so that allocation is not needed.
     688        char *path = malloc(size + 1);
     689        if (!path)
     690                return ret;
    689691
    690692        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
     
    794796                return ret;
    795797
    796         char *path = (char *) nfmalloc(size + 1);
    797         assert(path);
     798        // TODO: Change this so that allocation is not needed.
     799        char *path = malloc(size + 1);
     800        if (!path)
     801                return ret;
    798802
    799803        if ((copy_from_uspace(path, ptr, size + 1) == 0) &&
Note: See TracChangeset for help on using the changeset viewer.