Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 9076 → Rev 9075

/programs/develop/libraries/kos_mbedtls/README.md
0,0 → 1,0
#### port of mbedtls-2.16.6 library for KolibriOS
/programs/develop/libraries/kos_mbedtls/howto.md
0,0 → 1,5
on windows:
- how to build mdebtls static library:
- cd to library/
- to build: mingw32-make
- to clean: mingw32-make clean WINDOWS=1
/programs/develop/libraries/kos_mbedtls/include/CMakeLists.txt
0,0 → 1,16
option(INSTALL_MBEDTLS_HEADERS "Install mbed TLS headers." ON)
 
if(INSTALL_MBEDTLS_HEADERS)
 
file(GLOB headers "mbedtls/*.h")
 
install(FILES ${headers}
DESTINATION include/mbedtls
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
 
endif(INSTALL_MBEDTLS_HEADERS)
 
# Make config.h available in an out-of-source build. ssl-opt.sh requires it.
if (ENABLE_TESTING AND NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
link_to_source(mbedtls)
endif()
/programs/develop/libraries/kos_mbedtls/kosnet/Makefile
0,0 → 1,37
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
 
CC = kos32-gcc
AR = kos32-ar
 
CFLAGS ?= -O2
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
LDFLAGS ?=
 
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I $(NEWLIB_INCLUDES) -I include -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =
 
AR_DASH ?= -
ARFLAGS = $(AR_DASH)src
 
OBJS= socket.o network.o dlfcn.o
 
.PHONY: all static clean
 
all: static
 
static: libkosnet.a
 
libkosnet.a: $(OBJS)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS)
 
.c.o:
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
 
clean:
ifndef WINDOWS
rm -f *.o libkosnet.a
else
del /Q /F *.o libkosnet.a
endif
/programs/develop/libraries/kos_mbedtls/kosnet/dlfcn.c
0,0 → 1,92
#include <stdlib.h>
#include <string.h>
 
#include "kosnet/dlfcn.h"
#include "kosnet/kos32sys1.h"
 
typedef struct {
char *name;
void *ptr;
} KosExp;
 
typedef struct {
void **importNames;
char * libraryName;
} KosImp;
 
static int __attribute__ ((stdcall)) dll_Load(KosImp *importTableEntry);
 
static const char *__error;
 
static int __attribute__ ((stdcall)) dll_Load(KosImp *importTableEntry) {
for (; importTableEntry->importNames; importTableEntry++) {
char libPath[256] = "/sys/lib/";
KosExp *exports = NULL;
void **libImports = importTableEntry->importNames;
strcat(libPath, importTableEntry->libraryName);
if (!(exports = dlopen(libPath, 0))) { return 1; }
for (; *libImports; libImports++) {
if (!(*libImports = dlsym(exports, *libImports))) { return 1; }
}
}
return 0;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlopen.html
// Current implementation fully ignores "mode" parameter
void *dlopen(const char *name, int mode) {
KosExp *exports = NULL;
 
// load library using syscall
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(name));
if (!exports) {
char libPath[256] = "/sys/lib/";
 
strcat(libPath, name);
asm volatile ("int $0x40":"=a"(exports):"a"(68), "b"(19), "c"(libPath));
if (!exports) {
__error = "Library not found in \"/sys/lib/\" nor current folder";
return NULL;
}
}
// call anything starting with "lib_"
for (KosExp *export = exports; export->name; export++) {
if (!memcmp(export->name, "lib_", 4)) {
asm volatile (
"call *%4" ::
"a"(0),
"b"(0),
"c"(0),
"d"(dll_Load),
"r"(export->ptr));
// was asm volatile ("call *%4" ::"a"(sysmalloc),"b"(sysfree),"c"(sysrealloc),"d"(dll_Load),"r"(export->ptr));
}
}
return exports;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
void *dlsym(void *handle, const char *name) {
KosExp *exp = handle;
 
for (; exp->name; exp++) {
if (!strcmp(exp->name, name)) {
return exp->ptr;
}
}
__error = "Symbol not found";
return NULL;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlclose.html
int dlclose(void *handle) {
return 0;
}
 
// https://pubs.opengroup.org/onlinepubs/007908799/xsh/dlerror.html
char *dlerror(void) {
char *ret = __error ? strdup(__error) : NULL;
__error = NULL;
return ret;
}
/programs/develop/libraries/kos_mbedtls/kosnet/include/kosnet/dlfcn.h
0,0 → 1,14
#ifndef _DLFCN_H
#define _DLFCN_H
 
#define RTLD_LAZY 0x00001
#define RTLD_NOW 0x00002
#define RTLD_GLOBAL 0x00100
#define RTLD_LOCAL 0
 
int dlclose(void *handle);
char *dlerror(void);
void *dlopen(const char *name, int mode);
void *dlsym(void *restrict handle, const char *restrict name);
 
#endif
/programs/develop/libraries/kos_mbedtls/kosnet/include/kosnet/kos32sys1.h
0,0 → 1,836
#ifndef __KOS_32_SYS_H__
#define __KOS_32_SYS_H__
 
#include <stddef.h>
#include <stdarg.h>
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned long long uint64_t;
 
#ifdef __cplusplus
extern "C" {
#endif
 
#define TYPE_3_BORDER_WIDTH 5
#define WIN_STATE_MINIMIZED 0x02
#define WIN_STATE_ROLLED 0x04
#define POS_SCREEN 0
#define POS_WINDOW 1
 
#define IPC_NOBUFFER 1
#define IPC_LOCKED 2
#define IPC_OVERFLOW 3
#define IPC_NOPID 4
 
#define SHM_OPEN 0x00
#define SHM_OPEN_ALWAYS 0x04
#define SHM_CREATE 0x08
#define SHM_READ 0x00
#define SHM_WRITE 0x01
// for clipboard funtions
#define UTF 0
#define CP866 1
#define CP1251 2
#define TEXT 0
#define IMAGE 1
#define RAW 2
 
//Read/Write data as type (int char, etc.) at address "addr" with offset "offset". eg DATA(int, buff, 8);
#define DATA(type, addr, offset) *((type*)((uint8_t*)addr+offset))
 
typedef struct {
uint8_t blue;
uint8_t green;
uint8_t red;
}RGB;
typedef unsigned int color_t;
 
typedef union __attribute__((packed)) pos_t
{
uint32_t val;
struct
{
short x;
short y;
};
} pos_t;
 
 
typedef union __attribute__((packed)) oskey_t
{
uint32_t val;
struct
{
uint8_t state;
uint8_t code;
uint16_t ctrl_key;
};
} oskey_t;
 
typedef struct
{
unsigned handle;
unsigned io_code;
void *input;
int inp_size;
void *output;
int out_size;
}ioctl_t;
 
typedef union
{
struct
{
void *data;
size_t size;
} x;
unsigned long long raw;
}ufile_t;
 
struct kolibri_system_colors {
color_t frame_area;
color_t grab_bar;
color_t grab_bar_button;
color_t grab_button_text;
color_t grab_text;
color_t work_area;
color_t work_button;
color_t work_button_text;
color_t work_text;
color_t work_graph;
};
 
 
struct blit_call
{
int dstx;
int dsty;
int w;
int h;
 
int srcx;
int srcy;
int srcw;
int srch;
 
void *bitmap;
int stride;
};
 
struct ipc_message
{
uint32_t pid; // PID of sending thread
uint32_t datalen; // data bytes
char data[0]; // data begin
};
 
struct ipc_buffer
{
uint32_t lock; // nonzero is locked
uint32_t used; // used bytes in buffer
struct ipc_message data[0]; // data begin
};
static inline void begin_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(1));
};
 
static inline
void end_draw(void)
{
__asm__ __volatile__(
"int $0x40" ::"a"(12),"b"(2));
};
 
static inline
void sys_create_window(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
{
__asm__ __volatile__(
"int $0x40"
::"a"(0),
"b"((x << 16) | ((w-1) & 0xFFFF)),
"c"((y << 16) | ((h-1) & 0xFFFF)),
"d"((style << 24) | (workcolor & 0xFFFFFF)),
"D"(name),
"S"(0) : "memory");
};
 
static inline
void sys_change_window(int new_x, int new_y, int new_w, int new_h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
);
}
 
 
static inline
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(8),
"b"(x_w),
"c"(y_h),
"d"(id),
"S"(color));
};
 
