Various small fix
This commit is contained in:
parent
79d57bc476
commit
fb9bd8df7d
@ -159,12 +159,12 @@ int mmuContextSyncKernelPDE(int pdEntry, void *pde, size_t pdeSize)
|
||||
disable_IRQs(flags);
|
||||
list_foreach_forward(listContext, destContext, nbContexts)
|
||||
{
|
||||
void *dest_pd;
|
||||
vaddr_t dest_pd;
|
||||
|
||||
assert(destContext->ref > 0);
|
||||
|
||||
dest_pd = (void *)destContext->vaddr_PD;
|
||||
memcpy(dest_pd + pdEntry * pdeSize, pde, pdeSize);
|
||||
dest_pd = destContext->vaddr_PD;
|
||||
memcpy((void *)(dest_pd + pdEntry * pdeSize), pde, pdeSize);
|
||||
}
|
||||
restore_IRQs(flags);
|
||||
|
||||
|
@ -65,7 +65,7 @@ int allocPopulate()
|
||||
initSlab[i].isSelf, initSlab[i].neverEmpty))) {
|
||||
if (ret == -EEXIST)
|
||||
continue;
|
||||
pr_err("Fail to allocBookSlab %d for %d \n", ret, (1U << i));
|
||||
pr_err("Fail to allocBookSlab %d for %u \n", ret, (1U << i));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -82,7 +82,7 @@ int allocBookSlab(size_t sizeEl, size_t sizeSlab, int selfContained, int neverEm
|
||||
int ret;
|
||||
int flags;
|
||||
|
||||
pr_devel("%s for element of size %d is self %d\n", __func__, sizeEl, selfContained);
|
||||
pr_devel("%s for element of size %lu is self %d\n", __func__, sizeEl, selfContained);
|
||||
|
||||
disable_IRQs(flags);
|
||||
list_foreach(slub, slab, slabIdx)
|
||||
|
@ -56,20 +56,20 @@ struct memArea *areaFindFit(unsigned int nbPages)
|
||||
|
||||
static void insertSorted(struct memArea **list, struct memArea *item)
|
||||
{
|
||||
struct memArea *prev, *cur;
|
||||
struct memArea *prevArea, *cur;
|
||||
int count;
|
||||
prev = NULL;
|
||||
prevArea = NULL;
|
||||
|
||||
list_foreach(*list, cur, count)
|
||||
{
|
||||
if (cur->startAddr > item->startAddr)
|
||||
break;
|
||||
prev = cur;
|
||||
prevArea = cur;
|
||||
}
|
||||
if (prev)
|
||||
list_insert_after(*list, prev, item);
|
||||
if (prevArea)
|
||||
list_insert_after(*list, prevArea, item);
|
||||
else
|
||||
list_add_tail(*list, item);
|
||||
list_add_head(*list, item);
|
||||
}
|
||||
|
||||
vaddr_t areaBook(unsigned int nbPages, uint32_t flags)
|
||||
@ -216,24 +216,25 @@ int areaAdd(vaddr_t start, vaddr_t end, int isFree)
|
||||
if (newArea->prev)
|
||||
areaMergeFreeArea(newArea->prev, area);
|
||||
|
||||
if (newArea->next)
|
||||
if (newArea && newArea->next)
|
||||
areaMergeFreeArea(*area, &(newArea->next));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int areaMergeFreeArea(struct memArea *prev, struct memArea **next)
|
||||
static int areaMergeFreeArea(struct memArea *prevArea, struct memArea **nextArea)
|
||||
{
|
||||
if (prev->startAddr + prev->nbPages * PAGE_SIZE != (*next)->startAddr) {
|
||||
if (prevArea->startAddr + prevArea->nbPages * PAGE_SIZE != (*nextArea)->startAddr) {
|
||||
return -1;
|
||||
}
|
||||
struct memArea *toDelete = *nextArea;
|
||||
|
||||
prev->nbPages += (*next)->nbPages;
|
||||
list_delete(freeArea, *next);
|
||||
free(next);
|
||||
prevArea->nbPages += (*nextArea)->nbPages;
|
||||
list_delete(freeArea, toDelete);
|
||||
free(*nextArea);
|
||||
|
||||
*next = prev;
|
||||
*nextArea = prevArea;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -271,7 +272,7 @@ int areaFree(vaddr_t addr)
|
||||
if (area->prev)
|
||||
areaMergeFreeArea(area->prev, &area);
|
||||
|
||||
if (area->next)
|
||||
if (area && area->next)
|
||||
areaMergeFreeArea(area, &(area->next));
|
||||
|
||||
return 0;
|
||||
|
98
core/klibc.c
98
core/klibc.c
@ -283,8 +283,57 @@ int putc(const char c)
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define PRINT_UINT(name, type) \
|
||||
int print##name(type integer, char *str, size_t size) \
|
||||
{ \
|
||||
char num[sizeof(integer) * 3]; \
|
||||
int i = 0; \
|
||||
int c = 0; \
|
||||
int ret = 0; \
|
||||
\
|
||||
do { \
|
||||
int digit = integer % 10; \
|
||||
num[i++] = (digit > 0) ? digit : -digit; \
|
||||
integer = integer / 10; \
|
||||
} while (integer != 0); \
|
||||
\
|
||||
for (i = i - 1; i >= 0; i--) { \
|
||||
if (str) { \
|
||||
if (size) { \
|
||||
str[c++] = num[i] + '0'; \
|
||||
size--; \
|
||||
ret++; \
|
||||
} else { \
|
||||
return ret; \
|
||||
} \
|
||||
} else { \
|
||||
ret++; \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
PRINT_INT(Int, int);
|
||||
PRINT_INT(Int64, long long int);
|
||||
PRINT_INT(Lint, long int);
|
||||
PRINT_INT(Llint, long long int);
|
||||
PRINT_UINT(Uint, unsigned int);
|
||||
PRINT_UINT(Luint, long unsigned int);
|
||||
PRINT_UINT(Lluint, long long unsigned int);
|
||||
|
||||
#define PRINT_PART(func, type, str, size, c, ret) \
|
||||
{ \
|
||||
int s; \
|
||||
type d = va_arg(ap, type); \
|
||||
if (str) \
|
||||
s = func(d, &str[c], size); \
|
||||
else \
|
||||
s = func(d, NULL, size); \
|
||||
\
|
||||
size -= s; \
|
||||
c += s; \
|
||||
ret += s; \
|
||||
break; \
|
||||
}
|
||||
|
||||
int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
{
|
||||
@ -297,19 +346,8 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
case '%':
|
||||
switch (format[i + 1]) {
|
||||
case 'i':
|
||||
case 'd': {
|
||||
int s;
|
||||
int d = va_arg(ap, int);
|
||||
if (str)
|
||||
s = printInt(d, &str[c], size);
|
||||
else
|
||||
s = printInt(d, NULL, size);
|
||||
|
||||
size -= s;
|
||||
c += s;
|
||||
ret += s;
|
||||
break;
|
||||
}
|
||||
case 'd': PRINT_PART(printInt, int, str, size, c, ret)
|
||||
case 'u': PRINT_PART(printUint, uint, str, size, c, ret)
|
||||
case 'p':
|
||||
case 'x': {
|
||||
char val[sizeof(int) * 2];
|
||||
@ -370,19 +408,9 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
switch (format[i + 2]) {
|
||||
case 'l':
|
||||
switch (format[i + 3]) {
|
||||
case 'd': {
|
||||
int s;
|
||||
long long int d = va_arg(ap, long long int);
|
||||
if (str)
|
||||
s = printInt64(d, &str[c], size);
|
||||
else
|
||||
s = printInt64(d, NULL, size);
|
||||
|
||||
size -= s;
|
||||
c += s;
|
||||
ret += s;
|
||||
break;
|
||||
}
|
||||
case 'i':
|
||||
case 'd': PRINT_PART(printLlint, long long int, str, size, c, ret)
|
||||
case 'u': PRINT_PART(printLluint, long long unsigned int, str, size, c, ret)
|
||||
case 'p':
|
||||
case 'x': {
|
||||
char val[sizeof(long long int) * 2];
|
||||
@ -408,19 +436,8 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
i++;
|
||||
break;
|
||||
case 'i':
|
||||
case 'd': {
|
||||
int s;
|
||||
long int d = va_arg(ap, long int);
|
||||
if (str)
|
||||
s = printInt64(d, &str[c], size);
|
||||
else
|
||||
s = printInt64(d, NULL, size);
|
||||
|
||||
size -= s;
|
||||
c += s;
|
||||
ret += s;
|
||||
break;
|
||||
}
|
||||
case 'd': PRINT_PART(printLint, long int, str, size, c, ret)
|
||||
case 'u': PRINT_PART(printLuint, long unsigned int, str, size, c, ret)
|
||||
}
|
||||
i++;
|
||||
break;
|
||||
@ -441,7 +458,6 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
if (str) {
|
||||
if (size) {
|
||||
str[c++] = '\0';
|
||||
size--;
|
||||
} else {
|
||||
if (c > 0) {
|
||||
str[c - 1] = '\0';
|
||||
|
@ -143,7 +143,7 @@ int unrefPhyPage(paddr_t addr)
|
||||
if (!mem) {
|
||||
return -EINVAL;
|
||||
}
|
||||
if(mem->ref <= 0)
|
||||
if(mem->ref == 0)
|
||||
return -EINVAL;
|
||||
mem->ref--;
|
||||
if (mem->ref == 0) {
|
||||
|
@ -15,7 +15,7 @@ void printStackTrace(unsigned int maxFrames)
|
||||
// objdump -S kernel
|
||||
unsigned int *ebp = __builtin_frame_address(0);
|
||||
for (unsigned int frame = 0; frame < maxFrames; frame++) {
|
||||
unsigned int eip = ebp[1];
|
||||
unsigned int eip = *(ebp + 1);
|
||||
if (eip == 0) {
|
||||
// No caller on stack
|
||||
break;
|
||||
|
@ -48,7 +48,8 @@ typedef int ssize_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
|
||||
typedef void *va_list;
|
||||
//__builtin_va_list could be used instead
|
||||
typedef char *va_list;
|
||||
#define va_start(v, l) ((v) = (va_list) & (l) + sizeof(l))
|
||||
#define va_end(v) ((v) = NULL)
|
||||
#define va_arg(v, type) (*(type *)(((v) += sizeof(type)) - sizeof(type)))
|
||||
|
@ -417,7 +417,7 @@ int ATADetectDevice(struct ata_device *dev)
|
||||
{
|
||||
struct ata_controller *ctl = dev->ctl;
|
||||
outb(ctl->base + ATA_PIO_DRIVE,
|
||||
ATA_PIO_DRIVE_IBM | dev->isSlave ? ATA_PIO_DRIVE_SLAVE : ATA_PIO_DRIVE_MASTER);
|
||||
ATA_PIO_DRIVE_IBM | (dev->isSlave ? ATA_PIO_DRIVE_SLAVE : ATA_PIO_DRIVE_MASTER));
|
||||
unsigned st = inb(ctl->base + ATA_PIO_STATUS);
|
||||
if (st & ATA_PIO_STATUS_DRIVE_BUSY)
|
||||
goto no_disk;
|
||||
|
@ -406,7 +406,6 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
if (str) {
|
||||
if (size) {
|
||||
str[c++] = '\0';
|
||||
size--;
|
||||
} else {
|
||||
if (c > 0) {
|
||||
str[c - 1] = '\0';
|
||||
|
@ -48,7 +48,7 @@ typedef int ssize_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
#endif
|
||||
|
||||
typedef void *va_list;
|
||||
typedef char *va_list;
|
||||
#define va_start(v, l) ((v) = (va_list) & (l) + sizeof(l))
|
||||
#define va_end(v) ((v) = NULL)
|
||||
#define va_arg(v, type) (*(type *)(((v) += sizeof(type)) - sizeof(type)))
|
||||
|
Loading…
Reference in New Issue
Block a user