柿子不能和什么食物一起吃| 水化是什么意思| 眼前的苟且是什么意思| 滇红是什么茶| 二级医院什么意思| 扁平苔藓有什么症状| 什么重什么轻| 99年属什么生肖| 中药用什么锅熬效果最佳| 白带有血是什么原因| 1991是什么年| 军长是什么级别| 直白是什么意思| 鲔鱼是什么鱼| 嘴唇起泡用什么药| 梦见死人复活什么预兆| 浅表性胃炎吃什么药好| 吴亦凡为什么退出exo| 清影是什么意思| 脂肪肝吃什么好| 凝血功能差是什么原因| 长脚气是什么原因引起的| 梦见冬瓜是什么意思| 梦见别人死了是什么预兆| 尿道口感染吃什么药| 免疫组化检查是什么| 晚上2点是什么时辰| 牛和什么属相最配| 甲木代表什么| 头臀长是什么意思| 苏州为什么叫姑苏| 鳞状上皮细胞高是什么原因| 蚁后长什么样| 肝腹水有什么症状| 菱角什么时候上市| 慢性肠炎有什么症状| 肚脐上面疼是什么原因| 做彩超挂什么科| 十三幺是什么意思| 2b是什么意思| 什么是奇数什么是偶数| 腿走路没劲发软是什么原因| 闲暇的意思是什么| 副处级干部是什么级别| 股票尾盘拉升说明什么| 室内传导阻滞什么意思| 纠察是什么意思| 琼瑶是什么意思| 麟字五行属什么| 检查贫血挂什么科| 什么怎么什么造句| 自慰是什么| 去海边穿什么衣服拍照好看| 嗓子哑是什么原因引起的| 黄豆加什么打豆浆好喝又营养| 什么远什么长| 连翘败毒丸的功效与作用是什么| 八六年属什么| 守字五行属什么| 滴虫长什么样子图片| 多巴胺什么意思| 喝冰糖水有什么好处和坏处| 动爻是什么意思| 背部爱出汗是什么原因| 打酱油是什么意思啊| 热休克蛋白90a检查高是什么原因| 儿童肠系膜淋巴结炎吃什么药| 喝铁观音茶有什么好处| 闲云野鹤是什么意思| 房性逸搏心律是什么意思| 梦见纸人是什么意思| 嘴角烂了涂什么药| 买什么| p代表什么意思| 睡觉出汗多是什么原因| 重庆为什么叫重庆| 乙肝表面抗体阳性是什么意思| 个性是什么意思| 越吃越瘦是什么原因| 散光是什么原因导致的| 疼痛科主要看什么病| 云南简称是什么| 孕早期可以吃什么水果| 信保是什么| 羊水透声欠佳什么意思| 温婉是什么意思| 胃痛吃什么药效果最好| 塑胶厂是做什么的| 国字脸适合什么发型男| 保肝护肝吃什么| 子时是什么时候| 尿蛋白是什么病| 梦见别人给自己剪头发是什么意思| 勃是什么意思| 377是什么| rts是什么意思| 潜伏是什么意思| 淋巴吃什么药可以消除| 电解质水有什么好处| 柔然人是现在的什么人| 玻璃体切除后对眼睛有什么影响| 身份证尾号代表什么| 十五的月亮十六圆是什么意思| 喜欢绿色的女人是什么性格| 小酌怡情下一句是什么| 运钞车押运员是什么人| 除体内湿热最好的中成药是什么| 处女女和什么星座最配| 孕妇前三个月吃什么对胎儿好| 有炎症吃什么药| 尿胆原norm是什么意思| 七月十四是什么节| 清热去湿热颗粒有什么功效| 糖醋排骨用什么醋好吃| 什么食物热量高| 为什么会反胃想吐| 休渔期是什么时候| 两肺纹理增多什么意思| cmf是什么| 小孩吃榴莲有什么好处| 马不停蹄是什么生肖| 1947年属什么| 点石成金是什么意思| 咳嗽背部疼是什么原因| 红蓝是什么意思| 93年属什么的| 胆囊炎能吃什么食物| 细胞学说揭示了什么| 内分泌失调吃什么调理| 肺结节吃什么药能散结| 中筋面粉是什么粉| 为什么丰胸霜一抹就变大| 农历六月十五是什么星座| 卡哇伊内是什么意思| 足石念什么| 月子里能吃什么水果| 出气臭是什么原因| 什么是直肠炎| grace是什么意思| 紧急避孕药对身体有什么伤害| 经常口臭的人是什么原因引起的| 真心话大冒险问什么| 东坡肉属于什么菜系| 脚后跟疼什么原因| 什么球不能踢脑筋急转弯| 京兆尹是什么官| 老觉得饿是什么原因| 一阵什么| 8月份是什么星座| 今年养殖什么最挣钱| 老鼠爱吃什么食物| 蜂蜜可以做什么美食| 孟姜女姓什么| 健康证都检查什么项目| 恶心反胃想吐吃什么药| 小孩睡觉张开嘴巴是什么原因| 脚围指的是什么| 房产税什么时候开始征收| 专班是什么意思| 肺肾两虚吃什么中成药| 藏毛窦挂什么科| 布施蚂蚁什么食物最好| 巴沙鱼为什么不能吃| drg是什么意思| 接踵而至是什么意思| 人为什么要有性生活| 月经不来是什么原因导致的| 娃娃鱼属于什么类动物| 嘴角疱疹用什么药膏| 纤维灶是什么意思| 1994年什么命| 什么时候长智齿| 禅茶一味什么意思| as是什么材质| 儿女双全什么意思| 老人适合喝什么茶| 角膜炎吃什么药| 北京晚上有什么好玩的景点| 五官端正是什么意思| 身上起红疙瘩是什么原因| 什么东西清肺最好| 9月21日是什么星座| 肺炎挂什么科| 子宫肌瘤变性是什么意思| 于无声处是什么意思| 磨砂皮是什么皮| 5月26日是什么星座| 纯磨玻璃结节是什么意思| 什么的桃子| 弄虚作假是什么生肖| 什么药能治口臭| ps是什么意思| 逍遥丸配什么治失眠| 神经过敏是什么意思| 桂花是什么季节开的| 什么什么分明的成语| 高密度脂蛋白偏高是什么意思| 1945属什么生肖| 黄体酮有什么副作用| 掉眉毛是什么病| 强直是什么意思| 放炮是什么意思| 如花似玉是什么生肖| 脸浮肿是什么原因| zbc什么意思| 奶茶和奶绿有什么区别| 备孕需要注意些什么| 非文念什么| 牛的尾巴有什么作用| 10.1什么星座| 舌根放血有什么好处| 地级市市委书记是什么级别| 心肌缺血吃什么食物| 乡镇党委书记是什么级别| 吃什么瘦肚子脂肪最快| 筋皮是什么肉| 4ever是什么意思| 南京为什么叫金陵| 98年的属什么| 哈密瓜不能和什么一起吃| 牛蛙和青蛙有什么区别| 肾有问题挂什么科| 失眠吃什么药| 为什么会口腔溃疡| 车前草治什么病| 应届是什么意思| 什么是重力| 静脉曲张做什么检查| pap是什么意思| 面粉和淀粉有什么区别| 东北有什么特产| 济公原名叫什么| 尿蛋白是什么原因造成的| 俄罗斯为什么要打乌克兰| 白痰是什么原因| 射手男喜欢什么样的女生| 菲妮迪女装是什么档次| 1月21是什么星座| 烧心是什么原因引起的| ims是什么意思| 精子发黄是什么原因| 1995年的猪五行属什么| 对药物过敏是什么症状| 38妇女节送老婆什么礼物| 八纲辨证中的八纲是什么| 张属于五行属什么| 自慰是什么| 奥美拉唑和雷贝拉唑有什么区别| 为什么会长汗疱疹| 29周岁属什么生肖| 报恩是什么意思| 吃大蒜有什么好处| 榻榻米床垫什么材质的好| 输卵管造影什么时候检查最好| 50岁吃什么钙片补钙效果好| 鞭长莫及什么意思| 毋庸置疑什么意思| 头顶发热是什么原因| 什么样的贝壳| 植发用什么头发| 苏打水有什么作用和功效| 程门立雪是什么生肖| impress是什么意思| 马齿苋什么人不能吃| 百度Jump to content

