Skip to content

Commit

Permalink
Sync bela and wsudo add --retain
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Aug 26, 2024
1 parent 16da7ee commit 6b992e4
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 184 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@
"any": "cpp",
"codecvt": "cpp",
"ranges": "cpp"
}
},
"cmake.configureOnOpen": true
}
24 changes: 17 additions & 7 deletions lib/exec/appcontainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <bela/base.hpp>
#include <bela/codecvt.hpp>
#include <bela/escapeargv.hpp>
//#include <bela/phmap.hpp>
// #include <bela/phmap.hpp>
#define PUGIXML_HEADER_ONLY 1
#include <pugixml.hpp>
#include <sddl.h>
Expand Down Expand Up @@ -121,11 +121,16 @@ bool MakeDeriveSID(PSID &appcontainersid, capabilities_t &cas, appcommand &cmd,
if (cmd.appid.empty()) {
cmd.appid = appid;
}
DeleteAppContainerProfile(cmd.appid.data()); // ignore error
if (!cmd.retain) {
DeleteAppContainerProfile(cmd.appid.data()); // ignore error
}
if (CreateAppContainerProfile(cmd.appid.data(), cmd.appid.data(), cmd.appid.data(), (cas.empty() ? NULL : cas.data()),
(DWORD)cas.size(), &appcontainersid) != S_OK) {
ec = bela::make_system_error_code(L"MakeDeriveSID<CreateAppContainerProfile> ");
return false;
auto hr = ::DeriveAppContainerSidFromAppContainerName(cmd.appid.data(), &appcontainersid);
if (FAILED(hr)) {
ec = bela::make_system_error_code(L"MakeDeriveSID<CreateAppContainerProfile> ");
return false;
}
}
return true;
}
Expand Down Expand Up @@ -170,11 +175,16 @@ bool MakeSID(PSID &appcontainersid, capabilities_t &cas, appcommand &cmd, bela::
if (cmd.appid.empty()) {
cmd.appid = appid;
}
DeleteAppContainerProfile(cmd.appid.data()); // ignore error
if (!cmd.retain) {
DeleteAppContainerProfile(cmd.appid.data()); // ignore error
}
if (CreateAppContainerProfile(cmd.appid.data(), cmd.appid.data(), cmd.appid.data(), (cas.empty() ? NULL : cas.data()),
(DWORD)cas.size(), &appcontainersid) != S_OK) {
ec = bela::make_system_error_code(L"MakeSID<CreateAppContainerProfile> ");
return false;
auto hr = ::DeriveAppContainerSidFromAppContainerName(cmd.appid.data(), &appcontainersid);
if (FAILED(hr)) {
ec = bela::make_system_error_code(L"MakeDeriveSID<CreateAppContainerProfile> ");
return false;
}
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/exec/exec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct appcommand {
visible_t visible;
uint32_t pid{0};
bool islpac{false};
bool retain{false};
bool initialize(bela::error_code &ec);
bool execute(bela::error_code &ec);
};
Expand Down
2 changes: 1 addition & 1 deletion vendor/bela.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/fcharlie/bela/tree/bec4b4ae18a7158c2060d1f0d73f042579f30b4e
https://github.com/fcharlie/bela/tree/d92666ad2af8316ad9902723813d201a6217097a
8 changes: 4 additions & 4 deletions vendor/bela/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# bela sources
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.27)

project(bela CXX C ASM)

Expand All @@ -21,11 +21,11 @@ option(BELA_ENABLE_ASSEMBLY_FILES "bela enable assembly files" OFF)
message(STATUS "CMAKE_ASM_COMPILER_ID ${CMAKE_ASM_COMPILER_ID}")

if(NOT (DEFINED CMAKE_CXX_STANDARD))
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
endif()

if(CMAKE_CXX_STANDARD LESS 20 OR CMAKE_CXX_STANDARD STREQUAL "98")
message(FATAL_ERROR "Bela requires C++20 or later")
if(CMAKE_CXX_STANDARD LESS 23 OR CMAKE_CXX_STANDARD STREQUAL "98")
message(FATAL_ERROR "Bela requires C++23 or later")
endif()

set(CMAKE_CXX_STANDARD_REQUIRED YES)
Expand Down
2 changes: 1 addition & 1 deletion vendor/bela/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![license badge](https://img.shields.io/github/license/fcharlie/bela.svg)](LICENSE)
[![Master Branch Status](https://github.com/fcharlie/bela/workflows/BelaCI/badge.svg)](https://github.com/fcharlie/bela/actions)

Modern C++20 library collection, better development experience on Windows (10,11)
Modern C++23 library collection, better development experience on Windows (10,11)

A lot of the code supports wchar_t based on Abseil modifications, some of which come from Visual C++ STL.

Expand Down
2 changes: 1 addition & 1 deletion vendor/bela/include/bela/__phmap/VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/greg7mdp/parallel-hashmap.git
65775fa09fecaa65d0b0022ab6bf091c0e509445
10368163ab1f4367d2f0685b5928b1c973ebd1ec
29 changes: 12 additions & 17 deletions vendor/bela/include/bela/__phmap/phmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,23 @@ constexpr bool IsNoThrowSwappable(std::false_type /* is_swappable */) {
// --------------------------------------------------------------------------
template <typename T>
uint32_t TrailingZeros(T x) {
uint32_t res;
PHMAP_IF_CONSTEXPR(sizeof(T) == 8)
return base_internal::CountTrailingZerosNonZero64(static_cast<uint64_t>(x));
res = base_internal::CountTrailingZerosNonZero64(static_cast<uint64_t>(x));
else
return base_internal::CountTrailingZerosNonZero32(static_cast<uint32_t>(x));
res = base_internal::CountTrailingZerosNonZero32(static_cast<uint32_t>(x));
return res;
}

// --------------------------------------------------------------------------
template <typename T>
uint32_t LeadingZeros(T x) {
uint32_t res;
PHMAP_IF_CONSTEXPR(sizeof(T) == 8)
return base_internal::CountLeadingZeros64(static_cast<uint64_t>(x));
res = base_internal::CountLeadingZeros64(static_cast<uint64_t>(x));
else
return base_internal::CountLeadingZeros32(static_cast<uint32_t>(x));
res = base_internal::CountLeadingZeros32(static_cast<uint32_t>(x));
return res;
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -424,28 +428,21 @@ struct GroupSse2Impl
#endif
}

#ifdef __INTEL_COMPILER
#pragma warning push
#pragma warning disable 68
#endif
// Returns a bitmask representing the positions of empty or deleted slots.
// -----------------------------------------------------------------------
BitMask<uint32_t, kWidth> MatchEmptyOrDeleted() const {
auto special = _mm_set1_epi8(static_cast<uint8_t>(kSentinel));
auto special = _mm_set1_epi8(static_cast<char>(kSentinel));
return BitMask<uint32_t, kWidth>(
static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl))));
}

// Returns the number of trailing empty or deleted elements in the group.
// ----------------------------------------------------------------------
uint32_t CountLeadingEmptyOrDeleted() const {
auto special = _mm_set1_epi8(static_cast<uint8_t>(kSentinel));
auto special = _mm_set1_epi8(static_cast<char>(kSentinel));
return TrailingZeros(
static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)) + 1));
}
#ifdef __INTEL_COMPILER
#pragma warning pop
#endif

