'SYSTEM PROGRAMMING'에 해당되는 글 84건

  1. 2015.08.17 console output formatting by 뉴암스테르담 2
  2. 2015.08.16 race condition by 뉴암스테르담
  3. 2015.08.12 서브넷 마스크에 대한 문제 by 뉴암스테르담
  4. 2015.08.11 IP 주소로의 여행 by 뉴암스테르담
  5. 2015.08.11 경계적 대기 - win32 multihthreading by 뉴암스테르담
  6. 2015.08.10 기초적 쓰레드 동기화 by 뉴암스테르담
  7. 2015.08.10 SHELL PROGRAMMING by 뉴암스테르담
  8. 2015.08.06 GCC Compiiler - 02. 알아 두면 유용한 C소스 컴파일 과정 by 뉴암스테르담
  9. 2015.08.06 GCC Compiiler - 01. 컴파일의 이해 by 뉴암스테르담
  10. 2015.08.06 버추얼박스(VirtualBox) 공유폴더 사용하기 Host-Windows, Guest-Ubuntu(Linux) by 뉴암스테르담

console output formatting

 Jun 11, 2010 at 8:28pm
I am sorry, but I need a quick help

what would be analog to this function in C to C++
printf("%5d", var)

cout << var ?????????
but how to format it to take 5 places in console ?
 Jun 11, 2010 at 8:36pm
printf("%5d", var) will work in C++. Most C functions, at least all C functions i know, work in C++
 Jun 11, 2010 at 8:54pm
you must include <cstdio> and it works printf("%5d", var);
Last edited on Jun 11, 2010 at 8:55pm
 Jun 11, 2010 at 11:40pm
Neither answers his question, however...

To do that in C++, #include <iomanip> and use the following construct:

cout << setw( 5 ) << var;

Hope this helps.
 Jun 11, 2010 at 11:59pm
This reluctance to adopt C++ constructs is far too common. It's a pet peeve of mine.
 Jun 12, 2010 at 12:11am
Honestly, I still think printf/etc is easier (as in less typing, easier to remember the codes) than the iostream counterparts. Especially since iostream doesn't seem to remember the last modifiers you give it.

1
2
3
4
5
6
7
8
9
// print 2 numbers 'a' and 'b' in 0xAAAABBBB (hex) format
cout << "0x" << hex << uppercase << setw(4) << setfill('0') << a
             << hex << uppercase << setw(4) << setfill('0') << b << endl;

// vs.
printf("0x%04X%04X\n",a,b);

// or if you want more clarity
printf("0x" "%04X" "%04X" "\n",a,b);


The iostream approach is even more horrifying if you you're not using the "using" directive.


I'm not discounting the merits of iostream. I know that it's better in a lot of ways (and why). I'm just showing why so many people are still reluctant to use it.
Last edited on Jun 12, 2010 at 12:15am
 Jun 12, 2010 at 9:25pm
I disagree.

The reason people use C stuff over C++ stuff is because they have already been contaminated with C.

The C counterpart doesn't remember the last modifier you give it either.

The only thing that can be said against iostream is that it is more verbose...
 Jun 12, 2010 at 11:52pm
Wait, I never learnt C and I still prefer cstdio over iostream in some situations. Terseness is one reason, but the other is that "%08X" is much easier to remember than <<std::setw(8)<<std::setfill('0')<<std::hex. I often find it preferable to just sprintf() to an array than go look up voodoo incantations. Sure, it's laziness, but what exactly am I loosing, other than consistency?
 Jun 13, 2010 at 12:43am
It might be nice to have a manipulator to configure the stream output according to cstdio formatting rules:

 
std::cout << std::cformat("%08X") << ... etc
 Jun 13, 2010 at 2:56am
Duoas wrote:
The C counterpart doesn't remember the last modifier you give it either.


But repeating the format for the C counterpart doesn't involve a full line of text. It's just 4-6 characters tops.

Duaos wrote:
The only thing that can be said against iostream is that it is more verbose...


You say that like it's insignificant. For some things I guess it's not a big deal, but for writing trace logs and stuff where you're dumping lots of data, it's quite a big deal.

Galik wrote:
It might be nice to have a manipulator to configure the stream output according to cstdio formatting rules:


I've thought about that more than once. The thing is it kind of defeats half the point of using iostream.

cstdio's 2 big problems are:
- type safety
- having to parse a format string

By having a cformat() manipulator you're reintroducing half of the problems iostream solves.

