static void setup_rt_frame(int sig, struct target_sigaction *ka,

                           target_siginfo_t *info,

                           target_sigset_t *set, CPUOpenRISCState *env)

{

    int err = 0;

    abi_ulong frame_addr;

    unsigned long return_ip;

    struct target_rt_sigframe *frame;

    abi_ulong info_addr, uc_addr;



    frame_addr = get_sigframe(ka, env, sizeof(*frame));

    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {

        goto give_sigsegv;

    }



    info_addr = frame_addr + offsetof(struct target_rt_sigframe, info);

    __put_user(info_addr, &frame->pinfo);

    uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);

    __put_user(uc_addr, &frame->puc);



    if (ka->sa_flags & SA_SIGINFO) {

        copy_siginfo_to_user(&frame->info, info);

    }



    /*err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));*/

    __put_user(0, &frame->uc.tuc_flags);

    __put_user(0, &frame->uc.tuc_link);

    __put_user(target_sigaltstack_used.ss_sp,

               &frame->uc.tuc_stack.ss_sp);

    __put_user(sas_ss_flags(env->gpr[1]), &frame->uc.tuc_stack.ss_flags);

    __put_user(target_sigaltstack_used.ss_size,

               &frame->uc.tuc_stack.ss_size);

    err |= setup_sigcontext(&frame->sc, env, set->sig[0]);



    /*err |= copy_to_user(frame->uc.tuc_sigmask, set, sizeof(*set));*/



    if (err) {

        goto give_sigsegv;

    }



    /* trampoline - the desired return ip is the retcode itself */

    return_ip = (unsigned long)&frame->retcode;

    /* This is l.ori r11,r0,__NR_sigreturn, l.sys 1 */

    __put_user(0xa960, (short *)(frame->retcode + 0));

    __put_user(TARGET_NR_rt_sigreturn, (short *)(frame->retcode + 2));

    __put_user(0x20000001, (unsigned long *)(frame->retcode + 4));

    __put_user(0x15000000, (unsigned long *)(frame->retcode + 8));



    if (err) {

        goto give_sigsegv;

    }



    /* TODO what is the current->exec_domain stuff and invmap ? */



    /* Set up registers for signal handler */

    env->pc = (unsigned long)ka->_sa_handler; /* what we enter NOW */

    env->gpr[9] = (unsigned long)return_ip;     /* what we enter LATER */

    env->gpr[3] = (unsigned long)sig;           /* arg 1: signo */

    env->gpr[4] = (unsigned long)&frame->info;  /* arg 2: (siginfo_t*) */

    env->gpr[5] = (unsigned long)&frame->uc;    /* arg 3: ucontext */



    /* actually move the usp to reflect the stacked frame */

    env->gpr[1] = (unsigned long)frame;



    return;



give_sigsegv:

    unlock_user_struct(frame, frame_addr, 1);

    if (sig == TARGET_SIGSEGV) {

        ka->_sa_handler = TARGET_SIG_DFL;

    }

    force_sig(TARGET_SIGSEGV);

}

static void setup_rt_frame(int sig, struct target_sigaction *ka,

                           target_siginfo_t *info,

                           target_sigset_t *set, CPUOpenRISCState *env)

{

    int err = 0;

    abi_ulong frame_addr;

    unsigned long return_ip;

    struct target_rt_sigframe *frame;

    abi_ulong info_addr, uc_addr;



    frame_addr = get_sigframe(ka, env, sizeof(*frame));

    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {

        goto give_sigsegv;

    }



    info_addr = frame_addr + offsetof(struct target_rt_sigframe, info);

    __put_user(info_addr, &frame->pinfo);

    uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);

    __put_user(uc_addr, &frame->puc);



    if (ka->sa_flags & SA_SIGINFO) {

        copy_siginfo_to_user(&frame->info, info);

    }



    

    __put_user(0, &frame->uc.tuc_flags);

    __put_user(0, &frame->uc.tuc_link);

    __put_user(target_sigaltstack_used.ss_sp,

               &frame->uc.tuc_stack.ss_sp);

    __put_user(sas_ss_flags(env->gpr[1]), &frame->uc.tuc_stack.ss_flags);

    __put_user(target_sigaltstack_used.ss_size,

               &frame->uc.tuc_stack.ss_size);

    err |= setup_sigcontext(&frame->sc, env, set->sig[0]);



    



    if (err) {

        goto give_sigsegv;

    }



    

    return_ip = (unsigned long)&frame->retcode;

    

    __put_user(0xa960, (short *)(frame->retcode + 0));

    __put_user(TARGET_NR_rt_sigreturn, (short *)(frame->retcode + 2));

    __put_user(0x20000001, (unsigned long *)(frame->retcode + 4));

    __put_user(0x15000000, (unsigned long *)(frame->retcode + 8));



    if (err) {

        goto give_sigsegv;

    }



    



    

    env->pc = (unsigned long)ka->_sa_handler; 

    env->gpr[9] = (unsigned long)return_ip;     

    env->gpr[3] = (unsigned long)sig;           

    env->gpr[4] = (unsigned long)&frame->info;  

    env->gpr[5] = (unsigned long)&frame->uc;    



    

    env->gpr[1] = (unsigned long)frame;



    return;



give_sigsegv:

    unlock_user_struct(frame, frame_addr, 1);

    if (sig == TARGET_SIGSEGV) {

        ka->_sa_handler = TARGET_SIG_DFL;

    }

    force_sig(TARGET_SIGSEGV);

}

static void FUNC_0(int VAR_0, struct target_sigaction *VAR_1,

                           target_siginfo_t *VAR_2,

                           target_sigset_t *VAR_3, CPUOpenRISCState *VAR_4)

