Add PVS-Studio and cppcheck (and make some fixes detailed in Informe.docx)
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
917d377e67
commit
ae4eb5db87
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
/* BareMetal File System Utility */
|
||||
/* Written by Ian Seyler of Return Infinity */
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#ifndef NAIVE_CONSOLE_H
|
||||
#define NAIVE_CONSOLE_H
|
||||
// #ifndef NAIVE_CONSOLE_H
|
||||
// #define NAIVE_CONSOLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
// #include <stdint.h>
|
||||
|
||||
void ncPrint(const char * string);
|
||||
void ncPrintChar(char character);
|
||||
void ncNewline();
|
||||
void ncPrintDec(uint64_t value);
|
||||
void ncPrintHex(uint64_t value);
|
||||
void ncPrintBin(uint64_t value);
|
||||
void ncPrintBase(uint64_t value, uint32_t base);
|
||||
void ncClear();
|
||||
// void ncPrint(const char * string);
|
||||
// void ncPrintChar(char character);
|
||||
// void ncNewline();
|
||||
// void ncPrintDec(uint64_t value);
|
||||
// void ncPrintHex(uint64_t value);
|
||||
// void ncPrintBin(uint64_t value);
|
||||
// void ncPrintBase(uint64_t value, uint32_t base);
|
||||
// void ncClear();
|
||||
|
||||
#endif
|
||||
// #endif
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "keyboard.h"
|
||||
|
||||
#define SIZE 1
|
||||
|
@ -37,7 +39,8 @@ void testKeyboardInterrupt(unsigned char c) {
|
|||
if (flagChangeAlt == 0 && flagChangeF1 == 0) {
|
||||
flagChangeAlt = 1;
|
||||
flagChangeF1 = 1;
|
||||
saveChar('\v');
|
||||
// saveChar('\v');
|
||||
saveChar(-1);
|
||||
return;
|
||||
} else if (c == 0xB8) {
|
||||
flagChangeAlt = 1;
|
||||
|
|
|
@ -1,74 +1,76 @@
|
|||
#include <naiveConsole.h>
|
||||
// // This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
// #include <naiveConsole.h>
|
||||
|
||||
static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base);
|
||||
// static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base);
|
||||
|
||||
static char buffer[64] = {'0'};
|
||||
static uint8_t *const video = (uint8_t *) 0xB8000;
|
||||
static uint8_t *currentVideo = (uint8_t *) 0xB8000;
|
||||
static const uint32_t width = 80;
|
||||
static const uint32_t height = 25;
|
||||
// static char buffer[64] = {'0'};
|
||||
// static uint8_t *const video = (uint8_t *) 0xB8000;
|
||||
// static uint8_t *currentVideo = (uint8_t *) 0xB8000;
|
||||
// static const uint32_t width = 80;
|
||||
// static const uint32_t height = 25;
|
||||
|
||||
void ncPrint(const char *string) {
|
||||
for (int i = 0; string[i] != 0; i++)
|
||||
ncPrintChar(string[i]);
|
||||
}
|
||||
// void ncPrint(const char *string) {
|
||||
// for (int i = 0; string[i] != 0; i++)
|
||||
// ncPrintChar(string[i]);
|
||||
// }
|
||||
|
||||
void ncPrintChar(char character) {
|
||||
*currentVideo = character;
|
||||
currentVideo += 2;
|
||||
}
|
||||
// void ncPrintChar(char character) {
|
||||
// *currentVideo = character;
|
||||
// currentVideo += 2;
|
||||
// }
|
||||
|
||||
void ncNewline() {
|
||||
do {
|
||||
ncPrintChar(' ');
|
||||
} while ((uint64_t)(currentVideo - video) % (width * 2) != 0);
|
||||
}
|
||||
// void ncNewline() {
|
||||
// do {
|
||||
// ncPrintChar(' ');
|
||||
// } while ((uint64_t)(currentVideo - video) % (width * 2) != 0);
|
||||
// }
|
||||
|
||||
void ncPrintDec(uint64_t value) {
|
||||
ncPrintBase(value, 10);
|
||||
}
|
||||
// void ncPrintDec(uint64_t value) {
|
||||
// ncPrintBase(value, 10);
|
||||
// }
|
||||
|
||||
void ncPrintHex(uint64_t value) {
|
||||
ncPrintBase(value, 16);
|
||||
}
|
||||
// void ncPrintHex(uint64_t value) {
|
||||
// ncPrintBase(value, 16);
|
||||
// }
|
||||
|
||||
void ncPrintBin(uint64_t value) {
|
||||
ncPrintBase(value, 2);
|
||||
}
|
||||
// void ncPrintBin(uint64_t value) {
|
||||
// ncPrintBase(value, 2);
|
||||
// }
|
||||
|
||||
void ncPrintBase(uint64_t value, uint32_t base) {
|
||||
uintToBase(value, buffer, base);
|
||||
ncPrint(buffer);
|
||||
}
|
||||
// void ncPrintBase(uint64_t value, uint32_t base) {
|
||||
// uintToBase(value, buffer, base);
|
||||
// ncPrint(buffer);
|
||||
// }
|
||||
|
||||
void ncClear() {
|
||||
for (int i = 0; i < height * width; i++)
|
||||
video[i * 2] = ' ';
|
||||
currentVideo = video;
|
||||
}
|
||||
// void ncClear() {
|
||||
// for (int i = 0; i < height * width; i++)
|
||||
// video[i * 2] = ' ';
|
||||
// currentVideo = video;
|
||||
// }
|
||||
|
||||
static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base) {
|
||||
char *p = buffer;
|
||||
char *p1, *p2;
|
||||
uint32_t digits = 0;
|
||||
// static uint32_t uintToBase(uint64_t value, char *buffer, uint32_t base) {
|
||||
// char *p = buffer;
|
||||
// char *p1, *p2;
|
||||
// uint32_t digits = 0;
|
||||
|
||||
do {
|
||||
uint32_t remainder = value % base;
|
||||
*p++ = (remainder < 10) ? remainder + '0' : remainder + 'A' - 10;
|
||||
digits++;
|
||||
} while (value /= base);
|
||||
// do {
|
||||
// uint32_t remainder = value % base;
|
||||
// *p++ = (remainder < 10) ? remainder + '0' : remainder + 'A' - 10;
|
||||
// digits++;
|
||||
// } while (value /= base);
|
||||
|
||||
*p = 0;
|
||||
// *p = 0;
|
||||
|
||||
p1 = buffer;
|
||||
p2 = p - 1;
|
||||
while (p1 < p2) {
|
||||
char tmp = *p1;
|
||||
*p1 = *p2;
|
||||
*p2 = tmp;
|
||||
p1++;
|
||||
p2--;
|
||||
}
|
||||
// p1 = buffer;
|
||||
// p2 = p - 1;
|
||||
// while (p1 < p2) {
|
||||
// char tmp = *p1;
|
||||
// *p1 = *p2;
|
||||
// *p2 = tmp;
|
||||
// p1++;
|
||||
// p2--;
|
||||
// }
|
||||
|
||||
return digits;
|
||||
}
|
||||
// return digits;
|
||||
// }
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "time.h"
|
||||
|
||||
static unsigned long ticks = 0;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "video.h"
|
||||
|
||||
static uint8_t *const video = (uint8_t *) 0xB8000;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "exceptions.h"
|
||||
|
||||
static void zero_division();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "idtLoader.h"
|
||||
|
||||
#pragma pack(push)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "irqDispatcher.h"
|
||||
|
||||
void irqDispatcher(uint64_t irq) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "systemCalls.h"
|
||||
|
||||
uint64_t write(uint64_t fd, uint64_t buffer, uint64_t length) {
|
||||
|
@ -36,10 +38,9 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
|||
blockIO();
|
||||
}
|
||||
readBytes++;
|
||||
if (*bufferAux++ == '\v') {
|
||||
if (*bufferAux++ == -1) {
|
||||
break;
|
||||
}
|
||||
// blockIO();
|
||||
}
|
||||
} else {
|
||||
while (length-- > 0) {
|
||||
|
@ -47,12 +48,11 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
|||
if (*bufferAux == 0)
|
||||
break;
|
||||
readBytes++;
|
||||
if (*bufferAux++ == '\v') {
|
||||
if (*bufferAux++ == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// *bufferAux = 0;
|
||||
|
||||
return readBytes;
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "systemCallsDispatcher.h"
|
||||
|
||||
uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9) {
|
||||
|
@ -14,7 +16,7 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
|
|||
exitProcess();
|
||||
break;
|
||||
case 5:
|
||||
return dumpMM();
|
||||
return (uint64_t) dumpMM();
|
||||
case 6:
|
||||
return (uint64_t) processes();
|
||||
case 7:
|
||||
|
@ -51,11 +53,15 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
|
|||
case 20:
|
||||
return unblock(rsi);
|
||||
case 21:
|
||||
return wait();
|
||||
wait();
|
||||
break;
|
||||
case 22:
|
||||
return pipes();
|
||||
return (uint64_t) pipes();
|
||||
case 23:
|
||||
return quitCPU();
|
||||
case 24:
|
||||
closePipe(rsi);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <stdint.h>
|
||||
#include <lib.h>
|
||||
#include <moduleLoader.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "lib.h"
|
||||
|
||||
void *memset(void *destination, int32_t c, uint64_t length) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <stdint.h>
|
||||
#include <lib.h>
|
||||
#include <moduleLoader.h>
|
||||
|
|
|
@ -25,5 +25,6 @@ char openPipe(int * fds, char * name);
|
|||
void writePipe(int fd, char c);
|
||||
char readPipe(int fd);
|
||||
char * pipes();
|
||||
void closePipe(int fd);
|
||||
|
||||
#endif
|
|
@ -21,5 +21,7 @@ void sleep(int secs);
|
|||
char blockIO();
|
||||
void unblockIO();
|
||||
char getState(int pid);
|
||||
char isForeground();
|
||||
void wait();
|
||||
|
||||
#endif
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#ifdef BUDDY
|
||||
|
||||
// Basado en: https://github.com/cloudwu/buddy/blob/master/buddy.c
|
||||
|
@ -83,10 +85,9 @@ void * buddy_alloc(int s) {
|
|||
|
||||
int index = 0;
|
||||
int level = 0;
|
||||
int nextStep = 1;
|
||||
|
||||
while (index >= 0) {
|
||||
nextStep = 1;
|
||||
int nextStep = 1;
|
||||
if (size == length) {
|
||||
if (self.tree[index] == NODE_UNUSED) {
|
||||
self.tree[index] = NODE_USED;
|
||||
|
@ -181,50 +182,12 @@ int buddy_free(void * pointer) {
|
|||
}
|
||||
}
|
||||
|
||||
// char *dumpMM() {
|
||||
// return NULL;
|
||||
// }
|
||||
uint64_t getSize(int level, int max_level) {
|
||||
return (1 << (max_level - level)) * PAGE_SIZE;
|
||||
}
|
||||
|
||||
/*
|
||||
void buddy_dumpMM(struct buddy * self, int index , int level) {
|
||||
char buffer[10];
|
||||
switch (self->tree[index]) {
|
||||
case NODE_UNUSED:
|
||||
printStringLen(15, "(_", 1);
|
||||
printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 0);
|
||||
printStringLen(15, ":", 1);
|
||||
printStringLen(15, itoa(level, buffer, 10), 10);
|
||||
printStringLen(15, "_)", 1);
|
||||
break;
|
||||
case NODE_USED:
|
||||
printStringLen(15, "(*", 1);
|
||||
printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 10);
|
||||
printStringLen(15, ":", 1);
|
||||
printStringLen(15, itoa(level, buffer, 10), 10);
|
||||
printStringLen(15, "*)", 1);
|
||||
break;
|
||||
case NODE_FULL:
|
||||
printStringLen(15, "[", 1);
|
||||
buddy_dumpMM(self, index * 2 + 1, level + 1);
|
||||
buddy_dumpMM(self, index * 2 + 2, level + 1);
|
||||
printStringLen(15, "]", 1);
|
||||
break;
|
||||
default:
|
||||
printStringLen(15, "(", 1);
|
||||
buddy_dumpMM(self, index * 2 + 1, level + 1);
|
||||
buddy_dumpMM(self, index * 2 + 2, level + 1);
|
||||
printStringLen(15, ")", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
void buddy_dumpMM(int index , int level, uint64_t *size, uint64_t *used) {
|
||||
char buffer[10];
|
||||
switch (self.tree[index]) {
|
||||
case NODE_UNUSED:
|
||||
*size += getSize(level, self.level);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#ifndef BUDDY
|
||||
|
||||
#include "memManagerFRT4.h"
|
||||
|
@ -118,7 +120,6 @@ void *pvPortMalloc(size_t xWantedSize) {
|
|||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortFree(void *pv) {
|
||||
uint8_t *puc = (uint8_t *) pv;
|
||||
BlockLink_t *pxLink;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "pipe.h"
|
||||
|
||||
static int fdIndex = 2;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "scheduler.h"
|
||||
|
||||
enum states {
|
||||
READY = 0, DEAD, BLOCKED, BBCHILDREN, WAITING, BLOCKEDIO
|
||||
READY = 0, DEAD, BLOCKED, WAITING, BLOCKEDIO
|
||||
};
|
||||
|
||||
typedef struct processCDT {
|
||||
|
@ -18,6 +20,7 @@ typedef struct processCDT {
|
|||
int *fd;
|
||||
int children;
|
||||
char backWait;
|
||||
uint64_t bPointer;
|
||||
} processCDT;
|
||||
|
||||
typedef struct sleepCDT {
|
||||
|
@ -56,7 +59,6 @@ void removeProcess(processCDT *del, processCDT **first, processCDT **last) {
|
|||
uint64_t nextProcess(uint64_t currentRSP) {
|
||||
if (currentProcess != NULL)
|
||||
currentProcess->rsp = currentRSP;
|
||||
processCDT *prev = currentProcess;
|
||||
if (currentProcess != NULL && currentProcess->state == READY &&
|
||||
currentProcess->executions == MAX_PRIORITY - currentProcess->priority) {
|
||||
currentProcess->executions = 0;
|
||||
|
@ -69,7 +71,6 @@ uint64_t nextProcess(uint64_t currentRSP) {
|
|||
} else if (currentProcess == firstBlockedIteration) {
|
||||
idleFlag = 1;
|
||||
unblock(IDLE_PID);
|
||||
prev = currentProcess;
|
||||
currentProcess = currentProcess->next;
|
||||
} else if (currentProcess->state == DEAD) {
|
||||
processCDT *del = currentProcess;
|
||||
|
@ -80,7 +81,6 @@ uint64_t nextProcess(uint64_t currentRSP) {
|
|||
currentProcess->state == BLOCKEDIO) {
|
||||
if (firstBlockedIteration == NULL)
|
||||
firstBlockedIteration = currentProcess;
|
||||
prev = currentProcess;
|
||||
currentProcess = currentProcess->next;
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,7 @@ int enqueueProcess(void (*fn)(int, char **), char foreground, int argc, char *ar
|
|||
process->next = NULL;
|
||||
process->children = 0;
|
||||
process->backWait = 0;
|
||||
process->bPointer = (uint64_t) auxi;
|
||||
|
||||
process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
|
||||
|
||||
|
@ -341,8 +342,8 @@ char kill(int pid) {
|
|||
|
||||
vPortFree(del->fd);
|
||||
vPortFree(del->name);
|
||||
void *auxi = del->rbp - STACK_SIZE;
|
||||
vPortFree((void *) auxi);
|
||||
// vPortFree((void *) ((uint64_t) del->rbp - STACK_SIZE));
|
||||
vPortFree((void *) del->bPointer);
|
||||
del->state = DEAD;
|
||||
|
||||
if (pid == currentProcess->pid) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "sem.h"
|
||||
|
||||
static uint32_t semLock;
|
||||
|
@ -40,6 +42,8 @@ sem_t *semOpen(char *name, unsigned int value) {
|
|||
sem->name = pvPortMalloc(MAX_NAME);
|
||||
strcpy(sem->name, name);
|
||||
sem->value = value;
|
||||
sem->entering = NULL;
|
||||
sem->last = NULL;
|
||||
counter++;
|
||||
|
||||
leave_region(&semLock);
|
||||
|
|
8
Makefile
8
Makefile
|
@ -37,4 +37,10 @@ clean:
|
|||
cd Kernel; make clean
|
||||
cd Userland; make clean
|
||||
|
||||
.PHONY: bootloader image imageSpanish imageBuddy collections kernel kernelSpanish kernelBuddy userland all clean
|
||||
test:
|
||||
pvs-studio-analyzer trace -- make
|
||||
pvs-studio-analyzer analyze
|
||||
plog-converter -a '64:1,2,3;GA:1,2,3;OP:1,2,3' -t tasklist -o report.tasks PVS-Studio.log
|
||||
cppcheck --quiet --enable=all --force --inconclusive .
|
||||
|
||||
.PHONY: bootloader image imageSpanish imageBuddy collections kernel kernelSpanish kernelBuddy userland all clean test
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <stdint.h>
|
||||
|
||||
extern char bss;
|
||||
|
|
|
@ -3,7 +3,7 @@ GLOBAL _getMem, sys_loadProcess
|
|||
GLOBAL raiseOpcodeExc
|
||||
GLOBAL _getRegs, sys_switchContext
|
||||
GLOBAL cpu_id, cpu_id_support
|
||||
GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_semClose
|
||||
GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_closePipe, sys_semClose
|
||||
GLOBAL sys_nice, sys_semWait, sys_semPost, sys_semOpen, sys_sleep, sys_kill, sys_getPid,
|
||||
GLOBAL sys_block, sys_unblock, sys_wait, sys_pipes, sys_quitCPU, sys_dumpMM
|
||||
|
||||
|
@ -78,6 +78,24 @@ sys_openPipe:
|
|||
pop rbp
|
||||
ret
|
||||
|
||||
sys_closePipe:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
|
||||
mov rsi, rdi
|
||||
mov rdi, 24
|
||||
int 80h
|
||||
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov rsp, rbp
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
sys_exit:
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "bottler.h"
|
||||
|
||||
void bottler(int argc, char **argv) {
|
||||
|
|
|
@ -36,5 +36,7 @@ char sys_unblock(int pid);
|
|||
void sys_quitCPU();
|
||||
void sys_wait();
|
||||
char * sys_dumpMM();
|
||||
char * sys_pipes();
|
||||
void sys_closePipe();
|
||||
|
||||
#endif
|
|
@ -154,7 +154,7 @@ char *itoa(int value, char *buffer, int base) {
|
|||
}
|
||||
|
||||
int atoi(char *str, int length) {
|
||||
int i = 0, sign = 1, val = 0, nbr = 0;
|
||||
int i = 0, sign = 1, val = 0;
|
||||
while (str[i] != '\0') {
|
||||
if (str[i] == '-') {
|
||||
sign = -sign;
|
||||
|
@ -164,7 +164,7 @@ int atoi(char *str, int length) {
|
|||
}
|
||||
i = 0;
|
||||
while (str[i] >= '0' && str[i] <= '9' && str[i] != '\0') {
|
||||
nbr = (int) (str[i] - '0');
|
||||
int nbr = (int) (str[i] - '0');
|
||||
val = (val * 10) + nbr;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell/include/shell.h"
|
||||
#include "bottler/include/bottler.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "block.h"
|
||||
|
||||
void block(int argc, char ** argv) {
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "cat.h"
|
||||
|
||||
#define SIZE 1000
|
||||
|
||||
void debug2() {
|
||||
return;
|
||||
}
|
||||
|
||||
void cat(int argc, char ** argv) {
|
||||
char c;
|
||||
int i = 0, j = 0, line = 0;
|
||||
char buffer[SIZE] = {0};
|
||||
|
||||
while ((c = getChar()) > 0) {
|
||||
if (i >= SIZE)
|
||||
if (i > SIZE - 1)
|
||||
break;
|
||||
buffer[i++] = c;
|
||||
j++;
|
||||
|
@ -22,6 +28,10 @@ void cat(int argc, char ** argv) {
|
|||
buffer[--i] = 0;
|
||||
}
|
||||
}
|
||||
buffer[i++] = c;
|
||||
j++;
|
||||
|
||||
debug2();
|
||||
printStringLen(buffer + line, j);
|
||||
|
||||
newline();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
#include "clear.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "cpu_id.h"
|
||||
|
||||
int cpu_id(int *, int *, int *, int *);
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "excDiv.h"
|
||||
|
||||
void excdiv(int argc, char *argv[]) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "excOP.h"
|
||||
|
||||
void raiseOpcodeExc();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "filter.h"
|
||||
|
||||
#define SIZE 1000
|
||||
|
@ -28,6 +30,8 @@ void filter(int argc, char ** argv) {
|
|||
line = i;
|
||||
}
|
||||
}
|
||||
buffer[i++] = c;
|
||||
j++;
|
||||
|
||||
printStringLen(buffer + line, j);
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "inforeg.h"
|
||||
#include <stdint.h>
|
||||
#include "libc.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "kill.h"
|
||||
|
||||
void kill(int argc, char ** argv) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "loop.h"
|
||||
#define PUAN -1
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "nice.h"
|
||||
|
||||
void nice(int argc, char ** argv) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "phyloLib.h"
|
||||
|
||||
philosopher_t *firstPhil;
|
||||
|
@ -120,7 +122,6 @@ void phylo(int argc, char ** argv) {
|
|||
philosopher_t * left = NULL;
|
||||
for (int i = 0; i < philoCount; i++) {
|
||||
philosopher_t * phil = sys_malloc(sizeof(philosopher_t));
|
||||
phil->debug = i;
|
||||
phil->argv = sys_malloc(sizeof(char *) * 2);
|
||||
phil->buffer = sys_malloc(20);
|
||||
phil->state = THINKING;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "pipes.h"
|
||||
|
||||
void pipe(int argc, char *argv[]) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "inforeg.h"
|
||||
#include <stdint.h>
|
||||
#include "shell.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "quadratic.h"
|
||||
#include "shell.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "test_mm.h"
|
||||
|
||||
void *memset(void *destination, int32_t c, uint64_t length);
|
||||
|
||||
typedef struct MM_rq{
|
||||
void *address;
|
||||
uint32_t size;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "test_prio.h"
|
||||
|
||||
#define MINOR_WAIT 10000000 // TODO: To prevent a process from flooding the screen
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "test_processes.h"
|
||||
#include "ps.h"
|
||||
|
||||
|
@ -16,10 +18,6 @@ void endless_loop(){
|
|||
sys_exit();
|
||||
}
|
||||
|
||||
void debugPSA() {
|
||||
return;
|
||||
}
|
||||
|
||||
void test_processes(int argc, char ** argv){
|
||||
p_rq p_rqs[MAX_PROCESSES];
|
||||
uint8_t rq;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "test_sync.h"
|
||||
|
||||
#define TOTAL_PAIR_PROCESSES 2
|
||||
|
@ -25,11 +27,10 @@ void inc(int argc, char ** argv) {
|
|||
uint64_t N = atoi(argv[3], 10);
|
||||
uint64_t i;
|
||||
|
||||
char buff[10] = {0};
|
||||
for (i = 0; i < N; i++){
|
||||
if (semDir) sys_semWait(semDir);
|
||||
if (semDir) sys_semWait((sem_t *) semDir);
|
||||
slowInc(&global, value);
|
||||
if (semDir) sys_semPost(semDir);
|
||||
if (semDir) sys_semPost((sem_t *) semDir);
|
||||
}
|
||||
|
||||
char buffer[10] = {0};
|
||||
|
@ -48,7 +49,7 @@ void test_sync(int argc, char ** argv){
|
|||
|
||||
sem_t * sem = sys_semOpen(SEM_ID, 1);
|
||||
char semDir[10] = {0};
|
||||
itoa((int) sem, semDir, 10);
|
||||
itoa((uint64_t) sem, semDir, 10);
|
||||
|
||||
for(i = 0; i < TOTAL_PAIR_PROCESSES; i++){
|
||||
char * argv1[] = {"inc", semDir, "1", ITERS};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <stdint.h>
|
||||
#include "test_util.h"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "time.h"
|
||||
#include "libc.h"
|
||||
#include "shell.h"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "unblock.h"
|
||||
|
||||
void unblock(int argc, char ** argv) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "wc.h"
|
||||
|
||||
#define SIZE 1000
|
||||
|
@ -12,6 +14,7 @@ void wc(int argc, char ** argv) {
|
|||
if (c == '\n')
|
||||
i++;
|
||||
}
|
||||
buffer[i++] = c;
|
||||
|
||||
printStringLen(gtoa(i, buffer, 10, SIZE), SIZE);
|
||||
newline();
|
||||
|
|
|
@ -17,7 +17,6 @@ int * state;
|
|||
typedef enum states {EATING = 0, HUNGRY, THINKING} states;
|
||||
|
||||
typedef struct philosopher_t {
|
||||
int debug;
|
||||
char ** argv;
|
||||
char * buffer;
|
||||
sem_t * sem;
|
||||
|
@ -29,5 +28,7 @@ typedef struct philosopher_t {
|
|||
} philosopher_t;
|
||||
|
||||
void philosopher(int argc, char ** argv);
|
||||
void freePhilo(philosopher_t * phil);
|
||||
void end();
|
||||
|
||||
#endif
|
|
@ -1,3 +1,5 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "shell.h"
|
||||
|
||||
cmd_t commands[] = {
|
||||
|
@ -144,9 +146,11 @@ void processInput(char *input) {
|
|||
|
||||
if (commands[comm0].isForeground) {
|
||||
sys_wait();
|
||||
}
|
||||
sys_free(argv0);
|
||||
if (pipe == -1)
|
||||
if (pipe != -1) {
|
||||
sys_free(argv1);
|
||||
sys_closePipe(fd1[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
build.sh
2
build.sh
|
@ -12,6 +12,8 @@ cd ..
|
|||
if [ $# -eq 1 ]; then
|
||||
if [ $1 = "buddy" ]; then
|
||||
make buddy
|
||||
elif [ $1 = "spanish" ]; then
|
||||
make spanish
|
||||
else
|
||||
echo "Do you want to compile with the buddy memory manager? if so, you must pass buddy as argument"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue