<commit_before>#include <aos/aos.h>
#include <spawn/spawn.h>

#include <elf/elf.h>
#include <aos/dispatcher_arch.h>
#include <barrelfish_kpi/paging_arm_v7.h>
#include <barrelfish_kpi/domain_params.h>
#include <spawn/multiboot.h>

#define DPRINT(fmt, args...)  debug_printf("spawn: " fmt "\n", args)

#define CHECK(where, err)  if (err_is_fail(err)) {  \
                               DPRINT("ERROR %s: %s", where, err_getstring(err));  \
                               return err;  \
                           }

extern struct bootinfo *bi;

void setup_cspace(struct spawninfo *si) {
    CHECK("cnode_create_l1", cnode_create_l1(&(si->l1_cap), &(si->l1_cnoderef)));

    // Create TASKCN
    CHECK("taskcn", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_TASKCN, &(si->taskcn)));

    // Create SLOT PAGECN
    CHECK("pagecn", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_PAGECN, &(si->pagecn)))

    // Create SLOT BASE PAGE CN
    CHECK("base_pagecn", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_BASE_PAGE_CN, &(si->base_pagecn)));

    // Create SLOT ALLOC 0
    CHECL("alloc0", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC0, &(si->alloc0)));

    // Create SLOT ALLOC 1
    CHECK("alloc1", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC1, &(si->alloc1)));

    // Create SLOT ALLOC 2
    CHECK("alloc2", cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC2, &(si->alloc2)));

    // Create SLOT DISPATCHER
    si->dispatcher.cnode = si->taskcn;
    si->dispatcher.slot = TASKCN_SLOT_DISPATCHER;

    // Create SLOT ROOTCN
    si->rootcn.cnode = si->taskcn;
    si->rootcn.slot = TASKCN_SLOT_ROOTCN;

    // Create SLOT DISPFRAME
    si->dispframe.cnode = si->taskcn;
    si->dispframe.slot = TASKCN_SLOT_DISPFRAME;

    // Create SLOT ARGSPG
    si->argspg.cnode = si->taskcn;
    si->argspg.slot = TASKCN_SLOT_ARGSPAGE;

    cap_retype(si->selfep, si->dispatcher, 0, ObjType_EndPoint, 0, 1);

}

void setup_vspace(struct spawninfo *si) {
    si->l1_pagetable.cnode = si->pagecn;
    si->l1_pagetable.slot = 0;

//     //CHECK("", cap_copy(si->l1_pagetable, cnode_page));
     vnode_create(, ObjType_VNode_ARM_l1);
}

// TODO(M2): Implement this function such that it starts a new process
// TODO(M4): Build and pass a messaging channel to your child process
errval_t spawn_load_by_name(void * binary_name, struct spawninfo * si) {

    DPRINT("loading and starting: %s", binary_name);

    // Init spawninfo
    memset(si, 0, sizeof(*si));
    si->binary_name = binary_name;

    // - Get the binary from multiboot image<commit_msg>Revert "[Milestone 2] Tidy up code in spawn.c#setup_cspace"<commit_after>#include <aos/aos.h>
#include <spawn/spawn.h>

#include <elf/elf.h>
#include <aos/dispatcher_arch.h>
#include <barrelfish_kpi/paging_arm_v7.h>
#include <barrelfish_kpi/domain_params.h>
#include <spawn/multiboot.h>

#define DPRINT(fmt, args...)  debug_printf("spawn: " fmt "\n", args)

#define CHECK(where, err)  if (err_is_fail(err)) {  \
                               DPRINT("ERROR %s: %s", where, err_getstring(err));  \
                               return err;  \
                           }

extern struct bootinfo *bi;

void setup_cspace(struct spawninfo *si) {
    errval_t err;
    err = cnode_create_l1(&(si->l1_cap), &(si->l1_cnoderef));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create TASKCN
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_TASKCN, &(si->taskcn));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT PAGECN
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_PAGECN, &(si->pagecn));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT BASE PAGE CN
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_BASE_PAGE_CN, &(si->base_pagecn));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT ALLOC 0
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC0, &(si->alloc0));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT ALLOC 1
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC1, &(si->alloc1));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT ALLOC 2
    err = cnode_create_foreign_l2(si->l1_cap, ROOTCN_SLOT_SLOT_ALLOC2, &(si->alloc2));
    if(err_is_fail(err)) {
        printf("%s\n", err_getstring(err));
    }

    // Create SLOT DISPATCHER
    si->dispatcher.cnode = si->taskcn;
    si->dispatcher.slot = TASKCN_SLOT_DISPATCHER;

    // err = cap_copy(si->dispatcher, cap_dispatcher);
    // if(err_is_fail(err)) {
    //     printf("%s\n", err_getstring(err));
    // }

    // Create SLOT ROOTCN
    si->rootcn.cnode = si->taskcn;
    si->rootcn.slot = TASKCN_SLOT_ROOTCN;

    // err = cap_copy(si->rootcn, cap_root);
    // if(err_is_fail(err)) {
    //     printf("%s\n", err_getstring(err));
    // }

    // Create SLOT DISPFRAME
    si->dispframe.cnode = si->taskcn;
    si->dispframe.slot = TASKCN_SLOT_DISPFRAME;

    // err = cap_copy(si->dispframe, cap_dispframe);
    // if(err_is_fail(err)) {
    //     printf("%s\n", err_getstring(err));
    // }

    // Create SLOT ARGSPG
    si->argspg.cnode = si->taskcn;
    si->argspg.slot = TASKCN_SLOT_ARGSPAGE;

    // err = cap_copy(si->argspg, cap_argcn);
    // if(err_is_fail(err)) {
    //     printf("%s\n", err_getstring(err));
    // }

    cap_retype(si->selfep, si->dispatcher, 0, ObjType_EndPoint, 0, 1);

}

void setup_vspace(struct spawninfo *si) {
    si->l1_pagetable.cnode = si->pagecn;
    si->l1_pagetable.slot = 0;

//     //CHECK("", cap_copy(si->l1_pagetable, cnode_page));
     vnode_create(, ObjType_VNode_ARM_l1);
}

// TODO(M2): Implement this function such that it starts a new process
// TODO(M4): Build and pass a messaging channel to your child process
errval_t spawn_load_by_name(void * binary_name, struct spawninfo * si) {

    DPRINT("loading and starting: %s", binary_name);

    // Init spawninfo
    memset(si, 0, sizeof(*si));
    si->binary_name = binary_name;

    // - Get the binary from multiboot image
{'fraction_non_alphanumeric': 0.1517684887459807, 'fraction_numerical': 0.012379421221864952, 'mean_word_length': 3.1308100929614873, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2177317', 'n_tokens_mistral': 2496, 'n_tokens_neox': 2443, 'n_words': 419}