Plus, I don't think there's an iostream equivilent of %g, but I might be wrong on that.


Another idea would be to make modifiers for common output formats. Like:

1
2
std::cout << std::c08X << ...
std::cout << std::c04X << ...


But that would require you to write lots of modifiers.

'SYSTEM PROGRAMMING' 카테고리의 다른 글

race condition  (0) 2015.08.16
서브넷 마스크에 대한 문제  (0) 2015.08.12
IP 주소로의 여행  (0) 2015.08.11
경계적 대기 - win32 multihthreading  (0) 2015.08.11
기초적 쓰레드 동기화  (0) 2015.08.10
Posted by 뉴암스테르담
l

race condition

SYSTEM PROGRAMMING 2015. 8. 16. 12:42

경쟁조건

'SYSTEM PROGRAMMING' 카테고리의 다른 글

console output formatting  (2) 2015.08.17
서브넷 마스크에 대한 문제  (0) 2015.08.12
IP 주소로의 여행  (0) 2015.08.11
경계적 대기 - win32 multihthreading  (0) 2015.08.11
기초적 쓰레드 동기화  (0) 2015.08.10
Posted by 뉴암스테르담
l
  1. C 클래스 네트워크를 24개의 서브넷으로 나누려고 한다. 각 서브넷에는 4~5개의 호스트가 연결되어야 한다.  어떤 서브넷 마스크가 적절한가?
    1. 255.255.255.192
    2. 255.255.255.224
    3. 255.255.255.240
    4. 255.255.255.248
  2. IP 주소가 128.110.121.32(255.255.255.0) 이라면 네트워크 주소는 어떻게 되는가?   
    1. 128.0.0.1
    2. 128.110.0.0
    3. 128.110.121.0
    4. 129.110.121.32
  3. IP 주소 203.10.24.27이란 호스트의 서브넷 마스크의 255.255.255.240 이다. 이때 이 네트워크의 호스트 범위와 브로드캐스는 주소는 어떻게 되는가?
    1. 호스트 203.10.24.16~ 203.10.24.32,    브로드 캐스트  203.10.24.32
    2. 호스트 203.1.24.1 ~ 203.10.24.254     브로드 캐스트  203.10.24.255
    3. 호스트 203.10.24.17 ~ 203.10.24.31    브로드 캐스트  203.10.24.32
    4. 호스트 203.10.24.27 ~ 203.10.24.30    브로드 캐스트  203.10.24.31
  4. 클래스 B 주소를 가지고 서브넷 마스크 255.255.255.240 으로 서브넷 을 만들었으때 나오는 서브넷의 수와 호스트의 수가 맞게 짝지어 진것은?
    1. 서브넷 2048 / 호스트 14
    2. 서브넷 14   / 호스트 2048
    3. 서브넷 4094 / 호스트 14
    4. 서브넷 254  / 호스트 254
    5. 서브넷 254 / 호스트 8190
  5. C클래스 네트워크를 24개의 서브넷으로 나누려고 한다.  각 서브넷에는 4~5개의 호스트가 연결되어야 한다. 어떤 서브넷 마스크가 적절한가?
    1. 255.255.255.192
    2. 255.255.255.224
    3. 255.255.255.240
    4. 255.255.255.248



  1. 공인 IP 주소를 210.110.1.0 ( 서브넷 마스크 255.255.255.0 == ) 네트워크를 받았습니다.  그런데 네트워크 관리자인 여러분은 이 공인 주소를 이용해서 PC 30 대인 네트워크를 최소 4개 이상 만든 다음 네트워크를 라우터를 이용해서 통신하려고 합니다. 
    이 경우 ,  여러분이 서브넷 마스크를 만든다면 어떻게 해야 할까요?
  2. 일단 우리가 가지고 있는 공인 주소는 201.2225.5.0( 2


'SYSTEM PROGRAMMING' 카테고리의 다른 글

console output formatting  (2) 2015.08.17
race condition  (0) 2015.08.16
IP 주소로의 여행  (0) 2015.08.11
경계적 대기 - win32 multihthreading  (0) 2015.08.11
기초적 쓰레드 동기화  (0) 2015.08.10
Posted by 뉴암스테르담
l

IP 주소로의 여행

2015. 8. 11. 14:19 by 뉴암스테르담

보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

경계적 대기 ( Alertable Wait )


  • 일반적으로 스레드는 자원이 사용 가능해 질때 까지 대기해야 하는 경우에 Win32 API 의 대기 함수 중 하나 
    (WaitForSingleObject, WaitForMultipleObject ) 등을 호출
  • 그러나 때로는 이러한 대기 상태에서 자원이 사용가능해 지기 전에 리턴해야 할 필요가 있는 경우도 있다.
    이러한 대기 상태를 경계적 대기 ( alertable wait) 라고 한다.
  • 일반적으로 이것은 WaitForSingleObject 에 대해 beWaitAll 을 FALSE 로 하고 WaitForMultipleObjects 를
    호출한것과 같은 효과
    를 얻게 한다.
  • 이벤트 객체는 초기에 시그널되지 않은 상태여야 하고,  필요한 경우에는 대기하고 있는 스레드를 깨우기 위해 시그널 되어야 한다.
  • 이 기법은 보통 프로그램을 종료하거나 서브 시스템을 끝낼때 사용한다.
  • 특히 프로그램의 초기 스레드 프로시져에서 몇몇 스레드가 시스템 자원을 반환하는 것을 보장하기 위해서 반드시 리턴되어야 하는 
    경우 유용하게 사용
    할 수 있다.


Posted by 뉴암스테르담
l


"스레드 동기화가 필요한 대부분의 프로그램은 이런 간단한 시나리오만을 정확히 해결하면 되는 경우가 많으며,  복잡한 문제를

 내포하는 경우는 그다지 많지 않다. " 


그렇기 때문에 멀티스레드 소프트웨어를 작성할때는 디자인 패턴에 해당되는지 한번 살펴본후,  여기에서 제시하는 


해결책을 사용한다면 좋은 프로그램을 작성할 수 있다.



자원의 상호 배재


상호배제는 ( mutual exclusion ) 는 스레드 동기화의 가장 기초적인 디자인 패턴이다.

데이터나 코드와 같은 시스템 자원이 동시에 둘 이상의 스레드에 의해서 안전한 방법으로 접근될수 없을때 상호 배제가 사용된다.


한번에 하나의 스레드 만이 자원에 접근하도록 허용하고 싶은 경우에는 이 자원을 동기화 객체를 사용해서 보호해야 한다.


  • 직렬화 (serializing ) :  첫번째 스레드가 자원을 사용하는 동안 두번째 스레드가 접근하려고 하면 둘째 스레드는 블록되고
    수행이 보류된다.  이러한 방법으로 자원에 접근하는것이 serializing 이라고 한다.
  • win32 환경에서는 직렬화 하기 위해서 두개의 시스템 객체 임계영역과 뮤텍스를 사용한다. 
  • 임계영역은 부하가 적으며,  한 프로세스 안의 스레드 사이에서 사용될 때 유용하다. 
  • 뮤텍스는 다수의 프로세스에서 동작하는 스레드가 사용하는 자원에 사용되며 일반적으로 실행시간의 비용이 많이 든다.

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
typedef struct{
    int nTotalThreads;
    int nRedThreads;
    int nWhiteThreads;
    int nBlueThreads;
}MyThreadInfo;
 
MyThreadInfo g_myThreadInfo;
 
 
void InitializedMyThreadInfo(void);
 
void AddRedThread(void);
void AddWhiteThread(void);
void AddBlueThread(void);
 
void RemoveRedThread(void);
void RemoveWhiteThread(void);
void RemoveBlueThread(void);
 
int GetRedThreadCount(int *pnTotalThreads);
int GetWhiteThreadCount(int *pnTotalThreads);
int GetBlueThreadCount(int *pnTotalThreads);
cs


  • 다수의 스레드가 이런 함수들을 동시에 호출할 수 있기 때문에 하나의 스레드가 AddRedThread 를 호출하는 동안 다른 스레드가 GetReadThreadCount 를 호출하는 경우도 발생할 수 있다.
  • 또한 AddThreadCount 를 실행하는 스레드가 MyThreadInfo 의 hRedThreads 멤버를 증가시켯을지라도 GetRedThreadCount 를 호출한 스레드가 데이터를 읽을때 nTotalThreads 를 미처 증가 시키지 못했을수도 있다. 
  • 이런 경우가 발생하면 red 스레드의 개수와 모든 스레드의 개수가 일치하지 않을것이가. 
  • 결국 요구되는 것은 red 스레드의 개수와 모든 스레드의 개수를 동시에 읽는것이다
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    CMlcCriticalSection g_CriticalSecThreadInfo;
     
    int main(int argc, char* argv[])
    {
        return 0;
    }
     
     
    void InitializedMyThreadInfo(void)
    {
        g_myThreadInfo.nTotalThreads = 0;
        g_myThreadInfo.nRedThreads = 0;
        g_myThreadInfo.nWhiteThreads = 0;
        g_myThreadInfo.nBlueThreads = 0;
    }
     
    void AddRedThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads++;
        g_myThreadInfo.nRedThreads++;
        g_CriticalSecThreadInfo.Leave();
    }
    void AddWhiteThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads++;
        g_myThreadInfo.nWhiteThreads++;
        g_CriticalSecThreadInfo.Leave();
     
    }
    void AddBlueThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads++;
        g_myThreadInfo.nBlueThreads++;
        g_CriticalSecThreadInfo.Leave();
     
    }
     
    void RemoveRedThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads--;
        g_myThreadInfo.nRedThreads--;
        g_CriticalSecThreadInfo.Leave();
     
    }
    void RemoveWhiteThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads--;
        g_myThreadInfo.nWhiteThreads--;
        g_CriticalSecThreadInfo.Leave();
     
    }
    void RemoveBlueThread(void)
    {
        g_CriticalSecThreadInfo.Enter();
        g_myThreadInfo.nTotalThreads--;
        g_myThreadInfo.nRedThreads--;
        g_CriticalSecThreadInfo.Leave();
     
    }
     
    int GetRedThreadCount(int *pnTotalThreads)
    {
        g_CriticalSecThreadInfo.Enter();
        int nReadThread = g_myThreadInfo.nRedThreads;
        *pnTotalThreads = g_myThreadInfo.nTotalThreads;
        g_CriticalSecThreadInfo.Leave();
        return nReadThread;
    }
    int GetWhiteThreadCount(int *pnTotalThreads)
    {
        g_CriticalSecThreadInfo.Enter();
        int nReadThread = g_myThreadInfo.nRedThreads;
        *pnTotalThreads = g_myThreadInfo.nTotalThreads;
        g_CriticalSecThreadInfo.Leave();
        return nReadThread;
    }
    int GetBlueThreadCount(int *pnTotalThreads)
    {
        g_CriticalSecThreadInfo.Enter();
        int nReadThread = g_myThreadInfo.nRedThreads;
        *pnTotalThreads = g_myThreadInfo.nTotalThreads;
        g_CriticalSecThreadInfo.Leave();
        return nReadThread;
     
        return 0;
    }
     
    cs

  • 이러한 요구사항은 MyThreadInfo 구조체에 대한 접근을 직렬화 해서 쉽게 해결할 수 있다

