Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 300f4c4 in mainline


Ignore:
Timestamp:
2017-09-30T18:52:38Z (4 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
6886705
Parents:
91b60499
Message:

Let the resource allocator treat 0 as a valid resource

Location:
kernel/generic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/lib/ra.h

    r91b60499 r300f4c4  
    8080extern ra_arena_t *ra_arena_create(void);
    8181extern bool ra_span_add(ra_arena_t *, uintptr_t, size_t);
    82 extern uintptr_t ra_alloc(ra_arena_t *, size_t, size_t);
     82extern bool ra_alloc(ra_arena_t *, size_t, size_t, uintptr_t *);
    8383extern void ra_free(ra_arena_t *, uintptr_t, size_t);
    8484
  • kernel/generic/src/lib/ra.c

    r91b60499 r300f4c4  
    196196        ra_span_t *span;
    197197
    198         /*
    199          * At the moment, we can only create resources that don't include 0.
    200          * If 0 needs to be considered as a valid resource, we would need to
    201          * slightly change the API of the resource allocator.
    202          */
    203         if (base == 0)
    204                 return false;
    205 
    206198        span = ra_span_create(base, size);
    207199        if (!span)
     
    215207}
    216208
    217 static uintptr_t ra_span_alloc(ra_span_t *span, size_t size, size_t align)
     209static bool
     210ra_span_alloc(ra_span_t *span, size_t size, size_t align, uintptr_t *base)
    218211{
    219212        /*
     
    301294                hash_table_insert(&span->used, &key, &seg->fu_link);
    302295
    303                 return newbase;
    304         }
    305 
    306         return 0;
     296                *base = newbase;
     297                return true;
     298        }
     299
     300        return false;
    307301}
    308302
     
    382376
    383377/** Allocate resources from arena. */
    384 uintptr_t ra_alloc(ra_arena_t *arena, size_t size, size_t alignment)
    385 {
    386         uintptr_t base = 0;
     378bool
     379ra_alloc(ra_arena_t *arena, size_t size, size_t alignment, uintptr_t *base)
     380{
     381        bool success = false;
    387382
    388383        assert(size >= 1);
     
    392387        irq_spinlock_lock(&arena->lock, true);
    393388        list_foreach(arena->spans, span_link, ra_span_t, span) {
    394                 base = ra_span_alloc(span, size, alignment);
    395                 if (base)
     389                success = ra_span_alloc(span, size, alignment, base);
     390                if (success)
    396391                        break;
    397392        }
    398393        irq_spinlock_unlock(&arena->lock, true);
    399394
    400         return base;
     395        return success;
    401396}
    402397
  • kernel/generic/src/mm/km.c

    r91b60499 r300f4c4  
    117117uintptr_t km_page_alloc(size_t size, size_t align)
    118118{
    119         return ra_alloc(km_ni_arena, size, align);
     119        uintptr_t base;
     120        if (ra_alloc(km_ni_arena, size, align, &base))
     121                return base;
     122        else
     123                return (uintptr_t) NULL;
    120124}
    121125
Note: See TracChangeset for help on using the changeset viewer.