0

私は基本的に、私が書いているシステムコールで非常に奇妙な状況に遭遇しています。特定のタイプのエラーが発生したことを示す -2 が返される場合、いくつかの値を確認したいと思います。「else if」の直前にprintk()を使用して変数の値を出力していますが、それらは互いに等しいと言われていますが、条件は実行されていません(つまり、else ifを入力していません)カーネルで作業するのはかなり新しいですが、これは私には非常にずれているようで、カーネルで作業することに気付いていないニュアンスがあるかどうか疑問に思っています。条件が実行されない変数 助けていただければ幸いです

//-----------------------------------------------------//

/*  sys_receiveMsg421()
     Description:
    - Copies the first message in the mailbox into <msg>
*/
asmlinkage long sys_receiveMsg421(unsigned long mbxID, char *msg, unsigned long N)
{

int result = 0;
int mboxIndex = checkBoxId(mbxID);
int msgIndex = 0;

//acquire the lock
down_interruptible(&sem);

//check to make sure the mailbox with <mbxID> exists
if(!mboxIndex)
{
    //free our lock
    up(&sem);
    return -1;
}

else
    mboxIndex--;

printk("<1>mboxIndex = %d\nNumber of messages = %dCurrent Msg = %d\n",mboxIndex, groupBox.boxes[mboxIndex].numMessages, groupBox.boxes[mboxIndex].currentMsg );

//check to make sure we have a message to recieve

-----------CODE NOT EXECUTING HERE------------------------------------------------
if(groupBox.boxes[mboxIndex].numMessages == groupBox.boxes[mboxIndex].currentMsg)
{
    //free our lock
    up(&sem);   
    return -2;
}
//retrieve the message
else
{
     //check to make sure the msg is a valid pointer before continuing
    if(!access_ok(VERIFY_READ, msg, N * sizeof(char)))
    {
        printk("<1>Access has been denied for %lu\n", mbxID);
        //free our lock
        up(&sem);
        return -1;
    }
    else
    {
        //calculate the index of the message to be retrieved            
        msgIndex = groupBox.boxes[mboxIndex].currentMsg;    

        //copy from kernel to user variable     
        result = copy_to_user(msg, groupBox.boxes[mboxIndex].messages[msgIndex], N);

        //increment message position
        groupBox.boxes[mboxIndex].currentMsg++;

        //free our lock
        up(&sem);

        //return number of bytes copied
        return (N - result);
    }
}
}

更新:戻り値を別のものに変更するだけで問題を解決しましたが、非常に奇妙に機能します

4

2 に答える 2

4

句読点を忘れずに使用してください。問題を読んでいるときに息切れするのは好きではありません。

if ブロックが入力されていませんか? そこ (および対応する else ブロック内の別の printk) を使用すると、さらに一歩先に進むことができますよね?

質問に関しては: いいえ、これが機能しないカーネル コードに固有のものはありません。

また、同期もカバーしているようです。mboxIndexただし:クリティカルセクションの外で取得しているようです。それは問題を引き起こす可能性がありますか?groupBox宣言すらされていないこのスニペットからはわかりにくいです。

于 2012-04-22T00:42:01.407 に答える
1

おそらくnumMessagesおよび/またはcurrentMsgとして定義されていlongますか?
もしそうならprintk、を使用するyour%dはビットの一部だけを出力するので、そうではないのに等しいと思うかもしれません。

于 2012-04-22T04:39:29.983 に答える