山西代表团审议监察法草案修改稿等

From Wikipedia, the free encyclopedia
百度     26岁小伙宁帅(化名)是汉阳一名的哥,上月和父母一起参加了亲戚的婚礼后,整个人变得寡言少语,甚至不愿出车把自己关在房里。

In computer science, self-modifying code (SMC or SMoC) is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code, thus simplifying maintenance. The term is usually only applied to code where the self-modification is intentional, not in situations where code accidentally modifies itself due to an error such as a buffer overflow.

Self-modifying code can involve overwriting existing instructions or generating new code at run time and transferring control to that code.

Self-modification can be used as an alternative to the method of "flag setting" and conditional program branching, used primarily to reduce the number of times a condition needs to be tested.

The method is frequently used for conditionally invoking test/debugging code without requiring additional computational overhead for every input/output cycle.

The modifications may be performed:

  • only during initialization – based on input parameters (when the process is more commonly described as software 'configuration' and is somewhat analogous, in hardware terms, to setting jumpers for printed circuit boards). Alteration of program entry pointers is an equivalent indirect method of self-modification, but requiring the co-existence of one or more alternative instruction paths, increasing the program size.
  • throughout execution ("on the fly") – based on particular program states that have been reached during the execution

In either case, the modifications may be performed directly to the machine code instructions themselves, by overlaying new instructions over the existing ones (for example: altering a compare and branch to an unconditional branch or alternatively a 'NOP').