+ 잘설계된 C++ 프로그램에서는 이런 문제를 해결하기 위해서 데이터 구조와 임계 영역을 하나로 묶고,  이 임계 영역을 사용하는 루틴을 하나의 클래스로 만들며,  애플리케이션 안에

서 전역적으로 사용할 수 있는 이 클래스의 인스턴스를 생성한다.

  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    class CMyThreadInfo
    {
        int m_nTotalThreads;
        int m_nRedThread;
        int m_nWhiteThread;
        int m_nBlueThread;
     
        CMlcCriticalSection m_CricSec;
     
    public:
        CMyThreadInfo() {
            m_nTotalThreads = 0;
            m_nRedThread = 0;
            m_nWhiteThread = 0;
            m_nBlueThread = 0;
     
        };
        void AddRedThread()
        {
            m_CricSec.Enter();
            m_CricSec.m_nTotalThreads++;
            m_CricSec.m_nRedThread++;
            m_CricSec.Leave();
        };
        void AddWhiteThread()
        {
            m_CricSec.Enter();
            m_CricSec.m_nTotalThreads++;
            m_CricSec.m_nWhiteThread++;
            m_CricSec.Leave();
        };
        void AddBlueThread()
        {
            m_CricSec.Enter();
            m_CricSec.m_nTotalThreads++;
            m_CricSec.m_nBlueThread++;
            m_CricSec.Leave();
        };
     
     
     
    };
    cs



  • CMyThreadInfo 클래스는 자신만의 동기화를 제공한다. 이 클래스의 사용자는 동기회 되어 사용되는 데이터에 접근하는 것에 대해서는 알 필요가 없다.
  • 이런 동기화를 내부 동기화(Internal synchronization ) 이라 한다.  
  • 내부 동기화는 자원의 모든 사용자들이 정해진 방법을 통해서 자원을 사용할 때 유용하다.
  • 비슷한 기법으로  외부 동기화가 있다. 
    • 이 기법은 자원을 사용하는 소프트웨어 사이에서 다수의 객체가 동기화 될때 사용한다. 
  • 상호배제의 다른 사용 예는 동시에 하나 이상의 스레드에 의해서 특정 코드 영역이 사용되는 것을 막기 위한 경우이다.
  • 이런 기법은 프로세스에서도 사용될수  있으므로 매우 유용하다.
  • 가장 일반적이고 가장 간단한 형태로 상호 배제를 사용하는 방법은 한번에 하나의 애플리케이션 의 인스턴스만 동작하독 하는것이다.
    • 상다히 다양한 경우에 이런 방법이 필요하다. 
    • 프로그램이 동작하는 동안 특정 자원에 대해서 배타적으로 접근 하기를 원하거나 시스템 부하를 제한하고 싶을때  또는    프로그래므이 다수의 인스턴스가 동시에 동작하면 안되는 경우가 이에 해당한다.
    • 애플리케이션이 하나만 동작하도록 하는것은 뮤텍스를 사용하면 간단히 구현할 수 있다. 


