示例#1
0
func (q *Process) Dawn(flags uint64, c chan bool) {
	highest := q.highest
	pml4 := q.PML4
	q.highest = USERSTART
	q.NewPML4()
	q.Allocate(uint64(highest - USERSTART))
	buf := make([]byte, PAGESIZE)
	bufh := (*runtime.SliceHeader)(unsafe.Pointer(&buf))
	for v := uintptr(USERSTART); v < highest; v += PAGESIZE {
		runtime.SetLocalCR3(pml4)
		runtime.Memmove(bufh.Data, v, PAGESIZE)
		runtime.SetLocalCR3(q.PML4)
		runtime.Memmove(v, bufh.Data, PAGESIZE)
	}
	q.ProcState.ax = 0
	c <- false
	q.Run()
}
示例#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
}
示例#3
0
func syscall_wtf(p *Process) {
	var s string

	if p.IsInvalid(p.ProcState.sp, 020, MEMREAD) {
		return
	}
	buf := *p.stack(0)
	l := uint32(*p.stack(1))

	s = p.error
	if uint32(len(s)) > l {
		goto end
	}
	if p.IsInvalid(buf, uint64(l), MEMWRITE) {
		return
	}
	sh := (*runtime.StringHeader)(unsafe.Pointer(&s))
	runtime.Memmove(uintptr(buf), sh.Data, l)
end:
	p.ProcState.ax = uint64(len(s))
}
示例#4
0
func (p *Process) string(s, l /* i'm not really stanley lieber */ uint64) string {
	r := make([]byte, l)
	rh := (*runtime.SliceHeader)(unsafe.Pointer(&r))
	runtime.Memmove(rh.Data, uintptr(s), uint32(l))
	return string(r)
}