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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:33:10+00:00 2026-05-26T19:33:10+00:00

I have written a syscall that sets a variable in td_sched that I added

  • 0

I have written a syscall that sets a variable in td_sched that I added earlier

#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/sched.h>
#include <sys/lock.h>
#include <sys/mutex.h>


struct set_proc_args{
    pid_t pid;
    struct timeval WCET;
    struct timeval deadline;
};

static int set_process_slack(struct thread *tda ,struct set_proc_args * arg){

    struct proc * process = pfind(arg->pid);
    struct thread* td = FIRST_THREAD_IN_PROC(process);

    if(process == NULL)
    {
        tda->td_retval[0] = -1;
        return -1;
    }


    if(td == NULL)
    {
        tda->td_retval[0] = -1;
        return -1;
    }
    PROC_LOCK_ASSERT(process, MA_OWNED);
    td->td_sched->WCET = (1000000 * arg->WCET.tv_sec + arg->WCET.tv_usec);
    td->td_sched->deadline =(uint64_t)( 1000000 * arg->deadline.tv_sec+arg->deadline.tv_usec);
    td->td_sched->slack_mode = 1;
    PROC_UNLOCK(process);
    return 0;
}

So I want to return -1 when no process with this ID is found.
I’ve tested and saw that the code is working when the process is found
but if it’s not found FreeBSD reboots
Where is the problem?
Actually I don’t know how to return -1 correctly.

  • 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-26T19:33:11+00:00Added an answer on May 26, 2026 at 7:33 pm

    I’d be willing to bet my hard-earned money that it’s because of this:

    struct proc * process = pfind(arg->pid);
    struct thread* td = FIRST_THREAD_IN_PROC(process);
    if(process == NULL) {
        tda->td_retval[0] = -1;
        return -1;
    }
    

    In the case where no such process exists, pfind will have returned NULL as per the manpage:

    pfind() and zpfind() return a pointer to a proc structure on success and a NULL on failure.

    The FIRST_THREAD_IN_PROC function or macro then almost certainly tries to dereference process to find the first thread for it.

    Because process is NULL, the dereference will cause a core dump. Or, more correctly, it would cause a core dump if you were simply running as a normal process that the kernel could just toss out.

    The fact that this is in a syscall is far more serious, hence the reboot. You have to be far more bug-free in kernel-level code than user-level code.

    Try to re-arrange that code above so that you check process for a NULL value before trying to use it, something like:

    struct proc * process = pfind(arg->pid);
    struct thread* td;
    if(process == NULL) {
        tda->td_retval[0] = -1;
        return -1;
    }
    td = FIRST_THREAD_IN_PROC(process);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have written an AIR Application that downloads videos and documents from a server.
I have written a DLL that uses MS Word to spell check the content
I have written a watir script that downloads files. One of the files it
I have written a xml/php document that is pulling from a Magento Commerce database,
I have written a small HTML form and added it to the page. My
I have written some JavaScript that opens an element when an element is clicked.
I have written a web service that seems to be running fine - I
I have written a short python script that opens Google music in web view
I have written a c# win forms application that allows the user to open

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.