{

    int VAR_5 = 0;

    abi_ulong frame_addr;

    unsigned long VAR_6;

    struct target_rt_sigframe *VAR_7;

    abi_ulong info_addr, uc_addr;



    frame_addr = get_sigframe(VAR_1, VAR_4, sizeof(*VAR_7));

    if (!lock_user_struct(VERIFY_WRITE, VAR_7, frame_addr, 0)) {

        goto give_sigsegv;

    }



    info_addr = frame_addr + offsetof(struct target_rt_sigframe, VAR_2);

    __put_user(info_addr, &VAR_7->pinfo);

    uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc);

    __put_user(uc_addr, &VAR_7->puc);



    if (VAR_1->sa_flags & SA_SIGINFO) {

        copy_siginfo_to_user(&VAR_7->VAR_2, VAR_2);

    }



    

    __put_user(0, &VAR_7->uc.tuc_flags);

    __put_user(0, &VAR_7->uc.tuc_link);

    __put_user(target_sigaltstack_used.ss_sp,

               &VAR_7->uc.tuc_stack.ss_sp);

    __put_user(sas_ss_flags(VAR_4->gpr[1]), &VAR_7->uc.tuc_stack.ss_flags);

    __put_user(target_sigaltstack_used.ss_size,

               &VAR_7->uc.tuc_stack.ss_size);

    VAR_5 |= setup_sigcontext(&VAR_7->sc, VAR_4, VAR_3->VAR_0[0]);



    



    if (VAR_5) {

        goto give_sigsegv;

    }



    

    VAR_6 = (unsigned long)&VAR_7->retcode;

    

    __put_user(0xa960, (short *)(VAR_7->retcode + 0));

    __put_user(TARGET_NR_rt_sigreturn, (short *)(VAR_7->retcode + 2));

    __put_user(0x20000001, (unsigned long *)(VAR_7->retcode + 4));

    __put_user(0x15000000, (unsigned long *)(VAR_7->retcode + 8));



    if (VAR_5) {

        goto give_sigsegv;

    }



    



    

    VAR_4->pc = (unsigned long)VAR_1->_sa_handler; 

    VAR_4->gpr[9] = (unsigned long)VAR_6;     

    VAR_4->gpr[3] = (unsigned long)VAR_0;           

    VAR_4->gpr[4] = (unsigned long)&VAR_7->VAR_2;  

    VAR_4->gpr[5] = (unsigned long)&VAR_7->uc;    



    

    VAR_4->gpr[1] = (unsigned long)VAR_7;



    return;



give_sigsegv:

    unlock_user_struct(VAR_7, frame_addr, 1);

    if (VAR_0 == TARGET_SIGSEGV) {

        VAR_1->_sa_handler = TARGET_SIG_DFL;

    }

    force_sig(TARGET_SIGSEGV);

}

static void FUNC_0(int VAR_0, struct target_sigaction *VAR_1,
target_siginfo_t *VAR_2,
target_sigset_t *VAR_3, CPUOpenRISCState *VAR_4)
{ int VAR_5 = 0; abi_ulong frame_addr; unsigned long VAR_6; struct target_rt_sigframe *VAR_7; abi_ulong info_addr, uc_addr; frame_addr = get_sigframe(VAR_1, VAR_4, sizeof(*VAR_7)); if (!lock_user_struct(VERIFY_WRITE, VAR_7, frame_addr, 0)) { goto give_sigsegv; } info_addr = frame_addr + offsetof(struct target_rt_sigframe, VAR_2); __put_user(info_addr, &VAR_7->pinfo); uc_addr = frame_addr + offsetof(struct target_rt_sigframe, uc); __put_user(uc_addr, &VAR_7->puc); if (VAR_1->sa_flags & SA_SIGINFO) { copy_siginfo_to_user(&VAR_7->VAR_2, VAR_2); } __put_user(0, &VAR_7->uc.tuc_flags); __put_user(0, &VAR_7->uc.tuc_link); __put_user(target_sigaltstack_used.ss_sp,
&VAR_7->uc.tuc_stack.ss_sp); __put_user(sas_ss_flags(VAR_4->gpr[1]), &VAR_7->uc.tuc_stack.ss_flags); __put_user(target_sigaltstack_used.ss_size,
&VAR_7->uc.tuc_stack.ss_size); VAR_5 |= setup_sigcontext(&VAR_7->sc, VAR_4, VAR_3->VAR_0[0]); if (VAR_5) { goto give_sigsegv; } VAR_6 = (unsigned long)&VAR_7->retcode; __put_user(0xa960, (short *)(VAR_7->retcode + 0)); __put_user(TARGET_NR_rt_sigreturn, (short *)(VAR_7->retcode + 2)); __put_user(0x20000001, (unsigned long *)(VAR_7->retcode + 4)); __put_user(0x15000000, (unsigned long *)(VAR_7->retcode + 8)); if (VAR_5) { goto give_sigsegv; } VAR_4->pc = (unsigned long)VAR_1->_sa_handler; VAR_4->gpr[9] = (unsigned long)VAR_6; VAR_4->gpr[3] = (unsigned long)VAR_0; VAR_4->gpr[4] = (unsigned long)&VAR_7->VAR_2; VAR_4->gpr[5] = (unsigned long)&VAR_7->uc; VAR_4->gpr[1] = (unsigned long)VAR_7; return; give_sigsegv:
unlock_user_struct(VAR_7, frame_addr, 1); if (VAR_0 == TARGET_SIGSEGV) { VAR_1->_sa_handler = TARGET_SIG_DFL; } force_sig(TARGET_SIGSEGV); }