startup getmainargs

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
nullplan
Member
Member
Posts: 1907
Joined: Wed Aug 30, 2017 8:24 am

Re: startup getmainargs

Post by nullplan »

kerravon wrote: Mon Jun 23, 2025 5:25 am If the compiler uses - or can use - stack calling convention, then:

#define va_arg(ap, type) *(type *)(ap += sizeof(type), ap - sizeof(type))
Wow, such portable! It doesn't work on any platform I know except i386.
kerravon wrote: Mon Jun 23, 2025 5:25 am My application suite doesn't pass "short",
That is no issue because the type given to va_arg must be a promoted type, i.e. int or bigger. GCC warns me that executing va_arg(ap, short) will abort at run time.
Carpe diem!
iProgramInCpp
Member
Member
Posts: 88
Joined: Sun Apr 21, 2019 7:39 am

Re: startup getmainargs

Post by iProgramInCpp »

Octocontrabass wrote: Fri Jun 13, 2025 11:28 pm I was thinking more along the lines of having the entry point be inside (the equivalent of) msvcrt.dll. This is actually how dynamic linking works in Linux: dynamically linked ELF executables specify that ld-linux.so contains the entry point.
In Win32 applications, main() is called by a function that goes by either `_mainCRTStartup` or `_start` or `start` (I believe it depends on which compiler toolset it was compiled with). But that function is linked into the application.

Dynamic linking on Windows works in basically the same way as on Linux, yes, but the thing doing the loading is not msvcrt.dll. It's actually ntdll.dll. When a process is created, the main thread's first instruction is in ntdll.dll. Then, it loads all of the DLLs, and then the application. For each of the DLLs, its entry point (DllMain) is called with DLL_PROCESS_ATTACH (well, er, again, _DllMainCRTStartup etc), and then the application's entry point is called, which eventually calls main().
kerravon wrote: Sat Jun 14, 2025 1:18 am Universal across all compilers and linkers worldwide.
All compilers... that implement the C90 standard in a way that completely abides by the standard?
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.
Post Reply