Paging vs Segmentation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Lont

Paging vs Segmentation

Post by Lont »

Hello,

I'm developing MY PMode OS (MYPMOS :D) And I was wondering what would be a better paging or segmentation. I have read lots of online docs. And the main problem with paging is that programs at the same level (for example two applications) can crash each other. There is no way of protecting one code segment from the other. So if one pragram crashes it can crash the other program too...... Or is there a way I haven't thought of?

At this point I'm thinking of giving every task its own ldt with data, code and stack segment. And use paging also. Every task gets 64MB of virtual mem space (16 page tables) when the task needs more mem another page gets mapped into real adres space. The problem is that the task switching is slow because of the reloading of the segments.

Thanks in advance,

Lont
Anton

RE:Paging vs Segmentation

Post by Anton »

>And the main problem with paging is that programs at the same level (for
>example two applications) can crash each other
Do you realy think that this is true? I this was the case, then no one would have used paging:)! Each application will be running in it's own virtual space(task segment), and there will be NO way for it to acess pages from other applications, unless it calls some system kernel function().

>At this point I'm thinking of giving every task its own ldt with data, code
>and stack segment
And don't tell me that all of these ldt are in the same table. They should be seperated:each task should have it's own table.

>The problem is that the task switching is slow because of the reloading of
>the segments.
It should not be that long



Anton.
jcmatias

RE:Paging vs Segmentation

Post by jcmatias »

...dont't forget ,all 64 bits x86 CPUs have don't have segmentation.
Anton

RE:Paging vs Segmentation

Post by Anton »

Good point :)
Legend

RE:Paging vs Segmentation

Post by Legend »

And why there is no way for program A to access program B directly: They get different physical memory locations and no physical memory that belongs to process A will be mapped into the address space of process B (unless you want shared memory)
Lont

RE:Paging vs Segmentation

Post by Lont »

How is the memory of one task protected from another task? Does every task get an other page dir? Ok I think I'm going to drop the segmentation.

But how is the virtual memory from task one protected from task 2? Task 1 gets (for example) (virtual) adres space 4MB-8MB and task 2 gets 9MB-15MB. How is task 1 prevented from reading/writing 10MB? There is no limit specified or is there? Or is virtual adres 10MB for task 1 mapped to another physical adres then the 10MB of task 2? If yes, how is this done?

I believe I'm missing something, but I can't see what. So could you tell me what I am missing?

Thanks,
Lont
Legend

RE:Paging vs Segmentation

Post by Legend »

Give every task it's own address space (page directory) and you get the answers.
Then Address X may both be mapped in Addressspace A and B, but who says it has to be mapped to the same physical memory.

This means then, that for example both Task 1 and Task 2 may use virtual 4MB-8MB, as they both have their own 4gb of virtual space anyway.
hartyl

RE:Paging vs Segmentation

Post by hartyl »

ya, you're missing something.

first about, usually *every* task has it's own page directory.
THIS and only THIS seperates all memory from each task.

so, when you do a taskswitch you have to switch the pagedir-register (cr3) as well  that way, the whole memory is "switched" from one task, to the memory of the task you switched to.

as a conclusion, you have some tasks running, each having its own pagedirectory where the own code- and data-pages are mapped. and there is the kernel, which is mapped into each task's memory-space (so, the same physical pages are mapped for each task into its own pagedirectory).

hope you got it now :)

greets, hartyl
Lont

RE:Paging vs Segmentation

Post by Lont »

He,

OK thanks guys, I was thinking about giving every task its on page dir. Now I can see it is the only way to protect the tasks from each other.

I think I get it now.

Thanks a lot, this place is very usefull,

Lont
Post Reply