Skip to content

Commit 054cef4

Browse files
committed
minor changes
1 parent c44f8b3 commit 054cef4

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/kernel/drivers/vmfs.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ namespace newasm::Drivers::FileSystem_V
5151
}
5252
FORCE_INLINE inline void SaveFileTable(DISK& disk, const FILE_TABLE& table)
5353
{
54-
auto t = table;
55-
std::sort(t.begin(), t.end(), [](const auto& a, const auto& b) -> bool {
56-
return a.pos < b.pos;
57-
});
5854
std::string buf(sizeof(FILE) * NewASM::Drivers::FileSystem_V::GetMaxFiles(), '\0');
5955
std::memcpy(&buf[0], t.data(), buf.size());
6056
disk.WRITE_DSK(0, buf);
@@ -97,13 +93,13 @@ namespace newasm::Drivers::FileSystem_V
9793
{
9894
std::vector<std::pair<DISK_POS, DISK_POS>> pairs;
9995
auto table = GetFileTable(disk);
100-
std::sort(table.begin(), table.end(), [](const auto& a, const auto& b) -> bool {
101-
return a.pos < b.pos;
102-
});
10396
for(int i = 0; i < table.size(); ++i)
10497
{
10598
pairs.push_back({table[i].pos, table[i].pos + table[i].size});
10699
}
100+
std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b) -> bool {
101+
return a.first < b.first;
102+
});
107103
if(pairs.size() == 1)
108104
{
109105
return pairs.front().second + 1;
@@ -152,6 +148,10 @@ namespace newasm::Drivers::FileSystem_V
152148
inline void MKFILE(DISK& disk, FILE_NAME name, const std::string& content)
153149
{
154150
using namespace NewASM::Drivers::FileSystem_V;
151+
if(name.size() >= __newasm_MAX_FILENAME_LEN)
152+
{
153+
return;
154+
}
155155
FILE_TABLE table = GetFileTable(disk);
156156
for(int i = 0; i < table.size(); ++i)
157157
{

src/kernel/syscall_handle.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ namespace newasm
13741374
if(!NewASM::header::functions::isalphanum(TLR))
13751375
{
13761376
NewASM::header::functions::err("Permission denied. File names have to be alphanumeric!");
1377+
NewASM::terminate(NewASM::exit_codes::kernel_panic);
13771378
return 1;
13781379
}
13791380
if(newasm::ctl::data::path.size() > 1)
@@ -1398,6 +1399,13 @@ namespace newasm
13981399
if(EXISTS(NewASM::hardware::Disk, TLR))
13991400
{
14001401
NewASM::header::functions::err("File already exists.");
1402+
NewASM::terminate(NewASM::exit_codes::kernel_panic);
1403+
return 1;
1404+
}
1405+
if(TLR.size() >= __newasm_MAX_FILENAME_LEN)
1406+
{
1407+
NewASM::header::functions::err("Permission denied. File name exceeds a limit of 128 characters!");
1408+
NewASM::terminate(NewASM::exit_codes::kernel_panic);
14011409
return 1;
14021410
}
14031411
MKFILE(NewASM::hardware::Disk, TLR, STL);
@@ -1436,6 +1444,7 @@ namespace newasm
14361444
if(!EXISTS(NewASM::hardware::Disk, TLR))
14371445
{
14381446
NewASM::header::functions::err("File does not exist.");
1447+
NewASM::terminate(NewASM::exit_codes::kernel_panic);
14391448
return 1;
14401449
}
14411450
RMFILE(NewASM::hardware::Disk, TLR);
@@ -1492,6 +1501,7 @@ namespace newasm
14921501
if(!NewASM::header::functions::isalphanum(TLR))
14931502
{
14941503
NewASM::header::functions::err("Permission denied. File names have to be alphanumeric!");
1504+
NewASM::terminate(NewASM::exit_codes::kernel_panic);
14951505
return 1;
14961506
}
14971507

src/newasm_setup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ namespace newasm
8383
const int invalid_init = 55;
8484
const int linker_err = 56;
8585
const int jit_fail = 57;
86+
const int kernel_panic = 58;
8687

8788
const std::unordered_map<int, std::string> identifier = {
8889
{noterm_point, "NoTerminationPoint"},
@@ -142,7 +143,8 @@ namespace newasm
142143
{invalid_alloc, "InvalidAlloc"},
143144
{invalid_init, "InvalidVarInitializer"},
144145
{linker_err, "LinkerError"},
145-
{jit_fail, "JITCompilerFailure"}
146+
{jit_fail, "JITCompilerFailure"},
147+
{kernel_panic, "KernelPanicOrSysCrash"}
146148
};
147149
}
148150
namespace cmp_results

0 commit comments

Comments
 (0)