Search results
Top results related to what are protocols in operating systems list of parts
Top Answer
Answered May 29, 2021 · 146 votes
Linux x86 ring usage overview
Understanding how rings are used in Linux will give you a good idea of what they are designed for.
In x86 protected mode, the CPU is always in one of 4 rings. The Linux kernel only uses 0 and 3:
- 0 for kernel
- 3 for users
This is the most hard and fast definition of kernel vs userland.
Why Linux does not use rings 1 and 2: CPU Privilege Rings: Why rings 1 and 2 aren't used?
How is the current ring determined?
The current ring is selected by a combination of:
- global descriptor table: a in-memory table of GDT entries, and each entry has a field Privl which encodes the ring.The LGDT instruction sets the address to the current descriptor table.See also: http://wiki.osdev.org/Global_Descriptor_Table
- the segment registers CS, DS, etc., which point to the index of an entry in the GDT.For example, CS = 0 means the first entry of the GDT is currently active for the executing code.
What can each ring do?
The CPU chip is physically built so that:
- ring 0 can do anything
- ring 3 cannot run several instructions and write to several registers, most notably: cannot change its own ring! Otherwise, it could set itself to ring 0 and rings would be useless.In other words, cannot modify the current segment descriptor, which determines the current ring.
- cannot modify the page tables: How does x86 paging work?In other words, cannot modify the CR3 register, and paging itself prevents modification of the page tables.This prevents one process from seeing the memory of other processes for security / ease of programming reasons.
- cannot register interrupt handlers. Those are configured by writing to memory locations, which is also prevented by paging.Handlers run in ring 0, and would break the security model.In other words, cannot use the LGDT and LIDT instructions.
- cannot do IO instructions like in and out , and thus have arbitrary hardware accesses.Otherwise, for example, file permissions would be useless if any program could directly read from disk.More precisely thanks to Michael Petch: it is actually possible for the OS to allow IO instructions on ring 3, this is actually controlled by the Task state segment.What is not possible is for ring 3 to give itself permission to do so if it didn't have it in the first place.Linux always disallows it. See also: Why doesn't Linux use the hardware context switch via the TSS?
How do programs and operating systems transition between rings?
- when the CPU is turned on, it starts running the initial program in ring 0 (well kind of, but it is a good approximation). You can think this initial program as being the kernel (but it is normally a bootloader that then calls the kernel still in ring 0).
- when a userland process wants the kernel to do something for it like write to a file, it uses an instruction that generates an interrupt such as int 0x80 or syscall to signal the kernel. x86-64 Linux syscall hello world example:
.datahello_world: .ascii "hello world\n" hello_world_len = . - hello_world.text.global _start_start: /* write */ mov $1, %rax mov $1, %rdi mov $hello_world, %rsi mov $hello_world_len, %rdx syscall- /* exit */ mov $60, %rax mov $0, %rdi syscall-
compile and run:
as -o hello_world.o hello_world.Sld -o hello_world.out hello_world.o./hello_world.out-
GitHub upstream.
When this happens, the CPU calls an interrupt callback handler which the kernel registered at boot time. Here is a concrete baremetal example that registers a handler and uses it.
This handler runs in ring 0, which decides if the kernel will allow this action, do the action, and restart the userland program in ring 3. x86_64
- when the exec system call is used (or when the kernel will start /init), the kernel prepares the registers and memory of the new userland process, then it jumps to the entry point and switches the CPU to ring 3
- If the program tries to do something naughty like write to a forbidden register or memory address (because of paging), the CPU also calls some kernel callback handler in ring 0.But since the userland was naughty, the kernel might kill the process this time, or give it a warning with a signal.
- When the kernel boots, it setups a hardware clock with some fixed frequency, which generates interrupts periodically.This hardware clock generates interrupts that run ring 0, and allow it to schedule which userland processes to wake up.This way, scheduling can happen even if the processes are not making any system calls.
What is the point of having multiple rings?
There are two major advantages of separating kernel and userland:
- it is easier to make programs as you are more certain one won't interfere with the other. E.g., one userland process does not have to worry about overwriting the memory of another program because of paging, nor about putting hardware in an invalid state for another process.
- it is more secure. E.g. file permissions and memory separation could prevent a hacking app from reading your bank data. This supposes, of course, that you trust the kernel.
How to play around with it?
I've created a bare metal setup that should be a good way to manipulate rings directly: https://github.com/cirosantilli/x86-bare-metal-examples
I didn't have the patience to make a userland example unfortunately, but I did go as far as paging setup, so userland should be feasible. I'd love to see a pull request.
Alternatively, Linux kernel modules run in ring 0, so you can use them to try out privileged operations, e.g. read the control registers: How to access the control registers cr0,cr2,cr3 from a program? Getting segmentation fault
Here is a convenient QEMU + Buildroot setup to try it out without killing your host.
The downside of kernel modules is that other kthreads are running and could interfere with your experiments. But in theory you can take over all interrupt handlers with your kernel module and own the system, that would be an interesting project actually.
Negative rings
While negative rings are not actually referenced in the Intel manual, there are actually CPU modes which have further capabilities than ring 0 itself, and so are a good fit for the "negative ring" name.
One example is the hypervisor mode used in virtualization.
For further details see:
- https://security.stackexchange.com/questions/129098/what-is-protection-ring-1
- https://security.stackexchange.com/questions/216527/ring-3-exploits-and-existence-of-other-rings
ARM
In ARM, the rings are called Exception Levels instead, but the main ideas remain the same.
There exist 4 exception levels in ARMv8, commonly used as:
.text.global _start_start: /* write */ mov x0, 1 ldr x1, =msg ldr x2, =len mov x8, 64 svc 0- /* exit */ mov x0, 0 mov x8, 93 svc 0msg: .ascii "hello syscall v8\n"len = . - msg-
sudo apt-get install qemu-user gcc-arm-linux-gnueabihfarm-linux-gnueabihf-as -o hello.o hello.Sarm-linux-gnueabihf-ld -o hello hello.oqemu-arm hello-
- EL0: userland
- EL1: kernel ("supervisor" in ARM terminology).Entered with the svc instruction (SuperVisor Call), previously known as swi before unified assembly, which is the instruction used to make Linux system calls. Hello world ARMv8 example:hello.S .text.global _start_start: /* write */ mov x0, 1 ldr x1, =msg ldr x2, =len mov x8, 64 svc 0 /* exit */ mov x0, 0 mov x8, 93 svc 0msg: .ascii "hello syscall v8\n"len = . - msgGitHub upstream.Test it out with QEMU on Ubuntu 16.04: sudo apt-get install qemu-user gcc-arm-linux-gnueabihfarm-linux-gnueabihf-as -o hello.o hello.Sarm-linux-gnueabihf-ld -o hello hello.oqemu-arm helloHere is a concrete baremetal example that registers an SVC handler and does an SVC call.
- EL2: hypervisors, for example Xen.Entered with the hvc instruction (HyperVisor Call).A hypervisor is to an OS, what an OS is to userland.For example, Xen allows you to run multiple OSes such as Linux or Windows on the same system at the same time, and it isolates the OSes from one another for security and ease of debug, just like Linux does for userland programs.Hypervisors are a key part of today's cloud infrastructure: they allow multiple servers to run on a single hardware, keeping hardware usage always close to 100% and saving a lot of money.AWS for example used Xen until 2017 when its move to KVM made the news.
- EL3: yet another level. TODO example.Entered with the smc instruction (Secure Mode Call)
The ARMv8 Architecture Reference Model DDI 0487C.a - Chapter D1 - The AArch64 System Level Programmer's Model - Figure D1-1 illustrates this beautifully:
The ARM situation changed a bit with the advent of ARMv8.1 Virtualization Host Extensions (VHE). This extension allows the kernel to run in EL2 efficiently:
VHE was created because in-Linux-kernel virtualization solutions such as KVM have gained ground over Xen (see e.g. AWS' move to KVM mentioned above), because most clients only need Linux VMs, and as you can imagine, being all in a single project, KVM is simpler and potentially more efficient than Xen. So now the host Linux kernel acts as the hypervisor in those cases.
From the image we can see that when the bit E2H
of register HCR_EL2
equals 1, then VHE is enabled, and:
- the Linux kernel runs in EL2 instead of EL1
- when HCR_EL2.TGE == 1, we are a regular host userland program. Using sudo can destroy the host as usual.
- when HCR_EL2.TGE == 0 we are a guest OS (e.g. when you run an Ubuntu OS inside QEMU KVM inside the host Ubuntu. Doing sudo cannot destroy the host unless there's a QEMU/host kernel bug.
Note how ARM, maybe due to the benefit of hindsight, has a better naming convention for the privilege levels than x86, without the need for negative levels: 0 being the lower and 3 highest. Higher levels tend to be created more often than lower ones.
The current EL can be queried with the MRS instruction: what is the current execution mode/exception level, etc?
ARM does not require all exception levels to be present to allow for implementations that don't need the feature to save chip area. ARMv8 "Exception levels" says:
An implementation might not include all of the Exception levels. All implementations must include EL0 and EL1. EL2 and EL3 are optional.
QEMU for example defaults to EL1, but EL2 and EL3 can be enabled with command line options: qemu-system-aarch64 entering el1 when emulating a53 power up
Code snippets tested on Ubuntu 18.10.
1/5
Top Answer
Answered Nov 16, 2016 · 1 votes
Always try to read Linux documentation(man <command or system_call>) for these type of doubts.
for your case man sem_init
sem_init() initializes the unnamed semaphore at the address pointed to by sem. The value argument specifies the initial value for the semaphore.
web link of the man pages
2/5
Top Answer
Answered Oct 09, 2013 · 6 votes
There are no limits, except those that are imposed by your compiler. Clearly you cannot make "operating system calls" when you don't have an "operating system", but as long as somebody wrote a library that provides the functionality you need, there are indeed "no limits". Encryption - done. Malloc - easy. TCP/IP - got it. Lots of Arduino libraries. It's fun. Go for it.
Some helpful information at http://www.nongnu.org/avr-libc/user-manual/malloc.html
3/5
Top Answer
Answered Sep 04, 2021 · 13 votes
Processes are two types based on their types of categories. The first one which you mentioned is related to event-specific process categorization and the next categorization is based on their nature. But, if someone asks you, you should ask for more clarification as to which type of category does he/she wants the classification. If null, then you should state the first(default) category as shown below:-
- Event-specific based category of process
a) CPU Bound Process: Processes that spend the majority of their time simply using the CPU (doing calculations).
b) I/O Bound Process: Processes that are associated with input/output-based activity like reading from files, etc.
- Category of processes based on their nature
a) Independent Process: A process that does not need any other external factor to get triggered is an independent process.
b) Cooperative Process: A process that works on the occurrence of any event and the outcome affects any part of the rest of the system is a cooperating process.
But, Threads have got only one classification based on their nature(Single Level Thread and Multi-Level Threads).
Actually, in modern operating systems, there are two levels at which threads operate. They are system or kernel threads and user-level threads. This one is generally not the classification, though some of them freely do classify. It is a misuse.
If you've further doubts, leave a comment below.
4/5
Top Answer
Answered Dec 14, 2017 · 1 votes
It depends on the maximum UID and PID. UIDs are 32 bit, so it can be 4,294,967,296, but PID range is narrower: 2^22, which is exactly: 4,194,304. This is the theoretic maximum; in real world there are some running daemons already, so approximately 4 million. (on 32bit it's only 32,768)
5/5
www.geeksforgeeks.org › types-of-internet-protocolsTypes of Internet Protocols - GeeksforGeeks
www.geeksforgeeks.org › types-of-internet-protocolsMar 24, 2023 · Types of Internet Protocols; Types of Internet Security Protocols; What is Internet Protocol (IP)? Types Of Internetwork; Types of Network Protocols and Their Uses; Network Layer Protocols; Types of ICMP (Internet Control Message Protocol) Messages; Communication Protocols For RPCs; Types of Authentication Protocols; Internet Protocol version 6 ...
www.lifewire.com › computer-networks-protocols-817374How Do Computer Network Protocols Work? - Lifewire
www.lifewire.com › computer-networks-protocols-817374Jun 29, 2021 · Protocols typically divide each packet into three parts—header, payload, and footer. Some protocols, like IP, do not use footers. Packet headers and footers contain the contextual information required to support the network, including addresses of the sending and receiving devices.
- Bradley Mitchell
People also ask
What are the different types of network protocols?
- Different network protocols have been invented over the years, each attempting to support certain types of network communication. The three basic characteristics that distinguish one type of protocol from another are: Simplex vs. duplex: A simplex connection allows only one device to transmit on a network.
How Do Computer Network Protocols Work? - Lifewire
www.lifewire.com/computer-networks-protocols-817374What are the common network protocols in public use?
- The common network protocols in public use belong to the Internet Protocol family. IP is the basic protocol that enables home and other local networks across the internet to communicate with each other. IP works well for moving individual messages from one network to another.
How Do Computer Network Protocols Work? - Lifewire
www.lifewire.com/computer-networks-protocols-817374Which operating systems are supported by network devices?
- The operating systems of network devices include built-in support for some lower-level network protocols. All modern desktop computer operating systems support Ethernet and TCP/IP, for example. Many smartphones support Bluetooth and protocols from the Wi-Fi family.
How Do Computer Network Protocols Work? - Lifewire
www.lifewire.com/computer-networks-protocols-817374What is a network protocol?
- Each network protocol defines the rules for how its data packets must be organized in specific ways according to the protocols the network supports. It may be that the sender and receiver of data are parts of different networks, located in different parts of the world having different data transfer rates.
Types of Internet Protocols - GeeksforGeeks
www.geeksforgeeks.org/types-of-internet-protocols/en.wikipedia.org › wiki › List_of_operating_systemsList of operating systems - Wikipedia
en.wikipedia.org › wiki › List_of_operating_systemsThis is a list of operating systems. Computer operating systems can be categorized by technology, ownership, licensing, working state, usage, and by many other characteristics. In practice, many of these groupings may overlap.
inst.eecs.berkeley.edu › ~cs162 › sp08Lecture 8: Operating Systems Structures
inst.eecs.berkeley.edu › ~cs162 › sp08Operating system is divided many layers (levels) Each built on top of lower layers. Bottom layer (layer 0) is hardware. Highest layer (layer N) is the user interface. Each layer uses functions (operations) and services of only lower-level layers. Advantage: modularity Easier debugging/Maintenance.
graphics.stanford.edu › ~tolis › coursesChapter 3: Operating-System Structures - Stanford University
graphics.stanford.edu › ~tolis › coursesUNIX operating system had limited structuring. The UNIX OS consists of two separable parts. Systems programs The kernel Consists of everything below the system-call interface and above the physical hardware Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level.
medium.com › @fahriiyesill › demystifying-networkingNetwork Protocols: A Comprehensive Guide | by Fahri Yeşil ...
medium.com › @fahriiyesill › demystifying-networkingOct 16, 2023 · What Are Networking Protocols? In the realm of computer networking, protocols are the unsung heroes that lay the groundwork for successful communication and data exchange. A networking protocol...
en.wikipedia.org › wiki › Operating_systemOperating system - Wikipedia
en.wikipedia.org › wiki › Operating_systemOperating systems. Common features. Process management. Interrupts. Memory management. File system. Device drivers. Networking. Security. Input/output. v. t. e. An operating system ( OS) is system software that manages computer hardware and software resources, and provides common services for computer programs .
Searches related to what are protocols in operating systems list of parts