Exemplo n.º 1
0
Arquivo: show.c Projeto: rforge/muste
static int shadow_write(unsigned int j,unsigned int jj,int disp_frame)
{
    int i,k;
    long l;
    char x[LLENGTH];
    char y[LLENGTH];
    char *p;

    if (edit!=3)
    {
        for (k=0; k<n_shad; ++k)
        {
            if (j==shad_int[k]) break;
        }
        if (k==n_shad) return(1);
    }

    if (edit==3)
    {
        getc(text); /* LF */
        *x=(char)getc(text);
        /* Rprintf("*x=%c\n",*x); getch(); */
        if (*x!='S') return(1);
        while (1) {
            *x=(char)getc(text);
            if (*x=='|') break;
        }
        i=0;
        p=x;
        while (1)
        {
            *p=(char)getc(text);
            if (*p==CR) break;
            ++i;
            ++p;
        }
        for ( ; i<ted1; ++i) *p++=' ';
        *p=EOS;
    }
    else
    {
        l=(long)ted1*(long)(ted2+2+k)+2L;
        muste_fseek(text,l,0);
        for (i=2; i<ted1; ++i) x[i-2]=(char)getc(text);
        x[ted1-2]=EOS;
        strcat(x,"  ");
    }
    if (zs[jj]==0) {
        i=shadow_create(jj);
        if (i<0) return(0);
    }
    if (disp_frame)
    {
        strcpy(y,"      ");
        strcat(y,x);
        strcpy(x,y);
    }
    edwrite(x,zs[jj],0);
    return(1);
}
Exemplo n.º 2
0
Arquivo: show.c Projeto: rforge/muste
static int load(char *s)
{
    int i,k;
    long kk;
    long k1,k2;
    char *p;
    int alku;
    int shad_permit=1;
    char x[LLENGTH];
    char aika[26];
    int lev=0;

    if (*s==EOS) return(1);
    disp_frame=0;
    p=strchr(s,',');
    if (p==NULL)
    {
        k1=atol(s);
        if (k1<1L) k1=1L;
        k2=jmax;
    }
    else
    {
        *p=EOS;
        k1=atol(s);
        if (k1<1L) k1=1L;
        k2=atol(p+1);
        if (k2<k1) k2=jmax;
        if (strchr(p+1,'*')!=NULL) disp_frame=1;
    }

    if (edit) alku=0;
    else alku=1;

    if (disp_frame)
    {
        pvmaika(aika);
        k=sprintf(line,"*   -  - SURVO MM  ");
        k+=sprintf(line+k,"%s %20.20s%7d%5d 0",aika,edisk,ted2,ted1-1);
        edwrite(line,jj,0);
        if (zs[jj]==0) {
            i=shadow_create(jj);
            if (i<0) return(-1);
        }
        for (i=0; i<k; ++i) line[i]=' ';
        line[k]=EOS;
        line[1]='{';
        line[k-1]='}';
        lev=k;
        edwrite(line,zs[jj],0);
        ++jj;
    }

    for (kk=k1; kk<=k2; ++kk)
    {
        if (jj>r2) {
            ei_tilaa();
            break;
        }
        edread(line,jj);
        if (!empty_s(line+1))
        {
            /*  ei_tilaa();       */
            i=lis_rivit(jj,k2-kk+1L+(long)disp_frame);  /* 29.6.90 */
            if (i<0) break;
        }
        i=etsi(kk);
        if (i<0) {
            muste_fclose(text);
            return(-1);
        }
        i=lue_rivi(line);
        if (feof(text) && !*line) {
            jmax=kk-1;
            break;
        }
        if (i<0) return(-1);

        if (!disp_frame) edwrite(line,jj,alku);
        else
        {
            sprintf(x,"*%4ld %s",kk,line);   /* k -> kk 24.5.93 */
            edwrite(x,jj,0);
        }
        j=kk+1;
        if (edit!=3) talleta_alku((long)j,muste_ftell(text));
        if ((edit==1 || (edit==3 && !empty32)) && shad_permit)
            shad_permit=shadow_write((int)kk,jj,disp_frame); /* showsh */
        ++jj;
    }
    if (!shad_permit) return(-1);
    if (disp_frame)
    {
        strncpy(line,space,lev);
        line[lev]=EOS;
        line[0]='*';
        edwrite(line,jj,0);
        if (zs[jj]==0) {
            i=shadow_create(jj);
            if (i<0) return(-1);
        }
        for (i=0; i<lev; ++i) line[i]=' ';
        line[lev]=EOS;
        line[lev-1]='}';
        edwrite(line,zs[jj],0);
    }
    return(1);
}
Exemplo n.º 3
0
/*
 * The implementation of fork(2). Once this works,
 * you're practically home free. This is what the
 * entirety of Weenix has been leading up to.
 * Go forth and conquer.
 */
