kernel: port sandbox components

This commit is contained in:
2023-02-03 20:51:23 +00:00
parent 40f83922da
commit 247bb2b530
14 changed files with 16 additions and 85 deletions

View File

@@ -5,7 +5,6 @@
#include <stddef.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
/* One vm_pg_data_t per NUMA node. */
static vm_pg_data_t *node_data = NULL;

View File

@@ -1,6 +1,6 @@
#include <socks/queue.h>
#include <stdlib.h>
#include <assert.h>
#include <socks/compiler.h>
#include <stddef.h>
#include <socks/vm.h>
#define FREELIST_END ((unsigned int)-1)
@@ -103,7 +103,7 @@ static vm_slab_t *alloc_slab(vm_cache_t *cache, vm_flags_t flags)
return slab_hdr;
}
static void destroy_slab(vm_slab_t *slab)
static void __used destroy_slab(vm_slab_t *slab)
{
}
@@ -149,11 +149,9 @@ void *vm_cache_alloc(vm_cache_t *cache, vm_flags_t flags)
if (!queue_empty(&cache->c_slabs_partial)) {
/* prefer using up partially-full slabs before taking a fresh one */
queue_entry_t *slab_entry = queue_pop_front(&cache->c_slabs_partial);
assert(slab_entry);
slab = QUEUE_CONTAINER(vm_slab_t, s_list, slab_entry);
} else if (!queue_empty(&cache->c_slabs_empty)) {
queue_entry_t *slab_entry = queue_pop_front(&cache->c_slabs_empty);
assert(slab_entry);
slab = QUEUE_CONTAINER(vm_slab_t, s_list, slab_entry);
} else {
/* we've run out of slabs. create a new one */

View File

@@ -1,5 +1,5 @@
#include <socks/vm.h>
#include <string.h>
#include <socks/libc/string.h>
#define SIZE_N_CACHE(s) \
{ .c_name = "size-" # s, .c_obj_size = s, .c_page_order = VM_PAGE_16K }

View File

@@ -19,12 +19,10 @@
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
*/
#include "socks/types.h"
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <socks/types.h>
#include <socks/libc/string.h>
#include <socks/memblock.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -252,8 +250,7 @@ static phys_addr_t do_alloc(size_t size)
}
if (allocated_base == ADDR_MAX) {
fprintf(stderr, "memblock: cannot allocate %zu byte buffer!\n", size);
abort();
return 0;
}
int status = memblock_add_range(&memblock.reserved, allocated_base, size, MEMBLOCK_ALLOC);

View File

@@ -1,9 +1,7 @@
#include <socks/types.h>
#include <socks/memblock.h>
#include <socks/vm.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <socks/libc/string.h>
/* array of pages, one for each physical page frame present in RAM */
static vm_page_t *page_array = NULL;
@@ -52,7 +50,6 @@ void tmp_set_vaddr_base(void *p, size_t len)
phys_addr_t vm_virt_to_phys(void *p)
{
phys_addr_t x = (phys_addr_t)p - (phys_addr_t)tmp_vaddr_base;
assert(x < tmp_vaddr_len);
return x;
}
@@ -74,8 +71,6 @@ void vm_page_init_array()
page_array = memblock_alloc(sizeof(vm_page_t) * nr_pages);
page_array_count = nr_pages;
printf("page_array covers 0x%zx bytes, %zu page frames\n", pmem_size, pmem_size / VM_PAGE_SIZE);
printf("page_array is %zu bytes long\n", sizeof(vm_page_t) * nr_pages);
for (size_t i = 0; i < nr_pages; i++) {
memset(&page_array[i], 0x0, sizeof page_array[i]);
@@ -90,8 +85,6 @@ void vm_page_init_array()
nr_reserved++;
}
}
printf("%zu reserved page frames\n", nr_reserved);
}
vm_page_t *vm_page_get(phys_addr_t addr)

View File

@@ -2,11 +2,7 @@
#include <socks/queue.h>
#include <socks/types.h>
#include <socks/vm.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
#include <stdlib.h>
#include <socks/libc/string.h>
static vm_page_t *group_pages_into_block(vm_zone_t *z, phys_addr_t base, phys_addr_t limit, int order)
{
@@ -36,8 +32,6 @@ static void convert_region_to_blocks(vm_zone_t *zone,
int reserved)
{
size_t block_frames = vm_bytes_to_pages(limit - base + 1);
printf("adding region %08zx-%08zx (%zu frames) to zone %s\n",
base, limit, block_frames, zone->z_info.zd_name);
int reset_order = 0;
for (int order = VM_PAGE_MAX_ORDER; order >= VM_PAGE_MIN_ORDER; ) {
@@ -55,12 +49,6 @@ static void convert_region_to_blocks(vm_zone_t *zone,
continue;
}
printf("%s: %zu %s pages at %08" PRIxPTR "\n",
zone->z_info.zd_name,
order_frames,
reserved == 1 ? "reserved" : "free",
base);
phys_addr_t block_limit = base + (order_frames * VM_PAGE_SIZE) - 1;
vm_page_t *block_page = group_pages_into_block(zone, base, block_limit, order);
@@ -76,11 +64,6 @@ static void convert_region_to_blocks(vm_zone_t *zone,
reset_order = 0;
}
if (base > limit + 1) {
printf("too many pages created! %zx > %zx\n", base, limit);
abort();
}
if (base == limit) {
break;
}
@@ -93,8 +76,6 @@ void vm_zone_init(vm_zone_t *z, const vm_zone_descriptor_t *zone_info)
return;
}
printf("initialising zone %s (%08zx-%08zx)\n",
zone_info->zd_name, zone_info->zd_base, zone_info->zd_limit);
memset(z, 0x0, sizeof *z);
memcpy(&z->z_info, zone_info, sizeof *zone_info);
z->z_lock = SPIN_LOCK_INIT;