userlandfs: use std::bitset for FSCapabilities

gcc 13 is confused by the custom bitset implementation, so use the C++
standard one instead.

However, this results in including the C++ <string> header in kernel
code. This doesn't work for gcc2, because of two problems:

- That header includes a declaration of atomic_add that doesn't match
the one in SupportsDefs.h (which can in some cases replace the function
with a #define for an inline version). Adjust the header to use the
be a problem because it creates a risk of circular inclusions.
Standard C++ headers shouldn't depend on BeAPI ones.
- It also leads to the inclusion of iostream which defined lock and
unlock functions in the global namespace. We don't want these, and they
are not part of the C++ standard, so just remove them.

Ideally we could use std::hash for the GetHashCode implementation, but
that doesn't work because it depends on an helper function that's in
libstdc++, and we can't link that from kernel add-ons.

Change-Id: Iee07280beb4dddf7a9b6160e37f3b816e4de89ae
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6663
Reviewed-by: Niels Sascha Reedijk <niels.reedijk@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
PulkoMandy 2023-07-01 13:26:25 +02:00 committed by Niels Sascha Reedijk
parent 9aa43979f8
commit 899e0ef82b
6 changed files with 21 additions and 37 deletions

View File

@ -271,11 +271,6 @@ __asm__ ("__IO_clog")
#endif
;
extern istream& lock(istream& ins);
extern istream& unlock(istream& ins);
extern ostream& lock(ostream& outs);
extern ostream& unlock(ostream& outs);
struct Iostream_init { } ; // Compatibility hack for AT&T library.
inline ios& dec(ios& i)

View File

@ -66,8 +66,10 @@ extern void __length_error (const char *);
#endif
#ifdef __HAIKU__
#ifndef atomic_add
extern "C" __haiku_int32 atomic_add(__haiku_int32* value,
__haiku_int32 addvalue);
#endif
#endif /* __HAIKU__ */
template <class charT, class traits = string_char_traits<charT>,

View File

@ -8,6 +8,8 @@
#include <string.h>
#include <stdio.h>
#include <bitset>
#include "Debug.h"
enum client_fs_type {
@ -148,7 +150,7 @@ namespace UserlandFSUtil {
template<const int CapabilityCount>
struct FSCapabilitiesBase {
uint8 capabilities[(CapabilityCount + 7) / 8];
std::bitset<CapabilityCount> capabilities;
inline void ClearAll();
@ -171,7 +173,7 @@ template<const int CapabilityCount>
inline void
FSCapabilitiesBase<CapabilityCount>::ClearAll()
{
memset(capabilities, 0, sizeof(capabilities));
capabilities.reset();
}
@ -183,11 +185,7 @@ FSCapabilitiesBase<CapabilityCount>::Set(uint32 capability, bool set)
if (capability >= CapabilityCount)
return;
uint8 flag = uint8(1 << (capability % 8));
if (set)
capabilities[capability / 8] |= flag;
else
capabilities[capability / 8] &= ~flag;
capabilities.set(capability, set);
}
@ -196,7 +194,10 @@ template<const int CapabilityCount>
inline void
FSCapabilitiesBase<CapabilityCount>::Clear(uint32 capability)
{
Set(capability, false);
if (capability >= CapabilityCount)
return;
capabilities.reset(capability);
}
@ -208,8 +209,7 @@ FSCapabilitiesBase<CapabilityCount>::Get(uint32 capability) const
if (capability >= CapabilityCount)
return false;
uint8 flag = uint8(1 << (capability % 8));
return (capabilities[capability / 8] & flag);
return capabilities.test(capability);
}
@ -218,12 +218,10 @@ template<const int CapabilityCount>
inline uint32
FSCapabilitiesBase<CapabilityCount>::GetHashCode() const
{
uint32 hashCode = 0;
int byteCount = sizeof(capabilities);
for (int i = 0; i < byteCount; i++)
hashCode = hashCode * 37 + capabilities[i];
return hashCode;
uint32 hash = 0;
for (int i = 0; i < CapabilityCount; i++)
hash ^= capabilities.test(i) << (i % 32);
return hash;
}
@ -233,13 +231,7 @@ inline bool
FSCapabilitiesBase<CapabilityCount>::operator==(
const FSCapabilitiesBase<CapabilityCount>& other) const
{
int byteCount = sizeof(capabilities);
for (int i = 0; i < byteCount; i++) {
if (capabilities[i] != other.capabilities[i])
return false;
}
return true;
return capabilities == other.capabilities;
}
@ -249,12 +241,7 @@ inline void
FSCapabilitiesBase<CapabilityCount>::Dump() const
{
D(
char buffer[128];
int byteCount = sizeof(capabilities);
for (int i = 0; i < byteCount; i++)
sprintf(buffer + 2 * i, "%02x", (int)capabilities[i]);
PRINT(("FSCapabilities[%s]\n", buffer));
PRINT(("FSCapabilities[%s]\n", capabilities.to_string().c_str()));
)
}

View File

@ -33,5 +33,5 @@ SharedLibrary libuserlandfs_beos_kernel.so
:
<nogrist>userlandfs_server
[ TargetLibsupc++ ] libbsd.so
[ TargetLibsupc++ ] [ TargetLibstdc++ ] libbsd.so
;

View File

@ -36,7 +36,7 @@ SharedLibrary libuserlandfs_fuse.so
FUSEVolume.cpp
mime_ext_table.c
:
<nogrist>userlandfs_server shared be [ TargetLibsupc++ ]
<nogrist>userlandfs_server shared be [ TargetLibsupc++ ] [ TargetLibstdc++ ]
;
SEARCH on [ FGristFiles mime_ext_table.c ]

View File

@ -51,7 +51,7 @@ SharedLibrary libuserlandfs_haiku_kernel.so
:
<nogrist>userlandfs_server
be # for BLocker only
[ TargetLibsupc++ ]
[ TargetLibsupc++ ] [ TargetLibstdc++ ]
;