Re: gem(4): simplify gem_attach_pci() variant detection code a bit
I prefer a switch too, it shows you acknowledged those variants, anyhow i think the current idiom is bad and should be changed.
Re: gem(4): simplify gem_attach_pci() variant detection code a bit
On Wed, Sep 26, 2012 at 03:32:37PM -0400, Brad Smith wrote: Simplify the gem(4) variant detection code a bit. OK? How about this.. Index: if_gem_pci.c === RCS file: /home/cvs/src/sys/dev/pci/if_gem_pci.c,v retrieving revision 1.32 diff -u -p -r1.32 if_gem_pci.c --- if_gem_pci.c3 Apr 2011 15:36:02 - 1.32 +++ if_gem_pci.c28 Sep 2012 05:16:00 - @@ -227,22 +227,19 @@ gem_attach_pci(struct device *parent, st sc-sc_pci = 1; /* X should all be done in bus_dma. */ - if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_GEMNETWORK) + switch (PCI_PRODUCT(pa-pa_id)) { + case PCI_PRODUCT_SUN_GEMNETWORK: sc-sc_variant = GEM_SUN_GEM; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_ERINETWORK) + break; + case PCI_PRODUCT_SUN_ERINETWORK: sc-sc_variant = GEM_SUN_ERI; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_PANGEA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTHGMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTH2GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_K2_GMAC) + break; + case PCI_PRODUCT_APPLE_K2_GMAC: sc-sc_variant = GEM_APPLE_K2_GMAC; + break; + default: + sc-sc_variant = GEM_APPLE_GMAC; + } #define PCI_GEM_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0, -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Re: gem(4): simplify gem_attach_pci() variant detection code a bit
On Fri, Sep 28, 2012 at 02:42:18AM -0400, Brad Smith wrote: On Wed, Sep 26, 2012 at 03:32:37PM -0400, Brad Smith wrote: Simplify the gem(4) variant detection code a bit. OK? How about this.. Index: if_gem_pci.c === RCS file: /home/cvs/src/sys/dev/pci/if_gem_pci.c,v retrieving revision 1.32 diff -u -p -r1.32 if_gem_pci.c --- if_gem_pci.c 3 Apr 2011 15:36:02 - 1.32 +++ if_gem_pci.c 28 Sep 2012 05:16:00 - @@ -227,22 +227,19 @@ gem_attach_pci(struct device *parent, st sc-sc_pci = 1; /* X should all be done in bus_dma. */ - if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_GEMNETWORK) + switch (PCI_PRODUCT(pa-pa_id)) { + case PCI_PRODUCT_SUN_GEMNETWORK: sc-sc_variant = GEM_SUN_GEM; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_ERINETWORK) + break; + case PCI_PRODUCT_SUN_ERINETWORK: sc-sc_variant = GEM_SUN_ERI; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_PANGEA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTHGMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTH2GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_K2_GMAC) + break; + case PCI_PRODUCT_APPLE_K2_GMAC: sc-sc_variant = GEM_APPLE_K2_GMAC; + break; + default: + sc-sc_variant = GEM_APPLE_GMAC; + } #define PCI_GEM_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0, Ok by me, but when I said acknowledge I meant this, I'm ok with either, if kettenis doesn't mind :=). Index: if_gem_pci.c === RCS file: /cvs/src/sys/dev/pci/if_gem_pci.c,v retrieving revision 1.32 diff -d -u -p -r1.32 if_gem_pci.c --- if_gem_pci.c3 Apr 2011 15:36:02 - 1.32 +++ if_gem_pci.c28 Sep 2012 07:26:23 - @@ -227,22 +227,27 @@ gem_attach_pci(struct device *parent, st sc-sc_pci = 1; /* X should all be done in bus_dma. */ - if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_GEMNETWORK) + switch (PCI_PRODUCT(pa-pa_id)) { + case PCI_PRODUCT_SUN_GEMNETWORK: sc-sc_variant = GEM_SUN_GEM; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_ERINETWORK) + break; + case PCI_PRODUCT_SUN_ERINETWORK: sc-sc_variant = GEM_SUN_ERI; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_PANGEA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTHGMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTH2GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_K2_GMAC) + break; + case PCI_PRODUCT_APPLE_K2_GMAC: sc-sc_variant = GEM_APPLE_K2_GMAC; + break; + case PCI_PRODUCT_APPLE_INTREPID2_GMAC: + case PCI_PRODUCT_APPLE_PANGEA_GMAC: + case PCI_PRODUCT_APPLE_SHASTA_GMAC: + case PCI_PRODUCT_APPLE_UNINORTHGMAC: + case PCI_PRODUCT_APPLE_UNINORTH2GMAC: + sc-sc_variant = GEM_APPLE_GMAC; + break; + default: + printf(: unknown variant 0x%x\n, sc-sc_variant); + return; + } #define PCI_GEM_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0,
Re: Threads related SIGSEGV in random.c (diff, v2)
On Thu, 27 Sep 2012, Alexey Suslikov wrote: On Thursday, September 27, 2012, Alexey Suslikov wrote: On Thursday, September 27, 2012, Philip Guenther wrote: On Thu, 27 Sep 2012, Alexey Suslikov wrote: Removing only local variables part reverts us to previous behavior (i.e. crashes). My guess is your program is calling srandom(), srandomdev(), initstate() or setstate() as well. Your diff doesn't protect the alteration of state, end_ptr, fptr, and rptr on those paths, so a call to initstate() while another thread is in random() can walk fptr and/or rptr out of the state array. Add the necessary locking in them and run your tests again. Have you done this? You based your patch on changes made to some other BSD (NetBSD, IIRC): have you put in place all the locking calls that they did? If not, why are wasting everyone's time by ignoring their work? I'm starting to believe that static globals are not good. They are incredibly good at what they do. If you're trying to say that they fundamentally can't be thread-safe, you'll need some extraordinary evidence for such a claim. What good they do? Static globals provide low overhead shared storage that doesn't pollute the global namespace. Philip, can you help us to write threaded test case (spawning a number of threads each calling random)? Sorry, this isn't near the top of my TODO list, and I've already made my suggestions on what you should be trying. Philip Guenther
Re: gem(4): simplify gem_attach_pci() variant detection code a bit
On Fri, Sep 28, 2012 at 09:31:34AM +0200, Christiano F. Haesbaert wrote: On Fri, Sep 28, 2012 at 02:42:18AM -0400, Brad Smith wrote: On Wed, Sep 26, 2012 at 03:32:37PM -0400, Brad Smith wrote: Simplify the gem(4) variant detection code a bit. OK? How about this.. Index: if_gem_pci.c === RCS file: /home/cvs/src/sys/dev/pci/if_gem_pci.c,v retrieving revision 1.32 diff -u -p -r1.32 if_gem_pci.c --- if_gem_pci.c3 Apr 2011 15:36:02 - 1.32 +++ if_gem_pci.c28 Sep 2012 05:16:00 - @@ -227,22 +227,19 @@ gem_attach_pci(struct device *parent, st sc-sc_pci = 1; /* X should all be done in bus_dma. */ - if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_GEMNETWORK) + switch (PCI_PRODUCT(pa-pa_id)) { + case PCI_PRODUCT_SUN_GEMNETWORK: sc-sc_variant = GEM_SUN_GEM; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_ERINETWORK) + break; + case PCI_PRODUCT_SUN_ERINETWORK: sc-sc_variant = GEM_SUN_ERI; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_PANGEA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTHGMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTH2GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_K2_GMAC) + break; + case PCI_PRODUCT_APPLE_K2_GMAC: sc-sc_variant = GEM_APPLE_K2_GMAC; + break; + default: + sc-sc_variant = GEM_APPLE_GMAC; + } #define PCI_GEM_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0, Ok by me, but when I said acknowledge I meant this, I'm ok with either, if kettenis doesn't mind :=). Index: if_gem_pci.c === RCS file: /cvs/src/sys/dev/pci/if_gem_pci.c,v retrieving revision 1.32 diff -d -u -p -r1.32 if_gem_pci.c --- if_gem_pci.c 3 Apr 2011 15:36:02 - 1.32 +++ if_gem_pci.c 28 Sep 2012 07:26:23 - @@ -227,22 +227,27 @@ gem_attach_pci(struct device *parent, st sc-sc_pci = 1; /* X should all be done in bus_dma. */ - if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_GEMNETWORK) + switch (PCI_PRODUCT(pa-pa_id)) { + case PCI_PRODUCT_SUN_GEMNETWORK: sc-sc_variant = GEM_SUN_GEM; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_SUN_ERINETWORK) + break; + case PCI_PRODUCT_SUN_ERINETWORK: sc-sc_variant = GEM_SUN_ERI; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_INTREPID2_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_PANGEA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_SHASTA_GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTHGMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_UNINORTH2GMAC) - sc-sc_variant = GEM_APPLE_GMAC; - else if (PCI_PRODUCT(pa-pa_id) == PCI_PRODUCT_APPLE_K2_GMAC) + break; + case PCI_PRODUCT_APPLE_K2_GMAC: sc-sc_variant = GEM_APPLE_K2_GMAC; + break; + case PCI_PRODUCT_APPLE_INTREPID2_GMAC: + case PCI_PRODUCT_APPLE_PANGEA_GMAC: + case PCI_PRODUCT_APPLE_SHASTA_GMAC: + case PCI_PRODUCT_APPLE_UNINORTHGMAC: + case PCI_PRODUCT_APPLE_UNINORTH2GMAC: + sc-sc_variant = GEM_APPLE_GMAC; + break; + default: + printf(: unknown variant 0x%x\n, sc-sc_variant); + return; + } #define PCI_GEM_BASEADDR 0x10 if (pci_mapreg_map(pa, PCI_GEM_BASEADDR, type, 0, This is better IMHO. I was mildly concerned about the previous versions that seemed to recognize previously unknown chips. ok krw@ Ken
[hppa64] mkboot fix
This allows mkboot make bootable lif's. mkboot compiled on amd64, tested with rp2470. Index: mkboot.c === RCS file: /cvs/src/sys/arch/hppa64/stand/mkboot/mkboot.c,v retrieving revision 1.2 diff -u -p -r1.2 mkboot.c --- mkboot.c27 Oct 2009 23:59:34 - 1.2 +++ mkboot.c28 Sep 2012 13:32:53 - @@ -117,10 +117,10 @@ main(int argc, char **argv) bzero(buf, sizeof(buf)); /* clear possibly unused directory entries */ memset(lifd[1].dir_name, ' ', sizeof lifd[1].dir_name); - lifd[1].dir_type = -1; + lifd[1].dir_type = htobe16(-1); lifd[1].dir_addr = 0; lifd[1].dir_length = 0; - lifd[1].dir_flag = 0xFF; + lifd[1].dir_flag = htobe16(0xFF); lifd[1].dir_implement = 0; lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1]; @@ -131,7 +131,7 @@ main(int argc, char **argv) lifv-vol_oct = htobe16(LIF_VOL_OCT); lifv-vol_dirsize = htobe32(btolifs(LIF_DIRSIZE)); lifv-vol_version = htobe16(1); - lifv-vol_lastvol = lifv-vol_number = htobe16(1); + lifv-vol_lastvol = lifv-vol_number = htobe32(1); lifv-vol_length = LIF_FILESTART; bcddate(to_file, lifv-vol_toc); lifv-ipl_addr = htobe32(LIF_FILESTART); @@ -211,12 +211,12 @@ putfile(from_file, to) n = read(from, elf_header, sizeof (elf_header)); if (n != sizeof (elf_header)) err(1, %s: reading ELF header, from_file); - header_count = betoh32(elf_header.e_phnum); + header_count = betoh16(elf_header.e_phnum); memory_needed = header_count * sizeof (*elf_segments); elf_segments = malloc(memory_needed); if (elf_segments == NULL) err(1, malloc); - (void) lseek(from, betoh32(elf_header.e_phoff), SEEK_SET); + (void) lseek(from, betoh64(elf_header.e_phoff), SEEK_SET); n = read(from, elf_segments, memory_needed); if (n != memory_needed) err(1, %s: reading ELF segments, from_file); @@ -233,9 +233,10 @@ putfile(from_file, to) } if (elf_load_image_segment == -1) errx(1, %s: no suitable ELF program segment, from_file); - entry = betoh32(elf_header.e_entry) + - betoh32(elf_segments[elf_load_image_segment].p_offset) - - betoh32(elf_segments[elf_load_image_segment].p_vaddr); + entry = betoh64(elf_header.e_entry) + + betoh64(elf_segments[elf_load_image_segment].p_offset) - + betoh64(elf_segments[elf_load_image_segment].p_vaddr); + printf(entry = 0x%lx\n, entry); } else if (*(u_char *)ex == 0x1f ((u_char *)ex)[1] == 0x8b) { entry = 0; } else -- open source wizard
Re: gem(4): simplify gem_attach_pci() variant detection code a bit
On 2012/09/28 10:08, Kenneth R Westerback wrote: This is better IMHO. I was mildly concerned about the previous versions that seemed to recognize previously unknown chips. ok krw@ The driver won't attach to unknown chips anyway, if someone adds a new id to gem_pci_devices[], either the variant setting is correct (in which case no problem) or it's wrong (in which case it won't work anyway), so isn't it a bit unnecessary to do the extra check?
10月26日北京会议通知
23:13:06 [demime 1.01d removed an attachment of type application/octet-stream which had a name of =?utf-8?B?56eR5oqA6aG555uu6LWE6YeR55Sz5oql5LiO55+l6K+G5Lqn5p2D566h55CGKOWMl+S6rCkuZG9j?=]
802.11 power save fixes
I enabled power save for an rt2860 AP using the following diff: Index: sys/dev/ic/rt2860.c === RCS file: /cvs/src/sys/dev/ic/rt2860.c,v retrieving revision 1.65 diff -u -p -r1.65 sys/dev/ic/rt2860.c --- sys/dev/ic/rt2860.c 23 Oct 2010 14:24:54 - 1.65 +++ sys/dev/ic/rt2860.c 17 Sep 2012 12:15:41 - @@ -303,9 +303,7 @@ rt2860_attachhook(void *xsc) #ifndef IEEE80211_STA_ONLY IEEE80211_C_IBSS | /* IBSS mode supported */ IEEE80211_C_HOSTAP |/* HostAP mode supported */ -#ifdef notyet IEEE80211_C_APPMGT |/* HostAP power management */ -#endif #endif IEEE80211_C_SHPREAMBLE |/* short preamble supported */ IEEE80211_C_SHSLOT |/* short slot time supported */ I found that some devices (android phones) would eventually fail to associate. An ifconfig scan on the AP shows that the node would end up in IEEE80211_STA_COLLECT status with power save enabled. Attempts by the station to authenticate would then fail because the AP buffered the authentication responses. The AP refuses to change the power save status of a node that is not associated, which in turn prevents the station from associating. The first part of the solution is to clear the power save mode and savedq in ieee80211_node_leave: Index: ieee80211_node.c === RCS file: /cvs/src/sys/net80211/ieee80211_node.c,v retrieving revision 1.74 diff -u -p -r1.74 ieee80211_node.c --- ieee80211_node.c20 Sep 2012 17:21:13 - 1.74 +++ ieee80211_node.c28 Sep 2012 13:35:52 - @@ -1604,8 +1604,18 @@ ieee80211_node_leave(struct ieee80211com return; } - if (ni-ni_pwrsave == IEEE80211_PS_DOZE) + if (ni-ni_pwrsave == IEEE80211_PS_DOZE) { ic-ic_pssta--; + ni-ni_pwrsave = IEEE80211_PS_AWAKE; + } + +#ifndef IEEE80211_STA_ONLY + if (!IF_IS_EMPTY(ni-ni_savedq)) { + IF_PURGE(ni-ni_savedq); + if (ic-ic_set_tim != NULL) + (*ic-ic_set_tim)(ic, ni-ni_associd, 0); + } +#endif if (ic-ic_flags IEEE80211_F_RSNON) ieee80211_node_leave_rsn(ic, ni); This solves the problem providing the node leaves (either by disassociating or by timeout) before trying to reauthenticate. However if an associated station crashes while power save is enabled and then attempts to reauthenticate with the power save flag set the power save mode would become latched for that node. Normally this situation would be avoided because a station would not set the power save flag during authentication, but it can be avoided without relying on the behaviour of the station by preventing nodes from transitioning directly from IEEE80211_STA_ASSOC to IEEE80211_STA_AUTH. This has the additional benefit of preventing a rogue station from forcing an already associated node back to authenticated state, resulting in a DoS of an associated station. Index: ieee80211_proto.c === RCS file: /cvs/src/sys/net80211/ieee80211_proto.c,v retrieving revision 1.46 diff -u -p -r1.46 ieee80211_proto.c --- ieee80211_proto.c 18 Jan 2012 14:35:56 - 1.46 +++ ieee80211_proto.c 28 Sep 2012 13:35:53 - @@ -721,7 +721,8 @@ ieee80211_auth_open(struct ieee80211com ether_sprintf((u_int8_t *)ni-ni_macaddr), ni-ni_state != IEEE80211_STA_CACHE ? newly : already); - ieee80211_node_newstate(ni, IEEE80211_STA_AUTH); + if (ni-ni_state != IEEE80211_STA_ASSOC) + ieee80211_node_newstate(ni, IEEE80211_STA_AUTH); break; #endif /* IEEE80211_STA_ONLY */ Nathanael
[PATCH, TEST] Make functions in random.c thread safe
Hi. With input from tedu@, guenther@ and others, below are: 1) test case; 2) backtrace for test case; 3) locking diff; 4) dmesg (amd64 GENERIC.MP built from 2012-09-28 CVS). Diff introduces no changes to srandomdev(): correct me if I'm wrong, but no mutex can be used since sysctl can sleep. Rebuild and reinstall in src/lib/librthread and src/lib/libc after applying the diff. Expect test case (and Kannel port of course) not crashing after rebuild and reinstall. Cheers, Alexey 1) test case. #include pthread.h #include stdio.h #include stdlib.h #include assert.h #include unistd.h #define NUM_THREADS1800 void *TaskCode(void *argument) { struct timeval tv; gettimeofday(tv, 0); srandom((getpid() 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); return NULL; } int main(void) { pthread_t threads[NUM_THREADS]; int thread_args[NUM_THREADS]; int rc, i; /* create all threads */ for (i=0; iNUM_THREADS; ++i) { thread_args[i] = i; rc = pthread_create(threads[i], NULL, TaskCode, (void *) thread_args[i]); assert(0 == rc); } /* wait for all threads to complete */ for (i=0; iNUM_THREADS; ++i) { rc = pthread_join(threads[i], NULL); assert(0 == rc); } printf(Test srandom success\n); exit(EXIT_SUCCESS); } 2) backtrace for test case. Program received signal SIGSEGV, Segmentation fault. [Switching to thread 1030380] 0x19d34d618f8e in random () at /usr/src/lib/libc/stdlib/random.c:387 387 *fptr += *rptr; (gdb) bt #0 0x19d34d618f8e in random () at /usr/src/lib/libc/stdlib/random.c:387 #1 0x19d34d619169 in srandom (x=Variable x is not available. ) at /usr/src/lib/libc/stdlib/random.c:216 #2 0x19d14fe1 in TaskCode (argument=0x7f7ea004) at test_srandom.c:14 #3 0x19d34999d11e in _rthread_start (v=Variable v is not available. ) at /usr/src/lib/librthread/rthread.c:122 #4 0x19d34d5f0f9b in __tfork_thread () at /usr/src/lib/libc/arch/amd64/sys/tfork_thread.S:75 Cannot access memory at address 0x19d344efb000 3) locking diff. Index: lib/libc/include/thread_private.h === RCS file: /cvs/src/lib/libc/include/thread_private.h,v retrieving revision 1.25 diff -u -p -r1.25 thread_private.h --- lib/libc/include/thread_private.h 16 Oct 2011 06:29:56 - 1.25 +++ lib/libc/include/thread_private.h 27 Sep 2012 10:48:45 - @@ -172,4 +172,16 @@ void _thread_arc4_unlock(void); _thread_arc4_unlock();\ } while (0) +void _thread_random_lock(void); +void _thread_random_unlock(void); + +#define _RANDOM_LOCK() do {\ + if (__isthreaded) \ + _thread_random_lock(); \ + } while (0) +#define _RANDOM_UNLOCK() do {\ + if (__isthreaded) \ + _thread_random_unlock();\ + } while (0) + #endif /* _THREAD_PRIVATE_H_ */ Index: lib/libc/stdlib/random.c === RCS file: /cvs/src/lib/libc/stdlib/random.c,v retrieving revision 1.17 diff -u -p -r1.17 random.c --- lib/libc/stdlib/random.c1 Jun 2012 01:01:57 - 1.17 +++ lib/libc/stdlib/random.c27 Sep 2012 10:48:45 - @@ -35,6 +35,10 @@ #include stdio.h #include stdlib.h #include unistd.h +#include thread_private.h + +static void srandom_unlocked(unsigned int); +static long random_unlocked(void); /* * random.c: @@ -186,8 +190,8 @@ static int rand_sep = SEP_3; * introduced by the L.C.R.N.G. Note that the initialization of randtbl[] * for default usage relies on values produced by this routine. */ -void -srandom(unsigned int x) +static void +srandom_unlocked(unsigned int x) { int i; int32_t test; @@ -213,10 +217,18 @@ srandom(unsigned int x) fptr = state[rand_sep]; rptr = state[0]; for (i = 0; i 10 * rand_deg; i++) - (void)random(); + (void)random_unlocked(); } } +void +srandom(unsigned int x) +{ + _RANDOM_LOCK(); + srandom_unlocked(x); + _RANDOM_UNLOCK(); +} + /* * srandomdev: * @@ -273,12 +285,15 @@ initstate(u_int seed, char *arg_state, s { char *ostate = (char *)(state[-1]); + _RANDOM_LOCK(); if (rand_type == TYPE_0) state[-1] = rand_type; else state[-1] = MAX_TYPES * (rptr - state) + rand_type; - if (n BREAK_0) + if (n BREAK_0) { +