OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:54 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 6:26 am 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
I want to use the C Runtime Library functions in my kernel for some purposes like converting integers to text and vice versa. I'm using MSVC CL, I run vcvars64.bat and when I call for example _itoa() it gives unresolved external error.
Even compiling with /MT does not work.


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 6:51 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Are you including the appropriate .lib file in the list of files to link?


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 7:07 am 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
I'm not including anything, and talking about .lib files is there any static cruntime lib which I can include ?


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 7:18 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
atoi is implemented in libucrt.lib for static linking.


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 12:32 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
Thank you, now itoa works but I'm a little bit worried about this :
Code:
libucrt.lib
kernel32.lib(KERNEL32.dll) : warning LNK4237: /SUBSYSTEM:NATIVE specified when importing from 'KERNEL32.DLL';  Use /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS.


libucrt includes kernel32.dll, It's fine because I'm not using any windows related function but at the same time I'll be linking my kernel to some dlls in the future (for e.g. the driver development kit or Graphics API), so the time I'll add DLL importing to my bootloader the bootloader will likely fail because it cannot find kernel32.dll.

This is the related document : https://learn.microsoft.com/en-us/cpp/e ... w=msvc-170

On top of that I may be naming some functions a similar name to windows one's
here are the exported functions :
Code:
Section contains the following imports:

    KERNEL32.dll
      FFFF80000000B000 Import Address Table
      FFFF8000000138C0 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                         4F5 RtlCaptureContext
                         4FD RtlLookupFunctionEntry
                         504 RtlVirtualUnwind
                         3A0 IsDebuggerPresent
                         5E6 UnhandledExceptionFilter
                         5A4 SetUnhandledExceptionFilter
                         27D GetLastError
                         564 SetLastError
                         232 GetCurrentProcess
                         5C4 TerminateProcess
                         3A8 IsProcessorFeaturePresent
                         178 ExitProcess
                         1C5 FreeLibrary
                         295 GetModuleHandleW
                         294 GetModuleHandleExW
                         2CD GetProcAddress
                         36C HeapAlloc
                         370 HeapFree
                         149 EnterCriticalSection
                         3E0 LeaveCriticalSection
                         123 DeleteCriticalSection
                         1B6 FlsGetValue
                         1B7 FlsSetValue
                         386 InitializeCriticalSectionAndSpinCount
                         3E6 LoadLibraryExW
                         3D4 LCMapStringW
                         3AE IsValidCodePage
                         1CC GetACP
                         2B6 GetOEMCP
                         1DB GetCPInfo
                         2F8 GetStringTypeW
                         412 MultiByteToWideChar
                         637 WideCharToMultiByte
                          DA CreateFileW
                         503 RtlUnwindEx
                         145 EncodePointer
                         487 RaiseException
                         5D8 TlsGetValue
                         5D9 TlsSetValue
                         4FF RtlPcToFileHeader
                         555 SetFilePointerEx
                         57F SetStdHandle
                         1B9 FlushFileBuffers
                         64B WriteFile
                         21A GetConsoleOutputCP
                         216 GetConsoleMode
                          94 CloseHandle
                         64A WriteConsoleW


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 1:07 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
C runtime libraries are designed to be used in hosted environments. In a freestanding environment like an OS kernel, you will need to either find a library designed to be used in a freestanding environment or write the necessary functions yourself.


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 2:23 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
Ok So I think that I'm going to write the library by myself and I'll be copying some functions from Linux to speed up the coding process.
I will make a separate c runtime library (cruntime.dll) and a whole nos runtime library (nosrt.dll) for user mode programs.
If you have better name suggestion let me know and thanks!


Last edited by devc1 on Fri Mar 24, 2023 2:29 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 2:28 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
devc1 wrote:
I'll be copying some functions from Linux

Pay attention to the license. If you copy GPL code, your kernel must be released under the GPL.


Top
 Profile  
 
 Post subject: Re: How can I use runtime library without hardcoding it
PostPosted: Fri Mar 24, 2023 2:31 pm 
Offline
Member
Member

Joined: Fri Feb 11, 2022 4:55 am
Posts: 435
Location: behind the keyboard
Then I will just proceed and use existing functions from my previous OS, It has most of the functions that I need.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], nullplan and 48 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group