attribut_format #6

Merged
mathieu merged 2 commits from attribut_format into master 2023-11-09 23:45:15 +01:00
16 changed files with 61 additions and 40 deletions
Showing only changes of commit 18ea283213 - Show all commits

View File

@ -46,9 +46,8 @@ int exceptionSetRoutine(int exception, exception_handler handler)
void print_handler(struct cpu_state *frame, ulong intr) void print_handler(struct cpu_state *frame, ulong intr)
{ {
int intNbInt = intr; int intNbInt = intr;
VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "EXCEPTION %d %d", intNbInt, intr); VGAPrintf(RED, BLACK, 0, VGA_HEIGHT - 1, "EXCEPTION %d", intNbInt);
printf("Exception %d (Err %d) at 0x%x\n", intr, intr, printf("Exception %lu at 0x%p\n", intr, (void *)cpu_context_get_PC(frame));
cpu_context_get_PC(frame));
asm("hlt"); asm("hlt");
} }
@ -62,9 +61,8 @@ void pagefault_handler(struct cpu_state *frame, ulong intr)
if(!uAddrSpaceCheckNAlloc(as, faultAddr)) if(!uAddrSpaceCheckNAlloc(as, faultAddr))
return; return;
printf("page fault while in thread [%s] at 0x%p when trying to access 0x%p err_code 0x%x\n", current->name,
printf("page fault while in thread [%s] at 0x%x when trying to access 0x%x err_code 0x%x\n", current->name, (void *)cpu_context_get_PC(frame), (void *)faultAddr, cpu_context_get_EX_err(frame));
cpu_context_get_PC(frame), faultAddr, cpu_context_get_EX_err(frame));
if (cpu_context_is_in_user_mode(frame)) { if (cpu_context_is_in_user_mode(frame)) {
printf("Killing User Thread\n"); printf("Killing User Thread\n");
threadExit(); threadExit();

View File

@ -81,7 +81,7 @@ int allocBookSlab(size_t sizeEl, size_t sizeSlab, int selfContained, int neverEm
int ret; int ret;
int flags; int flags;
pr_devel("%s for element of size %lu is self %d\n", __func__, sizeEl, selfContained); pr_devel("%s for element of size %u is self %d\n", __func__, sizeEl, selfContained);
disable_IRQs(flags); disable_IRQs(flags);
list_foreach(slub, slab, slabIdx) list_foreach(slub, slab, slabIdx)
@ -229,7 +229,7 @@ static void *allocFromSlab(struct slabEntry *slab)
vaddr_t *next = slab->freeEl; vaddr_t *next = slab->freeEl;
if (*next == (vaddr_t)NULL) { if (*next == (vaddr_t)NULL) {
pr_devel("Slab @%d is now full\n", slab); pr_devel("Slab @%p is now full\n", slab);
slab->full = 1; slab->full = 1;
} }
slab->freeEl = (void *)(*next); slab->freeEl = (void *)(*next);

View File

@ -191,7 +191,7 @@ int areaAdd(vaddr_t start, vaddr_t end, int isFree)
struct memArea **area; struct memArea **area;
int nbPages = (end - start) / PAGE_SIZE; int nbPages = (end - start) / PAGE_SIZE;
pr_devel("Add %s area 0x%x->0x%x (%d)\n", isFree ? "free" : "used", start, end, nbPages); pr_devel("Add %s area 0x%p->0x%p (%d)\n", isFree ? "free" : "used", (void *)start, (void *)end, nbPages);
assert(nbPages > 0); assert(nbPages > 0);
assert(IS_ALIGNED(start, PAGE_SIZE)); assert(IS_ALIGNED(start, PAGE_SIZE));
@ -258,7 +258,7 @@ int areaFree(vaddr_t addr)
area = areaFindMemArea(usedArea, addr); area = areaFindMemArea(usedArea, addr);
if (!area) { if (!area) {
pr_info("Cannot find memArea associated to %p\n", addr); pr_info("Cannot find memArea associated to %p\n", (void *)addr);
return -1; return -1;
} }

View File

@ -160,7 +160,7 @@ uaddr_t loadElfProg(const char *prog, struct process * proc)
} }
if (elf_phdrs[i].p_vaddr < PAGING_BASE_USER_ADDRESS) { if (elf_phdrs[i].p_vaddr < PAGING_BASE_USER_ADDRESS) {
printf("User program has an incorrect address 0x%x\n", elf_phdrs[i].p_vaddr); printf("User program has an incorrect address 0x%p\n", (void *)elf_phdrs[i].p_vaddr);
return (uaddr_t)NULL; return (uaddr_t)NULL;
} }

View File

@ -447,7 +447,29 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
break; break;
case 'i': case 'i':
case 'd': PRINT_PART(printLint, long int, str, size, c, ret) case 'd': PRINT_PART(printLint, long int, str, size, c, ret)
case 'u': PRINT_PART(printLuint, long unsigned int, str, size, c, ret) case 'u':
PRINT_PART(printLuint, long unsigned int, str, size, c, ret)
case 'p':
case 'x': {
char val[sizeof(int) * 2];
unsigned int valIdx = 0;
long int d = va_arg(ap, long int);
itoa(d, val, 16);
if (str) {
while (val[valIdx]) {
if (size) {
str[c++] = val[valIdx++];
size--;
ret++;
} else {
return ret;
}
}
} else {
ret += strlen(val);
}
break;
}
} }
i++; i++;
break; break;

