Skip to content

Commit

Permalink
Cleanup userspace headers (#66)
Browse files Browse the repository at this point in the history
* General cleanup of userspace headers
* Ensure all definitions visible to userspace starts with `jinue_` or
`JINUE_`.
* Rename a few files for consistency.
  • Loading branch information
phaubertin authored Oct 21, 2024
1 parent 57b0f94 commit c3bef3a
Show file tree
Hide file tree
Showing 69 changed files with 263 additions and 254 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"compilerPath": "/usr/bin/clang",
"cStandard": "c99",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
"intelliSenseMode": "linux-clang-x86"
}
],
"version": 4
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"makefile.configureOnOpen": false,
"files.associations": {
"*.h": "c"
}
},
"C_Cpp.default.intelliSenseMode": "linux-gcc-x86"
}
3 changes: 2 additions & 1 deletion header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ endif
#
# These flags are used when preprocessing C and assembly language files.
CPPFLAGS.includes = -I$(includes)
CPPFLAGS.arch = -m32 -march=i686
CPPFLAGS.others = -nostdinc
CPPFLAGS = $(CPPFLAGS.includes) $(CPPFLAGS.debug) $(CPPFLAGS.others) $(CPPFLAGS.extra)
CPPFLAGS = $(CPPFLAGS.arch) $(CPPFLAGS.includes) $(CPPFLAGS.debug) $(CPPFLAGS.others) $(CPPFLAGS.extra)

# C compiler flags
CFLAGS.warnings = -std=c99 -pedantic -Wall -Werror=implicit -Werror=uninitialized -Werror=return-type
Expand Down
5 changes: 2 additions & 3 deletions include/jinue/jinue.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
#define _JINUE_JINUE_H

#include <jinue/shared/asm/errno.h>
#include <jinue/shared/asm/machine.h>
#include <jinue/shared/asm/memory.h>
#include <jinue/shared/asm/permissions.h>
#include <jinue/shared/ipc.h>
#include <jinue/shared/syscall.h>
#include <jinue/shared/asm/syscalls.h>
#include <jinue/shared/types.h>
#include <jinue/shared/vm.h>
#include <stddef.h>
#include <stdint.h>

Expand Down
12 changes: 10 additions & 2 deletions include/jinue/shared/asm/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,34 @@
#ifndef _JINUE_SHARED_ASM_ERRNO_H
#define _JINUE_SHARED_ASM_ERRNO_H

/** not enough space */
#define JINUE_ENOMEM 1

/** function not supported */
#define JINUE_ENOSYS 2

/** invalid argument */
#define JINUE_EINVAL 3

/** resource unavailable, try again */
#define JINUE_EAGAIN 4

/** bad descriptor */
#define JINUE_EBADF 5

/** I/O error */
#define JINUE_EIO 6

/** operation not permitted */
#define JINUE_EPERM 7

/** argument list too long */
#define JINUE_E2BIG 8

/** no message of the desired type */
#define JINUE_ENOMSG 9

/** not supported */
#define JINUE_ENOTSUP 10

#define _JINUE_ELAST 10

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,43 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _JINUE_KERNEL_I686_ASM_SHARED_H
#define _JINUE_KERNEL_I686_ASM_SHARED_H
#ifndef _JINUE_SHARED_ASM_I686_H
#define _JINUE_SHARED_ASM_I686_H

/* This file contains machine-specific definitions that need to be visible
/** This file contains machine-specific definitions that need to be visible
* outside the machine-specific parts of the code, both in user space and
* the kernel. */
* the kernel.
*
* It is OK to include this file from i686-specific code in the kernel.
* Otherwise, it should be included through either <jinue/jinue.h> or
* or <kernel/types.h> (which includes <kernel/machine/types.h>). */


/** number of bits in virtual address for offset inside page */
#define PAGE_BITS 12
/** number of bits in a virtual address that represent the offset within a page */
#define JINUE_PAGE_BITS 12

/** size of page */
#define PAGE_SIZE (1<<PAGE_BITS) /* 4096 */
/** size of a page */
#define JINUE_PAGE_SIZE (1<<JINUE_PAGE_BITS) /* 4096 */

/** bit mask for offset in page */
#define PAGE_MASK (PAGE_SIZE - 1)
/** bit mask for offset in a page */
#define JINUE_PAGE_MASK (JINUE_PAGE_SIZE - 1)

/** The virtual address range starting at KLIMIT is reserved by the kernel. The
region above KLIMIT has the same mapping in all address spaces. KLIMIT must
be aligned on a page directory boundary in PAE mode. */
#define KLIMIT 0xc0000000
/** The virtual address range starting at JINUE_KLIMIT is reserved by the
* kernel. The region above JINUE_KLIMIT has the same mapping in all address
* spaces. JINUE_KLIMIT must be aligned on a page directory boundary in PAE
* mode. */
#define JINUE_KLIMIT 0xc0000000

/** stack base address (stack top) */
#define STACK_BASE KLIMIT
#define JINUE_STACK_BASE JINUE_KLIMIT

