What is kernel mode?

Linux·内核编译错误 Linux·内核编译错误-cc1: error: code model kernel does not support PIC mode 阅读详情

What is kernel mode?

I've talked about this before but I want to really highlight it because I still see people wrestling with it.

In Windows CE 5.0 and earlier, "kernel mode" is an access level attached to a thread.  If a thread is "in kernel mode" it can access kernel address space.  You could call SetKMode to put your thread into or out of kernel mode, whenever you wanted (it required trust, of course).  Most system APIs were not implemented by the kernel (nk.exe), so calling an API didn’t put your thread into kernel mode.  Unless you called an API that was implemented by nk.exe, in which case your thread would temporarily enter kernel mode for the duration of the call.

In Windows CE 6.0 the implementation is actually the same, except that the SetKMode API is no longer supported.  You can't put threads into or out of kernel mode at a time of your choice.  However, most system APIs are implemented by modules that are now loaded into the kernel process, so calling an API usually puts your thread into kernel mode.

While the implementation is the same, the result is effectively different meanings.  In CE 5.0, "kernel mode" was a property a thread could acquire or release on demand.  In CE 6.0, the rule is fairly simple: your thread is in kernel mode while executing code inside the kernel process, and not in kernel mode when executing code inside a user process.  We use the term loosely, like talking about "kernel mode drivers," "kernel mode code" and "kernel mode addresses." Whenever people use these phrases they're trying to talk about code and addresses that are only accessible to the kernel process, that are at addresses above 0x80000000.  (Side note, you also have to be clear about whether you're talking about everything inside the kernel process vs. only the kernel module, kernel.dll.)

The one remaining gotcha in the CE 6.0 rule is callbacks.  If a user application passes a function pointer to kernel mode code, and the kernel mode code calls the function pointer directly, then the thread is STILL in kernel mode (remember it is still a property of the thread, just not so obviously) while executing user mode code.  And that is very bad for security.  Because the user mode code could do anything; it could access kernel addresses or call kernel-only APIs.  If you write a driver that takes a function pointer from the caller and later calls it, make sure your driver only does so by using the new CEDDK function, CeDriverPerformCallback.  That way your thread jumps back to the user process properly before calling the function, so that the function call can't do anything that the user process itself couldn't do already.  Or even better -- find a different way to implement what you're doing.  Ask yourself this: if an attacker passed me an evil function pointer, could they get me to do something bad on their behalf?  If you don't know the answer, don't take function pointers from your callers.

You might wonder about function pointers and memory marshalling.  "Marshalling" only applies to passing data buffers between processes -- not to passing function pointers between processes.  You can't "marshal" a function so that you can safely call it from kernel code.  The CeDriverPerformCallback function is the only way to shed the privileges that a kernel mode driver has, for the duration of the call.  I suppose you could consider that a form of "marshalling" but I don't.