Posted by 뉴암스테르담
l
  • 쉘이란 무엇인가?
  • 기본 고려사항
  • 난해한 문법 : 변수, 조건, 프로그램 제어
  • 리스트
  • 함수
  • 명령과 명령 실행
  • 하이 도큐먼트
  • 디버깅
  • grep 과 정규식
  • find
+ 쉘로 프로그래밍 하는 이유
  • 빠르고 간단하게 프로그래밍 할수 있다.
  • 효율성 보다는 구성, 유지보수, 이식성이 중요시되는 상황이 좋다. 
  • 쉘을 사용하여 프로세서 제어를 조직할수 있기 때문에 , 명령들은 각 단계의 성공 여부에 따라 미리 결정된  
    순서대로 실행한다.
  • ls -al | more

+ 쉘이란 무엇인가?
  • 윈도우 명령 프롬프트와 비슷하나 더 강력하다
  • < > 를 사용하여 입력과 출력 을 리다이렉트( redirect ) 할수 있고,  |
  • | 를 사용하여 프로그램을 실행함과 동시에 데이터를 파이르포 전달할수 있다.
  • $(... ) 를 사용하여 하위 프로세스의 결과를 받아 올수 있다.


  • ls -l > output.txt

    • ls 명령의 출력을 output.txt 파일로 저장하라

  • ps >> output.txt

    • 파일을 추가 ps 명령의 출력을 지정된 파일 끝에 추가한다.


