Beispiel #1
0
static int64_t
ioctl_add_module(char *file, int64_t len)
{
    char *buf;
    int64_t ret;

    if (g_num_pmodules >= MAX_NUM_MODULES)
    {
        ALERT("IOCTL_ADD_MODULE: too many modules have been loaded\n");
        return BF_IOCTL_FAILURE;
    }

    buf = platform_alloc_rwe(len);
    if (buf == NULL)
    {
        ALERT("IOCTL_ADD_MODULE: failed to allocate memory for the module\n");
        return BF_IOCTL_FAILURE;
    }

    platform_memset(buf, 0, len);
    platform_memcpy(buf, file, len);

    ret = common_add_module(buf, len);
    if (ret != BF_SUCCESS)
    {
        ALERT("IOCTL_ADD_MODULE: common_add_module failed: %p - %s\n",
              (void *)ret, ec_to_str(ret));
        goto failed;
    }

    pmodules[g_num_pmodules].data = buf;
    pmodules[g_num_pmodules].size = len;

    g_num_pmodules++;

    DEBUG("IOCTL_ADD_MODULE: succeeded\n");
    return BF_IOCTL_SUCCESS;

failed:

    platform_free_rwe(buf, len);

    DEBUG("IOCTL_ADD_MODULE: failed\n");
    return BF_IOCTL_FAILURE;
}
Beispiel #2
0
static int64_t
ioctl_dump_vmm(struct debug_ring_resources_t *user_drr)
{
    int64_t ret;
    struct debug_ring_resources_t *drr = 0;

    ret = common_dump_vmm(&drr, g_vcpuid);
    if (ret != BF_SUCCESS)
    {
        ALERT("IOCTL_DUMP_VMM: common_dump_vmm failed: %p - %s\n",
              (void *)ret, ec_to_str(ret));
        return BF_IOCTL_FAILURE;
    }

    platform_memcpy(user_drr, drr, sizeof(struct debug_ring_resources_t));

    DEBUG("IOCTL_DUMP_VMM: succeeded\n");
    return BF_IOCTL_SUCCESS;
}
Beispiel #3
0
RANDO_SECTION void *API::mem_realloc(void *old_ptr, size_t new_size, bool zeroed) {
    if (old_ptr == nullptr)
        return mem_alloc(new_size, zeroed);

    auto *old_size_ptr = reinterpret_cast<size_t*>(old_ptr);
    old_size_ptr--;

    auto old_size = *old_size_ptr;
    new_size = (new_size + sizeof(new_size) + kPageSize - 1) & ~(kPageSize - 1);
    if (new_size == old_size)
        return old_ptr;

    void *res = old_size_ptr;
    if (new_size < old_size) {
        // We're shrinking the region
        auto new_end = reinterpret_cast<BytePointer>(old_size_ptr) + new_size;
        RANDO_ASSERT((reinterpret_cast<uintptr_t>(new_end) & (kPageSize - 1)) == 0);
        platform_free_rw(new_end, old_size - new_size);
        if (new_size == 0)
            return nullptr;
        // Fall-through with res == old_size_ptr
    } else {
        // new_size > old_size
        // We're growing the region
        res = platform_alloc_rw(new_size);
        if (res == nullptr) {
            // Release the old memory, then return an error
            platform_free_rw(old_size_ptr, old_size);
            return nullptr;
        }
        // Copy over the old data, then release the old region
        platform_memcpy(res, old_size_ptr, old_size);
        if (zeroed) {
            auto old_end = reinterpret_cast<BytePointer>(old_size_ptr) + old_size;
            platform_memset(old_end, 0, new_size - old_size);
        }
        platform_free_rw(old_size_ptr, old_size);
    }
    auto new_size_ptr = reinterpret_cast<size_t*>(res);
    *new_size_ptr = new_size;
    return reinterpret_cast<void*>(new_size_ptr + 1);
}
Beispiel #4
0
OT_WEAK ot_u16 otapi_open_request(addr_type addr, routing_tmpl* routing) {
/// Set the header if the session is valid.  Also conditionally write the header
/// depending on the address type (a parameter).  
    if (session_notempty()) {
        m2session* s_active;
        s_active = session_top();
        
        // Set the dll parameters to a safe setting; can be changed later
        dll_set_defaults(s_active);
    
        // Unicast/Anycast support routing, so copy the supplied template
        if ((addr & M2QUERY_GLOBAL) == 0) {   
            platform_memcpy((ot_u8*)&m2np.rt, (ot_u8*)routing, sizeof(routing_tmpl));
        }

        // Load the header
        m2np_header(s_active, (ot_u8)addr, M2FI_FRDIALOG);
        return 1;
    }
    return 0;
}