UPDATE Jan 31, 2007: Andrew Tuck, one of our support engineers, pointed out another detail that can lead to confusion.  (Thanks, Andrew!)  Often (at least in Windows environments, if not all OS'), the most privileged processor mode is referred to as "kernel mode."  This usage of the term refers to when the CPU is operating with additional privileges, such as the ability to call special instructions that aren't normally legal.  For example interrupt handling often happens in this CPU "kernel mode."  This terminology is unrelated to the "kernel mode" concept I've been talking about in this article.  When a Windows CE thread is in "kernel mode" it is not running in the most privileged processor mode.  Only very restricted parts of the CE kernel and OAL run in that mode.  The Windows CE "kernel mode" thread property controls whether the page tables for kernel address space are mapped, and some other things. (For example, in CE 5.0 it controlled whether the thread could make fast-path API calls, like I described in the API call post I wrote a while back.)

 

Linux·驱动编译相关问题 lLinux驱动问题 阅读详情

相关推荐

基于STM32的HC-SR04超声波模块测距(新手级)

本人是嵌入式新手,学习了STM32的部分内容,最近想找些项目做,然后顺便学习了一下HC-SR04超声波模块,学习过程中也参考了一些大佬的文章。本文记录了自己的学习方法和学习过程,同时也希望能和各位大佬交流讨论。

weixin_63758495的博客 2210

编译驱动模块的一系列问题

一、cc1: error: code model kernel does not support PIC mode 原因:主机的gcc版本,和开发板的gcc工具版本不一致。需要指定gcc开发板工具的gcc 解决办法:编写Makefile文件的时候指定gcc工具 Makefile文件中指定gcc如下: ifeq ($(HOST), ubuntu) #ubuntu内核 KERNEL_DIR:=/usr/src/linux-headers-$(shell uname -r) CC:=gcc else

weixin_43473988的博客 2250

解密OpenVLA的ActionTokenizer:如何用256个Token控制7维机器人动作

本文深入解析了OpenVLA模型中ActionTokenizer的核心机制。该分词器通过将7维连续机器人动作空间离散化为256个Token,巧妙地解决了大语言模型输出精确控制指令的难题。文章详细阐述了其设计哲学、与Llama-2词表的集成方式,并分析了256个离散区间在精度与效率间的平衡,为机器人视觉-语言-动作控制提供了关键技术桥梁。

weixin_29209801的博客 487

【linux】kernel 编译个人小结

kernel、module 编译搭建及编译相关错误

过得精彩,无所谓好坏 1603

线结构光三维重建(二):光平面标定与激光轮廓提取的实战优化

本文深入探讨了线结构光三维重建中的光平面标定与激光轮廓提取两大核心环节的实战优化。详细介绍了从棋盘格标定板法到自动化高鲁棒性标定的流程优化,并分享了针对复杂工业场景(如低对比度、高反光表面)的激光轮廓提取组合策略,旨在提升三维重建系统的整体精度与稳定性。

weixin_29057237的博客 336

别再为H桥烧MOS管发愁了!手把手教你用IR2104搭建稳定电机驱动(附自举电路详解)

本文详细解析了使用IR2104半桥驱动芯片构建高可靠H桥电机驱动电路的全过程。从芯片内部架构、自举电路原理到PCB布局技巧和实战调试方法,帮助工程师彻底解决MOS管烧毁问题。重点讲解了自举电容选型、死区时间控制等关键设计要点,并附有示波器实测波形分析,是电机驱动设计的实用指南。

我的博客 745

驱动开发---cc1: error: code model kernel does not support PIC mode(改文件Unhelp?try it)

问题描述:在编译内核时出现 cc1: error: code model kernel does not support PIC mode的问题。 linux版本:3.14 问题分析:这极大原因是系统调用了默认的编译器导致的。 问题解决:在进行make编译的时候,加上ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- 或者在自己源码Makefile里面加上 :

少年,你渴望力量吗 4863

Vivado SDK中LWIP库版本冲突与RTL8211FDI兼容性实战解析

本文深入解析Vivado 2019.1 SDK中LWIP 1.0库与RTL8211FDI千兆PHY芯片的版本冲突问题,并提供实战解决方案。通过手动移植高版本LWIP库、整合第三方驱动及优化BSP配置,有效解决了以太网通信兼容性问题,确保千兆性能稳定运行。

ios99的博客 279

What is a tickless kernel?

To understand a tickless kernel, we first have to understand how a kernel usually functions. Numerous functions of an operating system need to be performed periodically—updating the time, decrementing...

ee230的专栏 543

通过Robotstudio修改机器人程序的具体方法和步骤

通过Robotstudio修改机器人程序的具体方法和步骤

Robot_PLC_HMI_Automation 6406

华为OD机试 - 小火车最多人时所在园区站点(Java 2024 E卷 100分)

刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、发现新题目,随时更新,全天CSDN在线答疑。

学Java,找哪吒 996

What is the difference between user level threads and kernel level threads?

Answer A kernel thread, sometimes called a LWP (Lightweight Process) is created and scheduled by the kernel. Kernel threads are often more expensive to create than user threads and the system calls

1756

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

What are threads (user/kernel)?

What are threads (user/kernel)?Threads are “light weight processes” (LWPs). The idea is a process has five fundamental parts: code (“text”), data (VM), stack, file I/O, and signal tables. “Heavy-weig

Burning Water 553

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

What Is Harmony OS? Huawei’s New Operating System Explained

After years of speculation and rumor, Chinese tech giant Huawei formally unveiled its Harmony OS operating system in 2019. It’s fair to say that more questions have been raised than answered. How does it work? What problems does it solve? And is it a pro..

Marswill 2441

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

What is a Microsoft Failover Cluster Virtual Adapter

What is a Microsoft Failover Cluster Virtual Adapter anyway? A question often asked is, "What is the Microsoft Cluster Virtual Adapter and what can I do with it?" The typical, and correct answer...

510

What Is GRUB Bootloader in Linux?

The。

ken2232的博客 195

ti linux git,linuxkernelTI: linux kernel from git://git.ti.com/ti-linux-kernel/ti-linux-kernel.git

Linux kernel release 4.x These are the release notes for Linux version 4. Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something go...

weixin_31437143的博客 380

oppo linux 内核,Admin/android_kernel_oppo_mt6771

Linux kernel release 4.x These are the release notes for Linux version 4. Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something go...

weixin_31143059的博客 553

小米6 linux内核版本是多少钱,android_kernel_xiaomi_msm8998

Linux kernel release 4.x These are the release notes for Linux version 4. Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something go...

weixin_32150221的博客 578

Linux kernel release 2.0.xx

These are the release notes for linux version 2.0.  Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something goes wrong.  WHAT IS LINU

t608的专栏 1721

What is the purpose of different Android partitions

-- [b]Boot partition[/b] stores the Android kernel. If this partition is empty, the LK bootloader will enter the fastboot mode. -- [b]System partition[/b] contains the Android user interface and all...

allenpettle的专栏 358

User-level and kernel-level thread comparison and which one to choose in what circustance

What are the two advantages that threads have over multiple processes? [2 marks] Inter-thread communication is easier/faster than inter-process communication. Threads incur less overhead to create/terminate/switch What are the differences between user-.

MyWang的博客 282

kernel android,GitHub - LineageOS/android_kernel_google_msm

Linux kernel release 3.x These are the release notes for Linux version 3. Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something go...

weixin_39999781的博客 267

64bit android kernel,GitHub - LineageOS/android_kernel_xiaomi_sdm845

Linux kernel release 4.x These are the release notes for Linux version 4. Read them carefully,as they tell you what this is all about, explain how to install thekernel, and what to do if something go...

weixin_39747049的博客 476
上一篇: VC6.0中常见的条件编译命令(#ifdef ... #else ... #endif)---指示编译器谁该参与编译
下一篇: 穷庙里也有富和尚,看程序员工作单位和职业道路的选择
PerfectToday
博客等级 码龄18年 46粉丝 129原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值