src/C/devices.c
retval_t dev_sanitize_user_defined_irq
    (device_t *udev, dev_irq_info_t irqinfo, e_task_id task_id)
{
    if ((irqinfo.handler == NULL) ||
        (!sanitize_is_pointer_in_txt_slot(irqinfo.handler, task_id)))
    {
        return FAILURE;
    }

    if (irqinfo.irq < USER_IRQ_MIN || irqinfo.irq > USER_IRQ_MAX) {
        return FAILURE;
    }

    if ((irqinfo.mode == IRQ_ISR_FORCE_MAINTHREAD) &&
        (!perm_ressource_is_granted(PERM_RES_TSK_FISR, task_id))) {
        return FAILURE;
    }

    for (int i=0; i<DEV_MAX_PH_INSTR; i++) {
        switch (irqinfo.posthook.action[i].instr) {
            case IRQ_PH_NIL:
                break;
            case IRQ_PH_READ:
                KERNLOG(DBG_INFO, "detecting PH_READ posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].read.offset > udev->size - 4) ||
                    (irqinfo.posthook.action[i].read.offset % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_WRITE:
                KERNLOG(DBG_INFO, "detecting PH_WRITE posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].write.offset > udev->size - 4) ||
                    (irqinfo.posthook.action[i].write.offset % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_AND:
                KERNLOG(DBG_INFO, "detecting PH_AND posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].and.offset_dest > udev->size - 4)
                    || (irqinfo.posthook.action[i].and.offset_dest % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].and.offset_src > udev->size - 4)
                    || (irqinfo.posthook.action[i].and.offset_src % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_MASK:
                KERNLOG(DBG_INFO, "detecting PH_MASK posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].mask.offset_dest > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_dest % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].mask.offset_src > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_src % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].mask.offset_mask > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_mask % 4)) {
                    return FAILURE;
                }
                break;
            default:
                return FAILURE;
        }
    }

    return SUCCESS;
}
/*
 * This file check that the device_t structure declare an existing device in
 * the current SoC. The address and size should be valid.
 *
 * All IRQ and GPIO contents should be properly defined and valid.
 *
 * Furthermore, this function check that the irq list and gpio list is
 * homogeneous (no table overflow), to avoid any memory fault in the kernel.
*/
This file check that the device_t structure declare an existing device in
the current SoC. The address and size should be valid.

All IRQ and GPIO contents should be properly defined and valid.

Furthermore, this function check that the irq list and gpio list is
homogeneous (no table overflow), to avoid any memory fault in the kernel.
This file check that the device_t structure declare an existing device in the current SoC . The address and size should be valid . All IRQ and GPIO contents should be properly defined and valid . Furthermore this function check that the irq list and gpio list is homogeneous ( no table overflow ) to avoid any memory fault in the kernel .
retval_t dev_sanitize_user_defined_irq
    (device_t *udev, dev_irq_info_t irqinfo, e_task_id task_id)
{
    if ((irqinfo.handler == NULL) ||
        (!sanitize_is_pointer_in_txt_slot(irqinfo.handler, task_id)))
    {
        return FAILURE;
    }
    if (irqinfo.irq < USER_IRQ_MIN || irqinfo.irq > USER_IRQ_MAX) {
        return FAILURE;
    }
    if ((irqinfo.mode == IRQ_ISR_FORCE_MAINTHREAD) &&
        (!perm_ressource_is_granted(PERM_RES_TSK_FISR, task_id))) {
        return FAILURE;
    }
    for (int i=0; i<DEV_MAX_PH_INSTR; i++) {
        switch (irqinfo.posthook.action[i].instr) {
            case IRQ_PH_NIL:
                break;
            case IRQ_PH_READ:
                KERNLOG(DBG_INFO, "detecting PH_READ posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].read.offset > udev->size - 4) ||
                    (irqinfo.posthook.action[i].read.offset % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_WRITE:
                KERNLOG(DBG_INFO, "detecting PH_WRITE posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].write.offset > udev->size - 4) ||
                    (irqinfo.posthook.action[i].write.offset % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_AND:
                KERNLOG(DBG_INFO, "detecting PH_AND posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].and.offset_dest > udev->size - 4)
                    || (irqinfo.posthook.action[i].and.offset_dest % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].and.offset_src > udev->size - 4)
                    || (irqinfo.posthook.action[i].and.offset_src % 4)) {
                    return FAILURE;
                }
                break;
            case IRQ_PH_MASK:
                KERNLOG(DBG_INFO, "detecting PH_MASK posthook for irq %x\n", irqinfo.irq);
                if ((irqinfo.posthook.action[i].mask.offset_dest > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_dest % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].mask.offset_src > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_src % 4)) {
                    return FAILURE;
                }
                if ((irqinfo.posthook.action[i].mask.offset_mask > udev->size - 4)
                    || (irqinfo.posthook.action[i].mask.offset_mask % 4)) {
                    return FAILURE;
                }
                break;
            default:
                return FAILURE;
        }
    }
    return SUCCESS;
}
retval_t dev_sanitize_user_defined_irq ( device_t * udev , dev_irq_info_t irqinfo , e_task_id task_id ) { if ( ( irqinfo . handler == NULL ) || ( ! sanitize_is_pointer_in_txt_slot ( irqinfo . handler , task_id ) ) ) { return FAILURE ; } if ( irqinfo . irq < USER_IRQ_MIN || irqinfo . irq > USER_IRQ_MAX ) { return FAILURE ; } if ( ( irqinfo . mode == IRQ_ISR_FORCE_MAINTHREAD ) && ( ! perm_ressource_is_granted ( PERM_RES_TSK_FISR , task_id ) ) ) { return FAILURE ; } for ( int i = 0 ; i < DEV_MAX_PH_INSTR ; i ++ ) { switch ( irqinfo . posthook . action [ i ] . instr ) { case IRQ_PH_NIL : break ; case IRQ_PH_READ : KERNLOG ( DBG_INFO , " \n " , irqinfo . irq ) ; if ( ( irqinfo . posthook . action [ i ] . read . offset > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . read . offset % 4 ) ) { return FAILURE ; } break ; case IRQ_PH_WRITE : KERNLOG ( DBG_INFO , " \n " , irqinfo . irq ) ; if ( ( irqinfo . posthook . action [ i ] . write . offset > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . write . offset % 4 ) ) { return FAILURE ; } break ; case IRQ_PH_AND : KERNLOG ( DBG_INFO , " \n " , irqinfo . irq ) ; if ( ( irqinfo . posthook . action [ i ] . and . offset_dest > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . and . offset_dest % 4 ) ) { return FAILURE ; } if ( ( irqinfo . posthook . action [ i ] . and . offset_src > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . and . offset_src % 4 ) ) { return FAILURE ; } break ; case IRQ_PH_MASK : KERNLOG ( DBG_INFO , " \n " , irqinfo . irq ) ; if ( ( irqinfo . posthook . action [ i ] . mask . offset_dest > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . mask . offset_dest % 4 ) ) { return FAILURE ; } if ( ( irqinfo . posthook . action [ i ] . mask . offset_src > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . mask . offset_src % 4 ) ) { return FAILURE ; } if ( ( irqinfo . posthook . action [ i ] . mask . offset_mask > udev -> size - 4 ) || ( irqinfo . posthook . action [ i ] . mask . offset_mask % 4 ) ) { return FAILURE ; } break ; default : return FAILURE ; } } return SUCCESS ; }
This file check that the device_t structure declare an existing device in
 the current SoC.
This file check that the device_t structure declare an existing device in the current SoC .