OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to map a specific C++ file as user code?
PostPosted: Sun Oct 02, 2022 8:34 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
I need to have a single C++ file mapped as user code and I can't figure out how to do it. I can't just map the whole kernel as user accessible, that would be stupidly dangerous. I just want this one object file and all of its data to be mapped as user code/data. I could load it as a separate module but I can't since I don't have any kernel libraries yet and even if I had, I would still have to access some kernel structures. So I was thinking maybe I should somehow obtain the address of that code and map it, but it is kind of impossible since we're dealing with C++ objects. So I guess there must be a linker flag or something that would allow me to specify a compiled object file and put it on a separate page?

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: How to map a specific C++ file as user code?
PostPosted: Sun Oct 02, 2022 8:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
If it’s user code then it shouldn’t be part of the kernel, and it shouldn’t be able to access kernel objects (other than through system calls. I think the problem may be your design.


Top
 Profile  
 
 Post subject: Re: How to map a specific C++ file as user code?
PostPosted: Sun Oct 02, 2022 10:34 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
That sounds similar to Linux's VSO.

I do something like this for my system calls. I basically put the code in a ".vdso" section. It is mapped in kernel space as it is part of the kernel. But then I also map this code at the end of user space. You just have to make sure this code is relocatable as it won't have the same address in user and kernel space.

Now this code is never actually called in kernel space. It is meant for user space to provide the functionality required to make system calls. I also plan to add functions to read the current time and monotonic timers without having to make a system call. Obviously this code can't reference any variable / function elsewhere in the kernel.

I wrote my user space code in assembly. I am not sure you can do this (easily) for C++ code and objects. What kind of functionality are you tried to map to user space?

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How to map a specific C++ file as user code?
PostPosted: Sun Oct 02, 2022 11:00 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Octacone wrote:
So I guess there must be a linker flag or something that would allow me to specify a compiled object file and put it on a separate page?

You can tell the linker to treat one object file differently from the rest.

But it won't be able to access any symbols that are elsewhere in your kernel, since the rest of your kernel will be inaccessible from ring 3, so I'm not sure if this is really the best way to do what you want.


Top
 Profile  
 
 Post subject: Re: How to map a specific C++ file as user code?
PostPosted: Sun Oct 02, 2022 1:32 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
Sorry, I should have been more clear. I'm adding virtual 8086 mode support which runs in user mode by default, which means I can't leave my VBE driver mapped as kernel, since it would generate a PF.
I can enter it just fine and the environment is set up properly I just can't execute any code because it has to be mapped as user.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 20 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