Subject: Are posix semaphores broken on current?
To: None <current-users@netbsd.org>
From: Tobias Nygren <tnn@NetBSD.org>
List: current-users
Date: 06/15/2007 17:56:48
Hi all,

I am able to trigger a panic on ~current with this code:

#include <semaphore.h>
#include <stdio.h>
sem_t s1;
int
main(void)
{
        if (sem_init(&s1, 0, 1) == -1)
                printf("fail\n");
	return 0;
}

On exit I end up with:

panic: lockdebug_lookup: uninitialized lock (1, id=-559038737)
Stopped in pid 112.1 (testcase) at      netbsd:cpu_Debugger+0x4
         popl    %ebp
db> bt
cpu_Debugger(c09d26d3,cd1eea98,c166b6d0,c047633e,c04c1d87)
at netbsd:cpu_Debugger+0x4
panic(c0a06dec,deadbeef,c1fb0040,c047a0f7,c04c1dce)
at netbsd:panic+0x155
lockdebug_abort(deadbeef,c1fb0050,c0a5666c,c0802ab0,c09a6d78)
at netbsd:lockdebug_abort+0x121
mutex_abort(c1fb0050,c0802ab0,c09a6d78,a8,c1cdf2b0)
at netbsd:mutex_abort+0x3c
mutex_vector_exit(c1fb0050,1,0,cc844e88,c1cd561c)
at netbsd:mutex_vector_exit+0x119
ksem_proc_dtor(c1cdf320,cca9fa90,0,cc8b8408,cbdaa0b4)
at netbsd:ksem_proc_dtor+0x4f
specificdata_destroy_datum(cbdaa014,c080329c,879,cc844e88,cc8b83a4)
at netbsd:specificdata_destroy_datum+0x35
specificdata_fini(cbdaa014,cc8b8408,cd1eebfc,c046f4d0,cc8b83a4)
at netbsd:specificdata_fini+0x5c
proc_finispecific(cc8b83a4,cc845f10,0,0,cc8b83bc)
at netbsd:proc_finispecific+0x1d
exit1(ccc16880,a00,bfbfee0c,bfbfee38,ccc16880) at netbsd:exit1+0x2b0
fork1(ccc16880,cd1eec48,cd1eec68,804b000,804b000) at netbsd:fork1
syscall_plain() at netbsd:syscall_plain+0xb9
--- syscall (number 1) ---
0xbbba20b7:
db> reboot 0x4
uhci0: host controller halted
rebooting...

I know I should be using sem_destroy(&s1) but forgetting to do
this is not an excuse to panic :-)
And another thing: according to the sem_init(3) manpage we don't
support "pshared" semaphores. A call to sem_init with pshared
set to nonzero should fail. But it doesn't. The library code
for sem_init just ignores the value of pshared.

kind regards,
-Tobias