Compare commits

..

No commits in common. "70366fa7be99ee9477448b94f671728916ea702b" and "0688afa76d144d79270ebd7c00babc00008ba269" have entirely different histories.

8 changed files with 52 additions and 97 deletions

View File

@ -5,14 +5,13 @@
#include "list.h" #include "list.h"
#include "mmuContext.h" #include "mmuContext.h"
#include "types.h" #include "types.h"
#include "thread.h"
#include "uaddrspace.h" #include "uaddrspace.h"
struct process { struct process {
char name[PROCESS_NAME_MAX_LENGTH]; char name[PROCESS_NAME_MAX_LENGTH];
int ref; int ref;
pid_t pid; int pid;
pid_t nextTid; int nextTid;
struct uAddrSpace *addrSpace; struct uAddrSpace *addrSpace;
struct thread *thList; struct thread *thList;
@ -69,7 +68,7 @@ void processListPrint()
struct thread *th; struct thread *th;
int nbTh; int nbTh;
printf("%lu %s %d %d\n", proc->pid, proc->name, processCountThread(proc), proc->ref); printf("%d %s %d %d\n", proc->pid, proc->name, processCountThread(proc), proc->ref);
list_foreach_named(proc->thList, th, nbTh, prevInProcess, nextInProcess) list_foreach_named(proc->thList, th, nbTh, prevInProcess, nextInProcess)
{ {
if (th == cur) { if (th == cur) {
@ -184,10 +183,10 @@ int processInitHeap(struct process *proc, uaddr_t lastUserAddr){
return uAddrSpaceSetHeap(proc->addrSpace, lastUserAddr, 0); return uAddrSpaceSetHeap(proc->addrSpace, lastUserAddr, 0);
} }
pid_t processGetId(struct process *proc){ int processGetId(struct process *proc){
return proc->pid; return proc->pid;
} }
pid_t processGetNextTid(struct process *proc){ int processGetNextTid(struct process *proc){
return proc->nextTid++; return proc->nextTid++;
} }

View File

@ -1,11 +1,9 @@
#pragma once #pragma once
#include "types.h" #include "thread.h"
#define PROCESS_NAME_MAX_LENGTH 32 #define PROCESS_NAME_MAX_LENGTH 32
typedef unsigned long int pid_t;
struct process; struct process;
struct thread;
int processSetup(); int processSetup();
struct process *processCreate(char *name); struct process *processCreate(char *name);
@ -20,5 +18,5 @@ int processRemoveThread(struct thread *th);
struct mmu_context *processGetMMUContext(struct process *th); struct mmu_context *processGetMMUContext(struct process *th);
struct uAddrSpace *processGetAddrSpace(struct process *proc); struct uAddrSpace *processGetAddrSpace(struct process *proc);
int processInitHeap(struct process *proc, uaddr_t lastUserAddr); int processInitHeap(struct process *proc, uaddr_t lastUserAddr);
pid_t processGetId(struct process *proc); int processGetId(struct process *proc);
pid_t processGetNextTid(struct process *proc); int processGetNextTid(struct process *proc);

View File

@ -14,7 +14,7 @@ static struct thread *currentThread;
static struct thread *threadWithTimeout; static struct thread *threadWithTimeout;
static thread_id_t nextTid; // This is the TID for kernel thread ONLY static thread_id_t nextTid; // This is the TID for kernel thread ONLY
pid_t threadGetId(struct thread *th) thread_id_t threadGetId(struct thread *th)
{ {
return th->tid; return th->tid;
} }

View File

@ -1,9 +1,8 @@
#pragma once #pragma once
#include "mmuContext.h" #include "mmuContext.h"
#include "process.h" #include "process.h"
#include "stddef.h"
#include "stdint.h"
#include "types.h" #include "types.h"
#include <stddef.h>
struct uAddrSpace; struct uAddrSpace;
struct uAddrVirtualReg; struct uAddrVirtualReg;

View File

@ -3,7 +3,6 @@
#include "alloc.h" #include "alloc.h"
#include "kernel.h" #include "kernel.h"
#include "klibc.h" #include "klibc.h"
#include "mem.h"
struct zeroMappedEntry { struct zeroMappedEntry {
int refCnt; int refCnt;

View File

@ -265,57 +265,8 @@ int puts(const char *str)
return ret; \ 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(Int, int);
PRINT_INT(Lint, long int); PRINT_INT(Int64, long 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) int vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ {
@ -323,13 +274,24 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
int i = 0; int i = 0;
int c = 0; int c = 0;
while (format[i] != '\0' && (size|| !str)) { while (format[i] != '\0' && (size || !str)) {
switch (format[i]) { switch (format[i]) {
case '%': case '%':
switch (format[i + 1]) { switch (format[i + 1]) {
case 'i': case 'i':
case 'd': PRINT_PART(printInt, int, str, size, c, ret) case 'd': {
case 'u': PRINT_PART(printUint, uint, str, size, c, ret) 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 'p': case 'p':
case 'x': { case 'x': {
char val[sizeof(int) * 2]; char val[sizeof(int) * 2];
@ -390,15 +352,24 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
switch (format[i + 2]) { switch (format[i + 2]) {
case 'l': case 'l':
switch (format[i + 3]) { switch (format[i + 3]) {
case 'i': case 'd': {
case 'd': PRINT_PART(printLlint, long long int, str, size, c, ret) int s;
case 'u': PRINT_PART(printLluint, long long unsigned int, str, size, c, ret) 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 'p': case 'p':
case 'x': { case 'x': {
char val[sizeof(long long int) * 2]; char val[sizeof(long long int) * 2];
unsigned int valIdx = 0; unsigned int valIdx = 0;
unsigned long long int d = long long int d = va_arg(ap, long long int);
va_arg(ap, unsigned long long int);
itoa(d, val, 16); itoa(d, val, 16);
if (str) { if (str) {
while (val[valIdx]) { while (val[valIdx]) {
@ -419,28 +390,17 @@ int vsnprintf(char *str, size_t size, const char *format, va_list ap)
i++; i++;
break; break;
case 'i': case 'i':
case 'd': PRINT_PART(printLint, long int, str, size, c, ret) case 'd': {
case 'u': int s;
PRINT_PART(printLuint, long unsigned int, str, size, c, ret) long int d = va_arg(ap, long int);
case 'p': if (str)
case 'x': { s = printInt64(d, &str[c], size);
char val[sizeof(int) * 2]; else
unsigned int valIdx = 0; s = printInt64(d, NULL, size);
unsigned long int d = va_arg(ap, unsigned long int);
itoa(d, val, 16); size -= s;
if (str) { c += s;
while (val[valIdx]) { ret += s;
if (size) {
str[c++] = val[valIdx++];
size--;
ret++;
} else {
return ret;
}
}
} else {
ret += strlen(val);
}
break; break;
} }
} }

View File

@ -123,7 +123,7 @@ int func_munmap()
static void *print_hello(void *arg) { static void *print_hello(void *arg) {
(void)arg; (void)arg;
printf("Hello World from thread %lu\n", gettid()); printf("Hello World from thread %d\n", gettid());
usleep(100); usleep(100);
return NULL; return NULL;

View File

@ -3,4 +3,4 @@
typedef unsigned int useconds_t; typedef unsigned int useconds_t;
int usleep(useconds_t usec); int usleep(useconds_t usec);
typedef unsigned long int pid_t; typedef int pid_t;