/** initial stack size */
#define STACK_SIZE (128 * KB)
#define JINUE_STACK_SIZE (128 * 1024)

/** stack portion reserved for environment, arguments and auxiliary vectors */
#define RESERVED_STACK_SIZE (32 * KB)
#define JINUE_RESERVED_STACK_SIZE (32 * 1024)

/** initial stack lower address */
#define STACK_START (STACK_BASE - STACK_SIZE)
#define JINUE_STACK_START (JINUE_STACK_BASE - JINUE_STACK_SIZE)

#endif
4 changes: 1 addition & 3 deletions include/jinue/shared/asm/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
#ifndef _JINUE_SHARED_ASM_IPC_H
#define _JINUE_SHARED_ASM_IPC_H

#include <jinue/shared/asm/types.h>

/** maximum size of a message */
#define JINUE_MAX_MESSAGE_SIZE 2048

/** maximum size of a send or receive buffer */
#define JINUE_MAX_BUFFER_SIZE (64 * MB)
#define JINUE_MAX_BUFFER_SIZE (64 * 1024 * 1024)

/** maximum number of buffers in a buffer array */
#define JINUE_MAX_BUFFERS_IN_ARRAY 256
Expand Down
6 changes: 4 additions & 2 deletions include/jinue/shared/asm/machine.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Philippe Aubertin.
* Copyright (C) 2024 Philippe Aubertin.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,8 @@
#ifndef _JINUE_SHARED_ASM_MACHINE_H
#define _JINUE_SHARED_ASM_MACHINE_H

#include <kernel/infrastructure/i686/asm/shared.h>
#ifdef __i686__
#include <jinue/shared/asm/i686.h>
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _JINUE_SHARED_ASM_SYSCALL_H
#define _JINUE_SHARED_ASM_SYSCALL_H
#ifndef _JINUE_SHARED_ASM_SYSCALLS_H
#define _JINUE_SHARED_ASM_SYSCALLS_H

/** interrupt vector for system call software interrupt */
#define JINUE_SYSCALL_IRQ 0x80
Expand Down
60 changes: 0 additions & 60 deletions include/jinue/shared/ipc.h

This file was deleted.

65 changes: 0 additions & 65 deletions include/jinue/shared/syscall.h

This file was deleted.

49 changes: 47 additions & 2 deletions include/jinue/shared/types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Philippe Aubertin.
* Copyright (C) 2019-2024 Philippe Aubertin.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,10 +32,55 @@
#ifndef _JINUE_SHARED_TYPES_H
#define _JINUE_SHARED_TYPES_H

#include <jinue/shared/asm/types.h>
#include <stddef.h>
#include <stdint.h>

/** Arguments and return values for system calls
*
* When invoking a system call, arg0 contains the call number and arg1 to arg3
* contain the arguments for the call. Call numbers SYSCALL_USER_BASE and up all
* identify the send system call and the call number is passed to the message
* recipient.
*
* On return from a system call, the contents of arg0 to arg3 depends on the
* call. Most, but not all, system calls follow the following convention:
*
* - arg0 contains a return value which should be cast as a signed integer
* (type int - see jinue_get_return()). If the value is positive (including
* zero), then the call was successful. A non-zero negative value indicates
* an error has occurred.
* - If the call failed, as indicated by the value in arg0, arg1 contains the
* error number.
* - arg2 and arg3 are reserved and should be ignored.
*
* */
typedef struct {
uintptr_t arg0;
uintptr_t arg1;
uintptr_t arg2;
uintptr_t arg3;
} jinue_syscall_args_t;

typedef struct {
void *addr;
size_t size;
} jinue_buffer_t;

typedef struct {
const void *addr;
size_t size;
} jinue_const_buffer_t;

typedef struct {
const jinue_const_buffer_t *send_buffers;
size_t send_buffers_length;
const jinue_buffer_t *recv_buffers;
size_t recv_buffers_length;
uintptr_t recv_function;
uintptr_t recv_cookie;
uintptr_t reply_max_size;
} jinue_message_t;

typedef struct {
uint64_t addr;
uint64_t size;
Expand Down
4 changes: 2 additions & 2 deletions include/jinue/util.h → include/jinue/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _JINUE_UTIL_H
#define _JINUE_UTIL_H
#ifndef _JINUE_UTILS_H
#define _JINUE_UTILS_H

#include <stdarg.h>

Expand Down
3 changes: 2 additions & 1 deletion include/kernel/domain/alloc/slab.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#ifndef JINUE_KERNEL_DOMAIN_SLAB_H
#define JINUE_KERNEL_DOMAIN_SLAB_H

#include <jinue/shared/vm.h>
#include <kernel/machine/asm/machine.h>
#include <kernel/utils/vm.h>
#include <kernel/types.h>

#define SLAB_SIZE PAGE_SIZE
Expand Down
Loading

0 comments on commit c3bef3a

Please sign in to comment.