ㅣㄴ








Posted by 뉴암스테르담
l



sdfsd



Posted by 뉴암스테르담
l
  • 컴파일은 인간이 이해할 수 있는 형식 언어 (C ,C++ 등) 로 작성된 소스 코드를 CPU 가  
    이해할 수 있는 기계어로 번역하는 과정
+ 인스트럭션과 어셈블리
  • 기계어를 다른 말로 머신 인스턱션(machine insturction ) 즉, 기계 명령이라 한다.
  • objdump -S likelike


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    likelike:     file format elf32-i386
     
     
    Disassembly of section .init:
     
    080482b0 <_init>:
     80482b0:    53                       push   %ebx
     80482b1:    83 ec 08                 sub    $0x8,%esp
     80482b4:    e8 97 00 00 00           call   8048350 <__x86.get_pc_thunk.bx>
     80482b9:    81 c3 47 1d 00 00        add    $0x1d47,%ebx
     80482bf:    8b 83 fc ff ff ff        mov    -0x4(%ebx),%eax
     80482c5:    85 c0                    test   %eax,%eax
     80482c7:    74 05                    je     80482ce <_init+0x1e>
     80482c9:    e8 32 00 00 00           call   8048300 <__gmon_start__@plt>
     80482ce:    83 c4 08                 add    $0x8,%esp
     80482d1:    5b                       pop    %ebx
     80482d2:    c3                       ret    
     
    Disassembly of section .plt:
     
    080482e0 <puts@plt-0x10>:
     80482e0:    ff 35 04 a0 04 08        pushl  0x804a004
     80482e6:    ff 25 08 a0 04 08        jmp    *0x804a008
     80482ec:    00 00                    add    %al,(%eax)
        ...
     
    080482f0 <puts@plt>:
     80482f0:    ff 25 0c a0 04 08        jmp    *0x804a00c
     80482f6:    68 00 00 00 00           push   $0x0
     80482fb:    e9 e0 ff ff ff           jmp    80482e0 <_init+0x30>
     
    08048300 <__gmon_start__@plt>:
     8048300:    ff 25 10 a0 04 08        jmp    *0x804a010
     8048306:    68 08 00 00 00           push   $0x8
     804830b:    e9 d0 ff ff ff           jmp    80482e0 <_init+0x30>
     
    08048310 <__libc_start_main@plt>:
     8048310:    ff 25 14 a0 04 08        jmp    *0x804a014
     8048316:    68 10 00 00 00           push   $0x10
     804831b:    e9 c0 ff ff ff           jmp    80482e0 <_init+0x30>
     
    Disassembly of section .text:
     
    08048320 <_start>:
     8048320:    31 ed                    xor    %ebp,%ebp
     8048322:    5e                       pop    %esi
     8048323:    89 e1                    mov    %esp,%ecx
     8048325:    83 e4 f0                 and    $0xfffffff0,%esp
     8048328:    50                       push   %eax
     8048329:    54                       push   %esp
     804832a:    52                       push   %edx
     804832b:    68 b0 84 04 08           push   $0x80484b0
     8048330:    68 40 84 04 08           push   $0x8048440
     8048335:    51                       push   %ecx
     8048336:    56                       push   %esi
     8048337:    68 1d 84 04 08           push   $0x804841d
     804833c:    e8 cf ff ff ff           call   8048310 <__libc_start_main@plt>
     8048341:    f4                       hlt    
     8048342:    66 90                    xchg   %ax,%ax
     8048344:    66 90                    xchg   %ax,%ax
     8048346:    66 90                    xchg   %ax,%ax
     8048348:    66 90                    xchg   %ax,%ax
     804834a:    66 90                    xchg   %ax,%ax
     804834c:    66 90                    xchg   %ax,%ax
     804834e:    66 90                    xchg   %ax,%ax
     
    08048350 <__x86.get_pc_thunk.bx>:
     8048350:    8b 1c 24                 mov    (%esp),%ebx
     8048353:    c3                       ret    
     8048354:    66 90                    xchg   %ax,%ax
     8048356:    66 90                    xchg   %ax,%ax
     8048358:    66 90                    xchg   %ax,%ax
     804835a:    66 90                    xchg   %ax,%ax
     804835c:    66 90                    xchg   %ax,%ax
     804835e:    66 90                    xchg   %ax,%ax
     
    08048360 <deregister_tm_clones>:
     8048360:    b8 23 a0 04 08           mov    $0x804a023,%eax
     8048365:    2d 20 a0 04 08           sub    $0x804a020,%eax
     804836a:    83 f8 06                 cmp    $0x6,%eax
     804836d:    77 01                    ja     8048370 <deregister_tm_clones+0x10>
     804836f:    c3                       ret    
     8048370:    b8 00 00 00 00           mov    $0x0,%eax
     8048375:    85 c0                    test   %eax,%eax
     8048377:    74 f6                    je     804836f <deregister_tm_clones+0xf>
     8048379:    55                       push   %ebp
     804837a:    89 e5                    mov    %esp,%ebp
     804837c:    83 ec 18                 sub    $0x18,%esp
     804837f:    c7 04 24 20 a0 04 08     movl   $0x804a020,(%esp)
     8048386:    ff d0                    call   *%eax
     8048388:    c9                       leave  
     8048389:    c3                       ret    
     804838a:    8d b6 00 00 00 00        lea    0x0(%esi),%esi
     
    08048390 <register_tm_clones>:
     8048390:    b8 20 a0 04 08           mov    $0x804a020,%eax
     8048395:    2d 20 a0 04 08           sub    $0x804a020,%eax
     804839a:    c1 f8 02                 sar    $0x2,%eax
     804839d:    89 c2                    mov    %eax,%edx
     804839f:    c1 ea 1f                 shr    $0x1f,%edx
     80483a2:    01 d0                    add    %edx,%eax
     80483a4:    d1 f8                    sar    %eax
     80483a6:    75 01                    jne    80483a9 <register_tm_clones+0x19>
     80483a8:    c3                       ret    
     80483a9:    ba 00 00 00 00           mov    $0x0,%edx
     80483ae:    85 d2                    test   %edx,%edx
     80483b0:    74 f6                    je     80483a8 <register_tm_clones+0x18>
     80483b2:    55                       push   %ebp
     80483b3:    89 e5                    mov    %esp,%ebp
     80483b5:    83 ec 18                 sub    $0x18,%esp
     80483b8:    89 44 24 04              mov    %eax,0x4(%esp)
     80483bc:    c7 04 24 20 a0 04 08     movl   $0x804a020,(%esp)
     80483c3:    ff d2                    call   *%edx
     80483c5:    c9                       leave  
     80483c6:    c3                       ret    
     80483c7:    89 f6                    mov    %esi,%esi
     80483c9:    8d bc 27 00 00 00 00     lea    0x0(%edi,%eiz,1),%edi
     
    080483d0 <__do_global_dtors_aux>:
     80483d0:    80 3d 20 a0 04 08 00     cmpb   $0x0,0x804a020
     80483d7:    75 13                    jne    80483ec <__do_global_dtors_aux+0x1c>
     80483d9:    55                       push   %ebp
     80483da:    89 e5                    mov    %esp,%ebp
     80483dc:    83 ec 08                 sub    $0x8,%esp
     80483df:    e8 7c ff ff ff           call   8048360 <deregister_tm_clones>
     80483e4:    c6 05 20 a0 04 08 01     movb   $0x1,0x804a020
     80483eb:    c9                       leave  
     80483ec:    f3 c3                    repz ret 
     80483ee:    66 90                    xchg   %ax,%ax
     
    080483f0 <frame_dummy>:
     80483f0:    a1 10 9f 04 08           mov    0x8049f10,%eax
     80483f5:    85 c0                    test   %eax,%eax
     80483f7:    74 1f                    je     8048418 <frame_dummy+0x28>
     80483f9:    b8 00 00 00 00           mov    $0x0,%eax
     80483fe:    85 c0                    test   %eax,%eax
     8048400:    74 16                    je     8048418 <frame_dummy+0x28>
     8048402:    55                       push   %ebp
     8048403:    89 e5                    mov    %esp,%ebp
     8048405:    83 ec 18                 sub    $0x18,%esp
     8048408:    c7 04 24 10 9f 04 08     movl   $0x8049f10,(%esp)
     804840f:    ff d0                    call   *%eax
     8048411:    c9                       leave  
     8048412:    e9 79 ff ff ff           jmp    8048390 <register_tm_clones>
     8048417:    90                       nop
     8048418:    e9 73 ff ff ff           jmp    8048390 <register_tm_clones>
     
    0804841d <main>:
    #include <stdio.h>
     
    int main()
    {
     804841d:    55                       push   %ebp
     804841e:    89 e5                    mov    %esp,%ebp
     8048420:    83 e4 f0                 and    $0xfffffff0,%esp
     8048423:    83 ec 10                 sub    $0x10,%esp
        printf("I like you\n");
     8048426:    c7 04 24 d0 84 04 08     movl   $0x80484d0,(%esp)
     804842d:    e8 be fe ff ff           call   80482f0 <puts@plt>
        return 0;
     8048432:    b8 00 00 00 00           mov    $0x0,%eax
    }
     8048437:    c9                       leave  
     8048438:    c3                       ret    
     8048439:    66 90                    xchg   %ax,%ax
     804843b:    66 90                    xchg   %ax,%ax
     804843d:    66 90                    xchg   %ax,%ax
     804843f:    90                       nop
     
    08048440 <__libc_csu_init>:
     8048440:    55                       push   %ebp
     8048441:    57                       push   %edi
     8048442:    31 ff                    xor    %edi,%edi
     8048444:    56                       push   %esi
     8048445:    53                       push   %ebx
     8048446:    e8 05 ff ff ff           call   8048350 <__x86.get_pc_thunk.bx>
     804844b:    81 c3 b5 1b 00 00        add    $0x1bb5,%ebx
     8048451:    83 ec 1c                 sub    $0x1c,%esp
     8048454:    8b 6c 24 30              mov    0x30(%esp),%ebp
     8048458:    8d b3 0c ff ff ff        lea    -0xf4(%ebx),%esi
     804845e:    e8 4d fe ff ff           call   80482b0 <_init>
     8048463:    8d 83 08 ff ff ff        lea    -0xf8(%ebx),%eax
     8048469:    29 c6                    sub    %eax,%esi
     804846b:    c1 fe 02                 sar    $0x2,%esi
     804846e:    85 f6                    test   %esi,%esi
     8048470:    74 27                    je     8048499 <__libc_csu_init+0x59>
     8048472:    8d b6 00 00 00 00        lea    0x0(%esi),%esi
     8048478:    8b 44 24 38              mov    0x38(%esp),%eax
     804847c:    89 2c 24                 mov    %ebp,(%esp)
     804847f:    89 44 24 08              mov    %eax,0x8(%esp)
     8048483:    8b 44 24 34              mov    0x34(%esp),%eax
     8048487:    89 44 24 04              mov    %eax,0x4(%esp)
     804848b:    ff 94 bb 08 ff ff ff     call   *-0xf8(%ebx,%edi,4)
     8048492:    83 c7 01                 add    $0x1,%edi
     8048495:    39 f7                    cmp    %esi,%edi
     8048497:    75 df                    jne    8048478 <__libc_csu_init+0x38>
     8048499:    83 c4 1c                 add    $0x1c,%esp
     804849c:    5b                       pop    %ebx
     804849d:    5e                       pop    %esi
     804849e:    5f                       pop    %edi
     804849f:    5d                       pop    %ebp
     80484a0:    c3                       ret    
     80484a1:    eb 0d                    jmp    80484b0 <__libc_csu_fini>
     80484a3:    90                       nop
     80484a4:    90                       nop
     80484a5:    90                       nop
     80484a6:    90                       nop
     80484a7:    90                       nop
     80484a8:    90                       nop
     80484a9:    90                       nop
     80484aa:    90                       nop
     80484ab:    90                       nop
     80484ac:    90                       nop
     80484ad:    90                       nop
     80484ae:    90                       nop
     80484af:    90                       nop
     
    080484b0 <__libc_csu_fini>:
     80484b0:    f3 c3                    repz ret 
     
    Disassembly of section .fini:
     
    080484b4 <_fini>:
     80484b4:    53                       push   %ebx
     80484b5:    83 ec 08                 sub    $0x8,%esp
     80484b8:    e8 93 fe ff ff           call   8048350 <__x86.get_pc_thunk.bx>
     80484bd:    81 c3 43 1b 00 00        add    $0x1b43,%ebx
     80484c3:    83 c4 08                 add    $0x8,%esp
     80484c6:    5b                       pop    %ebx
     80484c7:    c3                       ret    
     
  • objdump 명령은 바이너리 파일의 정보를 보기 위한 명령이다. 