static inline
void draw_line(int xs, int ys, int xe, int ye, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(38), "d"(color),
"b"((xs << 16) | xe),
"c"((ys << 16) | ye));
}
 
static inline
void draw_bar(int x, int y, int w, int h, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(13), "d"(color),
"b"((x << 16) | w),
"c"((y << 16) | h));
}
 
static inline
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
__asm__ __volatile__(
"int $0x40"
::"a"(7), "b"(bitmap),
"c"((w << 16) | h),
"d"((x << 16) | y));
}
 
static inline
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color)
:"memory");
}
static inline
void draw_text_sys_bg(const char *text, int x, int y, int len, color_t color, color_t bg)
{
__asm__ __volatile__(
"int $0x40"
::"a"(4),"d"(text),
"b"((x << 16) | y),
"S"(len),"c"(color), "D"(bg)
:"memory");
}
 
 
static inline
uint32_t get_skin_height(void)
{
uint32_t height;
 
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(height)
:"a"(48),"b"(4));
return height;
};
 
static inline
pos_t get_mouse_pos(int origin)
{
pos_t val;
 
__asm__ __volatile__(
"int $0x40 \n\t"
"rol $16, %%eax"
:"=a"(val)
:"a"(37),"b"(origin));
return val;
}
 
static inline
uint32_t get_mouse_buttons(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(2));
return val;
};
 
static inline
uint32_t get_mouse_wheels(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40 \n\t"
:"=a"(val)
:"a"(37),"b"(7));
return val;
};
 
static inline uint32_t load_cursor(void *path, uint32_t flags)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37), "b"(4), "c"(path), "d"(flags));
return val;
}
 
static inline uint32_t set_cursor(uint32_t cursor)
{
uint32_t old;
__asm__ __volatile__(
"int $0x40"
:"=a"(old)
:"a"(37), "b"(5), "c"(cursor));
return old;
};
 
static inline int destroy_cursor(uint32_t cursor)
{
int ret;
__asm__ __volatile__(
"int $0x40"
:"=a"(ret)
:"a"(37), "b"(6), "c"(cursor)
:"memory");
return ret;
};
 
 
static inline
uint32_t wait_for_event(uint32_t time)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(23), "b"(time));
return val;
};
 
static inline uint32_t check_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(11));
return val;
};
 
static inline uint32_t get_os_event()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(10));
return val;
};
 
static inline
uint32_t get_tick_count(void)
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(26),"b"(9));
return val;
};
 
static inline
uint64_t get_ns_count(void)
{
uint64_t val;
__asm__ __volatile__(
"int $0x40"
:"=A"(val)
:"a"(26), "b"(10));
return val;
};
 
static inline oskey_t get_key(void)
{
oskey_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(2));
return val;
}
 
static inline
uint32_t get_os_button()
{
uint32_t val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(17));
return val>>8;
};
 
static inline uint32_t get_service(char *name)
{
uint32_t retval = 0;
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(16),"c"(name)
:"memory");
 
return retval;
};
 
static inline int call_service(ioctl_t *io)
{
int retval;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(68),"b"(17),"c"(io)
:"memory","cc");
 
