From 521d00fdb869bd9b91fb42490d85c14d3925ea37 Mon Sep 17 00:00:00 2001 From: Egor00f Date: Thu, 8 May 2025 23:48:52 +0500 Subject: [PATCH] create buffer class && some warnings fixes && update manual && create vscode tasks --- .vscode/settings.json | 5 +- .vscode/tasks.json | 30 ++++++ Makefile | 10 +- doc/manual.md | 196 +++++++++++++++++++++++------------ lua | 1 + src/ARP_entry.c | 4 +- src/ARP_entry.h | 2 +- src/IPC/IPC_buffer.c | 232 ++++++++++++++++++++++++++++++++++++++++++ src/IPC/IPC_buffer.h | 22 ++++ src/IPC/IPC_msg.c | 38 +++++-- src/IPC/ipc.c | 49 ++++----- src/IPC/ipc.h | 2 +- src/debug/registers.h | 2 +- src/syscalls.c | 15 ++- tests/ipc_get.lua | 26 +++++ tests/ipc_send.lua | 20 ++++ 16 files changed, 547 insertions(+), 107 deletions(-) create mode 100644 .vscode/tasks.json create mode 160000 lua create mode 100644 src/IPC/IPC_buffer.c create mode 100644 src/IPC/IPC_buffer.h create mode 100644 tests/ipc_get.lua create mode 100644 tests/ipc_send.lua diff --git a/.vscode/settings.json b/.vscode/settings.json index 844e796..faf551b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,9 @@ "syscalls.h": "c", "registers.h": "c", "version_type.h": "c", - "library_version.h": "c" + "library_version.h": "c", + "scancodes.h": "c", + "ipc.h": "c" }, "cSpell.words": [ "syscalls", @@ -30,6 +32,7 @@ "luaL_checkudata", "luaL_optinteger", "luaL_pushfail", + "lua_pushlightuserdata", "lua_pushboolean", "lua_pushinteger", "lua_pushnumber", diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..63afc54 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build", + "type": "process", + "command": "make", + "args": [ + "syscalls.dll" + ], + "group": { + "isDefault": true, + "kind": "build" + }, + "problemMatcher": "$gcc" + }, + { + "label": "Clean", + "type": "process", + "command": "make", + "args": [ + "clean" + ], + "group": { + "isDefault": false, + "kind": "build" + } + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index e0d1b27..7a7e0f2 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ MYOBJS = Socket_O = src/sockets/socket.o src/sockets/socket_lua.o src/sockets/sockaddr.o -IPC_O = src/IPC/ipc.o src/IPC/IPC_msg.o +IPC_O = src/IPC/ipc.o src/IPC/IPC_msg.o src/IPC/IPC_buffer.o Debug_O = src/debug/debug.o src/debug/registers.o Version_O = src/version/coreversion.o src/version/version_type.o @@ -61,10 +61,11 @@ src/graphic.o: src/graphic.c src/graphic.h src/debug/debug.o: src/debug/debug.c src/debug/debug.h src/debug/registers.h src/IPC/ipc.o: src/IPC/ipc.c src/IPC/ipc.h src/IPC/IPC_msg.h src/IPC/IPC_msg.o: src/IPC/IPC_msg.c src/IPC/IPC_msg.h +src/IPC/IPC_buffer.o: src/IPC/IPC_buffer.c src/IPC/IPC_buffer.h src/debug/registers.o: src/debug/registers.c src/debug/registers.h src/syscalls.h src/debug.h src/version/coreversion.o: src/version/coreversion.c src/version/coreversion.h src/version/version_type.o: src/version/version_type.c src/version/version_type.h src/debug.h -src/background/background.o: src/background/background.c src/background/background.h +src/background/background.o: src/background/background.c src/background/background.h ## headers @@ -73,8 +74,9 @@ src/sockets/socket_lua.h: src/syscalls.h src/sockets/socket.h src/sockets/sockaddr.h: src/sockets/socket.h src/syscalls.h src/debug/debug.h: src/syscalls.h src/debug/registers.h: src/syscalls.h -src/IPC/IPC_msg.h: src/syscalls.h +src/IPC/IPC_msg.h: src/syscalls.h +src/IPC/IPC_buffer.h: src/syscalls.h src/IPC/ipc.h: src/syscalls.h src/version/coreversion.h: src/version/version_type.h src/version/version_type.h: src/syscalls.h -src/background/background.h: src/syscalls.h +src/background/background.h: src/syscalls.h diff --git a/doc/manual.md b/doc/manual.md index 008b973..84d88b1 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -4,24 +4,24 @@ This is KolibriOS lua syscalls library. Usually you shouldn't use this library Better if you read before [KolibriOS syscalls wiki](http://wiki.kolibrios.org/wiki/) -include: +include this library: ```lua local syscalls = require("syscalls") ``` ## Events -### `SetEventMask(newMask)` +### SetEventMask(newMask) -### `CheckEvent()` +### CheckEvent() -check event +check [event](#events-list) -### `WaitEvent()` +### WaitEvent() -Endless wait event +Endless wait [event](#events-list) -### `WaitEventTimeout(timeout)` +### WaitEventTimeout(timeout) Wait timeout 1/100 sec @@ -44,37 +44,37 @@ syscalls.Event. ## Window -### `CreateWindow(x, y, width, height, workColor, style, borderColor, titleColor)` +### CreateWindow(x, y, width, height, workColor, [style](#window-style), borderColor, titleColor) Define window -`borderColor` and `borderColor` only for `FixSizes` and `CanChangeSizes` (without skin styles) style. +`borderColor` and borderColor` only for FixSizes` and CanChangeSizes` (without skin styles) style. -### `StartRedraw()` +### StartRedraw() -Start window redraw. Just call it before `CreateWindow` +Start window redraw. Just call it before CreateWindow` -### `EndRedraw()` +### EndRedraw() End window redraw. Just call it after you done redraw window. -### `ChangeWindow(newX, newY, newWidth, newHeight)` +### ChangeWindow(newX, newY, newWidth, newHeight) -### `FocusWindow(slot)` +### FocusWindow(slot) -### `UnfocusWindow(slot)` +### UnfocusWindow(slot) -### `SetWindowTitle(newTitle)` +### SetWindowTitle(newTitle) -### `GetSkinHeight()` +### GetSkinHeight() return skin height. -### `SetSkin(path)` +### SetSkin(path) return error code -### `GetSkinTitleArea()` +### GetSkinTitleArea() return table: ```lua @@ -86,7 +86,7 @@ return table: } ``` -### Style +### Window Style ```lua syscalls.windowStyle. @@ -134,34 +134,35 @@ syscalls.textSize. + `56x112` + `64x128` -### `DrawText(text, xPos, yPos, textColor, textScale, textLen, backgroundColor, encoding)` +### DrawText(text, xPos, yPos, textColor, [textScale](#text-sizes), textLen, backgroundColor, [encoding](#text-encoding)) -### `DrawTextFixSize(text, xPos, yPos, textColor, textSize, textLen, backgroundColor, encoding)` +### DrawTextFixSize(text, xPos, yPos, textColor, [textScale](#text-sizes), textLen, backgroundColor, [encoding](#text-encoding)) Draw text. textSize, textLen, backgroundColor, encoding are optional. -### `DrawLine(x1, y1, x2, y2)` +### DrawLine(x1, y1, x2, y2) -### `DrawRectangle(x, y, widht, height, color)` +### DrawRectangle(x, y, width, height, color) -### `ReadPoint(x, y)` +### ReadPoint(x, y) return color ## Buttons -### `DefineButton(x, y, widht, height, id, color)` +### DefineButton(x, y, width, height, id, color) -### `DeleteButton(id)` +### DeleteButton(id) -### `GetButton()` +### GetButton() return pressed button or `nil` -### `SetButtonStyle(style)` +### SetButtonStyle([style](#button-styles)) +Set buttons style ### buttons @@ -174,20 +175,23 @@ syscalls.buttons. + `close` + `minimization` -### ButtonStyles +### Button styles ```lua syscalls.buttonStyle. ``` ++ `Flat` ++ `Volume` + ## Keyboard -### `GetKey()` +### GetKey() return: -+ nil if buffer empty ++ `nil` if buffer empty + if hotkey return second number -+ if key pressed and key input mode is ascii return string(1 char), else return scancode ++ if key pressed and key input mode is ascii return string(1 char), else return [scancode](#scancodes) example: @@ -199,15 +203,15 @@ if key then end if hotkey then - print(hotkey pressed) + print("hotkey pressed") end ``` -### `SetKeyInputMode(mode)` +### SetKeyInputMode(mode) by default is `ASCII` -### `GetKeyInputMode()` +### GetKeyInputMode() return key input mode. @@ -310,17 +314,18 @@ syscalls.SystemColors.new( ) ``` -### `GetSystemColors()` +### GetSystemColors() -return SystemColors +return [SystemColors](#systemcolors-type) -### `SetSystemColors(SystemColors)` +### SetSystemColors([SystemColors](#systemcolors-type)) ## Threads -### `ThreadInfo(pid)` +### ThreadInfo(pid) return table: + ```lua { name: string, @@ -339,7 +344,7 @@ return table: } ``` -### `KillBySlot(slot)` +### KillBySlot(slot) ### Slot states @@ -357,7 +362,9 @@ syscalls.slotState. ## Sockets -### `OpenSocket(domain, type, protocol)` +### OpenSocket([domain](#socket-types), [type](#address-families), [protocol](#ip-protocols)) + +return socket ```lua local socket, err = syscalls.OpenSocket( @@ -373,9 +380,9 @@ else end ``` -### `CloseSocket(socket)` +### CloseSocket(socket) -### `PairSocket()` +### PairSocket() ```lua local first, second = PairSocket() @@ -387,19 +394,19 @@ else end ``` -### `Bind(socket, address)` +### Bind(socket, address) -### `Listen(socket, backlog)` +### Listen(socket, backlog) -### `Connect(socket, address)` +### Connect(socket, address) -### `Accept(socket, , flags)` +### Accept(socket, , flags) -### `Receive(socket, , flags)` +### Receive(socket, , flags) -### `SetSocketOption(socket, opt)` +### SetSocketOption(socket, [opt](#socket-options)) -### `GetSocketOption(socket, opt)` +### GetSocketOption(socket, [opt](#socket-options)) ### Socket types @@ -468,53 +475,116 @@ syscalls.SO. } ``` -### `DebugPutc(char)` +### DebugPutc(char) Put char to debug board -### `DebugPuts(text)` +### DebugPuts(text) Put string to debug board -### `GetRegisters(pid)` +### GetRegisters(pid) The process must be loaded for debugging (as stated in the general description). return registers table -### `SetRegisters(pid, registers)` +### SetRegisters(pid, [registers](#registers-type)) The process must be loaded for debugging (as stated in the general description). -### `Disconnect(pid)` +### Disconnect(pid) The process must be loaded for debugging (as stated in the general description). If the process was suspended, it resumes execution. -### `Stop(pid)` +### Stop(pid) The process must be loaded for debugging (as stated in the general description). -### `Continue(pid)` +### Continue(pid) The process must be loaded for debugging (as stated in the general description). -### `ReadFromMem(pid, bytes, pointer, buffer)` +### ReadFromMem(pid, bytes, pointer, buffer) The process must be loaded for debugging (as stated in the general description). return or `nil` -### `WriteToMem(pid, bytes, pointer, buffer)` +### WriteToMem(pid, bytes, pointer, buffer) The process must be loaded for debugging (as stated in the general description). return or `nil` -### `Done(pid)` +### Done(pid) -### `DefineBreakpoint(pid, index, condition, len)` +### DefineBreakpoint(pid, index, condition, len) -### `UndefBreakpoint(pid, index, condition, len)` +### UndefBreakpoint(pid, index, condition, len) +## IPC + +### DefineIPCBuffer(size) + +Define buffer for IPC receive + +Return [buffer](#ipc_buffer) type + +### SendIPCMessage(pid, [message](#ipc_msg)) + +Send message to process by pid + +return [Error code](#ipc-error-codes) + +### IPC Error codes + +```lua +syscalls.IPCError. +``` + ++ `Ok` ++ `BufferLocked` ++ `BufferNotDefined` ++ `BufferOverflow` ++ `PIDNotExist` + +### IPC_buffer + +```lua +{ + used: number, + lock: boolean, + Lock: (self: IPC_buffer) -> nil + Unlock: (self: IPC_buffer) -> nil + GetMessage: (self: IPC_buffer, i: number) -> IPC_msg + GetLastMessage: (self: IPC_buffer) -> IPC_msg +} +``` + +#### Lock(self) + +Lock buffer + +#### Unlock(self) + +Unlock buffer + +#### GetMessage(self, i) + +return [message](#ipc_msg) that were send by number i + +#### GetLastMessage(self) + +return last sended [message](#ipc_msg) + +### IPC_msg + +```lua +{ + pid: number, + size: number +} +``` \ No newline at end of file diff --git a/lua b/lua new file mode 160000 index 0000000..eae2ea0 --- /dev/null +++ b/lua @@ -0,0 +1 @@ +Subproject commit eae2ea0aaa2c4d0ad9e9c5c6594f9b2378971ced diff --git a/src/ARP_entry.c b/src/ARP_entry.c index f2443b0..258c437 100644 --- a/src/ARP_entry.c +++ b/src/ARP_entry.c @@ -33,7 +33,7 @@ int syscalls_indexARPEntry(lua_State* L) else if (strcmp(index, "MAC") == 0) { char str[7]; - memset(str, entry->MAC, 6); + memcpy(str, &entry->MAC, 6); str[6] = '\n'; lua_pushstring(L, str); } @@ -79,7 +79,7 @@ int syscalls_newindexARPEntry(lua_State* L) } else { - _ksys_debug_puts("err\n"); + luaL_error(L, "wrong index: %s", index); } return 0; diff --git a/src/ARP_entry.h b/src/ARP_entry.h index 090ccd9..97b6979 100644 --- a/src/ARP_entry.h +++ b/src/ARP_entry.h @@ -10,7 +10,7 @@ struct ARP_entry { uint32_t IP; - char MAC[6]; + uint8_t MAC[6]; uint16_t Status; uint16_t TTL; }; diff --git a/src/IPC/IPC_buffer.c b/src/IPC/IPC_buffer.c new file mode 100644 index 0000000..92203e0 --- /dev/null +++ b/src/IPC/IPC_buffer.c @@ -0,0 +1,232 @@ +#include "IPC_buffer.h" +#include +#include "../debug.h" +#include + + + +static int syscalls_indexIPC_buffer(lua_State* L) +{ + struct IPC_buffer* r = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + const char* index = luaL_checkstring(L, 2); + + if (strcmp(index, "used") == 0) + { + lua_pushinteger(L, r->used); + } + else if (strcmp(index, "lock") == 0) + { + lua_pushboolean(L, r->lock); + } + else if (strcmp(index, "size") == 0) + { + lua_pushnumber(L, r->size); + } + else + { + lua_pushnil(L); + } + + return 1; +} + +static int syscalls_newindexIPC_buffer(lua_State* L) +{ + struct IPC_buffer* r = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + const char* index = luaL_checkstring(L, 2); + int val = luaL_checkinteger(L, 3); + + if (strcmp(index, "used") == 0) + { + r->used = val; + } + else if (strcmp(index, "lock") == 0) + { + r->lock = val; + } + else + { + luaL_error(L, "wrong index: %s", index); + } + + return 0; +} + +static bool compare_ipc_buffer(ksys_ipc_buffer* a, ksys_ipc_buffer* b) +{ // блять че за высер... + if (a == b) + return true; + + if (a->used == b->used) + { + return memcmp( + a + (2 * sizeof(unsigned)), + b + (2 * sizeof(unsigned)), + a->used + ); + } + else // длина сообщений не совпадает, занчитт они зразу не могут быть равны + { + return false; + } +} + +static int syscalls_eqIPC_buffer(lua_State* L) +{ + lua_pushboolean( + L, + compare_ipc_buffer( + luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name), + luaL_checkudata(L, 2, syscalls_IPC_buffer_metatable_name) + ) + ); + + return 1; +} + +static int syscalls_IPC_buffer_lock(lua_State* L) +{ + ksys_ipc_buffer* buffer = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + + buffer->lock = 1; + + return 0; +} + +static int syscalls_IPC_buffer_unlock(lua_State* L) +{ + ksys_ipc_buffer* buffer = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + + buffer->lock = 0; + + return 0; +} + +/** + * @brief Получить сообщение под номером + * @param buffer + * @param i + * @return указатель на сообщение, если такого сообщения ещё нет, то возвращает + */ +static ksys_ipc_msg* IPC_buffer_get_message(struct IPC_buffer* buffer, int i) +{ + ksys_ipc_msg* j = (ksys_ipc_msg*)(buffer + 8); + unsigned diff = 0; + + for (int k = 0; k < i; k++) + { + diff += j->datalen + 8; // прибавление длинны сообщения и заголовка + j += diff; + + if (diff >= buffer->used) + return 0; + } + + return j; +} + +static ksys_ipc_msg* IPC_buffer_get_last_message(struct IPC_buffer* buffer) +{ + ksys_ipc_msg* j = (ksys_ipc_msg*)(buffer + 8); + unsigned diff = 0; + + while (diff < buffer->used) + { + j += diff; + diff += j->datalen + 8; // прибавление длинны сообщения и заголовка + } + + return j; +} + +static int syscalls_IPC_buffer_get_message(lua_State* L) +{ + struct IPC_buffer* buffer = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + unsigned i = luaL_checkinteger(L, 1); + + ksys_ipc_msg* msg = IPC_buffer_get_message(buffer, i); + + if (msg) + { + lua_pushlightuserdata(L, msg); + } + else + { + lua_pushnil(L); + } + + return 1; +} + +static int syscalls_IPC_buffer_get_last_message(lua_State* L) +{ + struct IPC_buffer* buffer = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + + lua_pushlightuserdata(L, IPC_buffer_get_last_message(buffer)); + + return 1; +} + +static int syscalls_IPC_buffer_reset(lua_State* L) +{ + struct IPC_buffer* buffer = luaL_checkudata(L, 1, syscalls_IPC_buffer_metatable_name); + + buffer->used = 0; + memset(&buffer->data, 0, buffer->size); + + return 0; +} + +static const luaL_Reg syscalls_IPC_buffer_m[] = { + {"__index", syscalls_indexIPC_buffer}, + {"__newindex", syscalls_newindexIPC_buffer}, + {"__eq", syscalls_eqIPC_buffer}, + {"Lock", syscalls_IPC_buffer_lock}, + {"Unlock", syscalls_IPC_buffer_unlock}, + {"GetMessage", syscalls_IPC_buffer_get_message}, + {"GetLastMessage", syscalls_IPC_buffer_get_last_message}, + {"Reset", syscalls_IPC_buffer_reset}, + {NULL, NULL} +}; + +struct IPC_buffer* syscalls_pushIPC_buffer(lua_State* L, size_t size) +{ + DEBUG_LINE("push " syscalls_IPC_buffer_name " entry"); + + struct IPC_buffer* buffer = lua_newuserdata(L, sizeof(struct IPC_buffer) + size); + + luaL_setmetatable(L, syscalls_IPC_buffer_metatable_name); + + buffer->used = 0; + buffer->size = size; + + return buffer; +} + +static int syscalls_newIPC_buffer(lua_State* L) +{ + size_t size = luaL_checkinteger(L, 1); + struct IPC_buffer* buffer = syscalls_pushIPC_buffer(L, size); + + return 1; +} + +static const luaL_Reg syscalls_IPC_buffer_lib[] = { + {"new", syscalls_newIPC_buffer}, + {NULL, NULL} +}; + +void syscalls_register_IPC_buffer(lua_State* L) +{ + DEBUG_LINE("register " syscalls_IPC_buffer_name " entry"); + + luaL_newlib(L, syscalls_IPC_buffer_lib); + + lua_setfield(L, -2, syscalls_IPC_buffer_name); + + + luaL_newmetatable(L, syscalls_IPC_buffer_metatable_name); + luaL_setfuncs(L, syscalls_IPC_buffer_m, 0); + + lua_pop(L, 1); +} diff --git a/src/IPC/IPC_buffer.h b/src/IPC/IPC_buffer.h new file mode 100644 index 0000000..1686011 --- /dev/null +++ b/src/IPC/IPC_buffer.h @@ -0,0 +1,22 @@ +#ifndef __IPC_BUFFER_H__ +#define __IPC_BUFFER_H__ + +#include "../syscalls.h" + +struct IPC_buffer +{ + size_t size; + ksys_ipc_buffer; +}; + +#define syscalls_IPC_buffer_metatable_name "syscalls IPCbuffer metatable" +#define syscalls_IPC_buffer_name "IPCbuffer" + +struct IPC_buffer* syscalls_pushIPC_buffer(lua_State* L, size_t dataLen); + +/** + * Register SystemColors lib + */ +void syscalls_register_IPC_buffer(lua_State* L); + +#endif // __IPC_BUFFER_H__ diff --git a/src/IPC/IPC_msg.c b/src/IPC/IPC_msg.c index 9a08a97..3772326 100644 --- a/src/IPC/IPC_msg.c +++ b/src/IPC/IPC_msg.c @@ -52,7 +52,7 @@ static int syscalls_newindexIPC_msg(lua_State* L) } else { - if (index_i < r->data) + if (index_i < (unsigned)r->data) { ((lua_Integer*)r + (2 * sizeof(unsigned)))[index_i] = val; } @@ -62,9 +62,7 @@ static int syscalls_newindexIPC_msg(lua_State* L) } } - lua_pushboolean(L, true); - - return 1; + return 0; } static bool compare_ipc_msg(ksys_ipc_msg* a, ksys_ipc_msg* b) @@ -136,10 +134,19 @@ static int syscalls_IPC_msg_ReadInteger(lua_State* L) return 1; } +static int syscalls_IPC_msg_tostring(lua_State* L) +{ + ksys_ipc_msg* msg = luaL_checkudata(L, 1, syscalls_IPC_msg_metatable_name); + lua_pushstring(L, &msg->data); + + return 1; +} + static const luaL_Reg syscalls_IPC_msg_m[] = { {"__index", syscalls_indexIPC_msg}, {"__newindex", syscalls_newindexIPC_msg}, {"__eq", syscalls_eqIPC_msg}, + {"__tostring", syscalls_IPC_msg_tostring}, {"ReadByte", syscalls_IPC_msg_ReadByte}, {"ReadWord", syscalls_IPC_msg_ReadWord}, {"ReadDword", syscalls_IPC_msg_ReadDword}, @@ -151,24 +158,39 @@ ksys_ipc_msg* syscalls_pushIPC_msg(lua_State* L, size_t dataLen) { DEBUG_LINE("push IPC_msg entry"); - ksys_ipc_msg* entry = lua_newuserdata(L, sizeof(ksys_ipc_msg) + dataLen); + ksys_ipc_msg* msg = lua_newuserdata(L, sizeof(ksys_ipc_msg) + dataLen); luaL_setmetatable(L, syscalls_IPC_msg_metatable_name); - return entry; + msg->datalen = dataLen; + + return msg; } static int syscalls_newIPC_msg(lua_State* L) { size_t dataLen = luaL_checkinteger(L, 1); - ksys_ipc_msg* r = syscalls_pushIPC_msg(L, dataLen); - r->datalen = dataLen; + ksys_ipc_msg* msg = syscalls_pushIPC_msg(L, dataLen); return 1; } +static int syscalls_fromStringIPC_msg(lua_State* L) +{ + const char* text = luaL_checkstring(L, 1); + size_t len = strlen(text); + + ksys_ipc_msg* r = syscalls_pushIPC_msg(L, len); + + memcpy(&r->data, text, len); + + return 1; +} + + static const luaL_Reg syscalls_IPC_msg_lib[] = { {"new", syscalls_newIPC_msg}, + {"fromString", syscalls_fromStringIPC_msg}, {NULL, NULL} }; diff --git a/src/IPC/ipc.c b/src/IPC/ipc.c index 668d0d8..a3a2728 100644 --- a/src/IPC/ipc.c +++ b/src/IPC/ipc.c @@ -1,47 +1,48 @@ #include "ipc.h" #include "IPC_msg.h" +#include "IPC_buffer.h" #include -inline static void define_ipc(ksys_ipc_buffer* buffer, size_t bufLen) +inline static void define_ipc(struct IPC_buffer* buffer, size_t bufLen) { - asm_inline( - "int $0x40" - ::"a"(60), "b"(1), "c"(buffer), "d"(bufLen) - ); + asm_inline( + "int $0x40" + ::"a"(60), "b"(1), "c"(buffer + (sizeof(struct IPC_buffer) - sizeof(ksys_ipc_msg))), "d"(bufLen) + ); } inline static enum SendIPCErrors send_ipc(int pid, ksys_ipc_msg* msg) { - enum SendIPCErrors ret; + enum SendIPCErrors ret; - asm_inline( - "int $0x40" - : "=a"(ret) - : "a"(60), "b"(2), "c"(pid), "d"(msg), "S"(sizeof(ksys_ipc_msg) + msg->datalen) - ); + asm_inline( + "int $0x40" + : "=a"(ret) + : "a"(60), "b"(2), "c"(pid), "d"(msg), "S"((sizeof(ksys_ipc_msg)) + msg->datalen) + ); - return ret; + return ret; } int syscalls_DefineIPCBuffer(lua_State* L) { - uint32_t len = luaL_checkinteger(L, 1); - ksys_ipc_buffer* buffer; + uint32_t len = luaL_checkinteger(L, 1); + ksys_ipc_buffer* buffer = syscalls_pushIPC_buffer(L, len); - define_ipc(buffer, len); + define_ipc(buffer, len); - return 0; + return 1; } int syscalls_SendIPCMessage(lua_State* L) { - lua_pushinteger( - L, - send_ipc( - luaL_checkinteger(L, 1), - luaL_checkudata(L, 1, syscalls_IPC_msg_metatable_name) - ) - ); + lua_pushinteger( + L, + send_ipc( + luaL_checkinteger(L, 1), + luaL_checkudata(L, 2, syscalls_IPC_msg_metatable_name) + ) + ); - return 1; + return 1; } diff --git a/src/IPC/ipc.h b/src/IPC/ipc.h index 5bcfd5a..0f0aa42 100644 --- a/src/IPC/ipc.h +++ b/src/IPC/ipc.h @@ -29,4 +29,4 @@ inline void syscalls_push_IPC_errors(lua_State* L) lua_setfield(L, -2, "IPCError"); } -#endif // __IPC_H__ \ No newline at end of file +#endif // __IPC_H__ diff --git a/src/debug/registers.h b/src/debug/registers.h index e5dbd16..9bc5339 100644 --- a/src/debug/registers.h +++ b/src/debug/registers.h @@ -20,6 +20,6 @@ struct registers struct registers* syscalls_pushRegisters(lua_State* L); -inline void syscalls_register_registers(lua_State* L); +void syscalls_register_registers(lua_State* L); #endif // __REGISTERS_H__ diff --git a/src/syscalls.c b/src/syscalls.c index 9f9f077..f495896 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -17,6 +17,7 @@ #include "graphic.h" #include "IPC/ipc.h" #include "IPC/IPC_msg.h" +#include "IPC/IPC_buffer.h" #include "version/coreversion.h" #include "version/library_version.h" #include "background/background.h" @@ -252,7 +253,7 @@ static int syscalls_threadInfo(lua_State* L) { ksys_thread_t t; - _ksys_thread_info(&t, luaL_checkinteger(L, 1)); + _ksys_thread_info(&t, luaL_optinteger(L, 1, -1)); lua_createtable(L, 0, 13); @@ -1760,18 +1761,28 @@ LUALIB_API int luaopen_syscalls(lua_State* L) syscalls_push_events(L); syscalls_push_slotStates(L); + syscalls_register_scancodes(L); syscalls_push_hotkey_states(L); + syscalls_push_buttonsStyle(L); syscalls_push_windowStyles(L); + syscalls_push_buttons(L); + + // net syscalls_push_connectionStatus(L); + syscalls_register_ARPEntry(L); + syscalls_push_graphic(L); + + // Register IPC syscalls_register_IPC_msg(L); + syscalls_register_IPC_buffer(L); syscalls_push_IPC_errors(L); - syscalls_register_ARPEntry(L); syscalls_register_SystemColors(L); + syscalls_register_Version(L); _ksys_set_event_mask(7); // set default event mask diff --git a/tests/ipc_get.lua b/tests/ipc_get.lua new file mode 100644 index 0000000..82e8521 --- /dev/null +++ b/tests/ipc_get.lua @@ -0,0 +1,26 @@ +--[[ + Этот скрипт принимает данные от ipc_send и выводит в консоль +]] + +local syscalls = require("syscalls") + +syscalls.SetEventMask(1 << (syscalls.Event.IPC - 1)) + +local pid = syscalls.ThreadInfo().PID + +local f = io.open("/tmp0/1/lua_test_ipc_pid", "w") + +if f then + f:write(pid) + + f:close() +end + +local buffer = syscalls.DefineIPCBuffer(4096) + + +while true do + if syscalls.WaitEvent() == syscalls.Event.IPC then + print(buffer:GetLastMessage()) + end +end diff --git a/tests/ipc_send.lua b/tests/ipc_send.lua new file mode 100644 index 0000000..c6fd08e --- /dev/null +++ b/tests/ipc_send.lua @@ -0,0 +1,20 @@ +--[[ + скрипт который отправляет данные по IPC +]] + +local syscalls = require("syscalls") + +local f = io.open("/tmp0/1/lua_test_ipc_pid", "r") + +local pid + +if f then + pid = tonumber(f:read("l")) + f:close() +end + +if pid then + while true do + print(syscalls.SendIPCMessage(pid, syscalls.IPC_msg.fromString("Test aboba"))) + end +end