Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String cleanups #330

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arch/x86/ioapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int __get_system_bus_name(uint8_t bus_name[IOAPIC_SYSTEM_BUS_NAME_SIZE],
return -EINVAL;

memset(bus_name, ' ', IOAPIC_SYSTEM_BUS_NAME_SIZE);
memcpy(bus_name, (char *) name, namelen);
memcpy(bus_name, name, namelen);
return 0;
}

Expand Down
32 changes: 20 additions & 12 deletions common/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,39 @@ void register_console_callback(console_callback_t cb, void *arg) {
console_callbacks[num_console_callbacks++].arg = arg;
}

void __noreturn panic(const char *fmt, ...) {
va_list args;
static void oops_print(const char *fmt, va_list args, const char *type) {
static const char stars[] = "***********************************";
size_t slen = sizeof(stars) - 1;
size_t tlen = strlen(type);
int s1_len, s2_len;

if (tlen > slen - 4)
tlen = slen - 4;
minipli-oss marked this conversation as resolved.
Show resolved Hide resolved

printk("************** PANIC **************\n");
s1_len = (slen - tlen - 2) / 2;
s2_len = slen - tlen - 2 - s1_len;

printk("%.*s %s %.*s\n", s1_len, stars, type, s2_len, stars);
printk("CPU[%u]: ", smp_processor_id());
vprintk(fmt, args);
printk("\n%s\n", stars);
}

void panic(const char *fmt, ...) {
va_list args;

va_start(args, fmt);
vprintk(fmt, args);
oops_print(fmt, args, "PANIC");
va_end(args);

printk("\n***********************************\n");

while (1)
halt();
}

void warning(const char *fmt, ...) {
va_list args;

printk("************* WARNING *************\n");
printk("CPU[%u]: ", smp_processor_id());

va_start(args, fmt);
vprintk(fmt, args);
oops_print(fmt, args, "WARNING");
va_end(args);

printk("\n***********************************\n");
}
2 changes: 1 addition & 1 deletion include/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extern void fb_console_write(void *arg, const char *buf, size_t len);

extern void register_console_callback(console_callback_t func, void *arg);

extern void panic(const char *fmt, ...);
extern void panic(const char *fmt, ...) __noreturn;
extern void warning(const char *fmt, ...);

#endif /* KTF_CONSOLE_H */
18 changes: 10 additions & 8 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static inline void *memset(void *s, int c, size_t n) {
return s;
}

static inline void *memcpy(void *d, void *s, size_t n) {
static inline void *memcpy(void *d, const void *s, size_t n) {
unsigned long d0;

/* clang-format off */
Expand All @@ -138,7 +138,7 @@ static inline void *memmove(void *d, const void *s, size_t n) {

/* if we don't have a range overlap, just use memcpy */
if ((d > s && d > s + n) || (d < s && d + n < s)) {
return memcpy(d, (void *) s, n);
return memcpy(d, s, n);
}

/*
Expand All @@ -156,7 +156,7 @@ static inline void *memmove(void *d, const void *s, size_t n) {
* d -----
* normal copy
*/
return memcpy(d, (void *) s, n);
return memcpy(d, s, n);

return d;
}
Expand Down Expand Up @@ -263,16 +263,18 @@ static inline int string_equal(const char *s1, const char *s2) {
}

static inline char *strdup(const char *s1) {
size_t len;
char *s2;

if (string_empty(s1))
if (!s1)
return NULL;

s2 = (char *) kmalloc(strlen(s1) + 1);
if (!s2)
return NULL;
len = strlen(s1) + 1;
s2 = kmalloc(len);
if (s2)
memcpy(s2, s1, len);

return strcpy(s2, s1);
return s2;
}

static inline size_t strspn(const char *s1, const char *s2) {
Expand Down
Loading