In the IBM System/360 architecture, and its successors up to z/Architecture, an EXECUTE (EX) instruction logically overlays the second byte of its target instruction with the low-order 8 bits of register 1. This provides the effect of self-modification although the actual instruction in storage is not altered.

Application in low and high level languages

[edit]

Self-modification can be accomplished in a variety of ways depending upon the programming language and its support for pointers and/or access to dynamic compiler or interpreter 'engines':

  • overlay of existing instructions (or parts of instructions such as opcode, register, flags or addresses) or
  • direct creation of whole instructions or sequences of instructions in memory
  • creation or modification of source code statements followed by a 'mini compile' or a dynamic interpretation (see eval statement)
  • creating an entire program dynamically and then executing it

Assembly language

[edit]

Self-modifying code is quite straightforward to implement when using assembly language. Instructions can be dynamically created in memory (or else overlaid over existing code in non-protected program storage),[1] in a sequence equivalent to the ones that a standard compiler may generate as the object code. With modern processors, there can be unintended side effects on the CPU cache that must be considered. The method was frequently used for testing 'first time' conditions, as in this suitably commented IBM/360 assembler example. It uses instruction overlay to reduce the instruction path length by (N×1)?1 where N is the number of records on the file (?1 being the overhead to perform the overlay).

SUBRTN NOP OPENED      FIRST TIME HERE?
* The NOP is x'4700'<Address_of_opened>
       OI    SUBRTN+1,X'F0'  YES, CHANGE NOP TO UNCONDITIONAL BRANCH (47F0...)
       OPEN   INPUT               AND  OPEN THE INPUT FILE SINCE IT'S THE FIRST TIME THRU
OPENED GET    INPUT        NORMAL PROCESSING RESUMES HERE
      ...

Alternative code might involve testing a "flag" each time through. The unconditional branch is slightly faster than a compare instruction, as well as reducing the overall path length. In later operating systems for programs residing in protected storage this technique could not be used and so changing the pointer to the subroutine would be used instead. The pointer would reside in dynamic storage and could be altered at will after the first pass to bypass the OPEN (having to load a pointer first instead of a direct branch & link to the subroutine would add N instructions to the path length – but there would be a corresponding reduction of N for the unconditional branch that would no longer be required).

Below is an example in Zilog Z80 assembly language. The code increments register "B" in range [0,5]. The "CP" compare instruction is modified on each loop.

;==========
ORG 0H
CALL FUNC00
HALT
;==========
FUNC00:
LD A,6
LD HL,label01+1
LD B,(HL)
label00:
INC B
LD (HL),B
label01:
CP $0
JP NZ,label00
RET
;==========

Self-modifying code is sometimes used to overcome limitations in a machine's instruction set. For example, in the Intel 8080 instruction set, one cannot input a byte from an input port that is specified in a register. The input port is statically encoded in the instruction itself, as the second byte of a two byte instruction. Using self-modifying code, it is possible to store a register's contents into the second byte of the instruction, then execute the modified instruction in order to achieve the desired effect.

High-level languages

[edit]

Some compiled languages explicitly permit self-modifying code. For example, the ALTER verb in COBOL may be implemented as a branch instruction that is modified during execution.[2] Some batch programming techniques involve the use of self-modifying code. Clipper and SPITBOL also provide facilities for explicit self-modification. The Algol compiler on B6700 systems offered an interface to the operating system whereby executing code could pass a text string or a named disc file to the Algol compiler and was then able to invoke the new version of a procedure.