return retval;
};
 
 
static inline void yield(void)
{
__asm__ __volatile__(
"int $0x40"
::"a"(68), "b"(1));
};
 
static inline void delay(uint32_t time)
{
__asm__ __volatile__(
"int $0x40"
::"a"(5), "b"(time)
:"memory");
};
 
static inline
void *user_alloc(size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(12),"c"(size));
return val;
}
 
static inline
int user_free(void *mem)
{
int val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(13),"c"(mem));
return val;
}
 
static inline
void* user_realloc(void *mem, size_t size)
{
void *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(20),"c"(size),"d"(mem)
:"memory");
 
return val;
};
 
static inline
int *user_unmap(void *base, size_t offset, size_t size)
{
int *val;
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
return val;
};
 
static inline ufile_t load_file(const char *path)
{
ufile_t uf;
 
__asm__ __volatile__ (
"int $0x40"
:"=A"(uf.raw)
:"a" (68), "b"(27),"c"(path));
 
return uf;
};
 
static inline int GetScreenSize()
{
int retval;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(retval)
:"a"(61), "b"(1));
return retval;
}
 
 
static inline void get_proc_info(char *info)
{
__asm__ __volatile__(
"int $0x40"
:
:"a"(9), "b"(info), "c"(-1)
:"memory");
};
 
static inline void Blit(void *bitmap, int dst_x, int dst_y,
int src_x, int src_y, int w, int h,
int src_w, int src_h, int stride)
{
volatile struct blit_call bc;
 
bc.dstx = dst_x;
bc.dsty = dst_y;
bc.w = w;
bc.h = h;
bc.srcx = src_x;
bc.srcy = src_y;
bc.srcw = src_w;
bc.srch = src_h;
bc.stride = stride;
bc.bitmap = bitmap;
 
__asm__ __volatile__(
"int $0x40"
::"a"(73),"b"(0),"c"(&bc.dstx));
};
 
 
// newlib exclusive
#ifndef __TINYC__
int create_thread(int (*proc)(void *param), void *param, int stack_size);
 
void* load_library(const char *name);
 
void* get_proc_address(void *handle, const char *proc_name);
 
void enumerate_libraries(int (*callback)(void *handle, const char* name,
uint32_t base, uint32_t size, void *user_data),
void *user_data);
#endif
 
// May be next section need to be added in newlibc
 
enum KOLIBRI_GUI_EVENTS {
KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */
KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */
KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */
KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */
KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */
KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */
KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */
KOLIBRI_EVENT_NETWORK = 8, /* Network event */
KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */
KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
};
 
 
// copied from /programs/system/shell/system/kolibri.c
// fn's returned -1 as syserror, 1 as error, 0 as OK
static inline
int kol_clip_num()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0));
return val;
}
 
static inline
char* kol_clip_get(int n)
// returned buffer must be freed by user_free()
{
register char* val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n));
return val;
}
 
static inline
int kol_clip_set(int n, char buffer[])
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer));
return val;
}
 
static inline
int kol_clip_pop()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3));
return val;
}
 
static inline
int kol_clip_unlock()
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4));
return val;
}
 
static inline void get_system_colors(struct kolibri_system_colors *color_table)
{
__asm__ volatile ("int $0x40"
:
:"a"(48),"b"(3),"c"(color_table),"d"(40)
);
 
/* color_table should point to the system color table */
}
 
static inline void debug_board_write_byte(const char ch){
__asm__ __volatile__(
"int $0x40"
:
:"a"(63), "b"(1), "c"(ch));
}
 
 
static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){
register uint32_t fmt;
fmt = len << 16 | 0x80000000; // no leading zeros + width
// fmt = len << 16 | 0x00000000; // leading zeros + width
__asm__ __volatile__(
"int $0x40"
:
:"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
}
 
static inline void draw_number_sys_bg(int32_t number, int x, int y, int len, color_t color, color_t bg){
register uint32_t fmt;
fmt = len << 16 | 0x80000000; // no leading zeros + width
// fmt = len << 16 | 0x00000000; // leading zeros + width
__asm__ __volatile__(
"int $0x40"
:
:"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg));
}
 
static inline
uint32_t get_mouse_eventstate(void)
{
uint32_t val;
 
__asm__ __volatile__(
"int $0x40"
:"=a"(val)
:"a"(37),"b"(3));
return val;
};
 
static inline
uint32_t set_event_mask(uint32_t mask)
{
register uint32_t val;
asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask));
return val;
}
 
typedef void (*thread_proc)(void*);
 
static inline
int start_thread(thread_proc proc, char* stack_top)
{
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top));
return val;
}
 
static inline
void kos_exit()
{
asm volatile ("int $0x40"::"a"(-1));
}
 
static inline void focus_window(int slot){
asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot));
}
 
static inline int get_thread_slot(int tid){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid));
return val;
}
 
static inline void set_current_folder(char* dir){
asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir));
}
 
static inline int get_current_folder(char* buf, int bufsize){
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize));
return val;
}
 
static inline
void ipc_set_area(void* buf, int bufsize){
asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize));
}
 
static inline
int ipc_send_message(int pid_reciever, void *data, int datalen) {
register int val;
asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen));
return val;
}
 
static inline
void* shm_open(char *shm_name, int msize, int flags, int *retsz){
register int val, cod;
asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags));
 
if(retsz) *retsz = cod; // errcode if NULL or memsize when open
return (void*)val;
}
 
static inline
void shm_close(char *shm_name){
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name));
}
 
static inline
int start_app(char *app_name, char *args){
register int val;
struct file_op_t
{
uint32_t fn;
uint32_t flags;
char* args;
uint32_t res1, res2;
char zero;
char* app_name __attribute__((packed));
} file_op;
memset(&file_op, 0, sizeof(file_op));
file_op.fn = 7;
file_op.args = args;
file_op.app_name = app_name;
 
asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op));
 
