Skip to content

Commit

Permalink
coverity cleanup, wtty/ctty redone to support ctty refcount and deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
dzavalishin committed Mar 13, 2016
1 parent eaba432 commit c43e5c0
Show file tree
Hide file tree
Showing 38 changed files with 1,814 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ oldtree/kernel/phantom/phantom
run/fat/class/*.pc
run/*.img
run/serial0.log*
run/net.dmp
tools/jbulk/bin/*
cov-int
run/qemu/0.15.1/stderr.txt
build_log
oldtree/kernel/phantom/.gdb-local
tools/jbulk/mkbulk.jar
2 changes: 1 addition & 1 deletion coverity_com_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tar czvf phantom-cov.tgz cov-int
curl --form token=$COVERITY_TOKEN \
--form email=dz@dz.ru \
--form file=phantom-cov.tgz \
--form file=@phantom-cov.tgz \
--form version="Commit1668" \
--form description="Phantom OS build" \
https://scan.coverity.com/builds?project=dzavalishin%2Fphantomuserland
2 changes: 1 addition & 1 deletion include/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct phantom_disk_partition phantom_disk_partition_t;
#define PART_FLAG_IS_WHOLE_DISK 0x0040


phantom_disk_partition_t *phantom_create_partition_struct(phantom_disk_partition_t *base, long shift, long size) __attribute__((deprecated));
phantom_disk_partition_t *phantom_create_partition_struct(phantom_disk_partition_t *base, long shift, long size); // __attribute__((deprecated));

errno_t phantom_register_disk_drive(phantom_disk_partition_t *p);

Expand Down
5 changes: 4 additions & 1 deletion include/kernel/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Phantom OS
*
* Copyright (C) 2005-2011 Dmitry Zavalishin, dz@dz.ru
* Copyright (C) 2005-2016 Dmitry Zavalishin, dz@dz.ru
*
* Configuration. Turn on/off kernel parts.
*
Expand All @@ -12,6 +12,9 @@
#ifndef CONFIG_H
#define CONFIG_H

// use new (handle based) controlling ttys for threads
#define CONF_NEW_CTTY 1

// Use new partitioning functions (using handles) - UNFINISHED
#define CONF_NEW_PART_FUNC 1

Expand Down
2 changes: 2 additions & 0 deletions include/kernel/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ int pool_get_used( pool_t *pool );
errno_t pool_foreach( pool_t *pool, errno_t (*ff)(pool_t *pool, void *el, pool_handle_t handle, void *arg), void *arg );


//! Increase refcount
void *pool_get_el( pool_t *pool, pool_handle_t handle );
//! Decrease refcount
errno_t pool_release_el( pool_t *pool, pool_handle_t handle );
errno_t pool_destroy_el( pool_t *pool, pool_handle_t handle );

Expand Down
6 changes: 4 additions & 2 deletions include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ifndef _MACH_SETJMP_H_PROCESSED_
#define _MACH_SETJMP_H_PROCESSED_ 1

#include <sys/cdefs.h>

#ifdef ARCH_ia32
/*
* Setjmp/longjmp buffer for i386.
Expand Down Expand Up @@ -63,13 +65,13 @@ typedef int jmp_buf[_JBLEN];

// Wrapper
extern int setjmp (jmp_buf) __attribute__((returns_twice));
extern void longjmp (jmp_buf, int);
extern void longjmp (jmp_buf, int) __dead2;
//extern int _setjmp (jmp_buf) __attribute__((returns_twice));
//extern void _longjmp (jmp_buf, int);

// Machine dependent implementation
extern int setjmp_machdep (jmp_buf) __attribute__((returns_twice));
extern void longjmp_machdep (jmp_buf, int);
extern void longjmp_machdep (jmp_buf, int) __dead2;
//extern int _setjmp_machdep (jmp_buf) __attribute__((returns_twice));
//extern void _longjmp_machdep (jmp_buf, int);

Expand Down
4 changes: 2 additions & 2 deletions include/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void hal_wired_spin_unlock(hal_spinlock_t *l);
void hal_spin_lock_cli(hal_spinlock_t *sl);
void hal_spin_unlock_sti(hal_spinlock_t *sl);

static __inline__ int hal_spin_locked(hal_spinlock_t *sl) { return sl->lock; }
static __inline__ int hal_spin_is_locked(hal_spinlock_t *sl) { return sl->lock; }
static __inline__ int hal_spin_locked(const hal_spinlock_t *sl) { return sl->lock; }
static __inline__ int hal_spin_is_locked(const hal_spinlock_t *sl) { return sl->lock; }


#if SPIN_DEBUG && !HAVE_SMP
Expand Down
14 changes: 7 additions & 7 deletions include/testenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
#include <sys/cdefs.h>

/* coverity[+kill] */
void test_fail(errno_t rc); // Call from any test to return to test runner and signal failure
void test_fail(errno_t rc) __dead2; // Call from any test to return to test runner and signal failure

/* coverity[+kill] */
void test_fail_msg(errno_t rc, const char *msg); // Call from any test to return to test runner and signal failure
void test_fail_msg(errno_t rc, const char *msg) __dead2; // Call from any test to return to test runner and signal failure

void on_fail_call( void (*f)( void *arg), void *arg ); // Call f on failure


#define test_check_true(expr) if( !expr ) test_fail_msg( -1, #expr " is not true at " __XSTRING( __LINE__ ) );
#define test_check_true(expr) if( !(expr) ) test_fail_msg( -1, #expr " is not true at " __XSTRING( __LINE__ ) );
#define test_check_false(expr) if( expr ) test_fail_msg( -1, #expr " is not false at " __XSTRING( __LINE__ ) );