With interpreted languages, the "machine code" is the source text and may be susceptible to editing on-the-fly: in SNOBOL the source statements being executed are elements of a text array. Other languages, such as Perl and Python, allow programs to create new code at run-time and execute it using an eval function, but do not allow existing code to be mutated. The illusion of modification (even though no machine code is really being overwritten) is achieved by modifying function pointers, as in this JavaScript example:

    var f = function (x) {return x + 1};

    // assign a new definition to f:
    f = new Function('x', 'return x + 2');

Lisp macros also allow runtime code generation without parsing a string containing program code.

The Push programming language is a genetic programming system that is explicitly designed for creating self-modifying programs. While not a high level language, it is not as low level as assembly language.[3]

Compound modification

[edit]

Prior to the advent of multiple windows, command-line systems might offer a menu system involving the modification of a running command script. Suppose a DOS script (or "batch") file MENU.BAT contains the following:[4][nb 1]

   :start
   SHOWMENU.EXE

Upon initiation of MENU.BAT from the command line, SHOWMENU presents an on-screen menu, with possible help information, example usages and so forth. Eventually the user makes a selection that requires a command SOMENAME to be performed: SHOWMENU exits after rewriting the file MENU.BAT to contain

   :start
   SHOWMENU.EXE
   CALL SOMENAME.BAT
   GOTO start

Because the DOS command interpreter does not compile a script file and then execute it, nor does it read the entire file into memory before starting execution, nor yet rely on the content of a record buffer, when SHOWMENU exits, the command interpreter finds a new command to execute (it is to invoke the script file SOMENAME, in a directory location and via a protocol known to SHOWMENU), and after that command completes, it goes back to the start of the script file and reactivates SHOWMENU ready for the next selection. Should the menu choice be to quit, the file would be rewritten back to its original state. Although this starting state has no use for the label, it, or an equivalent amount of text is required, because the DOS command interpreter recalls the byte position of the next command when it is to start the next command, thus the re-written file must maintain alignment for the next command start point to indeed be the start of the next command.

Aside from the convenience of a menu system (and possible auxiliary features), this scheme means that the SHOWMENU.EXE system is not in memory when the selected command is activated, a significant advantage when memory is limited.[4][5]

Control tables

[edit]

Control table interpreters can be considered to be, in one sense, 'self-modified' by data values extracted from the table entries (rather than specifically hand coded in conditional statements of the form "IF inputx = 'yyy'").

Channel programs

[edit]

Some IBM access methods traditionally used self-modifying channel programs, where a value, such as a disk address, is read into an area referenced by a channel program, where it is used by a later channel command to access the disk.

History

[edit]

The IBM SSEC, demonstrated in January 1948, had the ability to modify its instructions or otherwise treat them exactly like data. However, the capability was rarely used in practice.[6] In the early days of computers, self-modifying code was often used to reduce use of limited memory, or improve performance, or both. It was also sometimes used to implement subroutine calls and returns when the instruction set only provided simple branching or skipping instructions to vary the control flow.[7][8] This use is still relevant in certain ultra-RISC architectures, at least theoretically; see for example one-instruction set computer. Donald Knuth's MIX architecture also used self-modifying code to implement subroutine calls.[9]

Usage

[edit]

Self-modifying code can be used for various purposes:

  • Semi-automatic optimizing of a state-dependent loop.
  • Dynamic in-place code optimization for speed depending on load environment.[10][11][nb 2]
  • Run-time code generation, or specialization of an algorithm in runtime or loadtime (which is popular, for example, in the domain of real-time graphics) such as a general sort utility – preparing code to perform the key comparison described in a specific invocation.
  • Altering of inlined state of an object, or simulating the high-level construction of closures.
  • Patching of subroutine (pointer) address calling, usually as performed at load/initialization time of dynamic libraries, or else on each invocation, patching the subroutine's internal references to its parameters so as to use their actual addresses (i.e. indirect self-modification).
  • Evolutionary computing systems such as neuroevolution, genetic programming and other evolutionary algorithms.
  • Hiding of code to prevent reverse engineering (by use of a disassembler or debugger) or to evade detection by virus/spyware scanning software and the like.
  • Filling 100% of memory (in some architectures) with a rolling pattern of repeating opcodes, to erase all programs and data, or to burn-in hardware or perform RAM tests.[12]
  • Compressing code to be decompressed and executed at runtime, e.g., when memory or disk space is limited.[10][11]
  • Some very limited instruction sets leave no option but to use self-modifying code to perform certain functions. For example, a one-instruction set computer (OISC) machine that uses only the subtract-and-branch-if-negative "instruction" cannot do an indirect copy (something like the equivalent of "*a = **b" in the C language) without using self-modifying code.
  • Booting. Early microcomputers often used self-modifying code in their bootloaders. Since the bootloader was keyed in via the front panel at every power-on, it did not matter if the bootloader modified itself. However, even today many bootstrap loaders are self-relocating, and a few are even self-modifying.[nb 3]
  • Altering instructions for fault-tolerance.[13]