return val;
}
 
//added nonstatic inline because incomfortabre stepping in in debugger
void __attribute__ ((noinline)) debug_board_write_str(const char* str);
void __attribute__ ((noinline)) debug_board_printf(const char *format,...);
 
/* copy body to only one project file
void __attribute__ ((noinline)) debug_board_write_str(const char* str){
while(*str)
debug_board_write_byte(*str++);
}
 
void __attribute__ ((noinline)) debug_board_printf(const char *format,...)
{
va_list ap;
char log_board[300];
 
va_start (ap, format);
vsnprintf(log_board, sizeof log_board, format, ap);
va_end(ap);
debug_board_write_str(log_board);
}
*/
 
// TinyC don't support aliasing of static inline funcs, but support #define :)
#ifndef __TINYC__
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
color_t workcolor, uint32_t style)
__attribute__ ((alias ("sys_create_window")));
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
__attribute__ ((alias ("draw_line")));
static inline void DrawBar(int x, int y, int w, int h, color_t color)
__attribute__ ((alias ("draw_bar")));
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
__attribute__ ((alias ("draw_bitmap")));
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor")));
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
#else
#define BeginDraw begin_draw
#define EndDraw end_draw
#define DrawWindow sys_create_window
#define DefineButton define_button
#define DrawLine draw_line
#define DrawBar draw_bar
#define DrawBitmap draw_bitmap
#define GetSkinHeight get_skin_height
#define GetMousePos get_mouse_pos
#define GetMouseButtons get_mouse_buttons
#define GetMouseWheels get_mouse_wheels
#define LoadCursor load_cursor
#define SetCursor set_cursor
#define DestroyCursor destroy_cursor
#define GetOsEvent get_os_event
#define UserAlloc user_alloc
#define UserFree user_free
#define UserRealloc user_realloc
#define UserUnmap user_unmap
#define LoadFile load_file
#define GetProcInfo get_proc_info
#endif
 
#ifdef __cplusplus
}
#endif
 
 
#endif
 
 
 
 
 
/programs/develop/libraries/kos_mbedtls/kosnet/include/kosnet/network.h
0,0 → 1,54
#ifndef __NETWORK_H
#define __NETWORK_H
 
#include "kosnet/socket.h"
 
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_OVERFLOW 14
 
// Flags for addrinfo
#define AI_PASSIVE 1
#define AI_CANONNAME 2
#define AI_NUMERICHOST 4
#define AI_NUMERICSERV 8
#define AI_ADDRCONFIG 0x400
 
#pragma pack(push, 1)
struct ARP_entry{
unsigned int IP;
unsigned char MAC[6];
unsigned short status;
unsigned short TTL;
};
#pragma pack(pop)
 
#pragma pack(push, 1)
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
int ai_addrlen;
char *ai_canonname;
sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#pragma pack(pop)
 
extern int load_network_obj();
extern int (*inet_addr)(const char* hostname) __attribute__ ((stdcall));
extern char* (*inet_ntoa)(int ip_addr) __attribute__ ((stdcall));
extern int (*getaddrinfo)(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res) __attribute__ ((stdcall));
extern void (*freeaddrinfo)(struct addrinfo* ai) __attribute__ ((stdcall));
 
#endif
/programs/develop/libraries/kos_mbedtls/kosnet/include/kosnet/socket.h
0,0 → 1,107
#ifndef __SOCKET_H
#define __SOCKET_H
 
#include <stddef.h>
 
// Socket Types
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
// IP protocols
#define IPPROTO_IP 0
#define IPPROTO_ICMP 1
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_RAW 255
// IP options
#define IP_TTL 2
// Address families
#define AF_UNSPEC 0
#define AF_LOCAL 1
#define AF_INET4 2 // IPv4
#define AF_INET6 10 // IPv6
 
#define PF_UNSPEC AF_UNSPEC
#define PF_LOCAL AF_LOCAL
#define PF_INET4 AF_INET4
#define PF_INET6 AF_INET6
// internal definition
#define AI_SUPPORTED 0x40F
 
// for system function 76
#define API_ETH (0<<16)
#define API_IPv4 (1<<16)
#define API_ICMP (2<<16)
#define API_UDP (3<<16)
#define API_TCP (4<<16)
#define API_ARP (5<<16)
#define API_PPPOE (6<<16)
 
// Socket flags for user calls
#define MSG_NOFLAG 0
#define MSG_PEEK 0x02
#define MSG_DONTWAIT 0x40
// Socket levels
#define SOL_SOCKET 0xffff
 
//Socket options
#define SO_BINDTODEVICE (1<<9)
#define SO_NONBLOCK (1<<31)
 
// Error Codes
#define ENOBUFS 1
#define EINPROGRESS 2
#define EOPNOTSUPP 4
#define EWOULDBLOCK 6
#define ENOTCONN 9
#define EALREADY 10
#define EINVALUE 11
#define EMSGSIZE 12
#define ENOMEM 18
#define EADDRINUSE 20
#define ECONNREFUSED 61
#define ECONNRESET 52
#define EISCONN 56
#define ETIMEDOUT 60
#define ECONNABORTED 53
 
 
#define PORT(X) (X<<8)
extern int err_code;
 
#pragma pack(push,1)
typedef struct{
unsigned short sin_family;
unsigned short sin_port;
unsigned int sin_addr;
unsigned long long sin_zero;
}sockaddr;
#pragma pack(pop)
 
#pragma pack(push,1)
typedef struct{
unsigned int level;
unsigned int optionname;
unsigned int optlenght;
unsigned char options;
}optstruct;
#pragma pack(pop)
 
int socket(int domain, int type, int protocol);
int closesocket(int socket);
int bind(int socket, const sockaddr *addres, int addres_len);
int listen(int socket, int backlog);
int connect(int socket, const sockaddr* address, int socket_len);
int accept(int socket, const sockaddr* address, int address_len);
int send(int socket, const void *message, size_t msg_len, int flag);
int recv(int socket, void *buffer, size_t buff_len, int flag);
int setsockopt(int socket,const optstruct* opt);
int getsockopt(int socket, optstruct* opt);
int socketpair(int *sock1, int *sock2);
 
#endif
/programs/develop/libraries/kos_mbedtls/kosnet/network.c
0,0 → 1,21
#include "kosnet/network.h"
#include "kosnet/dlfcn.h"
 
int (*inet_addr)(const char* hostname) __attribute__ ((stdcall));
char* (*inet_ntoa)(int ip_addr) __attribute__ ((stdcall));
int (*getaddrinfo)(const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo** res) __attribute__ ((stdcall));
void (*freeaddrinfo)(struct addrinfo* ai) __attribute__ ((stdcall));
int load_network_obj() {
void *network_lib = dlopen("/sys/lib/network.obj", RTLD_GLOBAL);
if (network_lib == NULL) {
return -1;
}
inet_addr = dlsym(network_lib, "inet_addr");
inet_ntoa = dlsym(network_lib, "inet_ntoa");
getaddrinfo = dlsym(network_lib, "getaddrinfo");
freeaddrinfo = dlsym(network_lib, "freeaddrinfo");
dlclose(network_lib);
return 0;
}
/programs/develop/libraries/kos_mbedtls/kosnet/sample/Makefile
0,0 → 1,24
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
APP_DYNAMIC_LDS=D:\KOSSDK\newlib/app-dynamic.lds
LIBDIR=D:\KOSSDK\kos32-msys-5.4.0\win32\lib
MAIN_TARGET=libkosnet_demo
 
CC=kos32-gcc
LD=kos32-ld
OBJCOPY=kos32-objcopy
 
CCFLAGS=-c -fomit-frame-pointer -I $(NEWLIB_INCLUDES) -I../include -Wall -Wextra
LDFLAGS=-call_shared -nostdlib --subsystem console -T $(APP_DYNAMIC_LDS) --image-base 0 -L $(LIBDIR) -L ../ -lkosnet -lgcc -lapp -lc.dll
 
all: libkosnet_demo
 
libkosnet_demo: libkosnet_demo.o
$(LD) libkosnet_demo.o -o $(MAIN_TARGET) $(LDFLAGS)
$(OBJCOPY) $(MAIN_TARGET) -O binary
 
libkosnet_demo.o: libkosnet_demo.c
$(CC) $(CCFLAGS) libkosnet_demo.c -o libkosnet_demo.o
 
clean:
del *.o
del $(MAIN_TARGET)
/programs/develop/libraries/kos_mbedtls/kosnet/sample/libkosnet_demo
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/develop/libraries/kos_mbedtls/kosnet/sample/libkosnet_demo.c
0,0 → 1,60
#include "kosnet/network.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
 
int main() {
load_network_obj();
 
char *host = "kolibrios.org";
int port = 80;
printf("Connecting to %s on port %d\n", host, port);
 
struct addrinfo *addr_info;
char port_str[16]; sprintf(port_str, "%d", port);
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; // IPv4 or IPv6 doesnt matter
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
if (getaddrinfo(host, port_str, 0, &addr_info) != 0) {
printf("Host %s not found!\n", host);
freeaddrinfo(addr_info);
exit(-1);
}
printf("IP address of %s is %s\n", host, inet_ntoa(addr_info->ai_addr->sin_addr));
//printf("Host port = %d\n", addr_info->ai_addr->sin_port >> 8);
 
char request[256];
sprintf(request, "GET /en/ HTTP/1.1\r\nHost: %s\r\n\r\n", host);
printf("request = %s\n", request);
 
int sock = socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP);
 
puts("Connecting...\n");
if (connect(sock, addr_info->ai_addr, addr_info->ai_addrlen) != 0) {
printf("Connection failed, err_code = %d\n", err_code);
exit(err_code);
}
puts("Connected successfully\n");
 
puts("Sending request...\n");
if (send(sock, request, strlen(request), MSG_NOFLAG) == -1) {
printf("Sending failed, err_code = %d\n", err_code);
exit(err_code);
}
puts("Request sended successfully, waiting for response...\n");
 
char buf[512 + 1];
if (recv(sock, buf, 512, MSG_NOFLAG) == -1) {
printf("Receive failed, err_code = %d\n", err_code);
exit(err_code);
}
 
printf("Response = %s\n", buf);
 
freeaddrinfo(addr_info);
 
closesocket(sock);
puts("\n goodbye)\n");
return 0;
}
/programs/develop/libraries/kos_mbedtls/kosnet/sample/run_img.bat
0,0 → 1,0
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.
/programs/develop/libraries/kos_mbedtls/kosnet/socket.c
0,0 → 1,124
#include "kosnet/socket.h"
 
int err_code = 0;
 
int socket(int domain, int type, int protocol)
{
int socket;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(socket)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
return socket;
}
int closesocket(int socket)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
return status;
}
 
