Forum Linux.noyau Créer mini-os unix

Posté par  . Licence CC By‑SA.
Étiquettes :
0
2
jan.
2013

Bonjour,
je suis en train de créer un kernel grâce à un tuto que voici Texte du lien mais quand j'utilise le make fournis dans l’archive le terminal m'affiche `__stack_chk_fail' alors j'ai ajouté l'option -fno-stack-protector dans le makefile puis un make clean et oh miracle ça marche… sauf quand j'ai voulu utiliser le kernel le terminal m'a affiché Erreur segmentation Fault. J'ai utiliser gdb et il m'affiche

Program received signal SIGSEGV, Segmentation fault.
0x00103d99 in hide_cursor () at screen.c:99
99      *(video + 1) = 0x0;

mais je soupçonne printk.c.

voici le code :

//screen.c

#include "io.h"
#include "types.h"

#define __SCREEN__
#include "screen.h"

void scrollup(unsigned int n)
{
    unsigned char *video, *tmp;

    for (video = (unsigned char *) RAMSCREEN;
         video < (unsigned char *) SCREENLIM; video += 2) {
        tmp = (unsigned char *) (video + n * 160);

        if (tmp < (unsigned char *) SCREENLIM) {
            *video = *tmp;
            *(video + 1) = *(tmp + 1);
        } else {
            *video = 0;
            *(video + 1) = 0x07;
        }
    }

    kY -= n;
    if (kY < 0)
        kY = 0;
}

void putcar(uchar c)
{
    unsigned char *video;

    hide_cursor();
    video = (unsigned char *) (RAMSCREEN + 2 * kX + 160 * kY);

    if (c == 10) {      /* CR-NL */
        kX = 0;
        kY++;
    } else if (c == 8) {    /* BS */
        if (kX) {
            *(video + 1) = 0x0;
            kX--;
        }
    } else if (c == 9) {    /* TAB */
        kX = kX + 8 - (kX % 8);
    } else if (c == 13) {   /* CR */
        kX = 0;
    } else {        /* autres caracteres */
        *video = c;
        *(video + 1) = kattr;

        kX++;
        if (kX > 79) {
            kX = 0;
            kY++;
        }
    }

    if (kY > 24)
        scrollup(kY - 24);

    show_cursor();
}

void move_hw_cursor(u8 x, u8 y)
{
    u16 c_pos;

    c_pos = y * 80 + x;

    outb(0x3d4, 0x0f);
    outb(0x3d5, (u8) c_pos);
    outb(0x3d4, 0x0e);
    outb(0x3d5, (u8) (c_pos >> 8));
}

void hide_hw_cursor(void)
{
    move_hw_cursor(-1, -1);
}

void show_cursor()
{
    unsigned char *video;

    cursorX = kX;
    cursorY = kY;

    video = (unsigned char *) (RAMSCREEN + 2 * cursorX + 160 * cursorY);
    *video = cursorC;
    *(video + 1) = cursorA;
}

void hide_cursor(void)
{
    unsigned char *video;

    video = (unsigned char *) (RAMSCREEN + 2 * cursorX + 160 * cursorY);
    *(video + 1) = 0x0;
}

//printk.c
#include <stdarg.h>
#include "screen.h"
#include "lib.h"

void printk(char *s, ...)
{
    va_list ap;

    char buf[16];
    int i, j, size, buflen, neg;

    unsigned char c;
    int ival;
    unsigned int uival;

    va_start(ap, s);

    while ((c = *s++)) {
        size = 0;
        neg = 0;

        if (c == 0)
            break;
        else if (c == '%') {
            c = *s++;
            if (c >= '0' && c <= '9') {
                size = c - '0';
                c = *s++;
            }

            if (c == 'd') {
                ival = va_arg(ap, int);
                if (ival < 0) {
                    uival = 0 - ival;
                    neg++;
                } else
                    uival = ival;
                itoa(buf, uival, 10);

                buflen = strlen(buf);
                if (buflen < size)
                    for (i = size, j = buflen; i >= 0;
                         i--, j--)
                        buf[i] =
                            (j >=
                             0) ? buf[j] : '0';

                if (neg)
                    printk("-%s", buf);
                else
                    printk(buf);
            } else if (c == 'u') {
                uival = va_arg(ap, int);
                itoa(buf, uival, 10);

                buflen = strlen(buf);
                if (buflen < size)
                    for (i = size, j = buflen; i >= 0;
                         i--, j--)
                        buf[i] =
                            (j >=
                             0) ? buf[j] : '0';

                printk(buf);
            } else if (c == 'x' || c == 'X') {
                uival = va_arg(ap, int);
                itoa(buf, uival, 16);

                buflen = strlen(buf);
                if (buflen < size)
                    for (i = size, j = buflen; i >= 0;
                         i--, j--)
                        buf[i] =
                            (j >=
                             0) ? buf[j] : '0';

                printk("0x%s", buf);
            } else if (c == 'p') {
                uival = va_arg(ap, int);
                itoa(buf, uival, 16);
                size = 8;

                buflen = strlen(buf);
                if (buflen < size)
                    for (i = size, j = buflen; i >= 0;
                         i--, j--)
                        buf[i] =
                            (j >=
                             0) ? buf[j] : '0';

                printk("0x%s", buf);
            } else if (c == 's') {
                printk((char *) va_arg(ap, int));
            } 
        } else
            putcar(c);
    }

    return;
}

si vous pouvez m'aider ça serai sympa.
merci et bonne journée

  • # hide_cursor()

    Posté par  . Évalué à 2.

    Bonjour,

    gdb dit: 0x00103d99 in hide_cursor () at screen.c:99

    printk() appelle putcar() et putcar() appelle hide_cursor()
    Si je compare hide_cursor() à show_cursor(), les
    variables suivantes ne sont pas fixées dans hide_cursor():

    cursorX
    cursorY

    alors qu'elles le sont dans show_cursor():

    cursorX = kX;
    cursorY = kY;

    Aller mettre un 0x0 à un endroit qui dépendent de variables non
    fixées, normal que ça parte en SIGSEV.
    Que se passe-t-il si les variables mentionnées sont fixées comme
    dans show_cursor() ?

    • [^] # Re: hide_cursor()

      Posté par  . Évalué à 0.

      J'ai fait comme ceci

      #include "io.h"
      #include "types.h"
      
      #define __SCREEN__
      #include "screen.h"
      
      void scrollup(unsigned int n)
      {
          unsigned char *video, *tmp;
      
          for (video = (unsigned char *) RAMSCREEN;
               video < (unsigned char *) SCREENLIM; video += 2) {
              tmp = (unsigned char *) (video + n * 160);
      
              if (tmp < (unsigned char *) SCREENLIM) {
                  *video = *tmp;
                  *(video + 1) = *(tmp + 1);
              } else {
                  *video = 0;
                  *(video + 1) = 0x07;
              }
          }
      
          kY -= n;
          if (kY < 0)
              kY = 0;
      }
      
      void putcar(uchar c)
      {
          unsigned char *video;
      
          hide_cursor();
          video = (unsigned char *) (RAMSCREEN + 2 * kX + 160 * kY);
      
          if (c == 10) {      /* CR-NL */
              kX = 0;
              kY++;
          } else if (c == 8) {    /* BS */
              if (kX) {
                  *(video + 1) = 0x0;
                  kX--;
              }
          } else if (c == 9) {    /* TAB */
              kX = kX + 8 - (kX % 8);
          } else if (c == 13) {   /* CR */
              kX = 0;
          } else {        /* autres caracteres */
              *video = c;
              *(video + 1) = kattr;
      
              kX++;
              if (kX > 79) {
                  kX = 0;
                  kY++;
              }
          }
      
          if (kY > 24)
              scrollup(kY - 24);
      
          show_cursor();
      }
      
      void move_hw_cursor(u8 x, u8 y)
      {
          u16 c_pos;
      
          c_pos = y * 80 + x;
      
          outb(0x3d4, 0x0f);
          outb(0x3d5, (u8) c_pos);
          outb(0x3d4, 0x0e);
          outb(0x3d5, (u8) (c_pos >> 8));
      }
      
      void hide_hw_cursor(void)
      {
          move_hw_cursor(-1, -1);
      }
      
      void show_cursor()
      {
          unsigned char *video;
      
          cursorX = kX;
          cursorY = kY;
      
          video = (unsigned char *) (RAMSCREEN + 2 * cursorX + 160 * cursorY);
          *video = cursorC;
          *(video + 1) = cursorA;
      }
      
      void hide_cursor(void)
      {
          unsigned char *video;
          cursorX = kX;
          cursorY = kY;
          video = (unsigned char *) (RAMSCREEN + 2 * cursorX + 160 * cursorY);
          *(video + 1) = 0x0;
      }
      
      

      mais il m'affiche toujours Program received signal SIGSEGV, Segmentation fault.
      0x00103dcf in hide_cursor () at screen.c:100
      100 *(video + 1) = 0x0;
      PS : désolé pour la réponse un peu tardive

  • # OS

    Posté par  . Évalué à 0.

    Il n y a plus personne ?

  • # erreur kernel Valgrind

    Posté par  . Évalué à 0.

    J ai utilise valgind pour voir d ou vient le probleme et voici le resultat

    ==8680== Memcheck, a memory error detector
    ==8680== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
    ==8680== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
    ==8680== Command: ./kernel
    ==8680==
    ==8680== Invalid write of size 1
    ==8680== at 0x103DB9: hide_cursor (screen.c:100)
    ==8680== by 0x103B54: putcar (screen.c:33)
    ==8680== by 0x103097: printk (printk.c:96)
    ==8680== by 0x101C3A: kmain (kernel.c:27)
    ==8680== by 0x100015: ??? (in /home/ubuntu/Shell/kern/kernel)
    ==8680== Address 0xb8501 is not stack'd, malloc'd or (recently) free'd
    ==8680==
    ==8680==
    ==8680== Process terminating with default action of signal 11 (SIGSEGV)
    ==8680== Access not within mapped region at address 0xB8501
    ==8680== at 0x103DB9: hide_cursor (screen.c:100)
    ==8680== by 0x103B54: putcar (screen.c:33)
    ==8680== by 0x103097: printk (printk.c:96)
    ==8680== by 0x101C3A: kmain (kernel.c:27)
    ==8680== by 0x100015: ??? (in /home/ubuntu/Shell/kern/kernel)
    ==8680== If you believe this happened as a result of a stack
    ==8680== overflow in your program's main thread (unlikely but
    ==8680== possible), you can try to increase the size of the
    ==8680== main thread stack using the --main-stacksize= flag.
    ==8680== The main thread stack size used in this run was 8388608.
    ==8680==
    ==8680== HEAP SUMMARY:
    ==8680== in use at exit: 0 bytes in 0 blocks
    ==8680== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==8680==
    ==8680== All heap blocks were freed—no leaks are possible
    ==8680==
    ==8680== For counts of detected and suppressed errors, rerun with: -v
    ==8680== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
    si vous pouvez m aider ca serai sympas
    bonne soiree

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.