Optimizing a state-dependent loop

[edit]

Pseudocode example:

repeat N times {
    if STATE is 1
        increase A by one
    else
        decrease A by one
    do something with A
}

Self-modifying code, in this case, would simply be a matter of rewriting the loop like this:

repeat N times {
    increase A by one
    do something with A
    when STATE has to switch {
        replace the opcode "increase" above with the opcode to decrease, or vice versa
    }
}

Note that two-state replacement of the opcode can be easily written as 'xor var at address with the value "opcodeOf(Inc) xor opcodeOf(dec)"'.

Choosing this solution must depend on the value of N and the frequency of state changing.

Specialization

[edit]

Suppose a set of statistics such as average, extrema, location of extrema, standard deviation, etc. are to be calculated for some large data set. In a general situation, there may be an option of associating weights with the data, so each xi is associated with a wi and rather than test for the presence of weights at every index value, there could be two versions of the calculation, one for use with weights and one not, with one test at the start. Now consider a further option, that each value may have associated with it a Boolean to signify whether that value is to be skipped or not. This could be handled by producing four batches of code, one for each permutation and code bloat results. Alternatively, the weight and the skip arrays could be merged into a temporary array (with zero weights for values to be skipped), at the cost of processing and still there is bloat. However, with code modification, to the template for calculating the statistics could be added as appropriate the code for skipping unwanted values, and for applying weights. There would be no repeated testing of the options and the data array would be accessed once, as also would the weight and skip arrays, if involved.

Use as camouflage

[edit]

Self-modifying code is more complex to analyze than standard code and can therefore be used as a protection against reverse engineering and software cracking. Self-modifying code was used to hide copy protection instructions in 1980s disk-based programs for systems such as IBM PC compatibles and Apple II. For example, on an IBM PC, the floppy disk drive access instruction int 0x13 would not appear in the executable program's image but it would be written into the executable's memory image after the program started executing.

Self-modifying code is also sometimes used by programs that do not want to reveal their presence, such as computer viruses and some shellcodes. Viruses and shellcodes that use self-modifying code mostly do this in combination with polymorphic code. Modifying a piece of running code is also used in certain attacks, such as buffer overflows.

Self-referential machine learning systems

[edit]

Traditional machine learning systems have a fixed, pre-programmed learning algorithm to adjust their parameters. However, since the 1980s Jürgen Schmidhuber has published several self-modifying systems with the ability to change their own learning algorithm. They avoid the danger of catastrophic self-rewrites by making sure that self-modifications will survive only if they are useful according to a user-given fitness, error or reward function.[14]

Operating systems

[edit]

The Linux kernel notably makes wide use of self-modifying code; it does so to be able to distribute a single binary image for each major architecture (e.g. IA-32, x86-64, 32-bit ARM, ARM64...) while adapting the kernel code in memory during boot depending on the specific CPU model detected, e.g. to be able to take advantage of new CPU instructions or to work around hardware bugs.[15][16] To a lesser extent, the DR-DOS kernel also optimizes speed-critical sections of itself at loadtime depending on the underlying processor generation.[10][11][nb 2]

Regardless, at a meta-level, programs can still modify their own behavior by changing data stored elsewhere (see metaprogramming) or via use of polymorphism.

Massalin's Synthesis kernel

[edit]

The Synthesis kernel presented in Alexia Massalin's Ph.D. thesis[17][18] is a tiny Unix kernel that takes a structured, or even object oriented, approach to self-modifying code, where code is created for individual quajects, like filehandles. Generating code for specific tasks allows the Synthesis kernel to (as a JIT interpreter might) apply a number of optimizations such as constant folding or common subexpression elimination.

The Synthesis kernel was very fast, but was written entirely in assembly. The resulting lack of portability has prevented Massalin's optimization ideas from being adopted by any production kernel. However, the structure of the techniques suggests that they could be captured by a higher level language, albeit one more complex than existing mid-level languages. Such a language and compiler could allow development of faster operating systems and applications.

Paul Haeberli and Bruce Karsh have objected to the "marginalization" of self-modifying code, and optimization in general, in favor of reduced development costs.[19]

