Ejemplo n.º 1
0
func (p *Process) NewPML4() {
	p.PML4 = p.KAllocate(1)
	_pml := runtime.MapTmp(p.PML4)
	runtime.Memclr(_pml, PAGESIZE)
	pdp := p.KAllocate(1)
	Write64(_pml, pdp|PAGEAVAIL|PAGEWRITE|PAGEUSER)
	_pdp := runtime.MapTmp(pdp)
	runtime.Memclr(_pdp, PAGESIZE)
	Write64(_pdp, runtime.KernelPD|PAGEAVAIL|PAGEWRITE|PAGEUSER)
	runtime.FreeTmp(_pdp)
	runtime.FreeTmp(_pml)
	runtime.SetLocalCR3(p.PML4)
}
Ejemplo n.º 2
0
func (p *Process) Exec(f File) Error {
	var header [40]byte
	var v uintptr
	buf := make([]byte, PAGESIZE)
	bufh := (*runtime.SliceHeader)(unsafe.Pointer(&buf))

	_, err := f.PRead(header[:], 0)
	if err != nil {
		return err
	}
	magic := BE32(header[:])
	if magic != AOUTMAGIC {
		return SimpleError("invalid executable")
	}
	textsize := uint64(BE32(header[4:]))
	datasize := uint64(BE32(header[8:]))
	bsssize := uint64(BE32(header[12:]))
	procsize := pageroundup(textsize+40) + datasize + bsssize

	p.CleanUp()
	p.NewPML4()
	p.highest = USERSTART
	p.Allocate(procsize)
	off := uint64(0)
	v = USERSTART
	end := USERSTART + uintptr(pageroundup(textsize+40)+datasize)
	for v < end {
		n, err := f.PRead(buf[:], off)
		if err != nil {
			if v+uintptr(n) >= end && err == EOF {
				break
			}
			return err
		}
		runtime.Memmove(v, bufh.Data, uint32(n))
		off += n
		v += uintptr(n)
	}
	runtime.Memclr(v, bsssize)
	p.ProcState.ip = uint64(BE32(header[20:]))
	return nil
}