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 8438437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:42:56+00:00 2026-06-10T07:42:56+00:00

I have C code that call a kernel module and I want to pass

  • 0

I have C code that call a kernel module and I want to pass a struct to it. This seems doable ex –
char device catch multiple (int) ioctl-arguments

However I am invoking the c code through java JNI. It was said C struct mapping is to Java object. so am passing an object to the C native function.

Here is my JNI c function

  JNIEXPORT jint JNICALL Java_com_context_test_ModCallLib_reNice
  (JNIEnv *env, jclass clazz, jobject obj){

     // convert objcet to struct  
     // call module through IOCTL passing struct as the parameter
  }

How should I get a struct from obj?

EDIT: here is the object that I am passing,

class Nice{

    int[] pids;
    int niceVal;

    Nice(List<Integer> pID, int n){
        pids = new int[pID.size()];
        for (int i=0; i < pids.length; i++)
        {
            pids[i] = pID.get(i).intValue();
        }
        niceVal = n;
    }
}

the struct I want to have is this,

struct mesg {
     int pids[size_of_pids];
     int niceVal;
};

How should I approach?

  • 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-06-10T07:42:58+00:00Added an answer on June 10, 2026 at 7:42 am

    You will need to use JNI methods to access the fields, for example:

    //access field s in the object
    jfieldID fid = (env)->GetFieldID(clazz, "s", "Ljava/lang/String;");
    if (fid == NULL) {
        return; /* failed to find the field */
    }
    
    jstring jstr = (env)->GetObjectField(obj, fid);
    jboolean iscopy;
    const char *str = (env)->GetStringUTFChars(jstr, &iscopy);
    if (str == NULL) {
        return; // usually this means out of memory
    }
    
    //use your string
    ...
    
    (env)->ReleaseStringUTFChars(jstr, str);
    
    ...
    
    //access integer field val in the object
    jfieldID ifld = (env)->GetFieldID(clazz, "val", "I");
    if (ifld == NULL) {
        return; /* failed to find the field */
    }
    jint ival = env->GetIntField(obj, ifld);
    int value = (int)ival;
    

    There are member functions in the JNIEnv class to do whatever you need: to read and modify member variables of the class, to invoke methods and even to create new classes. Have a look at the JNI Specifications for more details.

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

Sidebar

Related Questions

I have code that looks something like this in javascript: forloop { //async call,
I have code that I want to look like this: List<Type> Os; ... foreach
I have Perl code that uses the system() function to call robocopy.exe, but it
I have the following shortened classic ASP code that makes a SQL insert call...
I have code that looks like this: obj.foo(); // obj might, or might not
I have code that looks like this: template<class T> class list { public: class
I have a kernel module that provides data to a userland process through read().
I have code that generates a List<string[]> variable but can't quite figure out how
I have code that looks more or less like the code below but it
I have code that sends web requests through two parallel for each loops. Will

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.