summaryrefslogtreecommitdiff
path: root/dbus/dbus-internals.h
Commit message (Collapse)AuthorAgeFilesLines
* dbus-internals: use `_DBUS_FUNCTION_NAME` in `_dbus_verbose()`Barnabás Pőcze2023-05-151-1/+1
| | | | | | | | dbus-internals.h already defines a macro which expands to the name of the current function based on C standard version, etc. So use that instead of hard-coding `__FUNCTION__`. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
* Define _DBUS_ALIGNOF using _Alignof when using C11 or newerKhem Raj2023-01-141-0/+4
| | | | | | | | | | | | | | | WG14 N2350 made very clear that it is an UB having type definitions within "offsetof" [1]. This patch changes the implementation of macro _DBUS_ALIGNOF to builtin "_Alignof" to avoid undefined behavior. clang 16+ has started to diagnose this [2] Fixes build when using -std >= gnu11 and using clang16+ [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm [2] https://reviews.llvm.org/D133574 Signed-off-by: Khem Raj <raj.khem@gmail.com>
* Add SPDX license marker for the AFL-2.1 OR GPL-2.0-or-later licenseRalf Habacker2023-01-041-0/+2
| | | | | | | | | The full license texts are not added because they were already added in a previous commit. Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de> see #394
* dbus-mempool.c: ensure that all alignments are aligned to max_align_tAlex Richardson2022-09-211-0/+15
| | | | | | | | | This is required e.g. for CHERI-enabled targets such as Arm Morello where aligning to sizeof(long) is not sufficient to load/store pointers (which need 16 byte alignment instead of 8 bytes). As we can't depend on C11 yet, this commit adds a max_align_t emulation to dbus-internals.h.
* dbus-internals: use size_t in _DBUS_ALIGN_VALUE()Alex Richardson2022-09-211-1/+2
| | | | | | | | | | | | | | | When targeting CHERI-enabled architectures such as Arm Morello, performing a bitwise and with uintptr_t values can result in an ambiguous operation compiler warning. Fix this warning by telling compiler which operand is (potentially) a pointer and which one is an integer by changing the boundary type to size_t. This change has no functional effect on other architectures but is required to build with -Werror for Morello. Example warning message: ``` warning: binary expression on capability types 'unsigned __intcap' and 'unsigned __intcap'; it is not clear which should be used as the source of provenance; currently provenance is inherited from the left-hand side [-Wcheri-provenance] _dbus_assert (_DBUS_ALIGN_VALUE (insert_at, 8) == (unsigned) insert_at); ```
* dbus: add a few directory separator macrosMarc-André Lureau2022-07-151-0/+4
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* dbus: move DBUS_IS_DIR_SEPARATOR to dbus-internals.hMarc-André Lureau2022-07-151-0/+9
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* dbus-launch-x11: Ignore X11 connection when checking for memory leaksSimon McVittie2022-07-151-0/+22
| | | | | | | | | | | | | | The X11 connection is opened and never closed. Because dbus-launch forks and continues to run non-trivial code in a forked child, it is not clear whether (or where) it would be safe to close it; instead, we leave it open until process exit, at which point the socket is cleaned up by the kernel. Any memory allocated for the X11 connection is only allocated once per run of dbus-launch, so there's no need to keep track of it, and we can silence these memory leak warnings as uninteresting. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Add unit tests for platform-specific mutex implementation.Ralf Habacker2022-05-011-0/+3
| | | | | | | | | | | | | | | | | | | | The tests are enabled with the embedded tests; the required low-level functions from the dbus library are decorated with DBUS_EMBEDDED_TESTS_EXPORT to indicate the appropriate usage. On Windows, all tests are run; on unix-like operating systems, individual tests are disabled: - the tests on #NULL pointers of type DBus[C|R]Mutex, since they point to a data structure and would cause a segment violation when accessed. - the multiple lock test for type DBusCMutex, since it would block the current thread. Since the whole point of "rmutex" is to be able to lock multiple times, the "rmutex double lock" test is enabled on unix-like operating systems too. Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
* dbus: Move DBUS_ENABLE_EMBEDDED_TESTS to a new dbus-macros-internal.hSimon McVittie2022-05-011-6/+1
| | | | | | | | | This avoids a circular dependency: I want to use DBUS_ENABLE_EMBEDDED_TESTS in dbus-string.h, but DBUS_ENABLE_EMBEDDED_TESTS was previously defined in dbus-internals.h, which depends on dbus-string.h. Signed-off-by: Simon McVittie <smcv@collabora.com>
* internals: Use Standard C offsetof macro if availableSimon McVittie2021-12-131-0/+5
| | | | | | | | | | | | | | | | | | | clang 13 fails to compile our current implementation with: .../dbus/dbus-message.c:2070:3: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant] _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageRealIter) <= ^ .../dbus/dbus-internals.h:460:25: note: expanded from macro '_DBUS_STATIC_ASSERT' typedef struct { char _assertion[(expr) ? 1 : -1]; } \ This appears to be because the "traditional" definition of offsetof(), which we're hard-coding here, does not qualify as a constant expression under C rules due to its use of pointer casts. Modern compilers like gcc and clang have a built-in implementation of offsetof that *is* a constant expression. Signed-off-by: Simon McVittie <smcv@collabora.com>
* In _dbus_verbose_real() avoid possible stack overflows on output to the ↵Ralf Habacker2020-02-201-0/+1
| | | | | | | | | | Windows debug port Instead of creating a fixed memory area on the stack that can lead to a stack overflow if exceeded, this configuration now uses a DBusString instance that dynamically manages memory. Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/45
* Merge branch 'break-out-more-tests' into 'master'Simon McVittie2019-07-031-0/+6
|\ | | | | | | | | Break out more tests from libdbus See merge request dbus/dbus!121
| * Introduce a new macro to export symbols solely for testsSimon McVittie2019-07-031-0/+6
| | | | | | | | | | | | | | This lets us expose symbols in the embedded-tests build without expanding the symbol table of the production library. Signed-off-by: Simon McVittie <smcv@collabora.com>
* | tests: Improve messages when fd leaks are diagnosedSimon McVittie2019-07-021-0/+3
|/ | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* trivial: Remove trailing whitespace from copyright noticesSimon McVittie2018-12-171-2/+2
| | | | | | | | | | | | | | We don't usually mass-remove trailing whitespace from the actual source code because it would complicate cherry-picking bug fixes to older branches, but that reasoning doesn't really apply to the comments containing copyright and licensing notices. Removing trailing whitespace makes it much easier to move code around: we have a commit hook that rejects commits containing trailing whitespace, but that commit hook counts moving a file as a delete + add pair, so it objects to moving code that contains trailing whitespace. Signed-off-by: Simon McVittie <smcv@collabora.com>
* _dbus_threads_init_debug: RemoveSimon McVittie2018-12-141-3/+0
| | | | | | | | libdbus has been thread-safe by default since 1.7.6 (2013): dbus_threads_init_default() is called on a just-in-time basis whenever needed, and _dbus_thread_init_debug() is equivalent to that. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Improve diagnostics for error assertion failuresSimon McVittie2018-11-201-10/+22
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* _DBUS_ASSERT_ERROR_XOR_BOOL: Add and useSimon McVittie2018-11-201-0/+25
| | | | | | As suggested by Philip Withnall in dbus!43. Signed-off-by: Simon McVittie <smcv@collabora.com>
* internals: Assume compiler supports a subset of ISO varargs syntaxSimon McVittie2018-11-151-7/+1
| | | | | | | | | | | | | We have considerable anecdotal evidence that every relevant compiler supports at least the small part of ISO varargs syntax that we need here, because tools/tool-common.h has contained #define VERBOSE(...) do {} while (0) since dbus 1.9.2 (2014) and nobody has complained yet. With that in mind, let's simplify. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Enable "unused result" warning for Visual Studio >= 2012 (MSVC 11.0)Daniel Wendt2018-03-151-2/+3
| | | | | | | | | | | | | | The _Must_inspect_result_ annotation is documented to be used in both the declaration and implementation, but in testing with the MSVC 2012 compiler it appears to be sufficient to use the annotation only in the declaration to get a compiler warning, as with the GCC compiler. So the annotation is not necessary in the C implementation. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105460 [smcv: Rebase dbus-sysdeps.h changes on master] [smcv: Clarify commit message] Reviewed-by: Simon McVittie <smcv@collabora.com> Tested-by: Daniel Wendt <daniel.wendt@linux.com>
* bus/containers: Create a DBusServer and add it to the main loopSimon McVittie2017-12-121-0/+1
| | | | | | | | | | | | | | | | | This means we can accept connections on the new socket. For now, we don't process them and they get closed. For the system bus (or root's session bus, where the difference is harmless but makes automated testing easier), rely on system-wide infrastructure to create /run/dbus/containers. The upstream dbus distribution no longer contains integration glue for non-systemd boot systems, but downstreams that maintain a non-systemd boot system and are interested in the Containers interface should create /run/dbus/containers during boot. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
* bus: Silence most log messages when testing OOM handlingSimon McVittie2017-11-151-2/+3
| | | | | | | | | In parts of the OOM testing, our logging produces multiple megabytes of output. Let's not do that. Reviewed-by: Philip Withnall <withnall@endlessm.com> Signed-off-by: Simon McVittie <smcv@collabora.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
* internals: Make a minimal _dbus_test_oom_handling() universally availableSimon McVittie2017-07-051-2/+5
| | | | | | | | | | | | | | | | | | | Previously, it was only available under DBUS_ENABLE_EMBEDDED_TESTS, because the infrastructure to pretend malloc had failed is only compiled then. However, I'd like to use it in more modular tests, to avoid test-dbus continuing to grow. To facilitate that, inline a trivial version of it when DBUS_ENABLE_EMBEDDED_TESTS is disabled: it just calls the function, once, without doing any strange things to the malloc interface. Similarly, amend the stub implementation of _dbus_get_malloc_blocks_outstanding() so that references to it are syntactically valid, and move the DBusTestMemoryFunction typedef so that it can be used with or without DBUS_ENABLE_EMBEDDED_TESTS. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568
* driver: Implement the Peer interface, for completenessSimon McVittie2017-06-081-0/+1
| | | | | | Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101257
* Reimplement _dbus_warn_return_if_fail without -Wformat-nonliteralSimon McVittie2016-10-131-8/+7
| | | | | | | | | | | We can avoid duplicating the format string between translation units, without the compiler warning us that it can't check non-literal format strings for format-string security vulnerabilities based on %p, by breaking out the "assertion failed" case into a slow-path. Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
* Merge branch 'dbus-1.10'Ralf Habacker2016-05-131-0/+1
|\
| * On Windows make access to member 'refcount' of struct DBusBabysitter thread ↵Ralf Habacker2016-05-131-0/+1
| | | | | | | | | | | | | | safe. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95191 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* | Merge branch 'dbus-1.10'Simon McVittie2016-03-021-0/+3
|\ \ | |/
| * dbus-internals: add _DBUS_ALIGNOFSimon McVittie2016-03-021-0/+3
| | | | | | | | | | | | | | | | | | This is useful when making static assertions about our types' properties. Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Thiago Macieira <thiago@kde.org> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=94136
| * Revert "Rename function string_array_length() to _dbus_string_array_length() ↵Simon McVittie2016-02-121-2/+0
| | | | | | | | | | | | | | and move it to dbus-internals.c." This reverts commit 1370b44035da90a7fbcebea17074c66c832de0b1. This change was intended for 1.11.
| * Rename function string_array_length() to _dbus_string_array_length() and ↵Ralf Habacker2016-02-111-0/+2
| | | | | | | | | | | | | | move it to dbus-internals.c. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* | Rename function string_array_length() to _dbus_string_array_length() and ↵Ralf Habacker2016-02-121-0/+2
|/ | | | | | | move it to dbus-internals.c. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Make UUID generation failableSimon McVittie2015-05-141-3/+5
| | | | | | | | | | | | | Previously, this would always succeed, but might use weak random numbers in rare failure cases. I don't think these UUIDs are security-sensitive, but if they're generated by a PRNG as weak as rand() (<= 32 bits of entropy), we certainly can't claim that they're universally unique. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [smcv: document @error] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Split _dbus_set_fd_nonblocking vs. _dbus_set_socket_nonblockingSimon McVittie2015-05-121-3/+0
| | | | | | | | The former is Unix-specific, the latter is also portable to Windows. On Unix, they're really the same thing. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89444 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* Fix warning: 'the comparison will always evaluate as 'false' for the address ↵Ralf Habacker2015-03-021-2/+14
| | | | | | | of '....' will never be NULL [-Waddress]' Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89284 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Add DBUS_PRIVATE_EXPORT decoration to symbols used by dbus-daemon or testsSimon McVittie2015-02-201-0/+23
| | | | | | | | | | | | | | | | | | The rules are: * symbols in libdbus-1 with neither decoration are private to libdbus-1 * symbols in libdbus-1 with DBUS_EXPORT are public API * symbols in libdbus-1 with DBUS_PRIVATE_EXPORT are private to the dbus source package, but may be used by other programs in the dbus source tree, including tests * symbols in libdbus-internal must not have DBUS_EXPORT or DBUS_PRIVATE_EXPORT, and should be used by as few things as possible Thanks to Ralf Habacker for his contributions to this rather large commit. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83115 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* Add org.freedesktop.DBus.Verbose interface to dbus-daemon when compiled with ↵Ralf Habacker2015-02-131-0/+2
| | | | | | | | | | DBUS_ENABLE_VERBOSE_MODE. This interface contains methods 'EnableVerbose' and 'DisableVerbose' to control verbose mode on daemon runtime. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* _dbus_set_error_valist: addSimon McVittie2015-02-031-0/+4
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88810 Reviewed-by: Philip Withnall
* Add _DBUS_GNUC_UNUSED, and use it in _DBUS_STATIC_ASSERTSimon McVittie2014-09-151-1/+1
| | | | | | | | This means we can use _DBUS_STATIC_ASSERT at non-global scope without tripping -Wunused-local-typedefs. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83767 Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk>
* _dbus_write_uuid_file: factor out function to write a known UUIDSimon McVittie2014-04-281-0/+4
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77941 Reviewed-by: Lennart Poettering
* Remove support for platforms with no 64-bit integer typeSimon McVittie2013-09-161-2/+0
| | | | | | | | | | | | | | | This has been a soft requirement since 1.5.0; anyone on such platforms would have had to configure --without-64-bit, provoking a warning that instructed them to report a D-Bus bug with details of their platform. Nobody has done so, so if anyone still lacks a 64-bit integer type, they're on their own. (Also, I tried the build with --without-64-bit and it's full of fatal compiler warnings, so it's not clear that we're actually losing anything by removing this "feature".) Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65429 Reviewed-by: Chengwei Yang <chengwei.yang@intel.com>
* _dbus_get_tmpdir: be thread-safeSimon McVittie2013-08-291-1/+2
| | | | | | | | | Sharing a static variable between threads is not safe in general, and this function is used in the shared libdbus (for nonce files), so it can't rely on being single-threaded. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68610 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* tests to embedded tests: replaced in libdbusChengwei Yang2013-06-281-2/+2
| | | | | | Signed-off-by: Chengwei Yang <chengwei.yang@intel.com> Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=66291
* Make taking a global lock automatically initialize locking if neededSimon McVittie2013-06-171-2/+2
| | | | | | | | | | | | | | | | | | | This lets them be thread-safe by default, at the cost that they can now fail. init_uninitialized_locks() and init_global_locks() must now both reimplement the equivalent of _dbus_register_shutdown_func(), by using _dbus_platform_rmutex_lock() on the same underlying mutex around a call to _dbus_register_shutdown_func_unlocked(). This is because if they used the usual _DBUS_LOCK() API (as _dbus_register_shutdown_func() does), it would automatically try to initialize global locking, leading to infinite recursion. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Anas Nashif <anas.nashif@intel.com>
* Replace individual global-lock variables with an array of DBusRMutex *Simon McVittie2013-06-171-26/+33
| | | | | | | | | | | | | | | | | | | | | | This means we can use a much simpler code structure in data-slot allocators: instead of giving them a DBusRMutex ** at first-allocation, we can just give them an index into the array, which can be done statically. It doesn't make us any more thread-safe-by-default - the mutexes will only actually be used if threads were already initialized - but it's substantially better than nothing. These locks really do have to be recursive: for instance, internal_bus_get() calls dbus_bus_register() under the bus lock, and dbus_bus_register() can call _dbus_connection_close_possibly_shared(), which takes the bus lock. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Reviewed-by: Anas Nashif <anas.nashif@intel.com>
* Remove unused global mutexes for win_fds, sid_atom_cacheSimon McVittie2013-05-131-6/+4
| | | | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* DBusAtomic: on Unix, use pthreads mutexes for fallbackSimon McVittie2013-05-091-5/+0
| | | | | | | | | | | | | | | | | | | | | On pthreads platforms, POSIX guarantees that we can "allocate" mutexes as library-global variables, without involving malloc. This means we don't need to error-check their allocation - if the dynamic linker succeeds, then we have enough memory for all our globals - which is an important step towards being thread-safe by default. In particular, making atomic operations never rely on DBusMutex means that we are free to implement parts of DBusMutex in terms of DBusAtomic, if it would help. We do not currently support any non-Windows platform that does not have pthreads. This is unlikely to change. On Windows, we already used real atomic operations; we can just delete the unused global variable. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* Split DBUS_SESSION_BUS_DEFAULT_ADDRESS into listen, connect addresses and ↵Simon McVittie2012-08-131-4/+0
| | | | | | | | | | | | | | | | set better defaults On Unix, the connect address should basically always be "autolaunch:" but the listen address has to be something you can listen on. On Windows, you can listen on "autolaunch:" or "autolaunch:scope=*install-path", for instance, and the dbus-daemon is involved in the auto-launching process. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38201 Reviewed-by: David Zeuthen <davidz@redhat.com> [default address changed to autolaunch: for interop with GDBus -smcv] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Distinguish between two flavours of mutexSimon McVittie2012-02-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | dbus-threads.h warns that recursive pthreads mutexes are not compatible with our expectations for condition variables. However, the only two condition variables we actually use only have their corresponding mutexes locked briefly (and we don't call out to user code from there), so the mutexes don't need to be recursive anyway. That's just as well, because it turns out our implementation of recursive mutexes on pthreads is broken! The goal here is to be able to distinguish between "cmutexes" (mutexes compatible with a condition variable) and "rmutexes" (mutexes which are recursive if possible, to avoid deadlocking if we hold them while calling user code). This is complicated by the fact that callers are not guaranteed to have provided us with both versions of mutexes, so we might have to implement one by using the other (in particular, DBusRMutex *aims to be* recursive, it is not *guaranteed to be* recursive). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=43744 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Thiago Macieira <thiago@kde.org>