int
do_fork(struct regs *regs)
{
        /*NOT_YET_IMPLEMENTED("VM: do_fork");*/
        KASSERT(regs != NULL);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");
        KASSERT(curproc != NULL);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");
        KASSERT(curproc->p_state == PROC_RUNNING);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");

        proc_t *childproc=proc_create("childproc");
        KASSERT(childproc);

        vmmap_t *cmap=vmmap_clone(curproc->p_vmmap);
        cmap->vmm_proc=childproc;
        vmmap_destroy(childproc->p_vmmap);/********************/
        childproc->p_vmmap=cmap;
       
        childproc->p_status = curproc->p_status;
	childproc->p_brk = curproc->p_brk;
	childproc->p_start_brk = curproc->p_start_brk;

        KASSERT(childproc->p_state == PROC_RUNNING);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");
        KASSERT(childproc->p_pagedir != NULL);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");
        
/*
        vmarea_t* temp_pvmarea=NULL;

        list_link_t *childbegin=childproc->p_vmmap->vmm_list.l_next;

        list_iterate_begin(&(curproc->p_vmmap->vmm_list),temp_pvmarea,vmarea_t,vma_plink)
        {
                if(temp_pvmarea->vma_flags&MAP_PRIVATE)
                {
                        mmobj_t *shadow_obj=shadow_create();
                        shadow_obj->mmo_shadowed=temp_pvmarea->vma_obj;
                        shadow_obj->mmo_un.mmo_bottom_obj=temp_pvmarea->vma_obj->mmo_un.mmo_bottom_obj;

                        vmarea_t* tpvmarea1=list_item(childbegin,vmarea_t,vma_plink);
                        mmobj_t *chshadow_obj=shadow_create();
                        chshadow_obj->mmo_shadowed=temp_pvmarea->vma_obj;
                        chshadow_obj->mmo_un.mmo_bottom_obj=temp_pvmarea->vma_obj->mmo_un.mmo_bottom_obj;
                        
                        temp_pvmarea->vma_obj->mmo_ops->ref(temp_pvmarea->vma_obj);

                        tpvmarea1->vma_obj=chshadow_obj;
                        temp_pvmarea->vma_obj=shadow_obj;
             
                }
                childbegin=childbegin->l_next;

        }list_iterate_end();
*/

        list_link_t* pindex=NULL;
        list_link_t* cindex=NULL;
        for (pindex = (curproc->p_vmmap->vmm_list.l_next),cindex= (childproc->p_vmmap->vmm_list.l_next);pindex !=&(curproc->p_vmmap->vmm_list);pindex=pindex->l_next,cindex=cindex->l_next)
        {
               
                vmarea_t* temp_pvmarea=list_item(pindex,vmarea_t,vma_plink);
                vmarea_t* tpvmarea1;
                 if(temp_pvmarea->vma_flags&MAP_PRIVATE)
                {
               
                        mmobj_t *shadow_obj=shadow_create();
                        shadow_obj->mmo_shadowed=temp_pvmarea->vma_obj;
                        shadow_obj->mmo_un.mmo_bottom_obj=temp_pvmarea->vma_obj->mmo_un.mmo_bottom_obj;
                        temp_pvmarea->vma_obj=shadow_obj;

                        tpvmarea1=list_item(cindex,vmarea_t,vma_plink);
                        mmobj_t *chshadow_obj=shadow_create();
                        chshadow_obj->mmo_shadowed=temp_pvmarea->vma_obj->mmo_shadowed;
                        chshadow_obj->mmo_un.mmo_bottom_obj=temp_pvmarea->vma_obj->mmo_un.mmo_bottom_obj;
                        chshadow_obj->mmo_shadowed->mmo_ops->ref(chshadow_obj->mmo_shadowed);
                        list_insert_tail(&(chshadow_obj->mmo_un.mmo_bottom_obj->mmo_un.mmo_vmas), &tpvmarea1->vma_olink);
                        tpvmarea1->vma_obj=chshadow_obj;
                }
                else{
                        tpvmarea1=list_item(cindex,vmarea_t,vma_plink);
                        tpvmarea1->vma_obj=temp_pvmarea->vma_obj;
                        tpvmarea1->vma_obj->mmo_ops->ref(tpvmarea1->vma_obj);
                        list_insert_tail(&(tpvmarea1->vma_obj->mmo_un.mmo_vmas), &tpvmarea1->vma_olink);
                }
                
                
        }


        pt_unmap_range(curproc->p_pagedir,USER_MEM_LOW,USER_MEM_HIGH);
        tlb_flush_all();

        kthread_t *chthread=kthread_clone(curthr);
        chthread->kt_proc=childproc;
        list_insert_tail(&(childproc->p_threads),&(chthread->kt_plink));

        (chthread->kt_ctx).c_pdptr=childproc->p_pagedir;
        (chthread->kt_ctx).c_eip=(uint32_t)(userland_entry);
        regs->r_eax = 0;
        (chthread->kt_ctx).c_esp=fork_setup_stack(regs, chthread->kt_kstack);
        /*(chthread->kt_ctx).c_ebp*/
        (chthread->kt_ctx).c_kstack=(uintptr_t)chthread->kt_kstack;
        (chthread->kt_ctx). c_kstacksz=DEFAULT_STACK_SIZE;
        KASSERT(chthread->kt_kstack != NULL);
        dbg(DBG_PRINT, "(GRADING3A 7.a)\n");
        /*********how to set return value*********/

        int i = 0;
	while (i<NFILES)
	{
		childproc->p_files[i] = curproc->p_files[i];
                if(childproc->p_files[i]!=NULL)
                {
                        fref(childproc->p_files[i]);
                }
                i++;
	}
/*      has been added in proc_create();
        childproc->p_cwd=curproc->p_cwd;
        vref(childproc->p_cwd);
*/
        sched_make_runnable(chthread);
        return childproc->p_pid;
}