VM problem...

Pawel Jakub Dawidek nick at garage.freebsd.pl
Sun Jul 20 16:57:47 PDT 2003


Hello hackers...

I'll try to describe my problem carefully, maybe there will be someone
who will be able to help me with this.

Problem: Strage 'Bus errors'.

What I'm doing?

I allocate memory in process' vmspace with my version of obreak function.
It is quite simlar to those from /sys/vm/vm_unix.c.

	end = vm->vm_daddr + ctob(vm->vm_dsize);
	my_obreak(vm, end + size);

Now I'm marking newly allocated range as read-only (it is my version
of vm_map_protect() function, but is really simlar to):

	my_vm_protect(&vm->vm_map, end, end + size, VM_PROT_READ);

Now execve() for this process is called, so I can't remove this memory,
because this range isn't in process' vmspace anymore (I believe, that
it should be removed, by VM or execve()).

Process forks and now something happends in child and parent quits with
SIGBUS. I've add some debug to trapsignal() from /sys/kern/kern_sig.c.
Now I'm able to list every entry from process' vm_map with this function:

void
show_entries(struct proc *p)
{
	vm_map_entry_t entry;

	entry = p->p_vmspace->vm_map.hint;
	do {
		if ((entry->max_protection & VM_PROT_WRITE) == 0) {
			printf("ENTRY:%u: %p-%p (%d:%d)\n", p->p_pid,
			    (void *)entry->start, (void *)entry->end,
			    entry->protection, entry->max_protection);
		}
		entry = entry->next;
	} while (entry != p->p_vmspace->vm_map.hint);
}

So as you can see I'm listing every entry that isn't writable.
This function is called when process is killed by kernel with SIGBUS.
It shows me that only this region isn't writable:

	ENTRY:<PID>: 0-0xbfc00000 (0:0)

Ok! But all my allocations starts with 0x8xxxxxxx.

But core file that I get tells me, that:

	Cannot access memory at address 0xbfbffc20.

If I change VM_PROT_READ to VM_PROT_ALL when calling my_vm_protect()
everything is correct. There is no SIGBUS, but this region: 0-0xbfc00000
is still marked as not writable (and I really believe that it should be:)).

So how my allocations and read-only stuff interact with those bus errors?

PS. I'm CC-ing this to Matt Dillon also. I know he is quite busy now,
    but maybe he will be able to track this down.
PS2. I'm talking about FreeBSD 4.x here.

-- 
Pawel Jakub Dawidek                       pawel at dawidek.net
UNIX Systems Programmer/Administrator     http://garage.freebsd.pl
Am I Evil? Yes, I Am!                     http://cerber.sourceforge.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 305 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20030721/15b13b7d/attachment.bin


More information about the freebsd-hackers mailing list