Interaction of cache and self-modifying code

[edit]

On architectures without coupled data and instruction cache (for example, some SPARC, ARM, and MIPS cores) the cache synchronization must be explicitly performed by the modifying code (flush data cache and invalidate instruction cache for the modified memory area).

In some cases short sections of self-modifying code execute more slowly on modern processors. This is because a modern processor will usually try to keep blocks of code in its cache memory. Each time the program rewrites a part of itself, the rewritten part must be loaded into the cache again, which results in a slight delay, if the modified codelet shares the same cache line with the modifying code, as is the case when the modified memory address is located within a few bytes to the one of the modifying code.

The cache invalidation issue on modern processors usually means that self-modifying code would still be faster only when the modification will occur rarely, such as in the case of a state switching inside an inner loop.[citation needed]

Most modern processors load the machine code before they execute it, which means that if an instruction that is too near the instruction pointer is modified, the processor will not notice, but instead execute the code as it was before it was modified. See prefetch input queue (PIQ). PC processors must handle self-modifying code correctly for backwards compatibility reasons but they are far from efficient at doing so.[citation needed]

Security issues

[edit]

Because of the security implications of self-modifying code, all of the major operating systems are careful to remove such vulnerabilities as they become known. The concern is typically not that programs will intentionally modify themselves, but that they could be maliciously changed by an exploit.

One mechanism for preventing malicious code modification is an operating system feature called W^X (for "write xor execute"). This mechanism prohibits a program from making any page of memory both writable and executable. Some systems prevent a writable page from ever being changed to be executable, even if write permission is removed.[citation needed] Other systems provide a 'back door' of sorts, allowing multiple mappings of a page of memory to have different permissions. A relatively portable way to bypass W^X is to create a file with all permissions, then map the file into memory twice. On Linux, one may use an undocumented SysV shared memory flag to get executable shared memory without needing to create a file.[citation needed]

Advantages

[edit]

Disadvantages

[edit]

Self-modifying code is harder to read and maintain because the instructions in the source program listing are not necessarily the instructions that will be executed. Self-modification that consists of substitution of function pointers might not be as cryptic, if it is clear that the names of functions to be called are placeholders for functions to be identified later.

Self-modifying code can be rewritten as code that tests a flag and branches to alternative sequences based on the outcome of the test, but self-modifying code typically runs faster.

Self-modifying code conflicts with authentication of the code and may require exceptions to policies requiring that all code running on a system be signed.

Modified code must be stored separately from its original form, conflicting with memory management solutions that normally discard the code in RAM and reload it from the executable file as needed.

On modern processors with an instruction pipeline, code that modifies itself frequently may run more slowly, if it modifies instructions that the processor has already read from memory into the pipeline. On some such processors, the only way to ensure that the modified instructions are executed correctly is to flush the pipeline and reread many instructions.

Self-modifying code cannot be used at all in some environments, such as the following:

  • Application software running under an operating system with strict W^X security cannot execute instructions in pages it is allowed to write to—only the operating system is allowed to both write instructions to memory and later execute those instructions.
  • Many Harvard architecture microcontrollers cannot execute instructions in read-write memory, but only instructions in memory that it cannot write to, ROM or non-self-programmable flash memory.
  • A multithreaded application may have several threads executing the same section of self-modifying code, possibly resulting in computation errors and application failures.

See also

[edit]

Notes

[edit]
  1. ^ Later versions of DOS (since version 6.0) introduced the external CHOICE command (in DR-DOS also the internal command and CONFIG.SYS directive SWITCH), so, for this specific example application of a menu system, it was no longer necessary to refer to self-modifying batchjobs, however for other applications it continued to be a viable solution.
  2. ^ a b For example, when running on 386 or higher processors, later Novell DOS 7 updates as well as DR-DOS 7.02 and higher will dynamically replace some default sequences of 16-bit REP MOVSW ("copy words") instructions in the kernel's runtime image by 32-bit REP MOVSD ("copy double-words") instructions when copying data from one memory location to another (and half the count of necessary repetitions) in order to speed up disk data transfers. Edge cases such as odd counts are taken care of.[10][11]
  3. ^ As an example, the DR-DOS MBRs and boot sectors (which also hold the partition table and BIOS Parameter Block, leaving less than 446 respectively 423 bytes for the code) were traditionally able to locate the boot file in the FAT12 or FAT16 file system by themselves and load it into memory as a whole, in contrast to their MS-DOS/PC DOS counterparts, which instead relied on the system files to occupy the first two directory entries in the file system and the first three sectors of IBMBIO.COM to be stored at the start of the data area in contiguous sectors containing a secondary loader to load the remainder of the file into memory (requiring SYS to take care of all these conditions). When FAT32 and LBA support was added, Microsoft even switched to require 386 instructions and split the boot code over two sectors for size reasons, which was not an option for DR-DOS as it would have broken backward- and cross-compatibility with other operating systems in multi-boot and chain load scenarios, as well as with older PCs. Instead, the DR-DOS 7.07 boot sectors resorted to self-modifying code, opcode-level programming in machine language, controlled utilization of (documented) side effects, multi-level data/code overlapping and algorithmic folding techniques to still fit everything into a physical sector of only 512 bytes without giving up any of their extended functionality.

