[all] Remove dependencies on non-freestanding libc
This is the first of two rather big changes to clean up includes throughout the project. In this commit, the implicit semi-dependency on libc that bonnibel adds to every module is removed. Previously, I was sloppy with includes of libc headers and include directory order. Now, the freestanding headers from libc are split out into libc_free, and an implicit real dependency is added onto this module, unless `no_libc` is set to `True`. The full libc needs to be explicitly specified as a dependency to be used. Several things needed to change in order to do this: - Many places use `memset` or `memcpy` that cannot depend on libc. The kernel has basic implementations of them itself for this reason. Now those functions are moved into the lower-level `j6/memutils.h`, and libc merely references them. Other modules are now free to reference those functions from libj6 instead. - The kernel's `assert.h` was renamed kassert.h (matching its `kassert` function) so that the new `util/assert.h` can use `__has_include` to detect it and make sure the `assert` macro is usable in libutil code. - Several implementation header files under `__libj6/` also moved under the new libc_free. - A new `include_phase` property has been added to modules for Bonnibel, which can be "normal" (default) or "late" which uses `-idirafter` instead of `-I` for includes. - Since `<utility>` and `<new>` are not freestanding, implementations of `remove_reference`, `forward`, `move`, and `swap` were added to the `util` namespace to replace those from `std`, and `util/new.h` was added to declare `operator new` and `operator delete`.
This commit is contained in:
@@ -9,7 +9,6 @@ variables:
|
|||||||
|
|
||||||
ccflags: [
|
ccflags: [
|
||||||
"-I${source_root}/src/include",
|
"-I${source_root}/src/include",
|
||||||
"-I${source_root}/src/include/x86_64",
|
|
||||||
"-fcolor-diagnostics",
|
"-fcolor-diagnostics",
|
||||||
"-U__STDCPP_THREADS__",
|
"-U__STDCPP_THREADS__",
|
||||||
"-D_LIBCPP_HAS_NO_THREADS",
|
"-D_LIBCPP_HAS_NO_THREADS",
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ variables:
|
|||||||
"-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1",
|
"-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1",
|
||||||
"-DPRINTF_INCLUDE_CONFIG_H=1",
|
"-DPRINTF_INCLUDE_CONFIG_H=1",
|
||||||
|
|
||||||
"-isystem${build_root}/include/libc",
|
|
||||||
"-isystem${source_root}/sysroot/include",
|
|
||||||
"--sysroot='${source_root}/sysroot'" ]
|
"--sysroot='${source_root}/sysroot'" ]
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +44,7 @@ variables:
|
|||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fno-rtti",
|
"-fno-rtti",
|
||||||
"-nostdinc",
|
"-nostdinc",
|
||||||
"-isystem${source_root}/sysroot/include/c++/v1" ]
|
]
|
||||||
|
|
||||||
ldflags: [
|
ldflags: [
|
||||||
"-g",
|
"-g",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
rule compile.c
|
rule compile.c
|
||||||
command = $cc -MMD -MF $out.d $cflags $ccflags -o $out -c $in
|
command = $cc -MMD -MF $out.d $cflags $ccflags -o $out -c $in
|
||||||
description = Compiling $name
|
description = Compiling [$target]:$name
|
||||||
depfile = $out.d
|
depfile = $out.d
|
||||||
deps = gcc
|
deps = gcc
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ rule dump_c_run
|
|||||||
|
|
||||||
rule compile.cpp
|
rule compile.cpp
|
||||||
command = $cxx -MMD -MF $out.d $cxxflags $ccflags -o $out -c $in
|
command = $cxx -MMD -MF $out.d $cxxflags $ccflags -o $out -c $in
|
||||||
description = Compiling $name
|
description = Compiling [$target]:$name
|
||||||
depfile = $out.d
|
depfile = $out.d
|
||||||
deps = gcc
|
deps = gcc
|
||||||
|
|
||||||
@@ -32,13 +32,13 @@ rule dump_cpp_run
|
|||||||
|
|
||||||
rule compile.s
|
rule compile.s
|
||||||
command = $nasm -o $out -felf64 -MD $out.d $asflags $in
|
command = $nasm -o $out -felf64 -MD $out.d $asflags $in
|
||||||
description = Assembling $name
|
description = Assembling [$target]:$name
|
||||||
depfile = $out.d
|
depfile = $out.d
|
||||||
deps = gcc
|
deps = gcc
|
||||||
|
|
||||||
rule parse.cog
|
rule parse.cog
|
||||||
command = cog -o $out -d -D target=$target $cogflags $in
|
command = cog -o $out -d -D target=$target $cogflags $in
|
||||||
description = Parsing $name
|
description = Parsing [$target]:$name
|
||||||
|
|
||||||
rule exe
|
rule exe
|
||||||
command = $ld $ldflags -o $out $in $libs
|
command = $ld $ldflags -o $out $in $libs
|
||||||
@@ -46,11 +46,11 @@ rule exe
|
|||||||
|
|
||||||
rule lib
|
rule lib
|
||||||
command = $ar qcs $out $in
|
command = $ar qcs $out $in
|
||||||
description = Archiving $name
|
description = Archiving [$target]:$name
|
||||||
|
|
||||||
rule cp
|
rule cp
|
||||||
command = cp $in $out
|
command = cp $in $out
|
||||||
description = Copying $name
|
description = Copying [$target]:$name
|
||||||
|
|
||||||
rule dump
|
rule dump
|
||||||
command = objdump -DSC -M intel $in > $out
|
command = objdump -DSC -M intel $in > $out
|
||||||
|
|||||||
@@ -21,15 +21,13 @@ variables:
|
|||||||
"-U__linux",
|
"-U__linux",
|
||||||
"-U__linux__",
|
"-U__linux__",
|
||||||
|
|
||||||
"-isystem${source_root}/sysroot/include",
|
|
||||||
"-isystem${build_root}/include/libc",
|
|
||||||
"--sysroot='${source_root}/sysroot'" ]
|
"--sysroot='${source_root}/sysroot'" ]
|
||||||
|
|
||||||
|
|
||||||
cxxflags: [
|
cxxflags: [
|
||||||
"-fno-exceptions",
|
"-fno-exceptions",
|
||||||
"-fno-rtti",
|
"-fno-rtti",
|
||||||
"-isystem${source_root}/sysroot/include/c++/v1" ]
|
]
|
||||||
|
|
||||||
ldflags: [
|
ldflags: [
|
||||||
"-g",
|
"-g",
|
||||||
|
|||||||
2
external/zstd.module
vendored
2
external/zstd.module
vendored
@@ -3,7 +3,7 @@
|
|||||||
zstd = module("zstd",
|
zstd = module("zstd",
|
||||||
root = "${source_root}/external/zstd",
|
root = "${source_root}/external/zstd",
|
||||||
kind = "lib",
|
kind = "lib",
|
||||||
deps = [ ],
|
deps = [ "libc" ],
|
||||||
output = "libzstd.a",
|
output = "libzstd.a",
|
||||||
sources = [
|
sources = [
|
||||||
"decompress/zstd_decompress.c",
|
"decompress/zstd_decompress.c",
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ def resolve(path):
|
|||||||
return str(Path(path).resolve())
|
return str(Path(path).resolve())
|
||||||
|
|
||||||
class BuildOptions:
|
class BuildOptions:
|
||||||
def __init__(self, includes=tuple(), libs=tuple(), order_only=tuple(), ld_script=None):
|
def __init__(self, includes=tuple(), local=tuple(), late=tuple(), libs=tuple(), order_only=tuple(), ld_script=None):
|
||||||
self.includes = list(includes)
|
self.includes = list(includes)
|
||||||
|
self.local = list(local)
|
||||||
|
self.late = list(late)
|
||||||
self.libs = list(libs)
|
self.libs = list(libs)
|
||||||
self.order_only = list(order_only)
|
self.order_only = list(order_only)
|
||||||
self.ld_script = ld_script and str(ld_script)
|
self.ld_script = ld_script and str(ld_script)
|
||||||
@@ -30,6 +32,7 @@ class Module:
|
|||||||
"deps": (set, ()),
|
"deps": (set, ()),
|
||||||
"public_headers": (set, ()),
|
"public_headers": (set, ()),
|
||||||
"includes": (tuple, ()),
|
"includes": (tuple, ()),
|
||||||
|
"include_phase": (str, "normal"),
|
||||||
"sources": (tuple, ()),
|
"sources": (tuple, ()),
|
||||||
"drivers": (tuple, ()),
|
"drivers": (tuple, ()),
|
||||||
"variables": (dict, ()),
|
"variables": (dict, ()),
|
||||||
@@ -59,6 +62,9 @@ class Module:
|
|||||||
if not name in self.__fields:
|
if not name in self.__fields:
|
||||||
raise AttributeError(f"No attribute named {name} on Module")
|
raise AttributeError(f"No attribute named {name} on Module")
|
||||||
|
|
||||||
|
if not self.no_libc:
|
||||||
|
self.deps.add("libc_free")
|
||||||
|
|
||||||
# Turn strings into real Source objects
|
# Turn strings into real Source objects
|
||||||
self.sources = [make_source(root, f) for f in self.sources]
|
self.sources = [make_source(root, f) for f in self.sources]
|
||||||
self.public_headers = [make_source(root, f) for f in self.public_headers]
|
self.public_headers = [make_source(root, f) for f in self.public_headers]
|
||||||
@@ -132,8 +138,6 @@ class Module:
|
|||||||
|
|
||||||
header_targets = []
|
header_targets = []
|
||||||
if add_headers:
|
if add_headers:
|
||||||
if not self.no_libc:
|
|
||||||
header_targets.append(f"${{build_root}}/include/libc/{phony}")
|
|
||||||
if self.public_headers:
|
if self.public_headers:
|
||||||
header_targets.append(f"${{build_root}}/include/{self.name}/{phony}")
|
header_targets.append(f"${{build_root}}/include/{self.name}/{phony}")
|
||||||
|
|
||||||
@@ -184,7 +188,7 @@ class Module:
|
|||||||
build.variable("module_dir", target_rel(self.name + ".dir"))
|
build.variable("module_dir", target_rel(self.name + ".dir"))
|
||||||
|
|
||||||
modopts = BuildOptions(
|
modopts = BuildOptions(
|
||||||
includes = [self.root, "${module_dir}"],
|
local = [self.root, "${module_dir}"],
|
||||||
ld_script = self.ld_script and self.root / self.ld_script,
|
ld_script = self.ld_script and self.root / self.ld_script,
|
||||||
)
|
)
|
||||||
if self.public_headers:
|
if self.public_headers:
|
||||||
@@ -207,19 +211,37 @@ class Module:
|
|||||||
modopts.includes.append(str(incpath))
|
modopts.includes.append(str(incpath))
|
||||||
modopts.includes.append(destpath)
|
modopts.includes.append(destpath)
|
||||||
|
|
||||||
all_deps = walk_deps(self.depmods)
|
|
||||||
for dep in all_deps:
|
for dep in all_deps:
|
||||||
if dep.public_headers:
|
if dep.public_headers:
|
||||||
|
if dep.include_phase == "normal":
|
||||||
modopts.includes += [f"${{build_root}}/include/{dep.name}"]
|
modopts.includes += [f"${{build_root}}/include/{dep.name}"]
|
||||||
|
elif dep.include_phase == "late":
|
||||||
|
modopts.late += [f"${{build_root}}/include/{dep.name}"]
|
||||||
|
else:
|
||||||
|
from . import BonnibelError
|
||||||
|
raise BonnibelError(f"Module {dep.name} has invalid include_phase={dep.include_phase}")
|
||||||
|
|
||||||
if dep.kind == "lib":
|
if dep.kind == "lib":
|
||||||
modopts.libs.append(target_rel(dep.output))
|
modopts.libs.append(target_rel(dep.output))
|
||||||
else:
|
else:
|
||||||
modopts.order_only.append(target_rel(dep.output))
|
modopts.order_only.append(target_rel(dep.output))
|
||||||
|
|
||||||
|
cc_includes = []
|
||||||
|
if modopts.local:
|
||||||
|
cc_includes += [f"-iquote{i}" for i in modopts.local]
|
||||||
|
|
||||||
if modopts.includes:
|
if modopts.includes:
|
||||||
build.variable("ccflags", ["${ccflags}"] + [f"-I{i}" for i in modopts.includes])
|
cc_includes += [f"-I{i}" for i in modopts.includes]
|
||||||
build.variable("asflags", ["${asflags}"] + [f"-I{i}" for i in modopts.includes])
|
|
||||||
|
if modopts.late:
|
||||||
|
cc_includes += [f"-idirafter{i}" for i in modopts.late]
|
||||||
|
|
||||||
|
if cc_includes:
|
||||||
|
build.variable("ccflags", ["${ccflags}"] + cc_includes)
|
||||||
|
|
||||||
|
as_includes = [f"-I{d}" for d in modopts.local + modopts.includes + modopts.late]
|
||||||
|
if as_includes:
|
||||||
|
build.variable("asflags", ["${asflags}"] + as_includes)
|
||||||
|
|
||||||
if modopts.libs:
|
if modopts.libs:
|
||||||
build.variable("libs", ["${libs}"] + modopts.libs)
|
build.variable("libs", ["${libs}"] + modopts.libs)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "apic.h"
|
#include "apic.h"
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
|
|
||||||
using __exit_func = void (*)(void *);
|
using __exit_func = void (*)(void *);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#include <new>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
#include <util/bitset.h>
|
#include <util/bitset.h>
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#include <new>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/misc.h> // for checksum
|
#include <util/misc.h> // for checksum
|
||||||
#include <util/pointers.h>
|
#include <util/pointers.h>
|
||||||
#include <arch/acpi/tables.h>
|
#include <arch/acpi/tables.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "apic.h"
|
#include "apic.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <bootproto/kernel.h>
|
#include <bootproto/kernel.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "debugcon.h"
|
#include "debugcon.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include <stdint.h>
|
#include <j6/memutils.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#include <new>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <util/pointers.h>
|
#include <util/pointers.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "heap_allocator.h"
|
#include "heap_allocator.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "objects/vm_area.h"
|
#include "objects/vm_area.h"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
#include "hpet.h"
|
#include "hpet.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
|
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
/// \file idt.h
|
/// \file idt.h
|
||||||
/// Definitions relating to a CPU's IDT table
|
/// Definitions relating to a CPU's IDT table
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
|
|
||||||
class IDT
|
class IDT
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/format.h>
|
#include <util/format.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
|
|
||||||
namespace panic {
|
namespace panic {
|
||||||
@@ -10,7 +10,7 @@ kernel = module("kernel",
|
|||||||
ld_script = "kernel.ld",
|
ld_script = "kernel.ld",
|
||||||
sources = [
|
sources = [
|
||||||
"apic.cpp",
|
"apic.cpp",
|
||||||
"assert.cpp",
|
"kassert.cpp",
|
||||||
"boot.s",
|
"boot.s",
|
||||||
"capabilities.cpp",
|
"capabilities.cpp",
|
||||||
"clock.cpp",
|
"clock.cpp",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <bootproto/kernel.h>
|
#include <bootproto/kernel.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "debugcon.h"
|
#include "debugcon.h"
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#include <new>
|
#include <j6/memutils.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <util/format.h>
|
#include <util/format.h>
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "objects/system.h"
|
#include "objects/system.h"
|
||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
|
|||||||
@@ -3,26 +3,3 @@
|
|||||||
namespace std {
|
namespace std {
|
||||||
enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
|
enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of memset and memcpy because we're not
|
|
||||||
// linking libc into the kernel
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void *
|
|
||||||
memset(void *s, uint8_t v, size_t n)
|
|
||||||
{
|
|
||||||
uint8_t *p = reinterpret_cast<uint8_t *>(s);
|
|
||||||
for (size_t i = 0; i < n; ++i) p[i] = v;
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
memcpy(void *dest, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
const uint8_t *s = reinterpret_cast<const uint8_t *>(src);
|
|
||||||
uint8_t *d = reinterpret_cast<uint8_t *>(dest);
|
|
||||||
for (size_t i = 0; i < n; ++i) d[i] = s[i];
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
#include <new>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <arch/memory.h>
|
#include <arch/memory.h>
|
||||||
#include <bootproto/kernel.h>
|
#include <bootproto/kernel.h>
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
#include <j6/types.h>
|
#include <j6/types.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "objects/kobject.h"
|
#include "objects/kobject.h"
|
||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#include <new>
|
|
||||||
|
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "objects/process.h"
|
#include "objects/process.h"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <util/pointers.h>
|
#include <util/pointers.h>
|
||||||
|
|
||||||
|
#include "kassert.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "objects/vm_area.h"
|
#include "objects/vm_area.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
#include <util/pointers.h>
|
#include <util/pointers.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "page_table.h"
|
#include "page_table.h"
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
|
|
||||||
#include <arch/memory.h>
|
#include <arch/memory.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "page_tree.h"
|
#include "page_tree.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <new>
|
#include <util/new.h>
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <util/spinlock.h>
|
#include <util/spinlock.h>
|
||||||
|
|
||||||
#include "apic.h"
|
#include "apic.h"
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
/// \file slab_allocated.h
|
/// \file slab_allocated.h
|
||||||
/// A parent template class for slab-allocated objects
|
/// A parent template class for slab-allocated objects
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <j6/memutils.h>
|
||||||
#include <util/pointers.h>
|
#include <util/pointers.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
|
||||||
|
#include "kassert.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
template <typename T, size_t N>
|
template <typename T, size_t N>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// vim: ft=cpp
|
// vim: ft=cpp
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
|
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
|
#include <util/basic_types.h>
|
||||||
#include <util/node_map.h>
|
#include <util/node_map.h>
|
||||||
#include <util/spinlock.h>
|
#include <util/spinlock.h>
|
||||||
|
|
||||||
@@ -20,11 +21,11 @@ struct futex
|
|||||||
futex() = default;
|
futex() = default;
|
||||||
futex(futex &&other) :
|
futex(futex &&other) :
|
||||||
address {other.address},
|
address {other.address},
|
||||||
queue {std::move(other.queue)} {}
|
queue {util::move(other.queue)} {}
|
||||||
|
|
||||||
futex & operator=(futex &&other) {
|
futex & operator=(futex &&other) {
|
||||||
address = other.address;
|
address = other.address;
|
||||||
queue = std::move(other.queue);
|
queue = util::move(other.queue);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <j6/types.h>
|
#include <j6/types.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
#include "syscalls/helpers.h"
|
#include "syscalls/helpers.h"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
#include <util/no_construct.h>
|
#include <util/no_construct.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
|
|
||||||
#include <arch/memory.h>
|
#include <arch/memory.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "kassert.h"
|
||||||
#include "frame_allocator.h"
|
#include "frame_allocator.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <utility>
|
#include <util/basic_types.h>
|
||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
#include "wait_queue.h"
|
#include "wait_queue.h"
|
||||||
|
|
||||||
wait_queue::wait_queue(wait_queue &&other) :
|
wait_queue::wait_queue(wait_queue &&other) :
|
||||||
m_threads {std::move(other.m_threads)} {}
|
m_threads {util::move(other.m_threads)} {}
|
||||||
|
|
||||||
wait_queue::~wait_queue() { clear(); }
|
wait_queue::~wait_queue() { clear(); }
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ wait_queue &
|
|||||||
wait_queue::operator=(wait_queue &&other)
|
wait_queue::operator=(wait_queue &&other)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
m_threads = std::move(other.m_threads);
|
m_threads = util::move(other.m_threads);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
// but should not include the user-specific code.
|
// but should not include the user-specific code.
|
||||||
#ifndef __j6kernel
|
#ifndef __j6kernel
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <arch/memory.h>
|
#include <arch/memory.h>
|
||||||
#include <j6/channel.hh>
|
#include <j6/channel.hh>
|
||||||
#include <j6/condition.hh>
|
#include <j6/condition.hh>
|
||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
#include <j6/flags.h>
|
#include <j6/flags.h>
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <j6/mutex.hh>
|
#include <j6/mutex.hh>
|
||||||
#include <j6/syscalls.h>
|
#include <j6/syscalls.h>
|
||||||
#include <j6/syslog.hh>
|
#include <j6/syslog.hh>
|
||||||
|
|||||||
@@ -1,23 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
/** \file j6libc/copy.h
|
/// \file copy.h
|
||||||
* Internal implementations to aid in implementing mem* functions
|
/// Internal implementations to aid in implementing mem* functions
|
||||||
*
|
|
||||||
* This file is part of the C standard library for the jsix operating
|
|
||||||
* system.
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#error "__j6libc/copy.h included by non-C++ code"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <__j6libc/size_t.h>
|
|
||||||
|
|
||||||
namespace __j6libc {
|
namespace j6 {
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
inline void do_copy(char *s1, const char *s2) {
|
inline void do_copy(char *s1, const char *s2) {
|
||||||
@@ -52,4 +39,4 @@ inline void do_backward_copy(char *s1, const char *s2, size_t n) {
|
|||||||
s1[i] = s2[i];
|
s1[i] = s2[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace __j6libc
|
} // namespace j6
|
||||||
@@ -8,6 +8,7 @@ j6 = module("j6",
|
|||||||
"condition.cpp",
|
"condition.cpp",
|
||||||
"init.cpp",
|
"init.cpp",
|
||||||
"init.s",
|
"init.s",
|
||||||
|
"memutils.cpp",
|
||||||
"mutex.cpp",
|
"mutex.cpp",
|
||||||
"protocol_ids.cpp",
|
"protocol_ids.cpp",
|
||||||
"syscalls.s.cog",
|
"syscalls.s.cog",
|
||||||
@@ -23,6 +24,7 @@ j6 = module("j6",
|
|||||||
"j6/flags.h",
|
"j6/flags.h",
|
||||||
"j6/init.h",
|
"j6/init.h",
|
||||||
"j6/mutex.hh",
|
"j6/mutex.hh",
|
||||||
|
"j6/memutils.h",
|
||||||
"j6/protocols.h",
|
"j6/protocols.h",
|
||||||
"j6/protocols/service_locator.h",
|
"j6/protocols/service_locator.h",
|
||||||
"j6/syscalls.h.cog",
|
"j6/syscalls.h.cog",
|
||||||
|
|||||||
18
src/libraries/j6/j6/memutils.h
Normal file
18
src/libraries/j6/j6/memutils.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
/// \file memutils.h
|
||||||
|
/// Standard mem*() library functions
|
||||||
|
|
||||||
|
#include <__j6libc/restrict.h>
|
||||||
|
#include <__j6libc/size_t.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
|
||||||
|
void *memmove(void * restrict s1, const void * restrict s2, size_t n);
|
||||||
|
void *memset(void *s, int c, size_t n);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
@@ -1,19 +1,35 @@
|
|||||||
/** \file memset.cpp
|
#include <stddef.h>
|
||||||
*
|
#include <j6/memutils.h>
|
||||||
* This file is part of the C standard library for the jsix operating
|
|
||||||
* system.
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <__j6libc/bits.h>
|
#include <__j6libc/bits.h>
|
||||||
#include <__j6libc/casts.h>
|
#include <__j6libc/casts.h>
|
||||||
|
#include "copy.h"
|
||||||
|
|
||||||
|
using namespace j6;
|
||||||
using namespace __j6libc;
|
using namespace __j6libc;
|
||||||
|
|
||||||
|
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) {
|
||||||
|
asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory");
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void memmove_dispatch(char *s1, const char *s2, size_t n) {
|
||||||
|
if (s1 == s2) return;
|
||||||
|
|
||||||
|
if (s1 < s2 || s1 > s2 + n)
|
||||||
|
memcpy(s1, s2, n);
|
||||||
|
else
|
||||||
|
do_backward_copy(s1, s2, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *memmove(void * restrict s1, const void * restrict s2, size_t n) {
|
||||||
|
memmove_dispatch(
|
||||||
|
reinterpret_cast<char*>(s1),
|
||||||
|
reinterpret_cast<const char*>(s1),
|
||||||
|
n);
|
||||||
|
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
||||||
#if __UINTPTR_WIDTH__ != 64 && __UINTPTR_WIDTH__ != 32
|
#if __UINTPTR_WIDTH__ != 64 && __UINTPTR_WIDTH__ != 32
|
||||||
#error "memset: uintptr_t isn't 4 or 8 bytes"
|
#error "memset: uintptr_t isn't 4 or 8 bytes"
|
||||||
#endif
|
#endif
|
||||||
@@ -28,7 +44,6 @@ static inline uintptr_t repval(uint8_t c) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *memset(void *s, int c, size_t n) {
|
void *memset(void *s, int c, size_t n) {
|
||||||
if (!s) return nullptr;
|
if (!s) return nullptr;
|
||||||
|
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
// but should not include the user-specific code.
|
// but should not include the user-specific code.
|
||||||
#ifndef __j6kernel
|
#ifndef __j6kernel
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <j6/errors.h>
|
#include <j6/errors.h>
|
||||||
#include <j6/flags.h>
|
#include <j6/flags.h>
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <j6/syscalls.h>
|
#include <j6/syscalls.h>
|
||||||
#include <j6/thread.hh>
|
#include <j6/thread.hh>
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ libc = module("libc",
|
|||||||
kind = "lib",
|
kind = "lib",
|
||||||
deps = [ "j6" ],
|
deps = [ "j6" ],
|
||||||
output = "libc.a",
|
output = "libc.a",
|
||||||
|
include_phase = "late",
|
||||||
sources = sources,
|
sources = sources,
|
||||||
public_headers = headers,
|
public_headers = headers,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
/** \file memcpy.cpp
|
|
||||||
*
|
|
||||||
* This file is part of the C standard library for the jsix operating
|
|
||||||
* system.
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) {
|
|
||||||
asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory");
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
/** \file memmove.cpp
|
|
||||||
*
|
|
||||||
* This file is part of the C standard library for the jsix operating
|
|
||||||
* system.
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <__j6libc/copy.h>
|
|
||||||
|
|
||||||
using namespace __j6libc;
|
|
||||||
|
|
||||||
void memmove_dispatch(char *s1, const char *s2, size_t n) {
|
|
||||||
if (s1 == s2) return;
|
|
||||||
|
|
||||||
if (s1 < s2 || s1 > s2 + n)
|
|
||||||
memcpy(s1, s2, n);
|
|
||||||
else
|
|
||||||
do_backward_copy(s1, s2, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *memmove(void * restrict s1, const void * restrict s2, size_t n) {
|
|
||||||
memmove_dispatch(
|
|
||||||
reinterpret_cast<char*>(s1),
|
|
||||||
reinterpret_cast<const char*>(s2),
|
|
||||||
n);
|
|
||||||
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
24
src/libraries/libc_free/libc_free.module
Normal file
24
src/libraries/libc_free/libc_free.module
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# vim: ft=python
|
||||||
|
|
||||||
|
libc_free = module("libc_free",
|
||||||
|
kind = "lib",
|
||||||
|
no_libc = True,
|
||||||
|
include_phase = "late",
|
||||||
|
public_headers = [
|
||||||
|
'float.h',
|
||||||
|
'iso646.h',
|
||||||
|
'limits.h',
|
||||||
|
'stdalign.h',
|
||||||
|
'stdarg.h',
|
||||||
|
'stdbool.h',
|
||||||
|
'stddef.h',
|
||||||
|
'stdint.h.cog',
|
||||||
|
'stdnoreturn.h',
|
||||||
|
|
||||||
|
'__j6libc/bits.h',
|
||||||
|
'__j6libc/casts.h',
|
||||||
|
'__j6libc/null.h',
|
||||||
|
'__j6libc/restrict.h',
|
||||||
|
'__j6libc/size_t.h',
|
||||||
|
'__j6libc/wchar_t.h',
|
||||||
|
])
|
||||||
@@ -10,6 +10,7 @@ module("util",
|
|||||||
],
|
],
|
||||||
public_headers = [
|
public_headers = [
|
||||||
"util/allocator.h",
|
"util/allocator.h",
|
||||||
|
"util/assert.h",
|
||||||
"util/basic_types.h",
|
"util/basic_types.h",
|
||||||
"util/bip_buffer.h",
|
"util/bip_buffer.h",
|
||||||
"util/bitset.h",
|
"util/bitset.h",
|
||||||
@@ -22,6 +23,7 @@ module("util",
|
|||||||
"util/linked_list.h",
|
"util/linked_list.h",
|
||||||
"util/map.h",
|
"util/map.h",
|
||||||
"util/misc.h",
|
"util/misc.h",
|
||||||
|
"util/new.h",
|
||||||
"util/no_construct.h",
|
"util/no_construct.h",
|
||||||
"util/node_map.h",
|
"util/node_map.h",
|
||||||
"util/pointers.h",
|
"util/pointers.h",
|
||||||
|
|||||||
13
src/libraries/util/util/assert.h
Normal file
13
src/libraries/util/util/assert.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
/// \file assert.h
|
||||||
|
/// Utility header to include the right assert.h for the environment
|
||||||
|
|
||||||
|
#if __has_include("kassert.h")
|
||||||
|
#include "kassert.h"
|
||||||
|
#elif __has_include(<assert.h>)
|
||||||
|
#include <assert.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(assert)
|
||||||
|
#define assert(x) ((void)0)
|
||||||
|
#endif
|
||||||
@@ -73,4 +73,21 @@ template <unsigned N> struct sized_uint {
|
|||||||
using type = typename sized_uint_type<N>::type;
|
using type = typename sized_uint_type<N>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T> struct remove_reference { using type = T; };
|
||||||
|
template <typename T> struct remove_reference<T&> { using type = T; };
|
||||||
|
template <typename T> struct remove_reference<T&&> { using type = T; };
|
||||||
|
|
||||||
} // namespace types
|
} // namespace types
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename types::remove_reference<T>::type&&
|
||||||
|
move( T&& x ) { return (typename types::remove_reference<T>::type&&)x; }
|
||||||
|
|
||||||
|
template<typename T> T&& forward(typename types::remove_reference<T>::type&& param) { return static_cast<T&&>(param); }
|
||||||
|
template<typename T> T&& forward(typename types::remove_reference<T>::type& param) { return static_cast<T&&>(param); }
|
||||||
|
|
||||||
|
template<typename T> void swap(T &t1, T &t2) { T tmp = move(t1); t1 = move(t2); t2 = move(tmp); }
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
/// \file linked_list.h
|
/// \file linked_list.h
|
||||||
/// A generic templatized linked list.
|
/// A generic templatized linked list.
|
||||||
|
|
||||||
#include <utility>
|
#include <j6/memutils.h>
|
||||||
#include <assert.h>
|
#include <util/assert.h>
|
||||||
#include <string.h>
|
#include <util/basic_types.h>
|
||||||
#include <util/linked_list.h>
|
#include <util/linked_list.h>
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
deque(deque &&other) :
|
deque(deque &&other) :
|
||||||
m_first {other.m_first},
|
m_first {other.m_first},
|
||||||
m_next {other.m_next},
|
m_next {other.m_next},
|
||||||
m_list {std::move(other.m_list)} {}
|
m_list {util::move(other.m_list)} {}
|
||||||
|
|
||||||
~deque() { clear(); }
|
~deque() { clear(); }
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public:
|
|||||||
clear();
|
clear();
|
||||||
m_first = other.m_first;
|
m_first = other.m_first;
|
||||||
m_next = other.m_next;
|
m_next = other.m_next;
|
||||||
m_list = std::move(other.m_list);
|
m_list = util::move(other.m_list);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <util/hash.h>
|
#include <util/hash.h>
|
||||||
#include <util/vector.h>
|
#include <util/vector.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
|
|||||||
14
src/libraries/util/util/new.h
Normal file
14
src/libraries/util/util/new.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
/// \file new.h
|
||||||
|
/// Declarations for `operator new` to avoid including <new>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
void *operator new (size_t);
|
||||||
|
void *operator new [] (size_t);
|
||||||
|
void *operator new (size_t, void *) noexcept;
|
||||||
|
void *operator new [] (size_t, void *) noexcept;
|
||||||
|
void operator delete (void *) noexcept;
|
||||||
|
void operator delete [] (void *) noexcept;
|
||||||
|
void operator delete (void *, void *) noexcept;
|
||||||
|
void operator delete [] (void *, void *) noexcept;
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
/// http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
|
/// http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
#include <j6/memutils.h>
|
||||||
#include <util/allocator.h>
|
#include <util/allocator.h>
|
||||||
|
#include <util/basic_types.h>
|
||||||
#include <util/hash.h>
|
#include <util/hash.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ public:
|
|||||||
|
|
||||||
node_type new_node;
|
node_type new_node;
|
||||||
get_map_key(new_node) = key;
|
get_map_key(new_node) = key;
|
||||||
return insert(std::move(new_node));
|
return insert(util::move(new_node));
|
||||||
}
|
}
|
||||||
|
|
||||||
node_type * find(const key_type &key) {
|
node_type * find(const key_type &key) {
|
||||||
@@ -150,7 +150,7 @@ public:
|
|||||||
key_type &key_at_slot = get_map_key(node_at_slot);
|
key_type &key_at_slot = get_map_key(node_at_slot);
|
||||||
|
|
||||||
if (open(key_at_slot)) {
|
if (open(key_at_slot)) {
|
||||||
node_at_slot = std::move(node);
|
node_at_slot = util::move(node);
|
||||||
if (!found)
|
if (!found)
|
||||||
inserted_at = slot;
|
inserted_at = slot;
|
||||||
return m_nodes[inserted_at];
|
return m_nodes[inserted_at];
|
||||||
@@ -162,7 +162,7 @@ public:
|
|||||||
found = true;
|
found = true;
|
||||||
inserted_at = slot;
|
inserted_at = slot;
|
||||||
}
|
}
|
||||||
std::swap(node, node_at_slot);
|
util::swap(node, node_at_slot);
|
||||||
dist = psl_at_slot;
|
dist = psl_at_slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ protected:
|
|||||||
if (open(next_key) || psl(next_key, next_slot) == 0)
|
if (open(next_key) || psl(next_key, next_slot) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_nodes[slot] = std::move(next);
|
m_nodes[slot] = util::move(next);
|
||||||
next.~node_type();
|
next.~node_type();
|
||||||
next_key = invalid_id;
|
next_key = invalid_id;
|
||||||
++slot;
|
++slot;
|
||||||
@@ -236,7 +236,7 @@ protected:
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
--m_count;
|
--m_count;
|
||||||
insert(std::move(node));
|
insert(util::move(node));
|
||||||
node.~node_type();
|
node.~node_type();
|
||||||
key = invalid_id;
|
key = invalid_id;
|
||||||
}
|
}
|
||||||
@@ -297,7 +297,7 @@ public:
|
|||||||
bool add(item_type item) {
|
bool add(item_type item) {
|
||||||
if (contains(item))
|
if (contains(item))
|
||||||
return false;
|
return false;
|
||||||
m_map.insert(std::move(item));
|
m_map.insert(util::move(item));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/// Definition of a generic radix_tree structure
|
/// Definition of a generic radix_tree structure
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <j6/memutils.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
/// \file vector.h
|
/// \file vector.h
|
||||||
/// Definition of a simple dynamic vector collection for use in kernel space
|
/// Definition of a simple dynamic vector collection for use in kernel space
|
||||||
|
|
||||||
#include <assert.h>
|
#include <j6/memutils.h>
|
||||||
#include <new>
|
|
||||||
#include <string.h>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include <util/allocator.h>
|
#include <util/allocator.h>
|
||||||
|
#include <util/assert.h>
|
||||||
|
#include <util/basic_types.h>
|
||||||
|
#include <util/new.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
@@ -123,7 +122,7 @@ public:
|
|||||||
T & append(T &&item)
|
T & append(T &&item)
|
||||||
{
|
{
|
||||||
ensure_capacity(m_size + 1);
|
ensure_capacity(m_size + 1);
|
||||||
m_elements[m_size] = std::move(item);
|
m_elements[m_size] = util::move(item);
|
||||||
return m_elements[m_size++];
|
return m_elements[m_size++];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ public:
|
|||||||
T & emplace(Args&&... args)
|
T & emplace(Args&&... args)
|
||||||
{
|
{
|
||||||
ensure_capacity(m_size + 1);
|
ensure_capacity(m_size + 1);
|
||||||
new (&m_elements[m_size]) T(std::forward<Args>(args)...);
|
new (&m_elements[m_size]) T(util::forward<Args>(args)...);
|
||||||
return m_elements[m_size++];
|
return m_elements[m_size++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user