int bind(int socket, const sockaddr *addres, int addres_len)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
return status;
}
int listen(int socket, int backlog)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
return status;
}
int connect(int socket,const sockaddr* address, int socket_len)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
return status;
}
int accept(int socket, const sockaddr *address, int address_len)
{
int new_socket;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(new_socket)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
return new_socket;
}
int send(int socket, const void *message, size_t msg_len, int flag)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
return status;
}
int recv(int socket, void *buffer, size_t buff_len, int flag)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
return status;
}
int setsockopt(int socket,const optstruct* opt)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
return status;
}
int getsockopt(int socket, optstruct* opt)
{
int status;
asm volatile(
"int $0x40"
:"=b"(err_code), "=a"(status)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
return status;
}
int socketpair(int *socket1, int *socket2)
{
asm volatile(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
err_code=*socket2;
return *socket1;
}
/programs/develop/libraries/kos_mbedtls/library/libtcc/___chkstk_ms.c
File deleted
\ No newline at end of file
/programs/develop/libraries/kos_mbedtls/library/libtcc/memmove.c
File deleted
\ No newline at end of file
/programs/develop/libraries/kos_mbedtls/library/libtcc/memcpy.c
File deleted
\ No newline at end of file
/programs/develop/libraries/kos_mbedtls/library/libtcc/memset.c
File deleted
\ No newline at end of file
/programs/develop/libraries/kos_mbedtls/library/libtcc/libtcc1.c
File deleted
/programs/develop/libraries/kos_mbedtls/library/mbedtls_init.asm
File deleted
/programs/develop/libraries/kos_mbedtls/library/export.asm
File deleted
/programs/develop/libraries/kos_mbedtls/library/.gitignore
0,0 → 1,0
*.o
/programs/develop/libraries/kos_mbedtls/library/CMakeLists.txt
0,0 → 1,187
option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
 
set(src_crypto
aes.c
aesni.c
arc4.c
aria.c
asn1parse.c
asn1write.c
base64.c
bignum.c
blowfish.c
camellia.c
ccm.c
chacha20.c
chachapoly.c
cipher.c
cipher_wrap.c
cmac.c
ctr_drbg.c
des.c
dhm.c
ecdh.c
ecdsa.c
ecjpake.c
ecp.c
ecp_curves.c
entropy.c
entropy_poll.c
error.c
gcm.c
havege.c
hkdf.c
hmac_drbg.c
md.c
md2.c
md4.c
md5.c
md_wrap.c
memory_buffer_alloc.c
nist_kw.c
oid.c
padlock.c
pem.c
pk.c
pk_wrap.c
pkcs12.c
pkcs5.c
pkparse.c
pkwrite.c
platform.c
platform_util.c
poly1305.c
ripemd160.c
rsa.c
rsa_internal.c
sha1.c
sha256.c
sha512.c
threading.c
timing.c
version.c
version_features.c
xtea.c
)
 
set(src_x509
certs.c
pkcs11.c
x509.c
x509_create.c
x509_crl.c
x509_crt.c
x509_csr.c
x509write_crt.c
x509write_csr.c
)
 
set(src_tls
debug.c
net_sockets.c
ssl_cache.c
ssl_ciphersuites.c
ssl_cli.c
ssl_cookie.c
ssl_srv.c
ssl_ticket.c
ssl_tls.c
)
 
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
endif(CMAKE_COMPILER_IS_GNUCC)
 
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
endif(CMAKE_COMPILER_IS_CLANG)
 
if(UNSAFE_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error")
set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error")
endif(UNSAFE_BUILD)
 
if(WIN32)
set(libs ${libs} ws2_32)
endif(WIN32)
 
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
endif()
 
if(HAIKU)
set(libs ${libs} network)
endif(HAIKU)
 
if(USE_PKCS11_HELPER_LIBRARY)
set(libs ${libs} pkcs11-helper)
endif(USE_PKCS11_HELPER_LIBRARY)
 
if(ENABLE_ZLIB_SUPPORT)
set(libs ${libs} ${ZLIB_LIBRARIES})
endif(ENABLE_ZLIB_SUPPORT)
 
if(LINK_WITH_PTHREAD)
set(libs ${libs} pthread)
endif()
 
if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
 
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
set(mbedtls_static_target "mbedtls_static")
set(mbedx509_static_target "mbedx509_static")
set(mbedcrypto_static_target "mbedcrypto_static")
elseif(USE_STATIC_MBEDTLS_LIBRARY)
set(mbedtls_static_target "mbedtls")
set(mbedx509_static_target "mbedx509")
set(mbedcrypto_static_target "mbedcrypto")
endif()
 
if(USE_STATIC_MBEDTLS_LIBRARY)
add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
target_link_libraries(${mbedcrypto_static_target} ${libs})
 
add_library(${mbedx509_static_target} STATIC ${src_x509})
set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
 
add_library(${mbedtls_static_target} STATIC ${src_tls})
set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
 
install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
DESTINATION ${LIB_INSTALL_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(USE_STATIC_MBEDTLS_LIBRARY)
 
if(USE_SHARED_MBEDTLS_LIBRARY)
add_library(mbedcrypto SHARED ${src_crypto})
set_target_properties(mbedcrypto PROPERTIES VERSION 2.16.6 SOVERSION 3)
target_link_libraries(mbedcrypto ${libs})
 
add_library(mbedx509 SHARED ${src_x509})
set_target_properties(mbedx509 PROPERTIES VERSION 2.16.6 SOVERSION 0)
target_link_libraries(mbedx509 ${libs} mbedcrypto)
 
add_library(mbedtls SHARED ${src_tls})
set_target_properties(mbedtls PROPERTIES VERSION 2.16.6 SOVERSION 12)
target_link_libraries(mbedtls ${libs} mbedx509)
 
install(TARGETS mbedtls mbedx509 mbedcrypto
DESTINATION ${LIB_INSTALL_DIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif(USE_SHARED_MBEDTLS_LIBRARY)
 
add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
endif()
/programs/develop/libraries/kos_mbedtls/library/Makefile
1,13 → 1,29
# Also see "include/mbedtls/config.h"
 
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
KOSNET_INCLUDES=../kosnet/include
 
CC = kos32-gcc
FASM = fasm
CLINK= ../../../clink/clink
AR = kos32-ar
 
KLIBC_DIR = ../../../ktcc/trunk/libc.obj
CFLAGS ?= -O2
WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement
LDFLAGS ?=
 
CFLAGS = -c -nostdinc -I../include -DGNUC -fno-common -Os -fno-delete-null-pointer-checks -fno-ident -fno-builtin -fno-leading-underscore -D__TINYC__ -D_FILE_OFFSET_BITS=64
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I $(NEWLIB_INCLUDES) -I../include -I $(KOSNET_INCLUDES) -D_FILE_OFFSET_BITS=64
LOCAL_LDFLAGS =
 
INCLUDES = -I../include -I.. -I$(KLIBC_DIR)/include
ifdef DEBUG
LOCAL_CFLAGS += -g3
endif
 
# Set AR_DASH= (empty string) to use an ar implementation that does not accept
# the - prefix for command line options (e.g. llvm-ar)
AR_DASH ?= -
 
ARFLAGS = $(AR_DASH)src
 
 
OBJS_CRYPTO= aes.o aesni.o arc4.o \
aria.o asn1parse.o asn1write.o \
base64.o bignum.o blowfish.o \
41,25 → 57,36
ssl_srv.o ssl_ticket.o \
ssl_tls.o
OBJS_OTHER = libtcc/libtcc1.o libtcc/memmove.o \
libtcc/memset.o libtcc/memcpy.o \
libtcc/___chkstk_ms.o \
mbedtls_init.o \
export.o
.SILENT:
all: $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER)
ar -crs libmbedtls.a $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER)
$(CLINK) $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_OTHER) > clink.log
mv -f a.out.obj mbedtls.obj
strip --strip-unneeded -x mbedtls.obj
kpack mbedtls.obj
cp -f mbedtls.obj /home/max/.kex/root/RD/1/LIB
.PHONY: all static clean
 
%.o : %.c Makefile
$(CC) -c $(CFLAGS) $(INCLUDES) -o $@ $<
all: static
%.o : %.asm Makefile
$(FASM) $< $@
static: libmbedcrypto.a libmbedx509.a libmbedtls.a
 
# tls
libmbedtls.a: $(OBJS_TLS)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_TLS)
 
# x509
libmbedx509.a: $(OBJS_X509)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_X509)
 
# crypto
libmbedcrypto.a: $(OBJS_CRYPTO)
echo " AR $@"
$(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
 
.c.o:
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
 
clean:
rm -f $(OBJS_CRYPTO) $(OBJS_TLS) $(OBJS_X509) $(OBJS_LIBC) $(OBJS_OTHER)
ifndef WINDOWS
rm -f *.o libmbed*
else
del /Q /F *.o libmbed*
endif
/programs/develop/libraries/kos_mbedtls/library/net_sockets.c
44,9 → 44,9
 
#include <string.h>
 
#include <sys/socket.h>
#include <clayer/network.h>
/*
#include "kosnet/socket.h"
#include "kosnet/network.h"
/*#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
68,17 → 68,15
*/
static int net_prepare( void )
{
//load_network_obj();
load_network_obj();
return( 0 );
}
 
 
/*
* Initialize a context
*/
void mbedtls_net_init( mbedtls_net_context *ctx )
{
//printf("snprintf=%p\n", printf);
ctx->fd = -1;
}
 
121,7 → 119,7
break;
}
 
close( ctx->fd );
closesocket( ctx->fd );
ret = MBEDTLS_ERR_NET_CONNECT_FAILED;
}
 