View File

@ -31,9 +31,9 @@ int strcmp(const char s1[], const char s2[]);
__attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len); __attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len);
int puts(const char *str); int puts(const char *str);
int putc(const char str); int putc(const char str);
int vsnprintf(char *str, size_t size, const char *format, va_list ap); int vsnprintf(char *str, size_t size, const char *format, va_list ap) __attribute__ ((__format__ (printf, 3, 0)));
int vprintf(const char *format, va_list ap); int vprintf(const char *format, va_list ap) __attribute__ ((__format__ (printf, 1, 0)));
int printf(const char *format, ...); int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
// Could be used after malloc is available // Could be used after malloc is available
int asprintf(char **strp, const char *fmt, ...); int asprintf(char **strp, const char *fmt, ...);

View File

@ -164,7 +164,7 @@ void kmain(unsigned long magic, unsigned long addr)
} }
if (CHECK_FLAG(mbi->flags, 9)) { if (CHECK_FLAG(mbi->flags, 9)) {
printf("Loaded by %s. ", mbi->boot_loader_name); printf("Loaded by %s. ", (char *)mbi->boot_loader_name);
} }
/* Is the command line passed? */ /* Is the command line passed? */
@ -215,9 +215,9 @@ void kmain(unsigned long magic, unsigned long addr)
printf("Cannot get memory Mapping information, using default value\n"); printf("Cannot get memory Mapping information, using default value\n");
memAddBank(lastUsedByMem, upperMemKB * 1024, 1); memAddBank(lastUsedByMem, upperMemKB * 1024, 1);
} }
printf("%d pages used by kernel(0x%x->0x%x))", printf("%ld pages used by kernel(0x%lx->0x%lx))",
(lastUsedByMem - firstUsedByMem) / PAGE_SIZE, firstUsedByMem, lastUsedByMem); (lastUsedByMem - firstUsedByMem) / PAGE_SIZE, firstUsedByMem, lastUsedByMem);
printf(" (%d pages for MM)\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end) / PAGE_SIZE); printf(" (%lu pages for MM)\n", (lastUsedByMem - (paddr_t)&__ld_kernel_end) / PAGE_SIZE);
#ifdef RUN_TEST #ifdef RUN_TEST
testPhymem(); testPhymem();

View File

@ -23,7 +23,7 @@ int memSetup(paddr_t upperMemKB, paddr_t *firstUsed, paddr_t *lastMemUsedOut)
upperMemKB = ALIGN_DOWN(upperMemKB, PAGE_SIZE / 1024); upperMemKB = ALIGN_DOWN(upperMemKB, PAGE_SIZE / 1024);
unsigned long nbPage = ((upperMemKB) / (PAGE_SIZE / 1024)); unsigned long nbPage = ((upperMemKB) / (PAGE_SIZE / 1024));
printf("Available Mem from 0x%x to 0x%x: %dMB in %d Pages of %dB\n", &__ld_kernel_end, printf("Available Mem from 0x%lx to 0x%lx: %lu MB in %lu Pages of %dB\n",(paddr_t) &__ld_kernel_end,
upperMemKB * 1024, (upperMemKB * 1024 - (uint32_t)&__ld_kernel_end) / (1024 * 1024), upperMemKB * 1024, (upperMemKB * 1024 - (uint32_t)&__ld_kernel_end) / (1024 * 1024),
nbPage, PAGE_SIZE); nbPage, PAGE_SIZE);

View File

@ -70,9 +70,9 @@ void processListPrint()
list_foreach_named(proc->thList, th, nbTh, prevInProcess, nextInProcess) list_foreach_named(proc->thList, th, nbTh, prevInProcess, nextInProcess)
{ {
if (th == cur) { if (th == cur) {
printf(" th: 0x%x Current\n", th); printf(" th: 0x%lx Current\n", (vaddr_t)th);
} else { } else {
printf(" th: 0x%x in 0x%x\n", th, cpu_context_get_PC(th->cpuState)); printf(" th: 0x%lx in 0x%lx\n", (vaddr_t)th, cpu_context_get_PC(th->cpuState));
} }
} }
} }

