how to map kernel memory to user space

Chuck Tuffli ctuffli at gmail.com
Sun Feb 19 23:59:26 UTC 2017


I'm trying to work around a problem by mapping the data from a kernel
allocated buffer into a user space application. There was a post some
time back with a possible way to do this [1], but while this creates a
valid buffer in the user space application, the contents is all zeros
instead of containing the expected data. Is this approach not
possible? Does anything obviously stick out below? TIA.

--chuck

    rc = vm_map_lookup(&kernel_map, kaddr, VM_PROT_ALL,
                                                &entry, &obj, &pindex,
&prot, &is_wired);

    vm_map_lookup_done(kernel_map, entry);
    if (rc) printf("%s: vm_map_lookup() = %d\n", __func__, rc);

    PROC_LOCK(p);
    uaddr = round_page((vm_offset_t)vms->vm_daddr + lim_max(td, RLIMIT_DATA));
    PROC_UNLOCK(p);

    objoff = kaddr - (entry->start + entry->offset);

    vm_object_reference(obj);
    rc = vm_map_find(map,
            obj,
            objoff,
            &uaddr,
            sizeof(struct nvme_controller_data),
            0,
            VMFS_OPTIMAL_SPACE,
            VM_PROT_RW,
            VM_PROT_RW,
            MAP_INHERIT_SHARE);

[1] http://markmail.org/message/ph5yuonevqjhhbig


More information about the freebsd-hackers mailing list