// ----------------------------------------------------------------------
void ConvertSpecialToEmptyAndFullToDeleted(ctrl_t* dst) const {
Expand Down Expand Up @@ -581,8 +578,7 @@ inline size_t CapacityToGrowth(size_t capacity)
assert(IsValidCapacity(capacity));
// `capacity*7/8`
PHMAP_IF_CONSTEXPR (Group::kWidth == 8) {
if (capacity == 7)
{
if (capacity == 7) {
// x-x/8 does not work when x==7.
return 6;
}
Expand All @@ -598,8 +594,7 @@ inline size_t GrowthToLowerboundCapacity(size_t growth)
{
// `growth*8/7`
PHMAP_IF_CONSTEXPR (Group::kWidth == 8) {
if (growth == 7)
{
if (growth == 7) {
// x+(x-1)/7 does not work when x==7.
return 8;
}
Expand Down
9 changes: 9 additions & 0 deletions vendor/bela/include/bela/__phmap/phmap_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,15 @@
#define PHMAP_IF_CONSTEXPR(expr) if ((expr))
#endif

// ----------------------------------------------------------------------
// builtin unreachable
// ----------------------------------------------------------------------
#if PHMAP_HAVE_BUILTIN(__builtin_unreachable)
#define PHMAP_BUILTIN_UNREACHABLE() __builtin_unreachable()
#else
#define PHMAP_BUILTIN_UNREACHABLE() (void)0
#endif

// ----------------------------------------------------------------------
// base/macros.h
// ----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6b992e4

Please sign in to comment.