Changeset 60898b6 in mainline for uspace/lib/c
- Timestamp:
- 2010-11-05T16:17:48Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 08042bd
- Parents:
- a63ff7d (diff), a66e2993 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/c
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/include/fibril.h
ra63ff7d r60898b6 44 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 (ctx)->fp = 0; \ 46 47 (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \ 47 48 } while (0) … … 53 54 typedef struct { 54 55 uintptr_t sp; 56 uintptr_t fp; 55 57 uintptr_t pc; 56 58 uintptr_t tls; 57 59 } context_t; 60 61 static inline uintptr_t context_get_fp(context_t *ctx) 62 { 63 /* On real hardware, this function returns the frame pointer. */ 64 return ctx->fp; 65 } 58 66 59 67 #endif -
uspace/lib/c/arch/abs32le/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_abs32le__ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * On real hardware this stores the registers which 43 * need to be preserved during interupts. 44 */ 45 typedef struct istate { 46 uintptr_t ip; 47 uintptr_t fp; 48 uint32_t stack[]; 49 } istate_t; 50 51 static inline uintptr_t istate_get_pc(istate_t *istate) 52 { 53 return istate->ip; 54 } 55 56 static inline uintptr_t istate_get_fp(istate_t *istate) 57 { 58 return istate->fp; 59 } 38 #include <arch/istate.h> 60 39 61 40 #endif -
uspace/lib/c/arch/amd64/include/fibril.h
ra63ff7d r60898b6 56 56 */ 57 57 typedef struct { 58 uint64_t sp; 59 uint64_t pc; 60 61 uint64_t rbx; 62 uint64_t rbp; 58 uint64_t sp; 59 uint64_t pc; 63 60 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 61 uint64_t rbx; 62 uint64_t rbp; 68 63 69 uint64_t tls; 64 uint64_t r12; 65 uint64_t r13; 66 uint64_t r14; 67 uint64_t r15; 68 69 uint64_t tls; 70 70 } context_t; 71 72 static inline uintptr_t context_get_fp(context_t *ctx) 73 { 74 return ctx->rbp; 75 } 71 76 72 77 #endif -
uspace/lib/c/arch/amd64/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_amd64_ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 uint64_t rax; 46 uint64_t rcx; 47 uint64_t rdx; 48 uint64_t rsi; 49 uint64_t rdi; 50 uint64_t r8; 51 uint64_t r9; 52 uint64_t r10; 53 uint64_t r11; 54 uint64_t rbp; 55 uint64_t error_word; 56 uint64_t rip; 57 uint64_t cs; 58 uint64_t rflags; 59 uint64_t stack[]; /* Additional data on stack */ 60 } istate_t; 61 62 static inline uintptr_t istate_get_pc(istate_t *istate) 63 { 64 return istate->rip; 65 } 66 67 static inline uintptr_t istate_get_fp(istate_t *istate) 68 { 69 return istate->rbp; 70 } 38 #include <arch/istate.h> 71 39 72 40 #endif -
uspace/lib/c/arch/amd64/src/entry.s
ra63ff7d r60898b6 42 42 # 43 43 pushq $0 44 mov %rsp, %rbp44 movq %rsp, %rbp 45 45 46 46 # %rdi was deliberately chosen as the first argument is also in %rdi -
uspace/lib/c/arch/amd64/src/fibril.S
ra63ff7d r60898b6 49 49 movq %rax, OFFSET_TLS(%rdi) 50 50 51 xor q %rax,%rax # context_save returns 152 inc q %rax51 xorl %eax, %eax # context_save returns 1 52 incl %eax 53 53 ret 54 54 … … 67 67 # Set thread local storage 68 68 movq OFFSET_TLS(%rdi), %rdi # Set arg1 to TLS addr 69 mov q $1, %rax # SYS_TLS_SET69 movl $1, %eax # SYS_TLS_SET 70 70 syscall 71 71 72 xor q %rax,%rax # context_restore returns 072 xorl %eax, %eax # context_restore returns 0 73 73 ret -
uspace/lib/c/arch/arm32/include/fibril.h
ra63ff7d r60898b6 86 86 } context_t; 87 87 88 static inline uintptr_t context_get_fp(context_t *ctx) 89 { 90 return ctx->fp; 91 } 92 88 93 89 94 #endif -
uspace/lib/c/arch/arm32/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_arm32__ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 uint32_t spsr; 46 uint32_t sp; 47 uint32_t lr; 48 49 uint32_t r0; 50 uint32_t r1; 51 uint32_t r2; 52 uint32_t r3; 53 uint32_t r4; 54 uint32_t r5; 55 uint32_t r6; 56 uint32_t r7; 57 uint32_t r8; 58 uint32_t r9; 59 uint32_t r10; 60 uint32_t fp; 61 uint32_t r12; 62 63 uint32_t pc; 64 } istate_t; 65 66 static inline uintptr_t istate_get_pc(istate_t *istate) 67 { 68 return istate->pc; 69 } 70 71 static inline uintptr_t istate_get_fp(istate_t *istate) 72 { 73 return istate->fp; 74 } 38 #include <arch/istate.h> 75 39 76 40 #endif -
uspace/lib/c/arch/ia32/include/fibril.h
ra63ff7d r60898b6 67 67 } context_t; 68 68 69 static inline uintptr_t context_get_fp(context_t *ctx) 70 { 71 return ctx->ebp; 72 } 73 69 74 #endif 70 75 -
uspace/lib/c/arch/ia32/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_ia32__ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 uint32_t eax; 46 uint32_t ecx; 47 uint32_t edx; 48 uint32_t ebp; 49 50 uint32_t gs; 51 uint32_t fs; 52 uint32_t es; 53 uint32_t ds; 54 55 uint32_t error_word; 56 uint32_t eip; 57 uint32_t cs; 58 uint32_t eflags; 59 uint32_t stack[]; 60 } istate_t; 61 62 static inline uintptr_t istate_get_pc(istate_t *istate) 63 { 64 return istate->eip; 65 } 66 67 static inline uintptr_t istate_get_fp(istate_t *istate) 68 { 69 return istate->ebp; 70 } 38 #include <arch/istate.h> 71 39 72 40 #endif -
uspace/lib/c/arch/ia64/include/fibril.h
ra63ff7d r60898b6 130 130 } context_t; 131 131 132 static inline uintptr_t context_get_fp(context_t *ctx) 133 { 134 return 0; /* FIXME */ 135 } 136 132 137 #endif 133 138 -
uspace/lib/c/arch/ia64/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_ia64_ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 /* TODO */ 46 } istate_t; 47 48 static inline uintptr_t istate_get_pc(istate_t *istate) 49 { 50 /* TODO */ 51 return 0; 52 } 53 54 static inline uintptr_t istate_get_fp(istate_t *istate) 55 { 56 /* TODO */ 57 return 0; 58 } 38 #include <arch/istate.h> 59 39 60 40 #endif -
uspace/lib/c/arch/mips32/include/fibril.h
ra63ff7d r60898b6 85 85 } context_t; 86 86 87 static inline uintptr_t context_get_fp(context_t *ctx) 88 { 89 return ctx->sp; 90 } 91 87 92 #endif 88 93 -
uspace/lib/c/arch/mips32/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_mips32__ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 uint32_t at; 46 uint32_t v0; 47 uint32_t v1; 48 uint32_t a0; 49 uint32_t a1; 50 uint32_t a2; 51 uint32_t a3; 52 uint32_t t0; 53 uint32_t t1; 54 uint32_t t2; 55 uint32_t t3; 56 uint32_t t4; 57 uint32_t t5; 58 uint32_t t6; 59 uint32_t t7; 60 uint32_t t8; 61 uint32_t t9; 62 uint32_t gp; 63 uint32_t sp; 64 uint32_t ra; 65 66 uint32_t lo; 67 uint32_t hi; 68 69 uint32_t status; /* cp0_status */ 70 uint32_t epc; /* cp0_epc */ 71 uint32_t k1; /* We use it as thread-local pointer */ 72 } istate_t; 73 74 static inline uintptr_t istate_get_pc(istate_t *istate) 75 { 76 return istate->epc; 77 } 78 79 static inline uintptr_t istate_get_fp(istate_t *istate) 80 { 81 /* TODO */ 82 return 0; 83 } 38 #include <arch/istate.h> 84 39 85 40 #endif -
uspace/lib/c/arch/ppc32/include/fibril.h
ra63ff7d r60898b6 78 78 } __attribute__ ((packed)) context_t; 79 79 80 static inline uintptr_t context_get_fp(context_t *ctx) 81 { 82 return ctx->sp; 83 } 84 80 85 #endif 81 86 -
uspace/lib/c/arch/sparc64/include/fibril.h
ra63ff7d r60898b6 77 77 } context_t; 78 78 79 static inline uintptr_t context_get_fp(context_t *ctx) 80 { 81 return ctx->sp + STACK_BIAS; 82 } 83 79 84 #endif 80 85 -
uspace/lib/c/arch/sparc64/include/istate.h
ra63ff7d r60898b6 36 36 #define LIBC_sparc64_ISTATE_H_ 37 37 38 #include <sys/types.h> 39 40 /** Interrupt context. 41 * 42 * This is a copy of the kernel definition with which it must be kept in sync. 43 */ 44 typedef struct istate { 45 /* TODO */ 46 } istate_t; 47 48 static inline uintptr_t istate_get_pc(istate_t *istate) 49 { 50 /* TODO */ 51 return 0; 52 } 53 54 static inline uintptr_t istate_get_fp(istate_t *istate) 55 { 56 /* TODO */ 57 return 0; 58 } 38 #include <arch/istate.h> 59 39 60 40 #endif -
uspace/lib/c/generic/fibril.c
ra63ff7d r60898b6 275 275 fibril->func = func; 276 276 fibril->arg = arg; 277 278 fibril->waits_for = NULL; 277 279 278 280 context_save(&fibril->ctx); -
uspace/lib/c/generic/fibril_synch.c
ra63ff7d r60898b6 42 42 #include <errno.h> 43 43 #include <assert.h> 44 #include <stacktrace.h> 45 #include <stdlib.h> 44 46 45 47 static void optimize_execution_power(void) … … 56 58 } 57 59 60 static void print_deadlock(fibril_owner_info_t *oi) 61 { 62 fibril_t *f = (fibril_t *) fibril_get_id(); 63 64 printf("Deadlock detected.\n"); 65 stacktrace_print(); 66 67 printf("Fibril %p waits for primitive %p.\n", f, oi); 68 69 while (oi && oi->owned_by) { 70 printf("Primitive %p is owned by fibril %p.\n", 71 oi, oi->owned_by); 72 if (oi->owned_by == f) 73 break; 74 stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx), 75 oi->owned_by->ctx.pc); 76 printf("Fibril %p waits for primitive %p.\n", 77 oi->owned_by, oi->owned_by->waits_for); 78 oi = oi->owned_by->waits_for; 79 } 80 } 81 82 83 static void check_for_deadlock(fibril_owner_info_t *oi) 84 { 85 while (oi && oi->owned_by) { 86 if (oi->owned_by == (fibril_t *) fibril_get_id()) { 87 print_deadlock(oi); 88 abort(); 89 } 90 oi = oi->owned_by->waits_for; 91 } 92 } 93 94 58 95 void fibril_mutex_initialize(fibril_mutex_t *fm) 59 96 { 97 fm->oi.owned_by = NULL; 60 98 fm->counter = 1; 61 99 list_initialize(&fm->waiters); … … 64 102 void fibril_mutex_lock(fibril_mutex_t *fm) 65 103 { 104 fibril_t *f = (fibril_t *) fibril_get_id(); 105 66 106 futex_down(&async_futex); 67 107 if (fm->counter-- <= 0) { … … 73 113 link_initialize(&wdata.wu_event.link); 74 114 list_append(&wdata.wu_event.link, &fm->waiters); 115 check_for_deadlock(&fm->oi); 116 f->waits_for = &fm->oi; 75 117 fibril_switch(FIBRIL_TO_MANAGER); 76 118 } else { 119 fm->oi.owned_by = f; 77 120 futex_up(&async_futex); 78 121 } … … 86 129 if (fm->counter > 0) { 87 130 fm->counter--; 131 fm->oi.owned_by = (fibril_t *) fibril_get_id(); 88 132 locked = true; 89 133 } … … 99 143 link_t *tmp; 100 144 awaiter_t *wdp; 145 fibril_t *f; 101 146 102 147 assert(!list_empty(&fm->waiters)); … … 105 150 wdp->active = true; 106 151 wdp->wu_event.inlist = false; 152 153 f = (fibril_t *) wdp->fid; 154 fm->oi.owned_by = f; 155 f->waits_for = NULL; 156 107 157 list_remove(&wdp->wu_event.link); 108 158 fibril_add_ready(wdp->fid); 109 159 optimize_execution_power(); 160 } else { 161 fm->oi.owned_by = NULL; 110 162 } 111 163 } … … 120 172 void fibril_rwlock_initialize(fibril_rwlock_t *frw) 121 173 { 174 frw->oi.owned_by = NULL; 122 175 frw->writers = 0; 123 176 frw->readers = 0; … … 138 191 f->flags &= ~FIBRIL_WRITER; 139 192 list_append(&wdata.wu_event.link, &frw->waiters); 193 check_for_deadlock(&frw->oi); 194 f->waits_for = &frw->oi; 140 195 fibril_switch(FIBRIL_TO_MANAGER); 141 196 } else { … … 147 202 void fibril_rwlock_write_lock(fibril_rwlock_t *frw) 148 203 { 204 fibril_t *f = (fibril_t *) fibril_get_id(); 205 149 206 futex_down(&async_futex); 150 207 if (frw->writers || frw->readers) { 151 fibril_t *f = (fibril_t *) fibril_get_id();152 208 awaiter_t wdata; 153 209 … … 158 214 f->flags |= FIBRIL_WRITER; 159 215 list_append(&wdata.wu_event.link, &frw->waiters); 216 check_for_deadlock(&frw->oi); 217 f->waits_for = &frw->oi; 160 218 fibril_switch(FIBRIL_TO_MANAGER); 161 219 } else { 220 frw->oi.owned_by = f; 162 221 frw->writers++; 163 222 futex_up(&async_futex); … … 177 236 178 237 assert(!frw->readers && !frw->writers); 238 239 frw->oi.owned_by = NULL; 179 240 180 241 while (!list_empty(&frw->waiters)) { … … 185 246 wdp = list_get_instance(tmp, awaiter_t, wu_event.link); 186 247 f = (fibril_t *) wdp->fid; 248 249 f->waits_for = NULL; 187 250 188 251 if (f->flags & FIBRIL_WRITER) { … … 194 257 fibril_add_ready(wdp->fid); 195 258 frw->writers++; 259 frw->oi.owned_by = f; 196 260 optimize_execution_power(); 197 261 break; -
uspace/lib/c/include/fibril.h
ra63ff7d r60898b6 48 48 #define FIBRIL_WRITER 2 49 49 50 struct fibril; 51 52 typedef struct { 53 struct fibril *owned_by; 54 } fibril_owner_info_t; 55 50 56 typedef enum { 51 57 FIBRIL_PREEMPT, … … 68 74 int retval; 69 75 int flags; 76 77 fibril_owner_info_t *waits_for; 70 78 } fibril_t; 71 79 -
uspace/lib/c/include/fibril_synch.h
ra63ff7d r60898b6 43 43 44 44 typedef struct { 45 fibril_owner_info_t oi; /* Keep this the first thing. */ 45 46 int counter; 46 47 link_t waiters; … … 49 50 #define FIBRIL_MUTEX_INITIALIZER(name) \ 50 51 { \ 52 .oi = { \ 53 .owned_by = NULL \ 54 }, \ 51 55 .counter = 1, \ 52 56 .waiters = { \ … … 60 64 61 65 typedef struct { 66 fibril_owner_info_t oi; /* Keep this the first thing. */ 62 67 unsigned writers; 63 68 unsigned readers; … … 67 72 #define FIBRIL_RWLOCK_INITIALIZER(name) \ 68 73 { \ 74 .oi = { \ 75 .owned_by = NULL \ 76 }, \ 69 77 .readers = 0, \ 70 78 .writers = 0, \
Note:
See TracChangeset
for help on using the changeset viewer.