Skip to content

Commit 1ac8c4f

Browse files
committed
karm-base: Fix the weird dependency cycle between base and impl.
1 parent 675991d commit 1ac8c4f

File tree

58 files changed

+253
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+253
-214
lines changed

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ jobs:
3030
- name: Build Userspace (x86_64)
3131
run: ./skift.sh build --target=skift-x86_64
3232

33+
- name: Build Userspace (Host)
34+
run: ./skift.sh build

src/apps/hideo-file-manager/model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void reduce(State &s, Action a) {
2424
reduce(s, GoTo{parent});
2525
},
2626
[&](Navigate navigate) {
27-
Sys::Url dest = s.currentUrl();
27+
auto dest = s.currentUrl();
2828
dest.append(navigate.item);
2929
reduce(s, GoTo{dest});
3030
},

src/apps/hideo-file-manager/model.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#pragma once
22

3-
#include <karm-sys/url.h>
43
#include <karm-ui/reducer.h>
4+
#include <url/url.h>
55

66
namespace FileManager {
77

88
struct State {
9-
Vec<Sys::Url> history;
9+
Vec<Url::Url> history;
1010
usize currentIndex = 0;
1111

12-
State(Sys::Url path)
12+
State(Url::Url path)
1313
: history({path}) {}
1414

15-
Sys::Url currentUrl() const {
15+
Url::Url currentUrl() const {
1616
return history[currentIndex];
1717
}
1818

@@ -42,7 +42,7 @@ struct GoParent {
4242
};
4343

4444
struct GoTo {
45-
Sys::Url url;
45+
Url::Url url;
4646
};
4747

4848
struct Navigate {

src/apps/hideo-file-manager/widgets.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Mdi::Icon iconForLocation(Str loc) {
101101
return Mdi::FOLDER;
102102
}
103103

104-
Ui::Child breadcrumbRoot(Sys::Url url) {
104+
Ui::Child breadcrumbRoot(Url::Url url) {
105105
if (url.scheme == "location") {
106106
return Ui::button(
107107
Model::bind<GoRoot>(),

src/apps/hideo-font-viewer/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Ui::Child app(Strong<Media::Fontface> fontface) {
3737

3838
Res<> entryPoint(Ctx &ctx) {
3939
auto &args = useArgs(ctx);
40-
auto url = try$(Sys::parseUrlOrPath(args[0]));
40+
auto url = try$(Url::parseUrlOrPath(args[0]));
4141
auto fontface = try$(args.len()
4242
? Media::loadFontface(url)
4343
: Ok(Media::Fontface::fallback()));

src/apps/hideo-image-viewer/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Res<> entryPoint(Ctx &ctx) {
3030
Res<Media::Image> image = Error::invalidInput("No image provided");
3131

3232
if (args.len() > 0) {
33-
auto url = try$(Sys::parseUrlOrPath(args[0]));
33+
auto url = try$(Url::parseUrlOrPath(args[0]));
3434
image = Media::loadImage(url);
3535
}
3636

src/clis/dtb-dump/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Res<> entryPoint(Ctx &ctx) {
1010
return Error::invalidInput("Usage: dtb-dump <dtb-file>");
1111
}
1212

13-
auto url = try$(Sys::parseUrlOrPath(args[0]));
13+
auto url = try$(Url::parseUrlOrPath(args[0]));
1414
auto dtbFile = try$(Sys::File::open(url));
1515
auto dtbMem = try$(Sys::mmap().read().map(dtbFile));
1616
auto dtb = try$(DeviceTree::Blob::load(dtbMem.bytes()));

src/clis/handover-dump/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Res<> entryPoint(Ctx &ctx) {
1111
return Error::invalidInput("Usage: handover-dump <elf-file>");
1212
}
1313

14-
auto url = try$(Sys::parseUrlOrPath(args[0]));
14+
auto url = try$(Url::parseUrlOrPath(args[0]));
1515
Sys::File kernelFile = try$(Sys::File::open(url));
1616
auto kernelMem = try$(Sys::mmap().read().map(kernelFile));
1717
Elf::Image kernelElf{kernelMem.bytes()};

src/clis/hashsum/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Res<> entryPoint(Ctx &ctx) {
77
auto &args = useArgs(ctx);
88

9-
auto url = try$(Sys::parseUrlOrPath(args[0]));
9+
auto url = try$(Url::parseUrlOrPath(args[0]));
1010
auto file = try$(Sys::File::open(url));
1111
auto hash = try$(Hash::fromName(args[0]));
1212
auto digest = try$(Hash::digest(file, hash));

src/clis/ls/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <karm-sys/dir.h>
33

44
Res<> entryPoint(Ctx &) {
5-
auto url = try$(Sys::parseUrlOrPath("."));
5+
auto url = try$(Url::parseUrlOrPath("."));
66
auto dir = try$(Sys::Dir::open(url));
77
for (auto const &entry : dir.entries()) {
88
Sys::println(entry.name);

src/clis/ttf-dump/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Res<> entryPoint(Ctx &ctx) {
4343
return Error::invalidInput("Usage: dtb-dump <dtb-file>");
4444
}
4545

46-
auto url = try$(Sys::parseUrlOrPath(args[0]));
46+
auto url = try$(Url::parseUrlOrPath(args[0]));
4747
auto file = try$(Sys::File::open(url));
4848
auto map = try$(Sys::mmap().map(file));
4949
auto ttf = try$(Ttf::Font::load(map.bytes()));

src/impls/abi-sysv/abi.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx
22

33
#include <karm-base/lock.h>
4-
#include <karm-base/panic.h>
54

65
extern "C" int __cxa_atexit(void (*)(void *), void *, void *) {
76
return 0;

src/impls/abi-sysv/init.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <karm-base/panic.h>
21
#include <karm-base/std.h>
32

43
using InitFunc = void (*)();

src/impls/impl-efi/base.cpp

+1-55
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,11 @@
11
#include <efi/base.h>
22
#include <efi/spec.h>
3-
#include <karm-base/align.h>
4-
#include <karm-base/string.h>
5-
#include <karm-io/traits.h>
3+
64

75
#include <karm-base/_embed.h>
86

97
namespace Karm::_Embed {
108

11-
struct DebugOut : public Io::TextWriterBase<> {
12-
Res<usize> write(Bytes bytes) override {
13-
usize writen{};
14-
Array<u16, 129> buf{};
15-
// Some space for the null terminator.
16-
auto chunkSize = sizeOf(buf) - sizeof(u16);
17-
18-
while (not isEmpty(bytes)) {
19-
usize toCopy = alignDown(sizeOf(bytes), sizeof(u16));
20-
21-
// We need to copy the bytes into to a u16 aligned buffer.
22-
copy(sub(bytes, 0, toCopy), mutBytes(buf));
23-
24-
// If bytes.size() is not a multiple of sizeof(u16),
25-
// then the last byte will be ignored.
26-
buf[toCopy / sizeof(u16) + 1] = 0;
27-
28-
try$(Efi::st()->conOut->outputString(Efi::st()->conOut, buf.buf()));
29-
writen += toCopy;
30-
31-
bytes = next(bytes, chunkSize);
32-
}
33-
34-
return Ok(writen);
35-
}
36-
};
37-
38-
void debug(char const *buf) {
39-
Efi::st()->conOut->outputString(Efi::st()->conOut, (u16 const *)L"DEBUG: ").unwrap();
40-
DebugOut out{};
41-
(void)out.writeStr(buf);
42-
Efi::st()->conOut->outputString(Efi::st()->conOut, (u16 const *)EMBED_SYS_LINE_ENDING_L).unwrap();
43-
}
44-
45-
[[noreturn]] void panic(char const *buf) {
46-
Efi::st()->conOut->outputString(Efi::st()->conOut, (u16 const *)L"PANIC: ").unwrap();
47-
48-
DebugOut out{};
49-
(void)out.writeStr(buf);
50-
51-
Efi::st()->conOut->outputString(Efi::st()->conOut, (u16 const *)EMBED_SYS_LINE_ENDING_L).unwrap();
52-
53-
(void)Efi::st()->runtime->resetSystem(
54-
Efi::ResetType::RESET_SHUTDOWN,
55-
Efi::ERR_UNSUPPORTED,
56-
0,
57-
nullptr);
58-
59-
while (1)
60-
;
61-
}
62-
639
void relaxe() {
6410
#if defined(__x86_64__)
6511
asm volatile("pause");

src/impls/impl-efi/main.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <efi/base.h>
2+
#include <karm-base/align.h>
3+
#include <karm-base/string.h>
4+
#include <karm-io/traits.h>
5+
6+
struct DebugOut : public Io::TextWriterBase<> {
7+
Res<usize> write(Bytes bytes) override {
8+
usize writen{};
9+
Array<u16, 129> buf{};
10+
// Some space for the null terminator.
11+
auto chunkSize = sizeOf(buf) - sizeof(u16);
12+
13+
while (not isEmpty(bytes)) {
14+
usize toCopy = alignDown(sizeOf(bytes), sizeof(u16));
15+
16+
// We need to copy the bytes into to a u16 aligned buffer.
17+
copy(sub(bytes, 0, toCopy), mutBytes(buf));
18+
19+
// If bytes.size() is not a multiple of sizeof(u16),
20+
// then the last byte will be ignored.
21+
buf[toCopy / sizeof(u16) + 1] = 0;
22+
23+
try$(Efi::st()->conOut->outputString(Efi::st()->conOut, buf.buf()));
24+
writen += toCopy;
25+
26+
bytes = next(bytes, chunkSize);
27+
}
28+
29+
return Ok(writen);
30+
}
31+
};
32+
33+
void __panicHandler(Karm::PanicKind kind, char const *msg) {
34+
Efi::st()->conOut->outputString(Efi::st()->conOut, kind == Karm::PanicKind::PANIC ? (u16 const *)L"PANIC: " : (u16 const *)L"DEBUG: ").unwrap();
35+
36+
DebugOut out{};
37+
(void)out.writeStr(msg);
38+
Efi::st()->conOut->outputString(Efi::st()->conOut, (u16 const *)EMBED_SYS_LINE_ENDING_L).unwrap();
39+
40+
if (kind == Karm::PanicKind::PANIC) {
41+
(void)Efi::st()->runtime->resetSystem(
42+
Efi::ResetType::RESET_SHUTDOWN,
43+
Efi::ERR_UNSUPPORTED,
44+
0,
45+
nullptr);
46+
47+
while (1)
48+
;
49+
}
50+
}

src/impls/impl-efi/main.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include <karm-main/base.h>
77
#include <karm-sys/chan.h>
88

9-
#ifdef EMBED_EFI_MAIN_IMPL
9+
void __panicHandler(Karm::PanicKind kind, char const *msg);
1010

1111
extern "C" Efi::Status efi_main(Efi::Handle handle, Efi::SystemTable *st) {
1212
Efi::init(handle, st);
1313
Abi::Ms::init();
14+
Karm::registerPanicHandler(__panicHandler);
1415

1516
(void)Efi::st()->conOut->clearScreen(Efi::st()->conOut);
1617

@@ -29,5 +30,3 @@ extern "C" Efi::Status efi_main(Efi::Handle handle, Efi::SystemTable *st) {
2930

3031
return EFI_SUCCESS;
3132
}
32-
33-
#endif // EMBED_EFI_MAIN_IMPL

src/impls/impl-efi/manifest.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
"json-spec"
1515
],
1616
"provides": [
17-
"karm-base-impl",
1817
"karm-logger-impl",
1918
"karm-sys-impl",
2019
"karm-ui-impl"
2120
]
22-
}
21+
}

src/impls/impl-efi/sys.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Res<Strong<Sys::Fd>> createErr() {
140140

141141
static Opt<Json::Value> _index = NONE;
142142

143-
static Res<Sys::Path> resolve(Sys::Url url) {
143+
static Res<Url::Path> resolve(Url::Url url) {
144144
if (url.scheme == "file") {
145145
return Ok(url.path);
146146
}
@@ -184,9 +184,9 @@ static Res<Sys::Path> resolve(Sys::Url url) {
184184

185185
auto refStr = ref.asStr();
186186

187-
auto refUrl = Sys::Url::parse(refStr);
187+
auto refUrl = Url::Url::parse(refStr);
188188

189-
Sys::Path resolved = try$(resolve(refUrl));
189+
Url::Path resolved = try$(resolve(refUrl));
190190
logInfo("resolved to: {}", resolved);
191191
return Ok(resolved);
192192
} else {
@@ -195,7 +195,7 @@ static Res<Sys::Path> resolve(Sys::Url url) {
195195
}
196196
}
197197

198-
Res<Strong<Sys::Fd>> openFile(Sys::Url url) {
198+
Res<Strong<Sys::Fd>> openFile(Url::Url url) {
199199
static Efi::SimpleFileSystemProtocol *fileSystem = nullptr;
200200
if (not fileSystem) {
201201
fileSystem = try$(Efi::openProtocol<Efi::SimpleFileSystemProtocol>(Efi::li()->deviceHandle));
@@ -221,11 +221,11 @@ Res<Strong<Sys::Fd>> openFile(Sys::Url url) {
221221
return Ok(makeStrong<FileProto>(file));
222222
}
223223

224-
Res<Vec<Sys::DirEntry>> readDir(Sys::Url) {
224+
Res<Vec<Sys::DirEntry>> readDir(Url::Url) {
225225
return Error::notImplemented();
226226
}
227227

228-
Res<Strong<Sys::Fd>> createFile(Sys::Url) {
228+
Res<Strong<Sys::Fd>> createFile(Url::Url) {
229229
return Error::notImplemented();
230230
}
231231

src/impls/impl-hjert/manifest.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"libheap"
1414
],
1515
"provides": [
16-
"karm-base-impl",
1716
"karm-logger-impl"
1817
]
19-
}
18+
}

src/impls/impl-posix/base.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33

44
namespace Karm::_Embed {
55

6-
void debug(char const *buf) {
7-
fprintf(stderr, "DEBUG: %s\n", buf);
8-
}
9-
10-
[[noreturn]] void panic(char const *buf) {
11-
fprintf(stderr, "PANIC: %s\n", buf);
12-
abort();
13-
}
14-
156
void relaxe() {
167
#if defined(__x86_64__)
178
asm volatile("pause");

src/impls/impl-posix/main.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <karm-panic/panic.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
void __panicHandler(Karm::PanicKind kind, char const *msg) {
6+
fprintf(stderr, "%s: %s\n", kind == Karm::PanicKind::PANIC ? "panic" : "debug", msg);
7+
8+
if (kind == Karm::PanicKind::PANIC) {
9+
abort();
10+
__builtin_unreachable();
11+
}
12+
}

src/impls/impl-posix/main.h

+4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <karm-main/base.h>
44
#include <karm-sys/chan.h>
55

6+
void __panicHandler(Karm::PanicKind kind, char const *msg);
7+
68
int main(int argc, char const **argv) {
9+
Karm::registerPanicHandler(__panicHandler);
10+
711
Ctx ctx;
812
ctx.add<ArgsHook>(argc, argv);
913
Res<> code = entryPoint(ctx);

src/impls/impl-posix/manifest.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
},
1111
"requires": [],
1212
"provides": [
13-
"karm-base-impl",
1413
"karm-logger-impl",
1514
"karm-sys-impl",
1615
"karm-async-impl"
1716
]
18-
}
17+
}

0 commit comments

Comments
 (0)