Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
feat: std::kallocator
Browse files Browse the repository at this point in the history
fix: VS2019 build error.

build: revise
  • Loading branch information
MiroKaku committed Nov 20, 2022
1 parent b0e7656 commit 8195bfe
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 86 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ if exist bin rd /s /q bin
if exist lib rd /s /q lib
if exist ucxxrt rd /s /q ucxxrt

%msbuild% -p:Configuration=Debug -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -p:Configuration=Release -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Debug -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Release -p:Platform=x86 ..\..\ucxxrt.sln -t:ucxxrt

%msbuild% -p:Configuration=Debug -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -p:Configuration=Release -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Debug -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Release -p:Platform=x64 ..\..\ucxxrt.sln -t:ucxxrt

%msbuild% -p:Configuration=Debug -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -p:Configuration=Release -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Debug -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Release -p:Platform=ARM ..\..\ucxxrt.sln -t:ucxxrt

%msbuild% -p:Configuration=Debug -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -p:Configuration=Release -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Debug -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt
%msbuild% -m -p:Configuration=Release -p:Platform=ARM64 ..\..\ucxxrt.sln -t:ucxxrt

:exit
popd
Expand Down
70 changes: 1 addition & 69 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: build & publish
name: build

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
Expand Down Expand Up @@ -28,45 +28,12 @@ jobs:
with:
submodules: true

#- name: setup wdk.vsix
# shell: pwsh
# run: |
# $FilePath = Resolve-Path "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix"
# Install-VsixExtension -FilePath $FilePath -Name "WDK.vsix" -VSversion "2022" -InstallOnly

- name: enable X86 and ARM build support
working-directory: ${{github.workspace}}
shell: pwsh
run: |
.\.github\workflows\EnableX86AndARM.ps1
- name: build nuspec
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: pwsh
run: |
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
{
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
# github的内置版本有Bug,此行必须添加,否则无法获得内容
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
$content = [System.IO.File]::ReadAllText("nuget\ucxxrt.nuspec")
$releaseNotesToken = '$releaseNotes$'
$releaseNotesIndex = $content.IndexOf($releaseNotesToken)
if($releaseNotesIndex -ne -1)
{
echo $content.Substring(0, $releaseNotesIndex) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline
echo $releaseNotes | out-file "nuget\ucxxrt-new.nuspec" -Append
echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline -Append
}
}
- name: compile
working-directory: ${{github.workspace}}
shell: cmd
Expand All @@ -78,38 +45,3 @@ jobs:
name: ucxxrt
path: ucxxrt\
if-no-files-found: error

- name: pack zip
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: 7z a -tzip ucxxrt.zip ucxxrt\

- name: pack nuget
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: |
if "${{env.BuildVersion}}" NEQ "" (
nuget pack nuget\ucxxrt-new.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA%
)
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
- name: publish a version
if: contains(github.ref, 'tags/')
uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
ucxxrt.zip
*.nupkg
- name: publish nuget
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: |
nuget push ucxxrt.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
113 changes: 113 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This is a basic workflow to help you get started with Actions

name: publish

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
tags:
- v*

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: windows-2022

# Any commit that contains [build] will now trigger these jobs, everything else will be skipped.
# if: "contains(github.event.head_commit.message, '[build]')"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
submodules: true

#- name: setup wdk.vsix
# shell: pwsh
# run: |
# $FilePath = Resolve-Path "C:\Program Files (x86)\Windows Kits\10\Vsix\VS2022\*\WDK.vsix"
# Install-VsixExtension -FilePath $FilePath -Name "WDK.vsix" -VSversion "2022" -InstallOnly

- name: enable X86 and ARM build support
working-directory: ${{github.workspace}}
shell: pwsh
run: |
.\.github\workflows\EnableX86AndARM.ps1
- name: build nuspec
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: pwsh
run: |
if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase"))
{
$BuildVersion = $env:GITHUB_REF.Remove(0, 11);
echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV
# github的内置版本有Bug,此行必须添加,否则无法获得内容
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
$releaseNotes = & git tag -l --format='%(contents)' $env:GITHUB_REF.Remove(0, 10)
$content = [System.IO.File]::ReadAllText("nuget\ucxxrt.nuspec")
$releaseNotesToken = '$releaseNotes$'
$releaseNotesIndex = $content.IndexOf($releaseNotesToken)
if($releaseNotesIndex -ne -1)
{
echo $content.Substring(0, $releaseNotesIndex) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline
echo $releaseNotes | out-file "nuget\ucxxrt-new.nuspec" -Append
echo $content.Remove(0, $releaseNotesIndex + $releaseNotesToken.Length) | out-file "nuget\ucxxrt-new.nuspec" -NoNewline -Append
}
}
- name: compile
working-directory: ${{github.workspace}}
shell: cmd
run: call .\.github\workflows\build.bat

- name: upload an artifact
uses: actions/upload-artifact@v3
with:
name: ucxxrt
path: ucxxrt\
if-no-files-found: error

- name: pack zip
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: 7z a -tzip ucxxrt.zip ucxxrt\

