aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr/arch/i386
Commit message (Collapse)AuthorAgeFilesLines
* libthr/amd64: do not set THR_C_RUNTIME for thr_new() if the main thread did ↵Konstantin Belousov2025-06-221-0/+2
| | | | | | | | | | | | | | used AMD64_SET_TLSBASE It is up to the code that organizes the runtime to properly set the signal handler, and to set %fsbase if libthr signal handler is to be called. The change should leave the CPU state on the signal handler entry identical to what it was before introduction of TLSBASE, for code that provides its own startup and thread pointer, but still calls into libthr as a hack. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* libc, libthr: Ditch MD __pthread_distribute_static_tls helpersJessica Clarke2025-05-291-44/+0
| | | | | | | | | | | | | | | | | | _libc_get_static_tls_base() is just _tcb_get() followed by adding (for Variant I) or subtracting (for Variant II) the offset, so just inline that as the implementation (like we do in rtld-elf) rather than having another copy (or equivalent) of _tcb_get()'s assembly. _get_static_tls_base() doesn't even have any MD assembly as it's reading thr->tcb, the only difference is whether to add or subtract, so again just inline that. Whilst here add some missing blank lines to comply with style(9) for elf_utils.c's includes, and use a pointer type rather than uintptr_t to reduce the need to cast, as is done in rtld-elf. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50592
* libthr: Preresolve selected EABI symbols on arm.Michal Meloun2024-07-251-0/+5
| | | | | | | | | | | Add the ability to pre-resolve architecture-specific EABI symbols and use it on arm for selected EABI functions. These functions can be called with rtld bind lock write-locked, so they should be resolved in forward. Reported by: Mark Millard <marklmi@yahoo.com>, John F Carr <jfc@mit.edu> Reviewed by: kib, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46104
* libthr _get_curthread i386: quiet gcc -Warray-boundsRyan Libby2024-07-031-2/+2
| | | | | | | | | Use a constant input operand instead of a bogus memory reference to tell the compiler about offsetof(struct tcb, tcb_thread) in the gs segment. Otherwise gcc complains if we tell it we are reading memory offset 0x8. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45829
* libthr: move _umtx_op_err() to libsysBrooks Davis2024-02-053-44/+0
| | | | | | | | | | | Declare in sys/umtx.h and implement in libsys. Explicitly link libthr with libsys. When building libthr static include _umtx_op_err so we don't break static linkage with -lpthread. Reviewed by: kib, emaste, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/908
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-163-6/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-122-2/+2
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* Remove PAGE_SIZE from libthrAndrew Turner2022-05-031-0/+3
| | | | | | | | | | | | | | | | | In libthr we use PAGE_SIZE when allocating memory with mmap and to check various structs will fit into a single page so we can use this allocator for them. Ask the kernel for the page size on init for use by the page allcator and add a new machine dependent macro to hold the smallest page size the architecture supports to check the structure is small enough. This allows us to use the same libthr on arm64 with either 4k or 16k pages. Reviewed by: kib, markj, imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34984
* libthr: Use <machine/tls.h> for most MD TLS details.John Baldwin2021-12-091-52/+6
| | | | | | | | | | Note that on amd64 this effectively removes the unused tcb_spare field from the end of struct tcb since the definition of struct tcb in <x86/tls.h> does not include that field. Reviewed by: kib, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33352
* libthr: Remove the DTV_OFFSET macro.John Baldwin2021-12-091-2/+0
| | | | | | | | | | This macro is confusing as it is not related to the similarly named TLS_DTV_OFFSET. Instead, replace its one use with the desired expression which is the same on all platforms. Reviewed by: kib, emaste, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33345
* Add CFI start/end proc directives to arm64, i386, and ppcConrad Meyer2020-12-051-1/+4
| | | | | | | | | | | | | | Follow-up to r353959 and r368070: do the same for other architectures. arm32 already seems to use its own .fnstart/.fnend directives, which appear to be ARM-specific variants of the same thing. Likewise, MIPS uses .frame directives. Reviewed by: arichardson Differential Revision: https://reviews.freebsd.org/D27387 Notes: svn path=/head/; revision=368354
* Fix initial exec TLS mode for dynamically loaded shared objects.Konstantin Belousov2019-03-291-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | If dso uses initial exec TLS mode, rtld tries to allocate TLS in static space. If there is no space left, the dlopen(3) fails. If space if allocated, initial content from PT_TLS segment is distributed to all threads' pcbs, which was missed and caused un-initialized TLS segment for such dso after dlopen(3). The mode is auto-detected either due to the relocation used, or if the DF_STATIC_TLS dynamic flag is set. In the later case, the TLS segment is tried to allocate earlier, which increases chance of the dlopen(3) to succeed. LLD was recently fixed to properly emit the flag, ld.bdf did it always. Initial test by: dumbbell Tested by: emaste (amd64), ian (arm) Tested by: Gerald Aryeetey <aryeeteygerald_rogers.com> (arm64) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D19072 Notes: svn path=/head/; revision=345703
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-261-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326219
* Disable SSE in libthrEric van Gyzen2015-08-051-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang emits SSE instructions on amd64 in the common path of pthread_mutex_unlock. If the thread does not otherwise use SSE, this usage incurs a context-switch of the FPU/SSE state, which reduces the performance of multiple real-world applications by a non-trivial amount (3-5% in one application). Instead of this change, I experimented with eagerly switching the FPU state at context-switch time. This did not help. Most of the cost seems to be in the read/write of memory--as kib@ stated--and not in the #NM handling. I tested on machines with and without XSAVEOPT. One counter-argument to this change is that most applications already use SIMD, and the number of applications and amount of SIMD usage are only increasing. This is absolutely true. I agree that--in general and in principle--this change is in the wrong direction. However, there are applications that do not use enough SSE to offset the extra context-switch cost. SSE does not provide a clear benefit in the current libthr code with the current compiler, but it does provide a clear loss in some cases. Therefore, disabling SSE in libthr is a non-loss for most, and a gain for some. I refrained from disabling SSE in libc--as was suggested--because I can't make the above argument for libc. It provides a wide variety of code; each case should be analyzed separately. https://lists.freebsd.org/pipermail/freebsd-current/2015-March/055193.html Suggestions from: dim, jmg, rpaulo Approved by: kib (mentor) MFC after: 2 weeks Sponsored by: Dell Inc. Notes: svn path=/head/; revision=286317
* Merge all the copies of _tcb_ctor and _tcb_dtor.Andrew Turner2015-01-213-64/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The amd64, i386, and sparc64 versions were identical, with the one difference where the former two used inline asm instead of _tcb_get. I have compared the function before and after replacing the asm with _tcb_get and found the object files to be identical. The arm, mips, and powerpc versions were almost identical. The only difference was the powerpc version used an alignment of 1 where arm and mips used 16. As this is an increase in alignment is will be safe. Along with this arm, mips, and powerpc all passed, when initial was true, the value returned from _tcb_get as the first argument to _rtld_allocate_tls. This would then return this pointer back to the caller. We can remove these extra calls by checking if initial is set and setting the thread control block directly. As this is what the sparc64 code does we can use it directly. As after these observations all the architectures can now have identical code we can merge them into a common file. Differential Revision: https://reviews.freebsd.org/D1556 Reviewed by: kib Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=277490
* The TCB_GET32() and TCB_GET64() macros in the i386 and amd64-specificDimitry Andric2011-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | versions of pthread_md.h have a special case of dereferencing a null pointer. Clang warns about this with: In file included from lib/libthr/arch/i386/i386/pthread_md.c:36: lib/libthr/arch/i386/include/pthread_md.h:96:10: error: indirection of non-volatile null pointer will be deleted, not trap [-Werror,-Wnull-dereference] return (TCB_GET32(tcb_self)); ^~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:73:13: note: expanded from: : "m" (*(u_int *)(__tcb_offset(name)))); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ lib/libthr/arch/i386/include/pthread_md.h:96:10: note: consider using __builtin_trap() or qualifying pointer with 'volatile' Since this indirection is done relative to the fs or gs segment, to retrieve thread-specific data, it is an exception to the rule. Therefore, add a volatile qualifier to tell the compiler we really want to dereference a zero address. MFC after: 1 week Notes: svn path=/head/; revision=228536
* Add section .note.GNU-stack for assembly files used by 386 and amd64.Konstantin Belousov2011-01-071-0/+2
| | | | Notes: svn path=/head/; revision=217107
* Merge from tbemd, with a small amount of rework:Warner Losh2010-09-131-2/+0
| | | | | | | | | | | | | For all libthr contexts, use ${MACHINE_CPUARCH} for all libc contexts, use ${MACHINE_ARCH} if it exists, otherwise use ${MACHINE_CPUARCH} Move some common code up a layer (the .PATH statement was the same in all the arch submakefiles). # Hope she hasn't busted powerpc64 with this... Notes: svn path=/head/; revision=212516
* Replace function _umtx_op with _umtx_op_err, the later function directlyDavid Xu2008-04-023-1/+40
| | | | | | | | | returns errno, because errno can be mucked by user's signal handler and most of pthread api heavily depends on errno to be correct, this change should improve stability of the thread library. Notes: svn path=/head/; revision=177853
* style.Makefile(5)David E. O'Brien2008-02-131-1/+1
| | | | Notes: svn path=/head/; revision=176226
* - Remove variable _thr_scope_system, all threads are system scope.David Xu2006-12-151-0/+2
| | | | | | | | - Rename _thr_smp_cpus to boolean variable _thr_is_smp. - Define CPU_SPINWAIT macro for each arch, only X86 supports it. Notes: svn path=/head/; revision=165241
* Remove declaration of _thr_initial from MD header file, it is no longerDavid Xu2006-04-041-2/+0
| | | | | | | needed. Notes: svn path=/head/; revision=157462
* Simplify _get_curthread() and _tcb_ctor because libc and rtld nowDavid Xu2006-04-042-8/+3
| | | | | | | | already allocate thread pointer space in tls block for initial thread. Only i386 and amd64 have been done, others still have to be tested. Notes: svn path=/head/; revision=157461
* Remove functions i386_get_gsbase and i386_set_gsbase, they were alreadyDavid Xu2006-01-071-14/+0
| | | | | | | in libc. Notes: svn path=/head/; revision=154095
* Kill unused variable declaration.David Xu2005-10-291-2/+0
| | | | Notes: svn path=/head/; revision=151836
* Remove COMPAT_32BIT, it is no longer needed.David Xu2005-04-271-5/+0
| | | | Notes: svn path=/head/; revision=145578
* Remove unused variable.David Xu2005-04-231-1/+0
| | | | Notes: svn path=/head/; revision=145438
* Now libthr only uses GDT based tls on i386. using LDT can only increaseDavid Xu2005-04-232-53/+3
| | | | | | | clock cycles and has 8191 threads limitation. Notes: svn path=/head/; revision=145437
* Add i386_get_gsbase, i386_set_gsbase since old libc doesn't have theDavid Xu2005-04-231-0/+14
| | | | | | | functions, otherwise user ports have to be rebuilt. Notes: svn path=/head/; revision=145431
* Adapt the libpthread patch for using i386_set_gsbase() to libthr.Peter Wemm2005-04-142-16/+41
| | | | Notes: svn path=/head/; revision=145040
* Import my recent 1:1 threading working. some features improved includes:David Xu2005-04-025-155/+202
| | | | | | | | | | | | | | | | | | | 1. fast simple type mutex. 2. __thread tls works. 3. asynchronous cancellation works ( using signal ). 4. thread synchronization is fully based on umtx, mainly, condition variable and other synchronization objects were rewritten by using umtx directly. those objects can be shared between processes via shared memory, it has to change ABI which does not happen yet. 5. default stack size is increased to 1M on 32 bits platform, 2M for 64 bits platform. As the result, some mysql super-smack benchmarks show performance is improved massivly. Okayed by: jeff, mtm, rwatson, scottl Notes: svn path=/head/; revision=144518
* Fix inverted #ifdef that I added. Who had the pointy hat last?Peter Wemm2004-12-061-1/+1
| | | | | | | Submitted by: kan Notes: svn path=/head/; revision=138494
* Use the recently exposed fs/gs set functions when compiling libthr toPeter Wemm2004-11-061-0/+12
| | | | | | | | | | run as a 32 bit support library for an amd64 kernel. 32 bit consumers of libthr have zero chance of running on an amd64 kernel since we don't implement the i386_set_ldt() family of functions. Note that this commit doesn't make it actually work, it just removes one more obstacle. Notes: svn path=/head/; revision=137292
* Adjust code to support AMD64, on AMD64, thread needs to set fsbase byDavid Xu2004-08-191-3/+10
| | | | | | | | itself before it can execute any other code, so new thread should be created with all signals are masked until after fsbase is set. Notes: svn path=/head/; revision=134051
* Add TLS support for libthr on i386.Doug Rabson2004-08-152-74/+29
| | | | Notes: svn path=/head/; revision=133755
* Make NULL a (void*)0 whereever possible, and fix the warnings(-Werror)Mark Murray2004-03-051-1/+1
| | | | | | | | | | | | | | | | | | that this provokes. "Wherever possible" means "In the kernel OR NOT C++" (implying C). There are places where (void *) pointers are not valid, such as for function pointers, but in the special case of (void *)0, agreement settles on it being OK. Most of the fixes were NULL where an integer zero was needed; many of the fixes were NULL where ascii <nul> ('\0') was needed, and a few were just "other". Tested on: i386 sparc64 Notes: svn path=/head/; revision=126643
* Bump up the maximum number concurrent threads on x86.Mike Makonnen2004-02-011-1/+1
| | | | Notes: svn path=/head/; revision=125307
* Use dynamic instead of static LDT allocation.Mike Makonnen2003-12-021-5/+4
| | | | | | | Approved by: re (scottl) Notes: svn path=/head/; revision=123107
* The move to _retire() a thread in the GC instead of in the thread'sMike Makonnen2003-06-291-4/+2
| | | | | | | | | | exit function has invalidated the need for _spin[un]lock_pthread(). The _spin[un]lock() functions can now dereference curthread without the danger that the ldtentry containing the pointer to the thread has been cleared out from under them. Notes: svn path=/head/; revision=117012
* .S comments must be C comments, not ASM ones.David E. O'Brien2003-06-021-1/+1
| | | | Notes: svn path=/head/; revision=115666
* Missing unlock.Mike Makonnen2003-05-291-0/+2
| | | | | | | Approved by: re/jhb Notes: svn path=/head/; revision=115388
* Return gracefully, rather than aborting, when the maximum concurrentMike Makonnen2003-05-251-3/+8
| | | | | | | | | threads per process has been reached. Return EAGAIN, as per spec. Approved by: re/blanket libthr Notes: svn path=/head/; revision=115313
* Add two functions: _spinlock_pthread() and _spinunlock_pthread()Mike Makonnen2003-05-231-2/+4
| | | | | | | | | | | | | that take the address of a struct pthread as their first argument. _spin[un]lock() just become wrappers arround these two functions. These new functions are for use in situations where curthread can't be used. One example is _thread_retire(), where we invalidate the array index curthread uses to get its pointer.. Approved by: re/blanket libthr Notes: svn path=/head/; revision=115271
* Make WARNS2 clean. The fixes mostly included:Mike Makonnen2003-05-231-0/+5
| | | | | | | | | | | o removed unused variables o explicit inclusion of header files o prototypes for externally defined functions Approved by: re/blanket libthr Notes: svn path=/head/; revision=115260
* o Make the defenition of _set_curthread() match its declarationMike Makonnen2003-05-211-5/+27
| | | | | | | | | | | | | | | in thr_private.h o Lock down the ldt_entries array and ldt_free, which points to the next free slot. As noted in the comments, it's necessary to special case the initial_thread because %gs is not setup for it yet. This is ok because that early in the program there won't be any reentrancy issues anyways. Approved by: re/blanket libthr Notes: svn path=/head/; revision=115203
* Fix a null dereference leading to a core dump whenMike Makonnen2003-05-061-1/+4
| | | | | | | | | | | the number of threads exceeds the number of open slots in ldt_entries[]. Approved by: markm (mentor)(implicit) Reviewed by: jeff Notes: svn path=/head/; revision=114773
* - Pass a ucontext_t to _set_curthread. If non-NULL the new thread is setJake Burkholder2003-04-031-2/+6
| | | | | | | | | | | as curthread in the new context, so that it will be set automatically when the thread is switched to. This fixes a race where we'd run for a little while with curthread unset in _thread_start. Reviewed by: jeff Notes: svn path=/head/; revision=112995
* - Don't overrun the ldt buffer.Jeff Roberson2003-04-021-2/+2
| | | | | | | Submitted by: gordan@freebsd.org Notes: svn path=/head/; revision=112992
* - Adjust the makefiles so we have a per architecture makefile.Jeff Roberson2003-04-011-0/+5
| | | | Notes: svn path=/head/; revision=112925