[XP] windows fixed!

因為系統磁區的硬碟不夠大, 所以用Partition Magic來調整磁區, 所以先把D後面的linux磁區幹掉, 然後全部納入D裡面, 沒想到重開機後, 居然無法boot!
這時候拿出XP光碟, 她有一個修復模式, 進去後, 是普通的dos畫面, 輸入help, 發現有fixboot, fixmbr, 就執行看看
沒想到就成功回覆MBR!
第一次在XP下除了重裝以外的trouble shooting!!

Advertisements

[C/C++] Array allocation

In the following example, we can see the compiler allocate an array automatically.

C version:

#include <stdio.h>

int main()
{
    char temp[] = "/tmp/SRL-XXXXXX";

    return 0;
}

 

GAS verstion:

    .file   "a.c"
    .section    .rodata
.LC0:
    .string "/tmp/SRL-XXXXXX"
    .text
.globl main
    .type   main, @function
main:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $24, %esp      # allocate in steak
    andl    $-16, %esp
    movl    $0, %eax
    addl    $15, %eax
    addl    $15, %eax
    shrl    $4, %eax
    sall    $4, %eax
    subl    %eax, %esp
    movl    .LC0, %eax     # copy string to array
    movl    %eax, -24(%ebp)
    movl    .LC0+4, %eax
    movl    %eax, -20(%ebp)
    movl    .LC0+8, %eax
    movl    %eax, -16(%ebp)
    movl    .LC0+12, %eax
    movl    %eax, -12(%ebp)
    movl    $0, %eax
    leave
    ret
    .size   main, .-main
    .section    .note.GNU-stack,"",@progbits
    .ident  "GCC: (GNU) 3.4.6 20060404 (Red Hat 3.4.6-3)"

C pointer version:

#include <stdlib.h>
#include <stdio.h>

int main()
{
    char *temp = "/tmp/SRL-XXXXXX";

    return 0;
}

GAS pointer version:

    .file   "a.c"
    .section    .rodata
.LC0:
    .string "/tmp/SRL-XXXXXX"
    .text
.globl main
    .type   main, @function
main:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $8, %esp                # allocate local variable
    andl    $-16, %esp
    movl    $0, %eax
    addl    $15, %eax
    addl    $15, %eax
    shrl    $4, %eax
    sall    $4, %eax
    subl    %eax, %esp
    movl    $.LC0, -4(%ebp)  # copy the pointer to location variable
    movl    $0, %eax
    leave
    ret
    .size   main, .-main
    .section    .note.GNU-stack,"",@progbits
    .ident  "GCC: (GNU) 3.4.6 20060404 (Red Hat 3.4.6-3)"

As a result, you can see the difference between char * and char [].