- name: pack nuget
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: |
if "${{env.BuildVersion}}" NEQ "" (
nuget pack nuget\ucxxrt-new.nuspec -Properties version=${{env.BuildVersion}};commit=%GITHUB_SHA%
)
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
- name: publish a version
if: contains(github.ref, 'tags/')
uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
ucxxrt.zip
*.nupkg
- name: publish nuget
if: contains(github.ref, 'tags/')
working-directory: ${{github.workspace}}
shell: cmd
run: |
nuget push ucxxrt.${{env.BuildVersion}}.nupkg -ApiKey ${{ secrets.NUGET_TOKEN }} -Source https://api.nuget.org/v3/index.json
if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL%
153 changes: 153 additions & 0 deletions kext/kallocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* PROJECT: Universal C++ RunTime (UCXXRT)
* FILE: kallocator.cpp
* DATA: 2022/11/19
*
* PURPOSE: Universal C++ RunTime
*
* LICENSE: Relicensed under The MIT License from The CC BY 4.0 License
*
* DEVELOPER: MiroKaku (miro.kaku AT Outlook.com)
*/

#pragma once
#include <yvals.h>
#include "knew.h"
#include <type_traits>

_STD_BEGIN

#ifndef _HAS_DEPRECATED_ALLOCATOR_MEMBERS
#define _HAS_DEPRECATED_ALLOCATOR_MEMBERS 1
#endif

#ifndef _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
#define _CXX20_DEPRECATE_IS_ALWAYS_EQUAL
#endif

#ifndef _NODISCARD_RAW_PTR_ALLOC
#define _NODISCARD_RAW_PTR_ALLOC _NODISCARD
#endif


template <class T>
_NODISCARD constexpr void* ___voidify_iter(T iter) noexcept {
if constexpr (::std::is_pointer_v<T>) {
return const_cast<void*>(static_cast<const volatile void*>(iter));
}
else {
return const_cast<void*>(static_cast<const volatile void*>(::std::addressof(*iter)));
}
}

template <typename T, POOL_TYPE _Pool = PagedPool, unsigned long _Tag = 'trcu'>
class kallocator {
public:
static_assert(!::std::is_const_v<T>, "The C++ Standard forbids containers of const elements "
"because kallocator<const T> is ill-formed.");

using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using propagate_on_container_move_assignment = true_type;

#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
using pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = T*;
using const_pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const T*;
using reference _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = T&;
using const_reference _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const T&;
using is_always_equal _CXX20_DEPRECATE_IS_ALWAYS_EQUAL = true_type;

template <typename N>
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
using other = kallocator<N, _Pool, _Tag>;
};

_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD T* address(T& value) const noexcept {
return ::std::addressof(value);
}

_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD const T* address(const T& value) const noexcept {
return ::std::addressof(value);
}
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS

constexpr kallocator() noexcept {}
constexpr kallocator(const kallocator&) noexcept = default;

template <typename N>
constexpr kallocator(const kallocator<N, _Pool, _Tag>&) noexcept {}
_CONSTEXPR20 ~kallocator() = default;
_CONSTEXPR20 kallocator& operator=(const kallocator&) = default;

_CONSTEXPR20 void deallocate(T* const ptr, const size_t count) {
_STL_ASSERT(ptr != nullptr || count == 0, "null pointer cannot point to a block of non-zero size");
__noop(count); // ignore

// no overflow check on the following multiply; we assume allocate did that check
::operator delete(ptr, _Pool, _Tag);
}

_NODISCARD_RAW_PTR_ALLOC _CONSTEXPR20 __declspec(allocator) T* allocate(const size_t count) {
static_assert(sizeof(value_type) > 0, "value_type must be complete before calling allocate.");
return static_cast<T*>(::operator new(sizeof(T) * count, _Pool, _Tag));
}

#if _HAS_CXX23
_NODISCARD_RAW_PTR_ALLOC constexpr allocation_result<T*> allocate_at_least(
_CRT_GUARDOVERFLOW const size_t count) {
return { allocate(count), count };
}
#endif // _HAS_CXX23

#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD_RAW_PTR_ALLOC __declspec(allocator) T* allocate(
_CRT_GUARDOVERFLOW const size_t count, const void*) {
return allocate(count);
}

template <typename N, typename... Ns>
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS void construct(N* const ptr, Ns&&... args) {
::new (___voidify_iter(ptr)) N(::std::forward<Ns>(args)...);
}

template <typename N>
_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS void destroy(N* const object) {
object->~N();
}

_CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS _NODISCARD size_t max_size() const noexcept {
return static_cast<size_t>(-1) / sizeof(T);
}
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS
};


#if _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS
template <>
class kallocator<void> {
public:
using value_type = void;

#if _HAS_DEPRECATED_ALLOCATOR_MEMBERS
using pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = void*;
using const_pointer _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS = const void*;

template <class N>
struct _CXX17_DEPRECATE_OLD_ALLOCATOR_MEMBERS rebind {
using other = kallocator<N>;
};
#endif // _HAS_DEPRECATED_ALLOCATOR_MEMBERS

#if _HAS_CXX20
using size_type = size_t;
using difference_type = ptrdiff_t;

using propagate_on_container_move_assignment = true_type;
using is_always_equal _CXX20_DEPRECATE_IS_ALWAYS_EQUAL = true_type;
#endif // _HAS_CXX20
};
#endif // _HAS_DEPRECATED_ALLOCATOR_VOID || _HAS_DEPRECATED_ALLOCATOR_MEMBERS


_STD_END
2 changes: 1 addition & 1 deletion src/crt/stl/excptptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" _CRTIMP2 void* __cdecl __AdjustPointer(void*, const PMD&); // defined
using namespace std;

#ifndef _MSVC_NOOP_DTOR
#define _MSVC_NOOP_DTOR [[msvc::noop_dtor]]
#define _MSVC_NOOP_DTOR
#endif

namespace {
Expand Down
Loading

0 comments on commit 8195bfe

Please sign in to comment.