References

[edit]
  1. ^ "HP 9100A/B". MoHPC - The Museum of HP Calculators. 1998. Overlapped Data and Program Memory / Self-Modifying Code. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  2. ^ "The ALTER Statement". COBOL Language Reference. Micro Focus.
  3. ^ Spector, Lee. "Evolutionary Computing with Push: Push, PushGP, and Pushpop". Retrieved 2025-08-07.
  4. ^ a b Fosdal, Lars (2001). "Self-modifying Batch File". Archived from the original on 2025-08-07.
  5. ^ Paul, Matthias R. (2025-08-07) [2025-08-07, 1994]. Konzepte zur Unterstützung administrativer Aufgaben in PC-Netzen und deren Realisierung für eine konkrete Novell-LAN-Umgebung unter Benutzung der Batchsprache von DOS. 3.11 (in German). Aachen, Germany: Lehrstuhl für Kommunikationsnetze (ComNets) & Institut für Kunststoffverarbeitung (IKV), RWTH. pp. 51, 71–72. (110+3 pages, diskette) (NB. Design and implementation of a centrally controlled modular distributed management system for automatic client configuration and software deployment with self-healing update mechanism in LAN environments based on self-replicating and indirectly self-modifying batchjobs with zero memory footprint instead of a need for resident management software on the clients.)
  6. ^ Bashe, Charles J.; Buchholz, Werner; Hawkins, George V.; Ingram, J. James; Rochester, Nathaniel (September 1981). "The Architecture of IBM's Early Computers" (PDF). IBM Journal of Research and Development. 25 (5): 363–376. CiteSeerX 10.1.1.93.8952. doi:10.1147/rd.255.0363. ISSN 0018-8646. Retrieved 2025-08-07. p. 365: The SSEC was the first operating computer capable of treating its own stored instructions exactly like data, modifying them, and acting on the result.
  7. ^ Miller, Barton P. (2025-08-07). "Binary Code Patching: An Ancient Art Refined for the 21st Century". Triangle Computer Science Distinguished Lecturer Series - Seminars 2006–2007. NC State University, Computer Science Department. Retrieved 2025-08-07.
  8. ^ Wenzl, Matthias; Merzdovnik, Georg; Ullrich, Johanna; Weippl, Edgar R. (June 2019) [February 2019, November 2018, May 2018]. "From hack to elaborate technique - A survey on binary rewriting" (PDF). ACM Computing Surveys. 52 (3). Vienna, Austria: 49:1–49:36 [49:1]. doi:10.1145/3316415. S2CID 195357367. Article 49. Archived (PDF) from the original on 2025-08-07. Retrieved 2025-08-07. p. 49:1: […] Originally, binary rewriting was motivated by the need to change parts of a program during execution (e.g., run-time patching on the PDP-1 in the 1960's) […] (36 pages)
  9. ^ Knuth, Donald Ervin (2009) [1997]. "MMIX 2009 - a RISC computer for the third millennium". Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  10. ^ a b c d "Caldera OpenDOS Machine Readable Source Kit (M.R.S) 7.01". Caldera, Inc. 2025-08-07. Archived from the original on 2025-08-07. Retrieved 2025-08-07. [1]
  11. ^ a b c d Paul, Matthias R. (2025-08-07). "Caldera OpenDOS 7.01/7.02 Update Alpha 3 IBMBIO.COM README.TXT". Archived from the original on 2025-08-07. Retrieved 2025-08-07. [2]
  12. ^ Wilkinson, William "Bill" Albert (2003) [1996, 1984]. "The H89 Worm: Memory Testing the H89". Bill Wilkinson's Heath Company Page. Archived from the original on 2025-08-07. Retrieved 2025-08-07. […] Besides fetching an instruction, the Z80 uses half of the cycle to refresh the dynamic RAM. […] since the Z80 must spend half of each instruction fetch cycle performing other chores, it doesn't have as much time to fetch an instruction byte as it does a data byte. If one of the RAM chips at the memory location being accessed is a little slow, the Z80 may get the wrong bit pattern when it fetches an instruction, but get the right one when it reads data. […] the built-in memory test won't catch this type of problem […] it's strictly a data read/write test. During the test, all instruction fetches are from the ROM, not from RAM […] result[ing] in the H89 passing the memory test but still operating erratically on some programs. […] This is a program that tests memory by relocating itself through RAM. As it does so, the CPU prints the current address of the program on the CRT and then fetches the instruction at that address. If the RAM ICs are okay at that address, the CPU relocates the test program to the next memory location, prints the new address, and repeats the procedure. But, if one of the RAM ICs is slow enough to return an incorrect bit pattern, the CPU will misinterpret the instruction and behave unpredictably. However, it's likely that the display will lock up showing the address of faulty IC. This narrows the problem down eight ICs, which is an improvement over having to check as much as 32. […] The […] program will perform a worm test by pushing an RST 7 (RESTART 7) instruction from the low end of memory on up to the last working address. The rest of the program remains stationary and handles the display of the current location of the RST 7 command and its relocation. Incidentally, the program is called a worm test because, as the RST 7 instruction moves up through memory, it leaves behind a slime trail of NOPs (NO OPERATION). […]
  13. ^ Ortiz, Carlos Enrique (2025-08-07) [2025-08-07]. "On Self-Modifying Code and the Space Shuttle OS". Retrieved 2025-08-07.
  14. ^ Jürgen Schmidhuber's publications on self-modifying code for self-referential machine learning systems
  15. ^ Paltsev, Evgeniy (2025-08-07). "Self Modifying Code in Linux Kernel - What, Where and How". Retrieved 2025-08-07.
  16. ^ Wieczorkiewicz, Pawel. "Linux Kernel Alternatives". Retrieved 2025-08-07.
  17. ^ Pu, Calton; Massalin, Henry; Ioannidis, John (1992). Synthesis: An Efficient Implementation of Fundamental Operating System Services (PDF) (PhD thesis). New York, USA: Department of Computer Sciences, Columbia University. UMI Order No. GAX92-32050. Retrieved 2025-08-07. [3]
  18. ^ Henson, Valerie (2025-08-07). "KHB: Synthesis: An Efficient Implementation of Fundamental Operating Systems Services". LWN.net. Archived from the original on 2025-08-07. Retrieved 2025-08-07.
  19. ^ Haeberli, Paul; Karsh, Bruce (2025-08-07). "Io Noi Boccioni - Background on Futurist Programming". Grafica Obscura. Retrieved 2025-08-07.

Further reading

[edit]
[edit]
水瓶座与什么星座最配 做梦梦到狗是什么征兆 频繁是什么意思 哮喘有什么症状 激光脱毛有什么副作用
冷萃是什么意思 儿童发烧挂什么科 喷昔洛韦乳膏治什么 什么什么深长 mds是什么
甘油三酯偏高有什么危害 7.14什么星座 无利起早是什么生肖 新生儿呛奶是什么原因引起的 胃角在什么位置图片
静脉炎吃什么药好得快 女生小便带血是什么原因 四海扬名是什么生肖 额头上长痘痘是什么原因 脚气挂什么科
缺钾吃什么好hcv9jop3ns3r.cn pp材质是什么材质jinxinzhichuang.com 什么富什么车chuanglingweilai.com 水晶是什么shenchushe.com 一六年属什么生肖hcv8jop9ns3r.cn
命犯桃花是什么意思hcv8jop3ns8r.cn 什么食物含钙imcecn.com 门牙下面的牙叫什么wmyky.com 尿酸高什么不能吃hcv9jop2ns6r.cn 920是什么意思hcv9jop0ns9r.cn
乳酸菌素片什么时候吃zhiyanzhang.com 六月十一是什么日子hcv7jop5ns2r.cn castle是什么意思hcv9jop1ns7r.cn 主动权是什么意思0735v.com 11月25是什么星座onlinewuye.com
肾炎是什么病hcv8jop8ns0r.cn 去医院看嘴唇挂什么科hcv9jop7ns5r.cn 为什么头皮会疼mmeoe.com 7月31日是什么星座hcv8jop9ns4r.cn 吃什么有助于睡眠效果好hcv8jop2ns9r.cn
百度