207,7 → 205,7
return;
 
//shutdown( ctx->fd, 2 );
close( ctx->fd );
closesocket( ctx->fd );
 
ctx->fd = -1;
}
/programs/develop/libraries/kos_mbedtls/library/platform_util.c
70,7 → 70,7
* mbedtls_platform_zeroize() to use a suitable implementation for their
* platform and needs.
*/
static void * (* const volatile memset_func)( void *, int, size_t ) = &memset;
static void * (* const volatile memset_func)( void *, int, size_t ) = memset;
 
void mbedtls_platform_zeroize( void *buf, size_t len )
{
86,7 → 86,7
#if !defined(_WIN32) && (defined(unix) || \
defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \
defined(__MACH__)))
//#include <unistd.h>
#include <unistd.h>
#endif /* !_WIN32 && (unix || __unix || __unix__ ||
* (__APPLE__ && __MACH__)) */
 
/programs/develop/libraries/kos_mbedtls/programs/random/gen_entropy
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/develop/libraries/kos_mbedtls/programs/random/gen_random_ctr_drbg
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/develop/libraries/kos_mbedtls/programs/random/run_img.bat
0,0 → 1,0
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.
/programs/develop/libraries/kos_mbedtls/programs/ssl/load_mbedtls.asm
File deleted
/programs/develop/libraries/kos_mbedtls/programs/ssl/Makefile
1,12 → 1,24
FASM = fasm
TCC_DIR = /home/max/kolibri-svn/programs/develop/ktcc/trunk
TCC= $(TCC_DIR)/bin/kos32-tcc
NEWLIB_INCLUDES=D:\KOSSDK\newlib\libc\include
APP_DYNAMIC_LDS=D:\KOSSDK\newlib/app-dynamic.lds
LIBDIR=D:\KOSSDK\kos32-msys-5.4.0\win32\lib
MAIN_TARGET=ssl_client1
 
CFLAGS= -I../../include -I$(TCC_DIR)/libc.obj/include -stack=10000
CC=kos32-gcc
LD=kos32-ld
OBJCOPY=kos32-objcopy
 
all:
$(FASM) load_mbedtls.asm
$(TCC) $(CFLAGS) ssl_client1.c load_mbedtls.o -o ssl_client1 -ltcc -lc.obj
CCFLAGS=-c -fomit-frame-pointer -I $(NEWLIB_INCLUDES) -I../../include -I../../kosnet/include -Wall -Wextra
LDFLAGS=-call_shared -nostdlib --subsystem console -T $(APP_DYNAMIC_LDS) --image-base 0 -L $(LIBDIR) -L ../../kosnet -L ../../library -lmbedtls -lmbedx509 -lmbedcrypto -lkosnet -lgcc -lapp -lc.dll
 
