From 8908c48937b2b9bf50c08249b44fbdff82adcc80 Mon Sep 17 00:00:00 2001 From: xwashere Date: Fri, 1 Mar 2024 08:25:41 -0500 Subject: [PATCH] bash and curses --- CMakeLists.txt | 196 ++++++++++++++++++++++++++++-- lindows.ld.in | 209 ++++++++++++++++++++++++++++++++ lindows.spec | 3 + lsmss/CMakeLists.txt | 13 +- lsmss/main.cxx | 48 ++++++++ scripts/copyglibc | 11 -- scripts/copylib | 12 ++ src/glibc/ld.so.conf | 1 + src/glibc/patches/lindows.patch | 26 ++++ src/grub/grub.cfg | 2 +- 10 files changed, 494 insertions(+), 27 deletions(-) create mode 100644 lindows.ld.in create mode 100644 lindows.spec create mode 100644 lsmss/main.cxx delete mode 100755 scripts/copyglibc create mode 100755 scripts/copylib create mode 100644 src/glibc/ld.so.conf create mode 100644 src/glibc/patches/lindows.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index def235f..d710643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,95 @@ cmake_minimum_required(VERSION 3.28) # grab commands include(ExternalProject) +# set our stuff for cross compiling +set(CMAKE_CXX_STANDARD 23) +set_property(DIRECTORY . PROPERTY INCLUDE_DIRECTORIES "") + +# -- generate a file or two -- +configure_file(lindows.ld.in lindows.ld @ONLY) + +# -- macros for managing this nightmare multi toolchain shitshow -- + +# dependencies +add_executable(LindowsCompilerSpec IMPORTED) +set_property(TARGET LindowsCompilerSpec PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lindows.spec") +add_executable(LindowsLinkerScript IMPORTED) +set_property(TARGET LindowsLinkerScript PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/lindows.ld") +add_executable(LindowsLinkerScriptSource IMPORTED) +set_property(TARGET LindowsLinkerScriptSource PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/lindows.ld.in") + +# compiler stuff +set(LW_CROSS_CC "${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/bin/gcc") +set(LW_CROSS_CXX "${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/bin/g++") +set(LW_CROSS_LD "${LW_CROSS_CC}") +set(LW_CROSS_INCFLAGS -isystem${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/include/c++/13.2.0 -isystem${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/lib/gcc/x86_64-pc-linux-gnu/13.2.0/include -isystem${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/lib/gcc/x86_64-pc-linux-gnu/13.2.0/include-fixed -isystem${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/include/c++/13.2.0/x86_64-pc-linux-gnu -isystem${CMAKE_CURRENT_BINARY_DIR}/glibc/prefix/include -isystem${CMAKE_CURRENT_BINARY_DIR}/linux/headers/include) +set(LW_CROSS_CFLAGS -nostdinc ${LW_CROSS_INCFLAGS}) +set(LW_CROSS_CXXFLAGS -nostdinc ${LW_CROSS_INCFLAGS}) +set(LW_CROSS_LIBFLAGS -L${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/lib -L${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix/lib64 -L${CMAKE_CURRENT_BINARY_DIR}/glibc/lib) +set(LW_CROSS_LDFLAGS ${LW_CROSS_LIBFLAGS} -Xlinker --dynamic-linker /Windows/System32/ld-linux-x86-64.so.2 -Wl,-T,${CMAKE_CURRENT_BINARY_DIR}/lindows.ld --specs=${CMAKE_CURRENT_SOURCE_DIR}/lindows.spec) + +string(REPLACE ";" " " LW_CROSS_CFLAGS_FLAT "${LW_CROSS_CFLAGS}") +string(REPLACE ";" " " LW_CROSS_CXXFLAGS_FLAT "${LW_CROSS_CXXFLAGS}") +string(REPLACE ";" " " LW_CROSS_LDFLAGS_FLAT "${LW_CROSS_LDFLAGS}") + +# defines a project +function(lw_project PROJECTNAME) + set(cpa_flag) + set(cpa_single DESCRIPTION TARGET) + set(cpa_multi) + cmake_parse_arguments(PARSE_ARGV 1 ARG "${cpa_flag}" "${cpa_single}" "${cpa_multi}") + + if(NOT ARG_DESCRIPTION) + set(ARG_DESCRIPTION "No description provided.") + endif() + + if(NOT ARG_TARGET) + set(ARG_TARGET "HOST") + endif() + + project(PROJECTNAME + DESCRIPTION "${ARG_DESCRIPTION}" + ) + + set(LW_TARGET "${ARG_TARGET}" PARENT_SCOPE) + + if(${ARG_TARGET} STREQUAL "HOST") + + elseif(${ARG_TARGET} STREQUAL "LINDOWS") + set(CMAKE_C_COMPILER "${LW_CROSS_CC}" PARENT_SCOPE) + set(CMAKE_CXX_COMPILER "${LW_CROSS_CXX}" PARENT_SCOPE) + set_property(DIRECTORY . PROPERTY INCLUDE_DIRECTORIES "") + else() + message(FATAL_ERROR "Unrecognized target type \"${ARG_TARGET}\"") + endif() +endfunction() + +# defines a executable target, this must be used if lw_project is used +function(lw_add_executable NAME) + set(cpa_flag) + set(cpa_single) + set(cpa_multi SOURCES) + cmake_parse_arguments(PARSE_ARGV 1 ARG "${cpa_flag}" "${cpa_single}" "${cpa_multi}") + + add_executable(${NAME}) + if(ARG_SOURCES) + target_sources(${NAME} PRIVATE ${ARG_SOURCES}) + target_compile_options(${NAME} PRIVATE + $<$:${LW_CROSS_CFLAGS}> + $<$:${LW_CROSS_CXXFLAGS}> + ) + target_link_options(${NAME} PRIVATE ${LW_CROSS_LDFLAGS}) + endif() + + if(LW_TARGET) + add_dependencies(${NAME} GCC-install LindowsCompilerSpec LindowsLinkerScript) + else() + message(FATAL_ERROR "LW_TARGET not defined, are you in a lw_project?") + endif() +endfunction() + +# -- lindows -- + # dear god project(lindows) @@ -20,6 +109,25 @@ find_package(Python REQUIRED) # for GRUB file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_c") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lindows_efi") +# build cross compiler +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gcc") +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix") +ExternalProject_Add(GCC + GIT_REPOSITORY "git://gcc.gnu.org/git/gcc.git" + GIT_TAG "releases/gcc-13.2.0" + GIT_PROGRESS TRUE + UPDATE_COMMAND "" + CONFIGURE_COMMAND /configure + --prefix=${CMAKE_CURRENT_BINARY_DIR}/gcc/prefix + --target=x86_64-pc-linux-gnu + --enable-languages=c,c++ + --disable-nls + --disable-bootstrap + BUILD_COMMAND make + INSTALL_COMMAND make install + STEP_TARGETS install +) + # build grub file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/grub") ExternalProject_Add(GRUB @@ -57,24 +165,24 @@ ExternalProject_Add(Linux BUILD_IN_SOURCE TRUE INSTALL_COMMAND ${CoreUtils_Copy_EXECUTABLE} arch/x86_64/boot/bzImage ${CMAKE_CURRENT_BINARY_DIR}/linux COMMAND make modules_install INSTALL_MOD_PATH=${CMAKE_CURRENT_BINARY_DIR}/linux/modules - COMMAND make headers_install INSTALL_HDR_PATH=${CMAKE_CURRENT_BINARY_DIR}/linux/headers - STEP_TARGETS install + COMMAND make headers_install INSTALL_HDR_PATH=${CMAKE_CURRENT_BINARY_DIR}/linux/headers "" + STEP_TARGETS install ) ExternalProject_Add_StepDependencies(Linux configure LinuxConfig) +add_executable(LinuxKernel IMPORTED) +set_property(TARGET LinuxKernel PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/linux/bzImage) # build glibc file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/prefix") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/lib") -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/libexec") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/bin") -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/sbin") -file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/glibc/include") ExternalProject_Add(GLibC GIT_REPOSITORY "https://sourceware.org/git/glibc.git" GIT_TAG "glibc-2.39" GIT_PROGRESS TRUE UPDATE_COMMAND "" + PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/src/glibc/patches/lindows.patch CONFIGURE_COMMAND /configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/glibc/prefix --with-headers=${CMAKE_CURRENT_BINARY_DIR}/linux/headers/include @@ -89,6 +197,58 @@ ExternalProject_Add(GLibC COMMAND sh -c "cp -r ${CMAKE_CURRENT_BINARY_DIR}/glibc/prefix/lib/* ${CMAKE_CURRENT_BINARY_DIR}/glibc/lib" STEP_TARGETS install ) +add_executable(GLibCPatch IMPORTED) +set_property(TARGET GLibCPatch PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/glibc/patches/lindows.patch) +ExternalProject_Add_StepDependencies(GLibC patch GLibCPatch) + +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ncurses") +ExternalProject_Add(NCurses # oh wow no git + URL "https://invisible-island.net/archives/ncurses/ncurses-6.4.tar.gz" + URL_MD5 "5a62487b5d4ac6b132fe2bf9f8fad29b" # generated with md5sum at 2024-02-29 12:00 + UPDATE_COMMAND "" + CONFIGURE_COMMAND env + "CC=${LW_CROSS_CC}" + "CXX=${LW_CROSS_CXX}" + "LD=${LW_CROSS_LD}" + "CFLAGS=${LW_CROSS_CFLAGS_FLAT}" + "CXXFLAGS=${LW_CROSS_CXXFLAGS_FLAT}" + "LDFLAGS=${LW_CROSS_LDFLAGS_FLAT}" + + /configure + --prefix=${CMAKE_CURRENT_BINARY_DIR}/ncurses + --host=x86_64-pc-linux-gnu + --without-ada + --without-manpages + --enable-mixed-case + --without-gpm + --with-shared + BUILD_COMMAND make + INSTALL_COMMAND make install + STEP_TARGETS install +) +ExternalProject_Add_StepDependencies(NCurses configure GCC) + +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bash") +ExternalProject_Add(Bash + GIT_REPOSITORY "https://git.savannah.gnu.org/git/bash.git" + GIT_TAG "bash-5.2" + GIT_PROGRESS TRUE + UPDATE_COMMAND "" + CONFIGURE_COMMAND env + "CC=${LW_CROSS_CC}" + "LD=${LW_CROSS_LD}" + "CFLAGS=${LW_CROSS_CFLAGS_FLAT}" + "LDFLAGS=${LW_CROSS_LDFLAGS_FLAT}" + + /configure + --prefix=${CMAKE_CURRENT_BINARY_DIR}/bash + --host=x86_64-pc-linux-gnu + --with-curses + BUILD_COMMAND make + INSTALL_COMMAND make install + STEP_TARGETS install +) +ExternalProject_Add_StepDependencies(Bash configure GCC NCurses) # this should probably be a shell script, i unfortunately do not care add_custom_command(OUTPUT lindows_c.img @@ -97,7 +257,7 @@ add_custom_command(OUTPUT lindows_c.img if=/dev/zero of=lindows_c.img bs=1M - count=128 + count=256 # format disk with new NTFS filesystem COMMAND "${NTFS3g_Mkfs_EXECUTABLE}" ARGS -F # scary! -L Windows @@ -111,6 +271,7 @@ add_custom_command(OUTPUT lindows_c.img # create system folders COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Windows COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Windows/System32 + COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Windows/System32/LNXConfig COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Windows/GRUB COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Windows/GRUB/x86_64-efi @@ -122,7 +283,17 @@ add_custom_command(OUTPUT lindows_c.img COMMAND ${CoreUtils_Copy_EXECUTABLE} ARGS ${CMAKE_CURRENT_BINARY_DIR}/linux/bzImage lindows_c/Windows/vmlinux.exe # copy glibc files to system32 - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/copyglibc + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/copylib glibc + COMMAND ${CoreUtils_Copy_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/src/glibc/ld.so.conf lindows_c/Windows/System32/LNXConfig/ld.so.conf + + # copy bash to system32 + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/copylib bash + + # copy curses to system32 + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/copylib ncurses + + # copy lsmss + COMMAND ${CoreUtils_Copy_EXECUTABLE} ARGS $ lindows_c/Windows/System32/lsmss.exe # create users folder COMMAND ${CoreUtils_Mkdir_EXECUTABLE} ARGS lindows_c/Users @@ -134,8 +305,11 @@ add_custom_command(OUTPUT lindows_c.img lsmss Linux-install GLibC-install + Bash-install + LinuxKernel src/grub/grub.cfg - scripts/copyglibc + src/glibc/ld.so.conf + scripts/copylib ) # this makes the efi system partition @@ -165,12 +339,12 @@ add_custom_command(OUTPUT lindows.img COMMAND echo ARGS label: gpt > disk.sfdisk COMMAND echo ARGS unit: sectors >> disk.sfdisk COMMAND echo ARGS start=1MiB, size=33MiB, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B >> disk.sfdisk - COMMAND echo ARGS start=34MiB, size=128MiB, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=48D29DA8-2FF8-4F23-BA1A-0E8CCFC329E2 >> disk.sfdisk + COMMAND echo ARGS start=34MiB, size=256MiB, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=48D29DA8-2FF8-4F23-BA1A-0E8CCFC329E2 >> disk.sfdisk COMMAND "${CoreUtils_dd_EXECUTABLE}" ARGS if=/dev/zero of=lindows.img bs=1M - count=256 + count=300 # partition disk COMMAND sfdisk ARGS lindows.img < disk.sfdisk # write partitions @@ -185,7 +359,7 @@ add_custom_command(OUTPUT lindows.img if=lindows_c.img of=lindows.img bs=1M - count=128 + count=256 seek=34 conv=notrunc DEPENDS lindows_c.img lindows_efi.img diff --git a/lindows.ld.in b/lindows.ld.in new file mode 100644 index 0000000..b7b8e4e --- /dev/null +++ b/lindows.ld.in @@ -0,0 +1,209 @@ +/* i just copy and paste from the default script as needed :D */ + +OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") +OUTPUT_ARCH(i386:x86-64) + +/* gcc libs */ +SEARCH_DIR("@CMAKE_BINARY_DIR@/gcc/prefix/lib") +SEARCH_DIR("@CMAKE_BINARY_DIR@/gcc/prefix/lib/gcc/x86_64-pc-linux-gnu/13.2.0/") + +/* glibc libs */ +SEARCH_DIR("@CMAKE_BINARY_DIR@/glibc/lib") + +/* ncurses libs */ +SEARCH_DIR("@CMAKE_BINARY_DIR@/ncurses/lib") + +ENTRY(_start) + +SECTIONS { + PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); + . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS; + .interp : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .rela.dyn : { + *(.rela.init) + *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) + *(.rela.fini) + *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) + *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) + *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) + *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) + *(.rela.ctors) + *(.rela.dtors) + *(.rela.got) + *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) + *(.rela.ldata .rela.ldata.* .rela.gnu.linkonce.l.*) + *(.rela.lbss .rela.lbss.* .rela.gnu.linkonce.lb.*) + *(.rela.lrodata .rela.lrodata.* .rela.gnu.linkonce.lr.*) + *(.rela.ifunc) + } + .rela.plt : { + *(.rela.plt) + PROVIDE_HIDDEN (__rela_iplt_start = .); + *(.rela.iplt) + PROVIDE_HIDDEN (__rela_iplt_end = .); + } + .relr.dyn : { *(.relr.dyn) } + + . = ALIGN(CONSTANT (MAXPAGESIZE)); + .init : { KEEP (*(SORT_NONE(.init))) } + .plt : { *(.plt) *(.iplt) } + .plt.got : { *(.plt.got) } + .plt.sec : { *(.plt.sec) } + .text : { + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(SORT(.text.sorted.*)) + *(.text .stub .text.* .gnu.linkonce.t.*) + *(.gnu.warning) + } + .fini : { KEEP (*(SORT_NONE(.fini))) } + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + . = ALIGN(CONSTANT (MAXPAGESIZE)); + . = SEGMENT_START("rodata-segment", ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1))); + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } + .rodata1 : { *(.rodata1) } + .eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) } + .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) } + .sframe : ONLY_IF_RO { *(.sframe) *(.sframe.*) } + .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + .gnu_extab : ONLY_IF_RO { *(.gnu_extab*) } + .exception_ranges : ONLY_IF_RO { *(.exception_ranges*) } + + . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); + .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) } + .sframe : ONLY_IF_RW { *(.sframe) *(.sframe.*) } + .gnu_extab : ONLY_IF_RW { *(.gnu_extab) } + .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + .exception_ranges : ONLY_IF_RW { *(.exception_ranges*) } + .tdata : { + PROVIDE_HIDDEN (__tdata_start = .); + *(.tdata .tdata.* .gnu.linkonce.td.*) + } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .preinit_array : { + PROVIDE_HIDDEN(__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN(__preinit_array_end = .); + } + .init_array : { + PROVIDE_HIDDEN(__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .ctors)) + PROVIDE_HIDDEN(__init_array_end = .); + } + .fini_array : { + PROVIDE_HIDDEN(__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE(*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o) .dtors)) + PROVIDE_HIDDEN(__fini_array_end = .); + } + .ctors : { + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } + .dtors : { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } + .jcr : { KEEP (*(.jcr)) } + .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } + .dynamic : { *(.dynamic) } + .got : { *(.got) *(.igot) } + + . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 24 ? 24 : 0, .); + .got.plt : { *(.got.plt) *(.igot.plt) } + .data : { + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + } + .data1 : { *(.data1) } + + _edata = .; + PROVIDE (edata = .); + . = ALIGN(ALIGNOF(NEXT_SECTION)); + __bss_start = .; + .bss : { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(. != 0 ? 64 / 8 : 1); + } + .lbss : { + *(.dynlbss) + *(.lbss .lbss.* .gnu.linkonce.lb.*) + *(LARGE_COMMON) + } + + . = ALIGN(64 / 8); + . = SEGMENT_START("ldata-segment", .); + .lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) : { + *(.lrodata .lrodata.* .gnu.linkonce.lr.*) + } + .ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) : { + *(.ldata .ldata.* .gnu.linkonce.l.*) + . = ALIGN(. != 0 ? 64 / 8 : 1); + } + + . = ALIGN(64 / 8); + _end = .; + PROVIDE(end = .); + + . = DATA_SEGMENT_END (.); + + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 (INFO) : { *(.comment); LINKER_VERSION; } + .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) } + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .debug_addr 0 : { *(.debug_addr) } + .debug_line_str 0 : { *(.debug_line_str) } + .debug_loclists 0 : { *(.debug_loclists) } + .debug_macro 0 : { *(.debug_macro) } + .debug_names 0 : { *(.debug_names) } + .debug_rnglists 0 : { *(.debug_rnglists) } + .debug_str_offsets 0 : { *(.debug_str_offsets) } + .debug_sup 0 : { *(.debug_sup) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } +} diff --git a/lindows.spec b/lindows.spec new file mode 100644 index 0000000..ab64253 --- /dev/null +++ b/lindows.spec @@ -0,0 +1,3 @@ +*link_libgcc: + + diff --git a/lsmss/CMakeLists.txt b/lsmss/CMakeLists.txt index 34cdb76..45bfaac 100644 --- a/lsmss/CMakeLists.txt +++ b/lsmss/CMakeLists.txt @@ -1,8 +1,13 @@ cmake_minimum_required(VERSION 3.28) # Preinit process that prepares the os and uh yeah :astolfothumbsup: -#project(lsmss -# DESCRIPTION "Linux Session Manager Subsystem" -#) +lw_project(lsmss + DESCRIPTION "Linux Session Manager Subsystem" + TARGET LINDOWS +) -#add_executable(lsmss main.cxx) +lw_add_executable(lsmss + SOURCES main.cxx +) + +target_link_options(lsmss PRIVATE "-static") diff --git a/lsmss/main.cxx b/lsmss/main.cxx new file mode 100644 index 0000000..812707d --- /dev/null +++ b/lsmss/main.cxx @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include + +#include + +/** + * execute a program from an absolute path + * + * \param path absolute path to program (duh) + * \return program return value, 1 if it does not exist or -1 on error + */ +int execute(const std::string& path) { + if (pid_t child = fork()) { + int exitcode = -1; + waitpid(child, &exitcode, 0); + + return exitcode; + } else { + char* args[] = { strdup(path.c_str()), nullptr }; + execv(args[0], args); + + // this should only be reached if we cant load the program + std::exit(1); + } +} + +int main() { + bool ok = true; + + // dynamic linking fun + std::cout << "Regenerating dynamic linker cache\n"; + // ok = execute("/Windows/System32/ldconfig.exe") == 0; + + // we are never ok + ok = false; + + // failure :> + if (!ok) { + std::cout << "Unable to complete preinitialization. You have been dropped into a minimal recovery environment. Good luck" << std::endl; + execute("/Windows/System32/bash.exe"); + } + + return 0; +} diff --git a/scripts/copyglibc b/scripts/copyglibc deleted file mode 100755 index e94edfb..0000000 --- a/scripts/copyglibc +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -# copy libs -find glibc/bin glibc/lib -type d | sed -r 's/glibc\/(bin|lib)\///;Tn;s/^/mkdir lindows_c\/Windows\/System32\//;by;:n;d;:y;e' > /dev/null; -find glibc/bin -type f | sed -r 's/glibc\/bin\/(.*)/cp glibc\/bin\/\1 lindows_c\/Windows\/System32\/\1.exe/;e' > /dev/null -find glibc/lib -type f | sed -r 's/glibc\/lib\/(.*)/cp glibc\/lib\/\1 lindows_c\/Windows\/System32\/\1/;e' > /dev/null - -# copy lib links -for lib in $(cd glibc/lib && find -type l); do - ln -sr "lindows_c/Windows/System32/$(readlink glibc/lib/$lib)" "lindows_c/Windows/System32/$lib" -done diff --git a/scripts/copylib b/scripts/copylib new file mode 100755 index 0000000..d0a3a74 --- /dev/null +++ b/scripts/copylib @@ -0,0 +1,12 @@ +#!/bin/sh +# ARG 1: LIB PATH + +# copy libs +find $1/bin $1/lib -type d | sed -r 's/'$1'\/(bin|lib)\///;Tn;s/^/mkdir lindows_c\/Windows\/System32\//;by;:n;d;:y;e' > /dev/null; +find $1/bin -type f | sed -r 's/'$1'\/bin\/(.*)/cp '$1'\/bin\/\1 lindows_c\/Windows\/System32\/\1.exe/;e' > /dev/null +find $1/lib -type f | sed -r 's/'$1'\/lib\/(.*)/cp '$1'\/lib\/\1 lindows_c\/Windows\/System32\/\1/;e' > /dev/null + +# copy lib links +for lib in $(cd $1/lib && find -type l); do + ln -sr "lindows_c/Windows/System32/$(readlink $1/lib/$lib)" "lindows_c/Windows/System32/$lib" +done diff --git a/src/glibc/ld.so.conf b/src/glibc/ld.so.conf new file mode 100644 index 0000000..e437122 --- /dev/null +++ b/src/glibc/ld.so.conf @@ -0,0 +1 @@ +/Windows/System32 diff --git a/src/glibc/patches/lindows.patch b/src/glibc/patches/lindows.patch new file mode 100644 index 0000000..730d382 --- /dev/null +++ b/src/glibc/patches/lindows.patch @@ -0,0 +1,26 @@ +diff --git a/elf/ldconfig.c b/elf/ldconfig.c +index b64c54b53e..ce876a6e20 100644 +--- a/elf/ldconfig.c ++++ b/elf/ldconfig.c +@@ -47,7 +47,7 @@ + #include + + #ifndef LD_SO_CONF +-# define LD_SO_CONF SYSCONFDIR "/ld.so.conf" ++# define LD_SO_CONF "/Windows/System32/LNXConfig/ld.so.conf" + #endif + + /* Get libc version number. */ +diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h +index 919e49ffc8..781a6e93bd 100644 +--- a/sysdeps/generic/dl-cache.h ++++ b/sysdeps/generic/dl-cache.h +@@ -35,7 +35,7 @@ + #endif + + #ifndef LD_SO_CACHE +-# define LD_SO_CACHE SYSCONFDIR "/ld.so.cache" ++# define LD_SO_CACHE "/Windows/System32/LNXConfig/ld.so.cache" + #endif + + #ifndef add_system_dir diff --git a/src/grub/grub.cfg b/src/grub/grub.cfg index b137572..32579ce 100644 --- a/src/grub/grub.cfg +++ b/src/grub/grub.cfg @@ -2,5 +2,5 @@ clear # boot -linux /Windows/vmlinux.exe console=tty0 console=ttyS0 root=PARTUUID=48d29da8-2ff8-4f23-ba1a-0e8ccfc329e2 rw +linux /Windows/vmlinux.exe console=tty0 console=ttyS0 root=PARTUUID=48d29da8-2ff8-4f23-ba1a-0e8ccfc329e2 rw init=/Windows/System32/lsmss.exe boot