Skip to content

Commit d7aaf7f

Browse files
committed
LibLemon: message.h template fixes
1 parent ee6a78d commit d7aaf7f

File tree

11 files changed

+72
-23
lines changed

11 files changed

+72
-23
lines changed

Documentation/Build/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
### Building Lemon OS
44
[Building Lemon OS with Docker (Recommended)](https://github.com/fido2020/Lemon-OS/wiki/Building-Lemon-OS-with-Docker)
5-
[Building Lemon OS with Docker (Requires building an LLVM toolchain which will take a decent amount of time)](https://github.com/fido2020/Lemon-OS/wiki/Building-Lemon-OS)
5+
6+
[Building Lemon OS with Docker (Requires building an LLVM toolchain which will take a decent amount of time)](https://github.com/fido2020/Lemon-OS/wiki/Building-Lemon-OS)
7+
8+
### Lemon Toolchain
9+
[LIC (Lemon Interface Compiler)](lic.md)

Documentation/Kernel/Network.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
# Kernel Network Configuration Interface
1+
# Kernel Network Configuration Interface
2+
3+
`lemon.kernel/Networking`
4+
5+
## Synchronous Requests
6+
GetNumberOfInterfaces() -> (s32 status, u32 num)
7+
8+
GetInterfaceConfiguration() -> (u32 ipAdddress, u32 defaultGateway, u32 subnetMask)
9+
GetInterfaceMACAddress() -> (struct MACAddress macAddress)
10+
GetInterfaceName() -> (string name)
11+
GetInterfaceLink() -> (bool link)
12+
13+
SetInterfaceConfiguration(u32 ipAdddress, u32 defaultGateway, u32 subnetMask) -> (s32 status)

Documentation/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
[System/](System/README.md) System Interfaces and Design
66

7-
[API/](API/README.md) System APIs
8-
97
[Userspace/](Userspace/README.md) Userspace applications (CLI and GUI)
108

119
[Build/](Build/README.md) Building Lemon OS and Lemon OS toolchain

Documentation/Userspace/LemonWM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LemonWM
1+
# Using LemonWM
22

33
LemonWM is the window manager for Lemon OS.
44

Documentation/Userspace/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Lemon OS Userspace
2+
[Using LemonWM](LemonWM.md) - Configuration and usage of LemonWM

Kernel/src/net/interface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
#define NET_INTERFACE_STACKSIZE 32768
1414

15+
struct MessageSetInterfaceConfiguration {
16+
uint32_t ipAddress;
17+
uint32_t defaultGateway;
18+
uint32_t subnetMask;
19+
};
20+
1521
namespace Network::Interface{
1622
IPv4Address gateway = {0, 0, 0, 0};
1723
IPv4Address subnet = {255, 255, 255, 255};
@@ -79,7 +85,7 @@ namespace Network::Interface{
7985
assert(mainAdapter);
8086

8187
FancyRefPtr<MessageInterface> msgInterface;
82-
if(long e =ServiceFS::Instance()->kernelService->CreateInterface(msgInterface, "Network", 512); e){
88+
if(long e = ServiceFS::Instance()->kernelService->CreateInterface(msgInterface, "Network", 512); e){
8389
Log::Error("[Network] Failed to create message interface for network!");
8490

8591
Scheduler::EndProcess(Scheduler::GetCurrentProcess());

LibLemon/include/lemon/ipc/endpoint.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,6 @@ namespace Lemon{
134134
return EndpointQueue(handle, m.id(), m.length(), (m.length() > 8) ? reinterpret_cast<uintptr_t>(m.data()) : *(reinterpret_cast<const uint64_t*>(m.data())));
135135
}
136136

137-
template<typename ...T>
138-
inline long QueueObjects(uint64_t id, const T&... objects){
139-
uint16_t size = Message::GetSize(objects) + ...;
140-
uint8_t buffer[size]; // Faster than heap
141-
142-
Message m = Message(buffer, size, objects); // Create a message with our stack allocated buffer
143-
return Queue(m);
144-
}
145-
146137
inline long Poll(Message& m) const{
147138
uint64_t id;
148139
uint16_t size;
@@ -173,12 +164,12 @@ namespace Lemon{
173164

174165
inline long Call(Message& call, uint64_t id) const { // Use the same buffer for return
175166
uint16_t size = call.length();
176-
uint8_t* data = new uint8_t[msgSize];
167+
uint8_t* data = const_cast<uint8_t*>(call.data());
177168

178169
long ret = EndpointCall(handle, call.id(), (call.length() > 8) ? reinterpret_cast<uintptr_t>(call.data()) : *(reinterpret_cast<const uint64_t*>(call.data())), id, reinterpret_cast<uintptr_t>(call.data()), &size);
179170

180171
if(!ret){
181-
rmsg.Set(data, size, id);
172+
call.Set(data, size, id);
182173
} else {
183174
delete[] data;
184175
}

LibLemon/include/lemon/ipc/message.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace Lemon{
6363
}
6464
public:
6565
template<typename T>
66-
static inline constexpr uint16_t GetSize(const T& obj) {
66+
static uint16_t GetSize(const T& obj) {
6767
return sizeof(obj);
6868
}
6969

@@ -103,7 +103,7 @@ namespace Lemon{
103103
}
104104

105105
template<typename ...T>
106-
Message(uint8_t* data, uint16_t size, uint64_t id, const T&... objects) : msize(size), mid(id), mdata(data){ // Don't calculate the size as the caller should know the size beforehand as they have created a buffer
106+
Message(uint8_t* data, uint16_t size, uint64_t id, const T&... objects) : mdata(data), msize(size), mid(id){ // Don't calculate the size as the caller should know the size beforehand as they have created a buffer
107107
uint16_t pos = 0;
108108
(void)std::initializer_list<int>{ ((void)Insert(pos, objects), 0)... }; // HACK: Call insert for each object
109109
}
@@ -157,10 +157,10 @@ namespace Lemon{
157157
};
158158

159159
template<>
160-
uint16_t Message::GetSize<MessageRawDataObject>(const MessageRawDataObject& obj) const;
160+
uint16_t Message::GetSize<MessageRawDataObject>(const MessageRawDataObject& obj);
161161

162162
template<>
163-
uint16_t Message::GetSize<std::string>(const std::string& obj) const;
163+
uint16_t Message::GetSize<std::string>(const std::string& obj);
164164

165165
template<>
166166
void Message::Insert<MessageRawDataObject>(uint16_t& pos, const MessageRawDataObject& obj);

LibLemon/src/ipc/message.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace Lemon{
1616
}
1717

1818
template<>
19-
static uint16_t Message::GetSize<MessageRawDataObject>(const MessageRawDataObject& obj) {
19+
uint16_t Message::GetSize<MessageRawDataObject>(const MessageRawDataObject& obj) {
2020
return sizeof(uint16_t) + obj.second; // 2 byte length + data
2121
}
2222

2323
template<>
24-
static uint16_t Message::GetSize<std::string>(const std::string& obj) {
24+
uint16_t Message::GetSize<std::string>(const std::string& obj) {
2525
return sizeof(uint16_t) + obj.length(); // 2 byte length + data
2626
}
2727

Scripts/createdisk.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
SPATH=$(dirname $(readlink -f "$0"))
4+
5+
set -e
6+
7+
cd $SPATH/..
8+
export LEMONDIR=$(pwd)
9+
10+
qemu-img create -f vpc Disks/Lemon.vhd 1G
11+
sudo sh -c "qemu-nbd -c /dev/nbd0 Disks/Lemon.vhd
12+
sfdisk /dev/nbd0 < Scripts/partitions.sfdisk
13+
mkfs.ext2 -b 4096 /dev/nbd0p2
14+
mkfs.vfat -F 32 /dev/nbd0p3
15+
mkdir -p /mnt/Lemon
16+
mkdir -p /mnt/LemonEFI
17+
mount /dev/nbd0p2 /mnt/Lemon
18+
mount /dev/nbd0p3 /mnt/LemonEFI
19+
mkdir -p /mnt/Lemon/lemon/boot
20+
grub-install --target=x86_64-efi --boot-directory=/mnt/Lemon/lemon/boot --efi-directory=/mnt/LemonEFI /dev/nbd0 --removable
21+
grub-install --target=i386-pc --boot-directory=/mnt/Lemon/lemon/boot /dev/nbd0
22+
umount /mnt/Lemon
23+
umount /mnt/LemonEFI
24+
rmdir /mnt/Lemon
25+
rmdir /mnt/LemonEFI
26+
qemu-nbd -d /dev/nbd0"

Scripts/partitions.sfdisk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
label: gpt
2+
label-id: 7E8421FC-8351-C445-94B0-95B664609D03
3+
unit: sectors
4+
first-lba: 2048
5+
last-lba: 2097613
6+
sector-size: 512
7+
8+
start= 2048, size= 2048, type=21686148-6449-6E6F-744E-656564454649, uuid=FA2472D2-6D7D-D04A-A92C-F3531AFD1099
9+
start= 4096, size= 1828864, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DF83EE12-D78E-ED47-B52E-6C80AE4462A0
10+
start= 1832960, size= 262144, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=835FB81F-D999-A745-BABD-9E27C34E6799

0 commit comments

Comments
 (0)