From 9ebed302f68fa0d2cabb3b31deb18ee6dc9591e5 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Sat, 21 Oct 2023 16:19:34 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20fs=E6=9E=84=E5=BB=BA=E8=99=9A?= =?UTF-8?q?=E6=8B=9Fluadb=E6=97=B6=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E5=8F=A5=E6=9F=84=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- port/luat_fs_mini.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/port/luat_fs_mini.c b/port/luat_fs_mini.c index 9a0c440..d3260d5 100644 --- a/port/luat_fs_mini.c +++ b/port/luat_fs_mini.c @@ -214,6 +214,7 @@ void *check_cmd_args(int index) ptr = luat_heap_malloc(len); if (ptr == NULL) { + fclose(f); LLOGE("luadb镜像文件太大,内存放不下 %s", path); return NULL; } @@ -238,6 +239,7 @@ void *check_cmd_args(int index) char *tmp = luat_heap_malloc(len); if (tmp == NULL) { + fclose(f); LLOGE("lua文件太大,内存放不下 %s", path); return NULL; } From caf22a620cde9f49891ed94158aee7ec376055b4 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Mon, 23 Oct 2023 09:25:15 +0800 Subject: [PATCH 2/8] =?UTF-8?q?update:=20=E5=AE=8C=E5=85=A8=E7=A6=81?= =?UTF-8?q?=E7=94=A8ftp=E5=BA=93,=E5=B0=B1=E5=BD=93=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E9=80=82=E9=85=8D=E9=80=BB=E8=BE=91,=20=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原因是libuv的API基本上是线程不安全的, 这意味着network和rtos的实现, 都需要改成uv_async形式执行和等待结果, 工作量有点猛, 当前选择暂时关掉ftp适配 --- port/luat_base_mini.c | 2 +- xmake.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/port/luat_base_mini.c b/port/luat_base_mini.c index 3f8a168..85e0aeb 100644 --- a/port/luat_base_mini.c +++ b/port/luat_base_mini.c @@ -114,7 +114,7 @@ static const luaL_Reg loadedlibs[] = { {"http", luaopen_http}, {"mqtt", luaopen_mqtt}, {"websocket", luaopen_websocket}, - {"ftp", luaopen_ftp}, + // {"ftp", luaopen_ftp}, {"errDump", luaopen_errdump}, #endif {NULL, NULL} diff --git a/xmake.lua b/xmake.lua index 07a31e8..4ca3533 100644 --- a/xmake.lua +++ b/xmake.lua @@ -169,8 +169,8 @@ target("luatos-lua") add_files(luatos.."components/network/libhttp/*.c") -- libftp - add_includedirs(luatos.."components/network/libftp",{public = true}) - add_files(luatos.."components/network/libftp/*.c") + -- add_includedirs(luatos.."components/network/libftp",{public = true}) + -- add_files(luatos.."components/network/libftp/*.c") -- websocket add_includedirs(luatos.."components/network/websocket",{public = true}) From 942e33eec4510a92a554cdc6770fe1084c174c69 Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Mon, 23 Oct 2023 12:47:12 +0800 Subject: [PATCH 3/8] =?UTF-8?q?add:=20win=E7=9A=84ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug-report.yml | 70 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature-request.yml | 49 +++++++++++++++ .github/workflows/win.yml | 33 ++++++++++ build_windows_32bit_msvc.bat | 4 +- build_windows_64bit_msvc.bat | 4 +- 5 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.yml create mode 100644 .github/ISSUE_TEMPLATE/feature-request.yml create mode 100644 .github/workflows/win.yml diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 0000000..efe4f86 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,70 @@ +name: "🐛 上报bug / Bug report" +description: "提交bug以让改进软件功能 / Create a report to help us improve" +title: "[🐛Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + 感谢对项目的支持与关注。在提出问题之前,请确保你已查看相关开发或使用文档! / Thanks for taking the time to fill out this bug report! + - type: textarea + id: bug_description + attributes: + label: 描述一下这个bug / Describe the bug + description: 请使用简介并详细的语句,来描述这个bug。 / A clear and concise description of what the bug is. + placeholder: 我准备……我想要……但是实际上它……了 / I am doing ... What I expect is ... What actually happening is ... + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: 复现步骤 / To Reproduce + description: 按照下面的步骤,可以复现bug / Steps to reproduce the behavior + placeholder: 首先……然后……接着…… / Go to '...', Click on '....', Scroll down to '....' + validations: + required: true + - type: textarea + id: expected + attributes: + label: 如果正常,应该是什么样 / Expected behavior + description: 清楚简洁地描述,按这个步骤下来,本来应该运行得到的结果。 / A clear and concise description of what you expected to happen. + placeholder: 它应该打印…… / It should be... + validations: + required: true + - type: textarea + id: screenshots + attributes: + label: 截图 / Screenshots + description: 请放上你的截图,请给出完整的截图。 / Add screenshots to help explain your problem. + validations: + required: true + - type: textarea + id: logs + attributes: + label: 日志 / Logs + description: 日志贴到这里,请给出完整的日志。 / Upload your log files. + placeholder: | + ```log + 日志贴在这里 / logs here + ``` + validations: + required: true + - type: input + id: version + attributes: + label: PACK包版本 / Version + placeholder: 1.0.1.1 + validations: + required: true + - type: checkboxes + id: checkboxes + attributes: + label: 验证 + description: 提交前请确认已经做过以下操作 / Before submitting the issue, please make sure you do the following + options: + - label: 检查过该问题,之前没有人提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. + required: true + - label: 提供了最小可复现工程或详细的复现步骤,确保开发者可以复现 / The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug. + required: true + - label: 已经提供了完整的报错信息、日志、截图,没有经过删减。 + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..44c6d88 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,49 @@ +name: "🚀 请求某功能 / Feature request" +description: "为这个项目出一个好点子 / Suggest an idea for this project" +title: "[🚀新需求]: " +labels: ["待分类"] +body: + - type: markdown + attributes: + value: | + 感谢你提供新的想法! / Thanks for taking the time to fill out this Feature request! + - type: textarea + id: problem + attributes: + label: 您的功能请求是否与解决某些问题有关?请描述一下。/ Is your feature request related to a problem? Please describe. + validations: + required: true + - type: textarea + id: description + attributes: + label: 描述您想要的解决方案 / Describe the solution you'd like + validations: + required: true + - type: textarea + id: usage + attributes: + label: 描述您想要的详细使用步骤描述 / Describe the solution you'd like to use in what way + validations: + required: true + - type: textarea + id: other + attributes: + label: 其他备注信息或截图 / Add any other context or screenshots about the feature request here + validations: + required: false + - type: checkboxes + id: checkboxes + attributes: + label: 确认信息 + description: 提交前请确认已经做过以下操作 / Before submitting the issue, please make sure you do the following + options: + - label: 检查过该需求,之前没有人提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. + required: true + - label: 这个需求是真实存在的,并且对于本项目来说是必要的 + required: true + - label: 我已经提供了该需求的清晰、详细、完整的方案,请按该方案进行实施 + required: true + - label: 我认为我提供的信息已经足够,不需要其他人继续完善该需求的其他细节 + required: true + - label: 我同意跟进该需求的实施进程,并在适时提供合理的解释与纠正 + required: true diff --git a/.github/workflows/win.yml b/.github/workflows/win.yml new file mode 100644 index 0000000..a1cfb7a --- /dev/null +++ b/.github/workflows/win.yml @@ -0,0 +1,33 @@ +name: win + +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: windows-2019 + strategy: + matrix: + win_bits: ["32bit", "64bit"] + fail-fast: true + steps: + - uses: actions/checkout@v4 + - name: install xmake + run: | + Invoke-Expression (Invoke-Webrequest 'https://xmake.io/psget.text' -UseBasicParsing).Content + - name: clone LuatOS + run: | + cd .. + git clone https://github.com/openLuat/LuatOS.git + - name: build + env: + WINBITS: ${{ matrix.win_bits }} + run: | + $env:path+=";C:\Users\runneradmin\xmake;" + cmd /c build_windows_${env:WINBITS}_msvc.bat + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: luatos_win_${{ matrix.win_bits }} + path: build/out diff --git a/build_windows_32bit_msvc.bat b/build_windows_32bit_msvc.bat index d494021..39e1439 100644 --- a/build_windows_32bit_msvc.bat +++ b/build_windows_32bit_msvc.bat @@ -1,5 +1,5 @@ xmake clean -a set VM_64bit=0 -xmake f -a x86 -xmake -w -v +xmake f -a x86 -y +xmake -y -w -v diff --git a/build_windows_64bit_msvc.bat b/build_windows_64bit_msvc.bat index 9302e76..cf0623c 100644 --- a/build_windows_64bit_msvc.bat +++ b/build_windows_64bit_msvc.bat @@ -1,5 +1,5 @@ xmake clean -a set VM_64bit=1 -xmake f -a x86 -xmake -w -v +xmake f -a x86 -y +xmake -y -w -v From a4dbeeb929cd2448f525ecab45f6680289cde1e5 Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Mon, 23 Oct 2023 12:53:49 +0800 Subject: [PATCH 4/8] =?UTF-8?q?add:=20linux=E7=9A=84ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linux.yml | 37 +++++++++++++++++++++++++++++++++++++ build_linux_32bit.sh | 4 ++-- build_linux_64bit.sh | 4 ++-- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/linux.yml diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..e530ed6 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,37 @@ +name: linux + +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-22.04 + strategy: + matrix: + linux_bits: ["32bit", "64bit"] + fail-fast: true + steps: + - uses: actions/checkout@v4 + - name: prepare software + run: | + sudo apt-get update + sudo apt install git gcc-multilib libc6 libgcc1 libstdc++5 libstdc++6 p7zip-full binutils llvm libsdl2-dev -y + sudo apt install libncurses5-dev cmake -y + sudo add-apt-repository ppa:xmake-io/xmake -y + sudo apt update + sudo apt install xmake + - name: clone LuatOS + run: | + cd .. + git clone https://github.com/openLuat/LuatOS.git + - name: build + env: + LINUX_BITS: ${{ matrix.linux_bits }} + run: | + sh build_linux_${LINUX_BITS}.sh + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: luatos_linux_${{ matrix.linux_bits }} + path: build/out diff --git a/build_linux_32bit.sh b/build_linux_32bit.sh index db43927..a5ff799 100644 --- a/build_linux_32bit.sh +++ b/build_linux_32bit.sh @@ -4,5 +4,5 @@ xmake clean -a export VM_64bit=0 -xmake f -p linux -a i386 -m debug -xmake -w \ No newline at end of file +xmake f -p linux -a i386 -m debug -y +xmake -w -y diff --git a/build_linux_64bit.sh b/build_linux_64bit.sh index 269732c..477cbd8 100644 --- a/build_linux_64bit.sh +++ b/build_linux_64bit.sh @@ -1,4 +1,4 @@ xmake clean -a export VM_64bit=1 -xmake f -p linux -a i386 -xmake -w \ No newline at end of file +xmake f -p linux -a i386 -y +xmake -w -y From 8b517010a7c7bd25ec4587f4ff8b18b81659d9e2 Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Mon, 23 Oct 2023 13:22:42 +0800 Subject: [PATCH 5/8] =?UTF-8?q?add:=20osx=E7=9A=84ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/osx.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/osx.yml diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml new file mode 100644 index 0000000..1996ffa --- /dev/null +++ b/.github/workflows/osx.yml @@ -0,0 +1,26 @@ +name: osx + +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: macos-12 + steps: + - uses: actions/checkout@v4 + - name: prepare software + run: | + brew install git xmake libtool + - name: clone LuatOS + run: | + cd .. + git clone https://github.com/openLuat/LuatOS.git + - name: build + run: | + xmake -w -y + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: luatos_osx + path: build/out From fec7c94fd97dc6653d11154b6ddc28a62b52c929 Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Mon, 23 Oct 2023 13:28:03 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E8=A1=A5=E4=B8=8A=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- port/rtos/luat_rtos_mutex_pc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/port/rtos/luat_rtos_mutex_pc.c b/port/rtos/luat_rtos_mutex_pc.c index 828c2c3..a70df0e 100644 --- a/port/rtos/luat_rtos_mutex_pc.c +++ b/port/rtos/luat_rtos_mutex_pc.c @@ -41,27 +41,29 @@ void *luat_mutex_create(void) { } LUAT_RET luat_mutex_lock(void *mutex) { if (mutex == NULL) { - return; + return -1; } pc_mutex_t* m = (pc_mutex_t*)mutex; LLOGD("mutex lock1 %p %d", m, m->lock); uv_mutex_lock(&m->m); m->lock ++; LLOGD("mutex lock2 %p %d", m, m->lock); + return 0; } LUAT_RET luat_mutex_unlock(void *mutex) { if (mutex == NULL) - return; + return -1; pc_mutex_t* m = (pc_mutex_t*)mutex; LLOGD("mutex unlock1 %p %d", m, m->lock); if (m->lock == 0) { //LLOGI("该mutex未加锁,不能unlock %p", mutex); - return; + return -2; } uv_mutex_unlock(&m->m); m->lock --; LLOGD("mutex unlock2 %p %d", m, m->lock); + return 0; } void luat_mutex_release(void *mutex) { From 7b8a152c5afce07e0d79b18a83fca9cb8c555ee6 Mon Sep 17 00:00:00 2001 From: chenxuuu Date: Mon, 23 Oct 2023 13:34:50 +0800 Subject: [PATCH 7/8] =?UTF-8?q?add:=20=E7=94=A8tar=E6=89=93=E5=8C=85?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E7=95=99=E6=96=87=E4=BB=B6=E6=9D=83=E9=99=90?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/linux.yml | 6 +++++- .github/workflows/osx.yml | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index e530ed6..a0ef082 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -30,8 +30,12 @@ jobs: LINUX_BITS: ${{ matrix.linux_bits }} run: | sh build_linux_${LINUX_BITS}.sh + - name: Tar files + env: + LINUX_BITS: ${{ matrix.linux_bits }} + run: tar -cvf luatos_linux_${LINUX_BITS}.tar build/out - name: Upload artifact uses: actions/upload-artifact@v3 with: name: luatos_linux_${{ matrix.linux_bits }} - path: build/out + path: luatos_linux_${{ matrix.linux_bits }}.tar diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 1996ffa..0de37da 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -19,8 +19,10 @@ jobs: - name: build run: | xmake -w -y + - name: Tar files + run: tar -cvf luatos_osx.tar build/out - name: Upload artifact uses: actions/upload-artifact@v3 with: name: luatos_osx - path: build/out + path: luatos_osx.tar From 3c40baf6a0eec64f5ac1f74870cf1e7252cf7f30 Mon Sep 17 00:00:00 2001 From: Wendal Chen Date: Wed, 25 Oct 2023 10:33:16 +0800 Subject: [PATCH 8/8] =?UTF-8?q?update:=20=E8=B0=83=E6=95=B4msgbus=E5=92=8C?= =?UTF-8?q?uv=5Frun=E7=9A=84=E8=B0=83=E7=94=A8=E9=80=BB=E8=BE=91,=E4=BD=BF?= =?UTF-8?q?=E5=BE=97=E9=83=BD=E5=9C=A8=E5=90=8C=E4=B8=80=E4=B8=AA=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原因是libuv的大部分API不是线程安全的, uv主线程和luatos线程就存在互相竞争的情况, 现在改成在一个线程内 --- port/rtos/luat_msgbus_pc.c | 23 +++++++++++------------ port/rtos/luat_timer_pc.c | 2 +- src/main_mini.c | 7 ++++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/port/rtos/luat_msgbus_pc.c b/port/rtos/luat_msgbus_pc.c index c09df30..9117192 100644 --- a/port/rtos/luat_msgbus_pc.c +++ b/port/rtos/luat_msgbus_pc.c @@ -11,6 +11,7 @@ static uv_queue_item_t head; static uv_mutex_t m; +extern uv_loop_t *main_loop; void luat_msgbus_init(void) { @@ -19,6 +20,7 @@ void luat_msgbus_init(void) } uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout) { + (void)timeout; // LLOGD("luat_msgbus_put %p %d", msg, timeout); uv_queue_item_t *item = luat_heap_malloc(sizeof(uv_queue_item_t) + sizeof(rtos_msg_t)); if (item == NULL) @@ -37,10 +39,13 @@ uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout) uint32_t luat_msgbus_get(rtos_msg_t *msg, size_t timeout) { // LLOGD("luat_msgbus_get %d", timeout); + (void)timeout; uv_queue_item_t *item = luat_heap_malloc(sizeof(uv_queue_item_t) + sizeof(rtos_msg_t)); int ret = 0; + int ret2 = 0; while (1) { + ret2 = uv_run(main_loop, UV_RUN_NOWAIT); uv_mutex_lock(&m); ret = luat_queue_pop(&head, item); uv_mutex_unlock(&m); @@ -50,16 +55,10 @@ uint32_t luat_msgbus_get(rtos_msg_t *msg, size_t timeout) luat_heap_free(item); return 0; } - // 读不到, 只能返回错误了 - if (timeout == 0) - { - return 1; - } - if (timeout > 0 && timeout != (size_t)(-1)) - { - timeout--; - } - uv_sleep(1); + if (ret2 == 0) + uv_sleep(2); + else + uv_sleep(1); } return 1; } @@ -70,6 +69,6 @@ uint32_t luat_msgbus_freesize(void) uint8_t luat_msgbus_is_empty(void) { - // return head.next == NULL ? 1 : 0; - return 0; + return head.next == NULL ? 1 : 0; + // return 0; } diff --git a/port/rtos/luat_timer_pc.c b/port/rtos/luat_timer_pc.c index 4644c59..06ac79b 100644 --- a/port/rtos/luat_timer_pc.c +++ b/port/rtos/luat_timer_pc.c @@ -127,7 +127,7 @@ int luat_timer_stop(luat_timer_t *timer) { uv_mutex_lock(&timer_lock); // LLOGD("timer stop %d", timer); - uv_timer_t *timer_req = timer->os_timer; + uv_timer_t *timer_req = (uv_timer_t *)timer->os_timer; int ret = 0; for (size_t i = 0; i < TIMER_ID_MAX; i++) { diff --git a/src/main_mini.c b/src/main_mini.c index 6e320bf..76834e6 100644 --- a/src/main_mini.c +++ b/src/main_mini.c @@ -65,15 +65,16 @@ int main(int argc, char** argv) { luat_fs_init(); luat_network_init(); - uv_thread_t l_main; + // uv_thread_t l_main; uv_timer_t t; uv_timer_init(main_loop, &t); uv_timer_start(&t, timer_nop, 1000, 1000); uv_clock_gettime(UV_CLOCK_MONOTONIC, &boot_ts); - uv_thread_create(&l_main, uv_luat_main, NULL); + // uv_thread_create(&l_main, uv_luat_main, NULL); // uv_thread_join(&l_main); - uv_run(main_loop, UV_RUN_DEFAULT); + // uv_run(main_loop, UV_RUN_DEFAULT); + uv_luat_main(NULL); uv_loop_close(main_loop); free(main_loop);