Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 503221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:22:19+00:00 2026-05-13T06:22:19+00:00

In kernel space, I have the following: char * myData[MAX_BUF_SIZE][2]; I need to define

  • 0

In kernel space, I have the following:

char * myData[MAX_BUF_SIZE][2];

I need to define a kernel method that copies this data into user-space., so how would I go about defining this method? I’ve got the following, but I’m not quite sure what I’m doing.

asmlinkage int sys_get_my_data(char __user ***data, int rowLen, int bufferSize) {
    if (rowLen < 1 || bufferSize < 1 || rowLen > MAX_BUF_SIZE || bufferSize
            > MAX_BUF_SIZE) {
        return -1;
    }

    if( copy_to_user( data, myData, rowLen * bufferSize * dataCounter * 2) )
    {
        printk( KERN_EMERG "Copy to user failure for get all minifiles\n" );
        return -1;
    }

    return 0;
}

Help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:22:19+00:00Added an answer on May 13, 2026 at 6:22 am

    Per your comment, these char * values point to nul-terminated strings.

    Now, you can’t just go copying that whole fileDataMap memory block to userspace – that’ll just give userspace a bunch of char * values that point into kernel space, so it won’t actually be able to use them. You need to copy the strings themselves to userspace, not just the pointers (this is a “deep copy”).

    Now, there’s a few ways you can go about this. The easiest it to simply pack all the strings, one after another, into a big char array in userspace. It’s then up to userspace to scan through the block, reconstructing the pointers:

    asmlinkage int sys_get_my_data(char __user *data, size_t bufferSize)
    {
        size_t i;
    
        for (i = 0; i < MAX_BUF_SIZE; i++) {
            size_t s0_len = strlen(fileDataMap[i][0]) + 1;
            size_t s1_len = strlen(fileDataMap[i][1]) + 1;
    
            if (s0_len + s1_len > bufferSize) {
                return -ENOSPC;
            }
    
            if (copy_to_user(data, fileDataMap[i][0], s0_len)) {
                return -EINVAL;
            }
    
            data += s0_len;
            bufferSize -= s0_len;
    
            if (copy_to_user(data, fileDataMap[i][1], s1_len)) {
                return -EINVAL;
            }
    
            data += s1_len;
            bufferSize -= s1_len;
        }
    
        return 0;
    }
    

    This will only work if there are always MAX_BUF_SIZE string-pairs, because userspace will need to know how many strings it is expecting to recieve in order to be able to safely scan through them. If that’s not the case, you’ll have to return that information somehow – perhaps the return value of the syscall could be the number of string-pairs?

    If you want the kernel to reconstruct the pointer table in userspace, you’ll have to copy the strings as above, and then fill out the pointer table – userspace will have to pass two buffers, one for the strings themselves and one for the pointers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a kernel module that provides data to a userland process through read().
I have the following code in a kernel module that walks up the process
My question is about passing data from kernel to a user space program. I
I'm reading Understanding Linux Kernel. This is the snippet that explains how Linux uses
I am trying to link a user space library into a windows kernel driver.
This is an OpenCV2 question. I have a matrix representing a closed space curve.
On an x86 system, I have a Linux kernel module (watcher module) that gets
my application reads from a char device, which is filled from kernel space. Currently
I would like to write into a log file from the kernel space. I
Recently, I am reading some Linux kernel space codes, I see this uint64_t used;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.