To align with other supported POSIX features, add logging to
pthread key to provide better error reporting and diagnostics.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
pthread_cleanup_push() and pthread_cleanup_pop() are required
by the POSIX_THREADS_BASE Option Group as detailed in Section
E.1 of IEEE-1003.1-2017.
The POSIX_THREADS_BASE Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
In this change, we require the addition of a dedicated
pthread_key_t that will not be available for applilcation usage.
Rather than including that as part of
CONFIG_MAX_PTHREAD_KEY_COUNT, we increase the storage by 1 in
order to be least invasive from the application perspective.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Initialize the variable to zero. I don't think there is any way
out of this function without it being initialized, so IMHO it's
a false positive.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Zephyr must support all functionality of the XSI_THREADS_EXT
subprofiling option group in order to claim it supports that
subprofiling option group.
The XSI_THREADS_EXT option group is critical to be able to
run POSIX threads with statically allocated thread stacks, which
has been a feature of the implementation since it was initially
added.
The pthread_getconcurrency() and pthread_setconcurrency()
functions are the only remaining, unimplemented functions of
the XSI_THREADS_EXT option group.
Implement pthread_getconcurrency() and pthread_setconcurrency()
via the more "posixly correct" interpretation of the
specification.
I.e. as the pthread_t:k_thread relationship is 1:1 and not M:N,
Zephyr does not support multiplexing of user threads on top of
schedulable kernel entities (i.e. "user threads" are directly
mapped to native threads, just like linuxthreads or NPTL are in
Linux).
For that reason, to be "posixly correct", we should save the
provided value via pthread_setconcurrency(), in the absense of
errors, and also return that same value back via
pthread_getconcurrency(), even though that serves zero purpose
in Zephyr for the foreseeable future.
Note: the specification also states
"an implementation can always ignore any calls to
pthread_setconcurrency() and return a constant for
pthread_getconcurrency()."
For that reason, the implementation may be revisited at a later
time when when considering optimizations and when there is a
better system in place for documenting deviations.
Any such optimization should be explicitly controlled via
Kconfig.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
pthread_setcanceltype() is required by the POSIX_THREADS_BASE
Option Group as detailed in Section E.1 of IEEE-1003.1-2017.
The POSIX_THREADS_BASE Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory
for any POSIX conforming system as per Section A.2.1.3 of
IEEE-1003-1.2017.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
_PTHREAD_CANCEL_POS is an implementation detail and should not
be defined in the global scope. Furthermore, _PTHREAD_CANCEL_POS
uses a reserved identifier (underscore followed by capital
letter).
Adjust definitions so that the implementation detail is only
used in the implementation and not in the interface.
Additionally, modify naming so that the non-standard macro does
not use a reserved identifier.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
* "identity" functions grouped more closely
* posix_thread_pool_init() should be adjacent to the SYS_INIT()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously, `pthread_key_delete()` was only ever deleting key 0
rather than the key corresponding to the provided argument.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
pthread_atfork() is required by the POSIX_THREADS_BASE
Option Group as detailed in Section E.1 of IEEE-1003.1-2017.
The POSIX_THREADS_BASE Option Group is required for PSE51,
PSE52, PSE53, and PSE54 conformance, and is otherwise
mandatory for any POSIX conforming system as per Section
A.2.1.3 of IEEE-1003-1.2017.
Since Zephyr does not yet support processes and (by extension)
fork(), this implementation includes a deviation and should be
categorized as producing undefined behaviour.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add a Kconfig option to tell whether or not using thread
local storage to store current thread.
The function using it can be called from ISR and using
TLS variables in this context may (should ???) not be
allowed
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
Picolibc's 'minimal' printf mode reduces functionality and size even more
than the 'integer' mode. Use this where memory is at a premium and where
the application knows that it does not require exact printf semantics.
1.8.5 adds two more printf variants, 'long long' and 'minimal'. The 'long
long' variant is the same as the 'integer' variant but with long long
support enabled. The 'minimal' variant reduces functionality and size even
more than the 'integer' mode. Applications can use this where memory is at
a premium and where the application does not require exact printf
semantics.
With these two added variants, the SDK has enough options so that all of
the cbprintf modes can be supported with the pre-compiled bits:
1. CBPRINTF_NANO - picolibc's 'minimal' variant
2. CBPRINTF_REDUCED_INTEGRAL - picolibc's 'integer' variant
3. CBPRINTF_FULL_INTEGRAL - picolibc's 'long long' variant
4. CBPRINTF_FB_SUPPORT - picolibc's 'double' variant
This patch makes the cbprintf Kconfig values drive the default picolibc
variant, disables picolibc variants not capable of supporting the required
cbprintf level, but allows applications to select more functionality in
picolibc than cbprintf requires.
Note that this depends on the SDK including picolibc 1.8.5. Without that,
selecting the 'minimal' or 'long long' variant in Zephyr will end up with
the default variant from picolibc, which is the full version with floating
point support. When using the module things will work as specified.
Signed-off-by: Keith Packard <keithp@keithp.com>
This option in picolibc switches the assert macro between a chatty version
and one which provides no information at all. This latter mode avoids
placing the associated strings in memory.
The Zephyr option is PICOLIBC_ASSERT_VERBOSE and it is disable by default.
Signed-off-by: Keith Packard <keithp@keithp.com>
CBPRINTF_FULL_INTEGRAL doesn't happen to explicitly conflict with
CBPRINTF_NANO, but when CBPRINTF_NANO is enabled, there's no long long I/O
support provided.
Allow picolibc long-long I/O support to also be elided when CBPRINTF_NANO
is enabled to save similar amounts of space.
Signed-off-by: Keith Packard <keithp@keithp.com>
* Picolibc doesn't provide the %a-only mode.
* On advice from security experts, who report numerous vulnerabilities
caused by %n in printf specifiers, picolibc never supports this
feature.
* Picolibc doesn't use cbprintf for C-library compatible functions,
instead it provides aliases for the *printfcb functions using stdio
names.
Signed-off-by: Keith Packard <keithp@keithp.com>
Do not enable subsystem/driver shell modules by default and stop abusing
CONFIG_SHELL_MINIMAL, which is internal to the shell subsystem, to decide
when to enable a driver shell.
The list of shell modules has grown considerably through the
years. Enabling CONFIG_SHELL for doing e.g. an interactive debug session
leads to a large number of shell modules also being enabled unless
explicitly disabled, which again leads to non-negligible increases in
RAM/ROM usage.
This commit attempts to establish a policy of subsystem/driver shell
modules being disabled by default, requiring the user/application to
explicitly enable only those needed.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This moves the k_* memory management functions from sys/ into
kernel/ includes, as there are kernel public APIs. The z_*
functions are further separated into the kernel internal
header directory.
Also made a quick change to doxygen to group sys_mem_* into
the OS Memory Management group so they will appear in doc.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This change capitalizes on newly added support for dynamic
thread stacks and the existing pthread support to provide
an implementation of the ISO C11 `<threads.h>` API.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This prevents the compiler from optimizing calloc into an
infinite recursive call.
For example a call to malloc + memset zero at GCC -O2 will be
replaced by a call to calloc. This causes infinite recursion
if the function being implemented *is* calloc.
fno-builtin-malloc forces the compiler to avoid this optimization.
Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
The picolibc module can be built without thread local storage support if
desired. Allow that by using 'imply' instead of 'select'. However, when
using the toolchain picolibc, we assume that TLS will be enabled wherever
supported, so make sure we match by adding a 'select' for this case.
Signed-off-by: Keith Packard <keithp@keithp.com>
The ACPI table signature is not null terminated, so a precision needs to
be provided in format strings. There was an attempt to do this, but it
was done in an incorrect way, which resulted in garbage characters
getting printed.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
For most types, ACPICA provides both a struct name as well as a typedef.
The struct names follow the exact same naming style as Zephyr's ACPI
API, which makes it impossible to distinguish which type is defined by
Zephyr and which comes from ACPICA. It's therefore better to use the
typedefs, since they follow a distinct style compared to the Zephyr API.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The log functions themselves automatically add newline characters, so no
need to do it when calling the log macros.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The ACPI shell command create way too much vertical empty space. Remove
the unnecesary newlines and use indentation to indicate grouping of
lines. At the same time, place case statments with variable declarations
behind {} since otherwise both the Zephyr compliance checker and some
other static analyzers get confused by the code in the branch.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This was never used for anything, since the ACPI API overwrites the
pointer when fetching a resource list.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
ACPI_STATUS variables should not store values of any other error domain
(like negative POSIX error codes used for Zephyr's ACPI API).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The acpi_get_irq_table() function takes a pointer to a table that can
come from anywhere, i.e. it doesn't have to be the acpi.pci_prt.table
that acpi.c uses. Because of this, the correct place to iterate and
process the acpi.pci_prt_table is in the function that actually passes
acpi.pci_prt_table to the acpi_get_irq_table() function.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The acpi_get_irq_routing_table() takes a pointer to an array of
ACPI_PCI_ROUTING_TABLE elements rather than a generic buffer pointer
(e.g. void *).
Because of the above, it makes sense to specify the array size as an
actual ARRAY_SIZE() value, since it makes no sense to accept buffers
which are not a multiple of sizeof(ACPI_PCI_ROUTING_TABLE) long.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Use the appropriate ACPI_STATUS type for any status variable that stores
return values from ACPICA APIS.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
If the CONFIG_PCIE_PRT option is disabled it makes no sense to bloat the
ACPI build with PRT-related code or static tables. The diff looks a bit
larger since functions in acpi.c had to be shuffled around to be able to
be included in a single "#ifdef CONFIG_PCIE_PRT" block.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
ACPI currently uses implicit (auto) initialization, i.e. it doesn't need
any init level or priority.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The acpi_tables array is only needed for systems where dynamic memory
allocation is not available during the early ACPI init phase. In the
Zephyr case we can immediately start using k_malloc, so this is
unnecessary.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Move the syscall_handler.h header, used internally only to a dedicated
internal folder that should not be used outside of Zephyr.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The PRT bus name for most (especially older) platforms is _SB.PCI0. Only
newer platforms use something else (like _SB.PC00).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The upstream ACPICA example initialization order does AcpiLoadTables()
before calling AcpiEnableSubsystem(), so use this order in Zephyr too.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
ACPICA itself already registers its own handler (which works perfectly
fine for our purposes). Furthermore, ACPICA will always fail trying to
register another handler, unless the previous one is explicitly cleared
(which is something the Zephyr code didn't do).
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>