Thread func parameter address problem (BSD 4.8)

Dan at Dan at
Tue Oct 14 11:59:16 PDT 2003


I have a threading runtime problem, and I was hoping you all could give
me a little direction.  I am writing a little divert sockets app on
FreeBSD 4.8 release.  I recompiled the kernel with the following

options 	MROUTING				# Multicast
options 	IPFIREWALL				#firewall
options 	IPFIREWALL_VERBOSE		#enable logging to
options 	IPFIREWALL_FORWARD		#enable transparent
proxy support
options 	IPFIREWALL_VERBOSE_LIMIT=100	#limit verbosity
options 	IPFIREWALL_DEFAULT_TO_ACCEPT	#allow everything by
options 	IPV6FIREWALL			#firewall for IPv6
options 	IPDIVERT				#divert sockets
options 	IPSTEALTH				#support for
stealth forwarding
options 	TCPDEBUG

# Because I have a dual Pentium pro
options 	SMP					# Symmetric
MultiProcessor Kernel
options 	APIC_IO				# Symmetric (APIC) I/O
options 	HTT					# HyperThreading

Things worked fine until I tried to add a thread to my code.  Here is my
init code:

void initialize_threads(sendqueuehead *sq, dc_info *pinfo)
	pthread_t pth;
	pthread_attr_t pth_atr = NULL;
	int retval = 0;

	if (pthread_mutex_init(&pth_mutex, NULL)) {
		syslog(LOGERR, "cannot create mutext)");
		perror("[initialize_threads] cannot create mutext");
	if (pthread_mutex_init(&pth_mutex_sendq, NULL)) {
		syslog(LOGERR, "cannot create mutext)");
		perror("[initialize_threads] cannot create mutext");

	pthread_attr_setdetachstate(&pth_atr, PTHREAD_CREATE_DETACHED);
	retval =pthread_create(&pth, &pth_atr, hacpackets, (char

	pthread_create(&pth, &pth_atr, heartbeat_timeout, sq);


When the function hacpackets() is started, its parameter address is off
by 1 byte.  In gdb, pinfo is fine in the initialize_threads functions,
but in the hacpackets() function (since the address is off by one) I get
a segmentation fault.  Do threads work OK on 4.8?  Is this an SMP
problem?  Any ideas?  Thanks for the help.

P.S.  My dmesg at boot...
Copyright (c) 1992-2003 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights
FreeBSD 4.8-RELEASE #2: Sun Aug 17 17:55:54 PDT 2003
    root at
Timecounter "i8254"  frequency 1193182 Hz
CPU: Pentium Pro (198.67-MHz 686-class CPU)
  Origin = "GenuineIntel"  Id = 0x617  Stepping = 7
real memory  = 134217728 (131072K bytes)
avail memory = 125902848 (122952K bytes)
Programming 24 pins in IOAPIC #0
FreeBSD/SMP: Multiprocessor motherboard
 cpu0 (BSP): apic id:  0, version: 0x00040011, at 0xfec08000
 cpu1 (AP):  apic id:  4, version: 0x00040011, at 0xfec08000
 io0 (APIC): apic id: 13, version: 0x00170011, at 0xfec00000
Preloaded elf kernel "kernel" at 0xc049a000.
Pentium Pro MTRR support enabled
md0: Malloc disk
npx0: <math processor> on motherboard
npx0: INT 16 interface
pcib0: <Host to PCI bridge> on motherboard
pci0: <PCI bus> on pcib0
isab0: <Intel 82371SB PCI to ISA bridge> at device 18.0 on pci0
isa0: <ISA bus> on isab0
atapci0: <Intel PIIX3 ATA controller> port 0xffa0-0xffaf at device 18.1
on pci0
ata0: at 0x1f0 irq 14 on atapci0
ata1: at 0x170 irq 15 on atapci0
pcib1: <DEC 21152 PCI-PCI bridge> at device 20.0 on pci0
pci1: <PCI bus> on pcib1
ahc0: <Adaptec aic7880 Ultra SCSI adapter> port 0xec00-0xecff mem
0xfaeff000-0xfaefffff irq 11 at device 5.0 on pci1
ahc0: Using left over BIOS settings
aic7880: Ultra Wide Channel A, SCSI Id=7, 16/253 SCBs
fxp0: <Intel Pro 10/100B/100+ Ethernet> port 0xe800-0xe81f mem
0xfad00000-0xfadfffff,0xf78ff000-0xf78fffff irq 11 at device 10.0 on
fxp0: Ethernet address 00:a0:c9:06:69:f7
nsphy0: <DP83840 10/100 media interface> on miibus0
nsphy0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
pci1: <Cirrus Logic GD5430 SVGA controller> at 15.0
orm0: <Option ROMs> at iomem
0xc0000-0xc7fff,0xc8000-0xccfff,0xe8000-0xe9fff,0xea000-0xebfff on isa0
fdc0: <NEC 72065B or clone> at port 0x3f0-0x3f5,0x3f7 irq 6 drq 2 on
fdc0: FIFO enabled, 8 bytes threshold
fd0: <1440-KB 3.5" drive> on fdc0 drive 0
atkbdc0: <Keyboard controller (i8042)> at port 0x60,0x64 on isa0
atkbd0: <AT Keyboard> flags 0x1 irq 1 on atkbdc0
kbd0 at atkbd0
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: model Generic PS/2 mouse, device ID 0
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on
sc0: <System console> at flags 0x100 on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0
sio0: type 16550A
sio1 at port 0x2f8-0x2ff irq 3 on isa0
sio1: type 16550A
ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
ep0: <3Com 3C509B-TPO EtherLink III (PnP)> at port 0x210-0x21f irq 5 on
ep0: Ethernet address 00:50:04:a3:08:82
APIC_IO: routing 8254 via 8259 and IOAPIC #0 intpin 0
IP packet filtering initialized, divert enabled, rule-based forwarding
enabled, default to accept, logging limited to 100 packets/entry by
Waiting 15 seconds for SCSI devices to settle
SMP: AP CPU #1 Launched!
da0 at ahc0 bus 0 target 0 lun 0
da0: <QUANTUM XP39100W LXY4> Fixed Direct Access SCSI-2 device
da0: 40.000MB/s transfers (20.000MHz, offset 8, 16bit), Tagged Queueing
da0: 8682MB (17781520 512 byte sectors: 64H 32S/T 8682C)
Mounting root from ufs:/dev/da1s1a
da1 at ahc0 bus 0 target 1 lun 0
da1: <IBM DGHS09V 03E0> Fixed Direct Access SCSI-3 device
da1: 40.000MB/s transfers (20.000MHz, offset 8, 16bit), Tagged Queueing
da1: 8748MB (17916240 512 byte sectors: 64H 32S/T 8748C)
cd0 at ahc0 bus 0 target 6 lun 0
cd0: <PLEXTOR CD-ROM PX-20TS 1.00> Removable CD-ROM SCSI-2 device
cd0: 10.000MB/s transfers (10.000MHz, offset 15)
cd0: Attempt to query device size failed: NOT READY, Medium not present
IP Filter: v3.4.31 initialized.  Default = pass all, Logging = enabled

More information about the freebsd-threads mailing list