all: ssl_client1
 
ssl_client1: ssl_client1.o
$(LD) ssl_client1.o -o $(MAIN_TARGET) $(LDFLAGS)
$(OBJCOPY) $(MAIN_TARGET) -O binary
 
ssl_client1.o: ssl_client1.c
$(CC) $(CCFLAGS) ssl_client1.c -o ssl_client1.o
 
clean:
rm -f *.o ssl_client1
del *.o
del $(MAIN_TARGET)
/programs/develop/libraries/kos_mbedtls/programs/ssl/run_img.bat
0,0 → 1,0
qemu-system-i386 -m 256 -fda ../../test_kos_images/kolibri.img -boot a -vga vmware -net nic,model=rtl8139 -net user -soundhw ac97 -usb -usbdevice tablet -drive file=fat:rw:.
/programs/develop/libraries/kos_mbedtls/programs/ssl/ssl_client1
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/develop/libraries/kos_mbedtls/programs/ssl/ssl_client1.c
20,6 → 20,7
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
 
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
26,11 → 27,9
#include MBEDTLS_CONFIG_FILE
#endif
 
#include <sys/ksys.h>
 
//#if defined(MBEDTLS_PLATFORM_C)
//#include "mbedtls/platform.h"
//#else
#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#include <stdlib.h>
#define mbedtls_time time
38,16 → 37,16
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#define mbedtls_exit exit
#define MBEDTLS_EXIT_SUCCESS 0
#define MBEDTLS_EXIT_FAILURE -1
//#endif /* MBEDTLS_PLATFORM_C */
#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif /* MBEDTLS_PLATFORM_C */
 
//#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
!defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
!defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C) || \
!defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
/*int main( void )
int main( void )
{
mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
"MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
56,7 → 55,7
"not defined.\n");
return( 0 );
}
//#else*/
#else
 
#include "mbedtls/net_sockets.h"
#include "mbedtls/debug.h"
71,22 → 70,13
//#define SERVER_PORT "443"
//#define SERVER_NAME "wikipedia.org"
//#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
static char SERVER_PORT[16];
static char SERVER_NAME[128];
static char GET_REQUEST[512];
char SERVER_PORT[16];
char SERVER_NAME[128];
char GET_REQUEST[512];
 
#define DEBUG_LEVEL 1
 
extern int *_mbedtls_test_cas_pem_len;
extern char* _mbedtls_test_cas_pem;
 
#define mbedtls_test_cas_pem_len *_mbedtls_test_cas_pem_len
#define mbedtls_test_cas_pem _mbedtls_test_cas_pem
 
//gmtime(time_t t){puts("gmtime stub");};
 
//int load_network_obj(){return networklib_init();}
 
static void my_debug( void *ctx, int level,
const char *file, int line,
const char *str )
100,21 → 90,11
 
int main( void )
{
if(mbedtls_load()){
printf("mbedtls.obj not load!\n");
return -1;
}
if(mbedtls_init()){
puts("mbedtls.obj not init!");
return -1;
}
puts("Enter SERVER_NAME : ");
gets(SERVER_NAME);
puts("Enter SERVER_PORT : ");
gets(SERVER_PORT);
sprintf(GET_REQUEST, "GET / HTTP/1.1\r\nHost: %s\r\n\r\n", SERVER_NAME);
//puts(GET_REQUEST);
 
int ret = 1, len;
int exit_code = MBEDTLS_EXIT_FAILURE;
122,6 → 102,7
uint32_t flags;
unsigned char buf[1024];
const char *pers = "ssl_client1";
 
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
129,7 → 110,7
mbedtls_x509_crt cacert;
 
#if defined(MBEDTLS_DEBUG_C)
// mbedtls_debug_set_threshold( DEBUG_LEVEL );
mbedtls_debug_set_threshold( DEBUG_LEVEL );
#endif
 
/*
140,8 → 121,10
mbedtls_ssl_config_init( &conf );
mbedtls_x509_crt_init( &cacert );
mbedtls_ctr_drbg_init( &ctr_drbg );
 
mbedtls_printf( "\n . Seeding the random number generator..." );
//fflush( stdout );
 
mbedtls_entropy_init( &entropy );
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
155,7 → 138,7
/*
* 0. Initialize certificates
*/;
*/
mbedtls_printf( " . Loading the CA root certificate ..." );
//fflush( stdout );
221,6 → 204,7
}
 
mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
 
/*
* 4. Handshake
*/
317,14 → 301,15
exit_code = MBEDTLS_EXIT_SUCCESS;
 
exit:
//#ifdef MBEDTLS_ERROR_C
 
#ifdef MBEDTLS_ERROR_C
if( exit_code != MBEDTLS_EXIT_SUCCESS )
{
static char error_buf[100];
char error_buf[100];
mbedtls_strerror( ret, error_buf, 100 );
mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
}
//#endif
#endif
 
mbedtls_net_free( &server_fd );
 
337,7 → 322,7
 
return( exit_code );
}
/*#endif MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C &&
MBEDTLS_X509_CRT_PARSE_C */
/programs/develop/libraries/kos_mbedtls/test_kos_images/about_image.md
0,0 → 1,6
Test KOS image features:
- rev 8498
- kernel unpacked (to run faster in qemu for windows)
- kolibrios/ directory with lib/libc.dll (newlib) inside automatically mounts on start
- DOCKY removed from autorun.dat (cuz its very annoying :D )
- removed 3d, demos, games, fnav, kfm, animage, iconedit, etc. to get free space for things above
/programs/develop/libraries/kos_mbedtls/test_kos_images/kolibri.img
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property