View File

@ -42,6 +42,6 @@ void printStackTrace(unsigned int maxFrames)
printf("Must be compiled with -fno-omit-frame-pointer for full stack\n"); printf("Must be compiled with -fno-omit-frame-pointer for full stack\n");
unsigned int *ebp = &maxFrames - 2; unsigned int *ebp = &maxFrames - 2;
unsigned int *eip = ebp + sizeof(unsigned int); unsigned int *eip = ebp + sizeof(unsigned int);
printf("[0] 0x%x\n", eip); printf("[0] 0x%x\n", (unsigned int)eip);
#endif #endif
} }

View File

@ -30,7 +30,7 @@ int mutexFree(struct mutex *m)
if (list_is_empty(m->wait)) { if (list_is_empty(m->wait)) {
#ifdef DEBUG #ifdef DEBUG
if (m->owner) { if (m->owner) {
printf("Warning: freeing a owned mutex 0x%. owned by 0x%p 0x%p\n", m, m->owner, printf("Warning: freeing a owned mutex 0x%p. owned by 0x%p 0x%p\n", m, m->owner,
getCurrentThread()); getCurrentThread());
} }
#endif #endif

View File

@ -5,6 +5,7 @@
#include "klibc.h" #include "klibc.h"
#include "list.h" #include "list.h"
#include "mmuContext.h" #include "mmuContext.h"
#include "process.h"
#include "time.h" #include "time.h"
#include "types.h" #include "types.h"
#include "vga.h" #include "vga.h"
@ -67,7 +68,7 @@ struct thread *threadCreate(const char *name, cpu_kstate_function_arg1_t func, v
return NULL; return NULL;
} }
#ifdef DEBUG #ifdef DEBUG
printf("Alloc stack at 0x%x struct at 0x%x\n", thread->stackAddr, thread); printf("Alloc stack at 0x%p struct at 0x%p\n", (void *)thread->stackAddr, thread);
#endif #endif
thread->stackSize = THREAD_DEFAULT_STACK_SIZE; thread->stackSize = THREAD_DEFAULT_STACK_SIZE;
@ -149,7 +150,7 @@ void threadDelete(struct thread *thread)
processRemoveThread(thread); processRemoveThread(thread);
#ifdef DEBUG #ifdef DEBUG
printf("Free stack at 0x%x struct at 0x%x\n", thread->stackAddr, thread); printf("Free stack at 0x%p struct at 0x%p\n", (void *)thread->stackAddr, thread);
#endif #endif
free((void *)thread->stackAddr); free((void *)thread->stackAddr);
free((void *)thread); free((void *)thread);
@ -298,7 +299,7 @@ int threadMsleep(unsigned long msec)
disable_IRQs(flags); disable_IRQs(flags);
current = currentThread; current = currentThread;
assertmsg(current->state == RUNNING, "thread %s is in state %d for %d\n", current->name, assertmsg(current->state == RUNNING, "thread %s is in state %d for %lu\n", current->name,
current->state, msec); current->state, msec);
current->state = SLEEPING; current->state = SLEEPING;

View File

@ -113,7 +113,7 @@ uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop)
int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr) int uAddrSpaceCheckNAlloc(struct uAddrSpace *as, vaddr_t addr)
{ {
pr_devel("Checking %p inside %p and %p\n", addr, as->heapStart, as->heapStart +as->heapSize); pr_devel("Checking %lx inside %lx and %lx\n", addr, as->heapStart, as->heapStart +as->heapSize);
if (addr < as->heapStart || addr >= as->heapStart + as->heapSize) { if (addr < as->heapStart || addr >= as->heapStart + as->heapSize) {
return -1; return -1;
} }

View File

@ -69,8 +69,8 @@ void testPhymem(void)
assert((usedPageStatAlloc - usedPageStatBegin) == (uint)allocCount); assert((usedPageStatAlloc - usedPageStatBegin) == (uint)allocCount);
while ((allocated_page_list != NULL) && (page = list_pop_head(allocated_page_list)) != NULL) { while ((allocated_page_list != NULL) && (page = list_pop_head(allocated_page_list)) != NULL) {
assertmsg(page->phy_addr == (ulong)freeCount, "page %d modified", page); assertmsg(page->phy_addr == (ulong)freeCount, "page %p modified", page);
assertmsg(unrefPhyPage((ulong)page) >= 0, "Failed to free page %d\n", (ulong)page); assertmsg(unrefPhyPage((ulong)page) >= 0, "Failed to free page %p\n", page);
freeCount++; freeCount++;
} }
printf("%d pages freed\n", freeCount); printf("%d pages freed\n", freeCount);
@ -117,7 +117,7 @@ void testAlloc(void)
assert((char *)malloc2 == ((char *)malloc1 + sizeof(void *))); assert((char *)malloc2 == ((char *)malloc1 + sizeof(void *)));
free(malloc2); free(malloc2);
void *malloc3 = malloc(sizeof(void *)); void *malloc3 = malloc(sizeof(void *));
assertmsg((char *)malloc2 == (char *)malloc3, " %d %d\n", malloc2, malloc3); assertmsg((char *)malloc2 == (char *)malloc3, " %p %p\n", malloc2, malloc3);
free(malloc1); free(malloc1);
free(malloc3); free(malloc3);
void *alloc1 = testAllocNSet(1024); void *alloc1 = testAllocNSet(1024);
@ -169,8 +169,8 @@ void testPaging(void)
while (!list_is_empty(allocated_page_list) && while (!list_is_empty(allocated_page_list) &&
(page = list_pop_head(allocated_page_list)) != NULL) { (page = list_pop_head(allocated_page_list)) != NULL) {
assertmsg((char)page->phy_addr == (char)freeCount, "page modified %d but is %d\n", assertmsg((char)page->phy_addr == (char)freeCount, "page modified %d but is %p\n",
freeCount, page->phy_addr); freeCount, (void *)page->phy_addr);
areaFree((vaddr_t)page); areaFree((vaddr_t)page);
freeCount++; freeCount++;
} }
@ -305,7 +305,7 @@ void sleepThread(void *arg)
threadMsleep(100); threadMsleep(100);
} }
unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies); unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies);
assertmsg(ellapsedTime >= 500 && ellapsedTime < 510, "ellapsedTime %d\n", ellapsedTime); assertmsg(ellapsedTime >= 500 && ellapsedTime < 510, "ellapsedTime %lu\n", ellapsedTime);
threadMsleep(0); threadMsleep(0);
printf("I should never be showed\n"); printf("I should never be showed\n");
assert(1); assert(1);