Posted by 뉴암스테르담
l

0. 게스트 확장 설치 in Guest-Ubuntu(Linux) with VirtualBox

게스트 확장이 설치 안되어 있다면 설치합니다.

Guest-Ubuntu(Linux)를 부팅 한 후

VirtualBox의 '장치' - '게스트 확장 설치 ...' 메뉴를 통해 설치

 

1. 공유폴더 생성 in Host-Windows

공유 할 폴더를 우선 윈도우에 등록한다.

ex) C:\virtualbox_share 폴더 생성

 

2. 앞에서 생성한 공유폴더를 등록 in VirtualBox

버추얼 박스의 해당 Guest(Ubuntu, Linux)에서 설정 메뉴로 들어가면 좌측 하단에 공유 폴더 메뉴가 있음. 선택.

(스크린샷 머신 폴더에 항목이 있는건 폴더를 등록해서 그런것임.

처음엔 아무 항목이 존재하지 않음.)

우측의 우측의 파란 폴더 초록 플러스 아이콘을 눌러 앞에서 생성한 폴더 등록.

 

항상 사용하기 체크. 자동마운트는 작동이 잘 안되는 것으로 확인되어 체크하지 않음.

 

3. 공유 폴더를 마운트(mount) in Guest-Ubuntu(Linux)

터미널에서 /mnt/share폴더 생성

1
$ sudo mkdir /mnt/share

 

터미널에서 마운트

1
$ sudo mount -t vboxsf virtualbox_share /mnt/share

명령의 중간의 virtualbox_share는 바로 위 공유 추가에서 정한 폴더 이름과 동일하게

Guest-Ubuntu(Linux)를 재 부팅 하면 마운트는 다시 해줘야 함

 

4. 공유폴더 확인

Host-Windows, Guest-Ubuntu(Linux) 둘중 아무곳에서 파일 넣으면 양쪽에 보임.

테스트로 Guest-Ubuntu(Linux)에서 share.png 생성해서 넣어둠

 

Guest-Ubuntu(Linux)

 

Host-Windows

 

폴더가 공유되어 동일한 파일이 양쪽에 보이는 것을 확인 할 수 있다.

 

[참고자료]

http://kalkins.blog.me/80208578043

Posted by 뉴암스테르담
l