#define test_check_eq(expr, val) if( expr != val ) test_fail_msg( -1, #expr " != " #val " at " __XSTRING( __LINE__ ) );
#define test_check_ne(expr, val) if( expr == val ) test_fail_msg( -1, #expr " == " #val " at " __XSTRING( __LINE__ ) );
#define test_check_gt(expr, val) if( expr <= val ) test_fail_msg( -1, #expr " <= " #val " at " __XSTRING( __LINE__ ) );
#define test_check_ge(expr, val) if( expr < val ) test_fail_msg( -1, #expr " < " #val " at " __XSTRING( __LINE__ ) );
#define test_check_eq(expr, val) if( (expr) != (val) ) test_fail_msg( -1, #expr " != " #val " at " __XSTRING( __LINE__ ) );
#define test_check_ne(expr, val) if( (expr) == (val) ) test_fail_msg( -1, #expr " == " #val " at " __XSTRING( __LINE__ ) );
#define test_check_gt(expr, val) if( (expr) <= (val) ) test_fail_msg( -1, #expr " <= " #val " at " __XSTRING( __LINE__ ) );
#define test_check_ge(expr, val) if( (expr) < (val) ) test_fail_msg( -1, #expr " < " #val " at " __XSTRING( __LINE__ ) );



Expand Down
37 changes: 32 additions & 5 deletions include/thread_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <wtty.h>
#include <threads.h>

#if CONF_NEW_CTTY
# include <kernel/pool.h>
#endif

/**
* \ingroup Threads
* \defgroup Threads Threads and syncronization
Expand Down Expand Up @@ -69,8 +73,14 @@ struct phantom_thread
//! phantom thread ref, etc
void * owner;

#if CONF_NEW_CTTY
//! "controlling" tty
pool_handle_t ctty_h;
wtty_t * ctty_w;
#else
//! "controlling" tty
wtty_t * ctty;
#endif

//! if this thread runs Unix simulation process - here is it
//struct uuprocess * u;
Expand Down Expand Up @@ -406,11 +416,6 @@ void dump_thread_stack(phantom_thread_t *t);
void dump_thread_stacks(void);


// ToDO move to more adequate header

//void hal_set_thread_death_handler(void (*handler)( phantom_thread_t * ));
//void hal_set_thread_name(const char *name);


// --------------------------------------------------------------
// Cond/mutex impl
Expand Down Expand Up @@ -443,6 +448,28 @@ struct phantom_sem_impl
};


// --------------------------------------------------------------
// Controlling tty
// --------------------------------------------------------------

#if CONF_NEW_CTTY


typedef struct ctty
{
wtty_t *wtty;
} ctty_t;

void t_init_ctty_pool(void);

errno_t t_inherit_ctty( phantom_thread_t *t );
errno_t t_make_ctty( phantom_thread_t *t );
errno_t t_kill_ctty( phantom_thread_t *t );


#endif


/** @} */

#endif // THREAD_PRIVATE_H
Expand Down
5 changes: 3 additions & 2 deletions include/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <phantom_types.h>
#include <errno.h>
#include <sys/cdefs.h>


/**
* \ingroup Threads
Expand Down Expand Up @@ -256,10 +258,9 @@ void phantom_scheduler_soft_interrupt(void);




//void* hal_start_kernel_thread(void (*thread)(void));
void hal_start_kernel_thread(void (*thread)(void));
void hal_exit_kernel_thread(void);
void hal_exit_kernel_thread(void) __dead2;



Expand Down
2 changes: 1 addition & 1 deletion include/wtty.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C) 2005-2009 Dmitry Zavalishin, dz@dz.ru
*
* Window subsystem 'controlling terminal' data structures
* Window subsystem 'controlling terminal' data structures. Actually just a simple byte FIFO.
*
*
**/
Expand Down
6 changes: 5 additions & 1 deletion oldtree/kernel/phantom/console_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,13 @@ static void phantom_debug_window_loop()

int wx = 600;

#if CONF_NEW_CTTY
if( t_new_ctty( get_current_tid() ) )
panic("console t_new_ctty");
#else
// Need separate ctty
t_set_ctty( get_current_tid(), wtty_init() );

#endif
// TODO HACK! Need ioctl to check num of bytes?
wtty_t *tty;
t_get_ctty( get_current_tid(), &tty );
Expand Down
7 changes: 4 additions & 3 deletions oldtree/kernel/phantom/driver_pci_rtl8169.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ static int rtl8169_get_address( struct phantom_device *dev, void *buf, int len)
phantom_device_t * driver_rtl_8169_probe( pci_cfg_t *pci, int stage )
{
(void) stage;
rtl8169 * nic = NULL;
static int seq_number = 0;

#if 1
(void) pci;
return 0; // on real hw beheaves strangely
#else
rtl8169 * nic = NULL;
static int seq_number = 0;

SHOW_FLOW0( 1, "probe" );

//nic = rtl8169_new();
Expand Down
5 changes: 5 additions & 0 deletions oldtree/kernel/phantom/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,9 +2797,13 @@ FRESULT f_unlink (
dir = dj.dir;
if (!dir) {
res = FR_INVALID_NAME; /* Cannot remove the start directory */
goto ret;
} else {
if (dir[DIR_Attr] & AM_RDO)
{
res = FR_DENIED; /* Cannot remove R/O object */
goto ret;
}
}
dclst = LD_CLUST(dir);
if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
Expand Down Expand Up @@ -2829,6 +2833,7 @@ FRESULT f_unlink (
}
}
}
ret:
FREE_BUF();
}
LEAVE_FF(dj.fs, res);
Expand Down
Loading

0 comments on commit c43e5c0

Please sign in to comment.