View File

@ -443,7 +443,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
{ {
int n = 0; int n = 0;
size_t size = 0; size_t size = 0;
char p[256]; //TODO replace by malloc char *p = malloc(256);
/* Determine required size */ /* Determine required size */

View File

@ -24,13 +24,13 @@ int strcmp(const char s1[], const char s2[]);
__attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len); __attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len);
int puts(const char *str); int puts(const char *str);
int putc(const int c); int putc(const int c);
int vsnprintf(char *str, size_t size, const char *format, va_list ap); int vsnprintf(char *str, size_t size, const char *format, va_list ap) __attribute__ ((__format__ (printf, 3, 0)));
int vprintf(const char *format, va_list ap); int vprintf(const char *format, va_list ap) __attribute__ ((__format__ (printf, 1, 0)));
int printf(const char *format, ...); int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
// Could be used after malloc is available // Could be used after malloc is available
int asprintf(char **strp, const char *fmt, ...); int asprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__ (printf, 2, 3)));
int vasprintf(char **strp, const char *fmt, va_list ap); int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__ ((__format__ (printf, 2, 0)));
int syscall5(int id, unsigned int arg1, unsigned int arg2, unsigned int arg3, int syscall5(int id, unsigned int arg1, unsigned int arg2, unsigned int arg3,
unsigned int arg4, unsigned int arg5); unsigned int arg4, unsigned int arg5);