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

View File

@ -81,7 +81,7 @@ int allocBookSlab(size_t sizeEl, size_t sizeSlab, int selfContained, int neverEm
int ret;
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);
list_foreach(slub, slab, slabIdx)
@ -229,7 +229,7 @@ static void *allocFromSlab(struct slabEntry *slab)
vaddr_t *next = slab->freeEl;
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->freeEl = (void *)(*next);

View File

@ -191,7 +191,7 @@ int areaAdd(vaddr_t start, vaddr_t end, int isFree)
struct memArea **area;
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(IS_ALIGNED(start, PAGE_SIZE));
@ -258,7 +258,7 @@ int areaFree(vaddr_t addr)
area = areaFindMemArea(usedArea, addr);
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;
}

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) {
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;
}

View File

@ -447,7 +447,29 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
break;
case 'i':
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++;
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);
int puts(const char *str);
int putc(const char str);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int vprintf(const char *format, va_list ap);
int printf(const char *format, ...);
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) __attribute__ ((__format__ (printf, 1, 0)));
int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
// Could be used after malloc is available
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)) {
printf("Loaded by %s. ", mbi->boot_loader_name);
printf("Loaded by %s. ", (char *)mbi->boot_loader_name);
}
/* 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");
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);
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
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);
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),
nbPage, PAGE_SIZE);

View File

@ -70,9 +70,9 @@ void processListPrint()
list_foreach_named(proc->thList, th, nbTh, prevInProcess, nextInProcess)
{
if (th == cur) {
printf(" th: 0x%x Current\n", th);
printf(" th: 0x%lx Current\n", (vaddr_t)th);
} 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");
unsigned int *ebp = &maxFrames - 2;
unsigned int *eip = ebp + sizeof(unsigned int);
printf("[0] 0x%x\n", eip);
printf("[0] 0x%x\n", (unsigned int)eip);
#endif
}

View File

@ -30,7 +30,7 @@ int mutexFree(struct mutex *m)
if (list_is_empty(m->wait)) {
#ifdef DEBUG
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());
}
#endif

View File

@ -5,6 +5,7 @@
#include "klibc.h"
#include "list.h"
#include "mmuContext.h"
#include "process.h"
#include "time.h"
#include "types.h"
#include "vga.h"
@ -67,7 +68,7 @@ struct thread *threadCreate(const char *name, cpu_kstate_function_arg1_t func, v
return NULL;
}
#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
thread->stackSize = THREAD_DEFAULT_STACK_SIZE;
@ -149,7 +150,7 @@ void threadDelete(struct thread *thread)
processRemoveThread(thread);
#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
free((void *)thread->stackAddr);
free((void *)thread);
@ -298,7 +299,7 @@ int threadMsleep(unsigned long msec)
disable_IRQs(flags);
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 = SLEEPING;

View File

@ -113,7 +113,7 @@ uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop)
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) {
return -1;
}

View File

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

View File

@ -443,7 +443,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap)
{
int n = 0;
size_t size = 0;
char p[256]; //TODO replace by malloc
char *p = malloc(256);
/* 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);
int puts(const char *str);
int putc(const int c);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int vprintf(const char *format, va_list ap);
int printf(const char *format, ...);
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) __attribute__ ((__format__ (printf, 1, 0)));
int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
// Could be used after malloc is available
int asprintf(char **strp, const char *fmt, ...);
int vasprintf(char **strp, const char *fmt, va_list ap);
int asprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__ (printf, 2, 3)));
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,
unsigned int arg4, unsigned int arg5);