- Timestamp:
- 2011-06-01T17:48:03Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 18626b3
- Parents:
- 9bd5746 (diff), 5d1b3aa (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
- Files:
-
- 9 added
- 52 edited
- 2 moved
-
Makefile (modified) (1 diff)
-
Makefile.common (modified) (1 diff)
-
app/klog/klog.c (modified) (4 diffs)
-
app/tester/Makefile (modified) (1 diff)
-
app/tester/devs/devman2.c (added)
-
app/tester/devs/devman2.def (added)
-
app/tester/mm/common.c (added)
-
app/tester/mm/common.h (added)
-
app/tester/mm/malloc1.c (modified) (13 diffs)
-
app/tester/mm/malloc3.c (added)
-
app/tester/mm/malloc3.def (added)
-
app/tester/tester.c (modified) (1 diff)
-
app/tester/tester.h (modified) (3 diffs)
-
drv/rootvirt/devices.def (modified) (1 diff)
-
drv/test3/Makefile (added)
-
drv/test3/test3.c (added)
-
drv/test3/test3.ma (added)
-
lib/c/Makefile (modified) (1 diff)
-
lib/c/arch/ia32/Makefile.common (modified) (1 diff)
-
lib/c/arch/ppc32/_link.ld.in (modified) (2 diffs)
-
lib/c/generic/adt/prodcons.c (moved) (moved from kernel/test/fpu/fpu1_skip.c ) (2 diffs)
-
lib/c/generic/as.c (modified) (3 diffs)
-
lib/c/generic/assert.c (modified) (1 diff)
-
lib/c/generic/event.c (modified) (1 diff)
-
lib/c/generic/io/klog.c (modified) (2 diffs)
-
lib/c/generic/io/vprintf.c (modified) (1 diff)
-
lib/c/generic/malloc.c (modified) (30 diffs)
-
lib/c/generic/thread.c (modified) (1 diff)
-
lib/c/include/adt/fifo.h (modified) (1 diff)
-
lib/c/include/adt/list.h (modified) (11 diffs)
-
lib/c/include/adt/measured_strings.h (modified) (1 diff)
-
lib/c/include/adt/prodcons.h (moved) (moved from kernel/test/fpu/sse1_skip.c ) (2 diffs)
-
lib/c/include/as.h (modified) (1 diff)
-
lib/c/include/event.h (modified) (1 diff)
-
lib/c/include/fibril.h (modified) (1 diff)
-
lib/c/include/io/klog.h (modified) (1 diff)
-
lib/c/include/malloc.h (modified) (1 diff)
-
lib/net/il/ip_client.c (modified) (3 diffs)
-
lib/net/include/ip_header.h (modified) (5 diffs)
-
lib/softfloat/generic/add.c (modified) (4 diffs)
-
lib/softfloat/generic/common.c (modified) (3 diffs)
-
lib/softfloat/generic/comparison.c (modified) (3 diffs)
-
lib/softfloat/generic/div.c (modified) (2 diffs)
-
lib/softfloat/generic/mul.c (modified) (2 diffs)
-
lib/softfloat/generic/other.c (modified) (1 diff)
-
lib/softfloat/generic/softfloat.c (modified) (2 diffs)
-
lib/softfloat/generic/sub.c (modified) (3 diffs)
-
lib/softfloat/include/add.h (modified) (2 diffs)
-
lib/softfloat/include/common.h (modified) (2 diffs)
-
lib/softfloat/include/comparison.h (modified) (2 diffs)
-
lib/softfloat/include/conversion.h (modified) (2 diffs)
-
lib/softfloat/include/div.h (modified) (2 diffs)
-
lib/softfloat/include/mul.h (modified) (2 diffs)
-
lib/softfloat/include/other.h (modified) (2 diffs)
-
lib/softfloat/include/sftypes.h (modified) (3 diffs)
-
lib/softfloat/include/softfloat.h (modified) (2 diffs)
-
lib/softfloat/include/sub.h (modified) (2 diffs)
-
srv/net/il/ip/ip.c (modified) (14 diffs)
-
srv/net/tl/tcp/tcp.c (modified) (8 diffs)
-
srv/net/tl/tcp/tcp_header.h (modified) (2 diffs)
-
srv/vfs/vfs.h (modified) (1 diff)
-
srv/vfs/vfs_file.c (modified) (5 diffs)
-
srv/vfs/vfs_ops.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r9bd5746 rcf5e86e 96 96 drv/rootvirt \ 97 97 drv/test1 \ 98 drv/test2 98 drv/test2 \ 99 drv/test3 99 100 100 101 ## Networking -
uspace/Makefile.common
r9bd5746 rcf5e86e 157 157 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \ 158 158 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \ 159 - Werror-implicit-function-declaration -Wwrite-strings \159 -std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \ 160 160 -pipe -g -D__$(ENDIANESS)__ 161 161 -
uspace/app/klog/klog.c
r9bd5746 rcf5e86e 44 44 #include <io/klog.h> 45 45 #include <sysinfo.h> 46 #include <malloc.h> 47 #include <fibril_synch.h> 48 #include <adt/list.h> 49 #include <adt/prodcons.h> 46 50 47 51 #define NAME "klog" 48 52 #define LOG_FNAME "/log/klog" 53 54 /* Producer/consumer buffers */ 55 typedef struct { 56 link_t link; 57 size_t length; 58 wchar_t *data; 59 } item_t; 60 61 static prodcons_t pc; 49 62 50 63 /* Pointer to klog area */ … … 52 65 static size_t klog_length; 53 66 54 static FILE *log; 55 56 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 57 { 67 /* Notification mutex */ 68 static FIBRIL_MUTEX_INITIALIZE(mtx); 69 70 /** Klog producer 71 * 72 * Copies the contents of a character buffer to local 73 * producer/consumer queue. 74 * 75 * @param length Number of characters to copy. 76 * @param data Pointer to the kernel klog buffer. 77 * 78 */ 79 static void producer(size_t length, wchar_t *data) 80 { 81 item_t *item = (item_t *) malloc(sizeof(item_t)); 82 if (item == NULL) 83 return; 84 85 size_t sz = sizeof(wchar_t) * length; 86 wchar_t *buf = (wchar_t *) malloc(sz); 87 if (data == NULL) { 88 free(item); 89 return; 90 } 91 92 memcpy(buf, data, sz); 93 94 link_initialize(&item->link); 95 item->length = length; 96 item->data = buf; 97 prodcons_produce(&pc, &item->link); 98 } 99 100 /** Klog consumer 101 * 102 * Waits in an infinite loop for the character data created by 103 * the producer and outputs them to stdout and optionally into 104 * a file. 105 * 106 * @param data Unused. 107 * 108 * @return Always EOK (unreachable). 109 * 110 */ 111 static int consumer(void *data) 112 { 113 FILE *log = fopen(LOG_FNAME, "a"); 114 if (log == NULL) 115 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME, 116 str_error(errno)); 117 118 while (true) { 119 link_t *link = prodcons_consume(&pc); 120 item_t *item = list_get_instance(link, item_t, link); 121 122 for (size_t i = 0; i < item->length; i++) 123 putchar(item->data[i]); 124 125 if (log != NULL) { 126 for (size_t i = 0; i < item->length; i++) 127 fputc(item->data[i], log); 128 129 fflush(log); 130 fsync(fileno(log)); 131 } 132 133 free(item->data); 134 free(item); 135 } 136 137 fclose(log); 138 return EOK; 139 } 140 141 /** Kernel notification handler 142 * 143 * Receives kernel klog notifications. 144 * 145 * @param callid IPC call ID. 146 * @param call IPC call structure. 147 * 148 */ 149 static void notification_received(ipc_callid_t callid, ipc_call_t *call) 150 { 151 /* 152 * Make sure we process only a single notification 153 * at any time to limit the chance of the consumer 154 * starving. 155 * 156 * Note: Usually the automatic masking of the klog 157 * notifications on the kernel side does the trick 158 * of limiting the chance of accidentally copying 159 * the same data multiple times. However, due to 160 * the non-blocking architecture of klog notifications, 161 * this possibility cannot be generally avoided. 162 */ 163 164 fibril_mutex_lock(&mtx); 165 58 166 size_t klog_start = (size_t) IPC_GET_ARG1(*call); 59 167 size_t klog_len = (size_t) IPC_GET_ARG2(*call); 60 168 size_t klog_stored = (size_t) IPC_GET_ARG3(*call); 61 size_t i; 62 63 for (i = klog_len - klog_stored; i < klog_len; i++) { 64 wchar_t ch = klog[(klog_start + i) % klog_length]; 65 66 putchar(ch); 67 68 if (log != NULL) 69 fputc(ch, log); 70 } 71 72 if (log != NULL) { 73 fflush(log); 74 fsync(fileno(log)); 75 } 169 170 size_t offset = (klog_start + klog_len - klog_stored) % klog_length; 171 172 /* Copy data from the ring buffer */ 173 if (offset + klog_stored >= klog_length) { 174 size_t split = klog_length - offset; 175 176 producer(split, klog + offset); 177 producer(klog_stored - split, klog); 178 } else 179 producer(klog_stored, klog + offset); 180 181 event_unmask(EVENT_KLOG); 182 fibril_mutex_unlock(&mtx); 76 183 } 77 184 … … 111 218 } 112 219 220 prodcons_initialize(&pc); 221 async_set_interrupt_received(notification_received); 113 222 rc = event_subscribe(EVENT_KLOG, 0); 114 223 if (rc != EOK) { … … 118 227 } 119 228 120 log = fopen(LOG_FNAME, "a"); 121 if (log == NULL) 122 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME, 123 str_error(errno)); 124 125 async_set_interrupt_received(interrupt_received); 229 fid_t fid = fibril_create(consumer, NULL); 230 if (!fid) { 231 fprintf(stderr, "%s: Unable to create consumer fibril\n", 232 NAME); 233 return ENOMEM; 234 } 235 236 fibril_add_ready(fid); 237 event_unmask(EVENT_KLOG); 126 238 klog_update(); 239 240 task_retval(0); 127 241 async_manager(); 128 242 -
uspace/app/tester/Makefile
r9bd5746 rcf5e86e 51 51 ipc/ping_pong.c \ 52 52 loop/loop1.c \ 53 mm/common.c \ 53 54 mm/malloc1.c \ 54 55 mm/malloc2.c \ 56 mm/malloc3.c \ 55 57 devs/devman1.c \ 58 devs/devman2.c \ 56 59 hw/misc/virtchar1.c \ 57 60 hw/serial/serial1.c \ -
uspace/app/tester/mm/malloc1.c
r9bd5746 rcf5e86e 30 30 31 31 #include <stdio.h> 32 #include <unistd.h>33 32 #include <stdlib.h> 34 #include <malloc.h>33 #include "common.h" 35 34 #include "../tester.h" 36 35 … … 45 44 */ 46 45 47 /**48 * sizeof_array49 * @array array to determine the size of50 *51 * Returns the size of @array in array elements.52 */53 #define sizeof_array(array) \54 (sizeof(array) / sizeof((array)[0]))55 56 #define MAX_ALLOC (16 * 1024 * 1024)57 58 /*59 * Subphase control structures: subphase termination conditions,60 * probabilities of individual actions, subphase control structure.61 */62 63 typedef struct {64 unsigned int max_cycles;65 unsigned int no_memory;66 unsigned int no_allocated;67 } sp_term_cond_s;68 69 typedef struct {70 unsigned int alloc;71 unsigned int free;72 } sp_action_prob_s;73 74 typedef struct {75 const char *name;76 sp_term_cond_s cond;77 sp_action_prob_s prob;78 } subphase_s;79 80 81 /*82 * Phase control structures: The minimum and maximum block size that83 * can be allocated during the phase execution, phase control structure.84 */85 86 typedef struct {87 size_t min_block_size;88 size_t max_block_size;89 } ph_alloc_size_s;90 91 typedef struct {92 const char *name;93 ph_alloc_size_s alloc;94 subphase_s *subphases;95 } phase_s;96 97 98 46 /* 99 47 * Subphases are defined separately here. This is for two reasons: … … 101 49 * how many subphases a phase contains. 102 50 */ 103 static subphase_ ssubphases_32B[] = {51 static subphase_t subphases_32B[] = { 104 52 { 105 53 .name = "Allocation", … … 140 88 }; 141 89 142 static subphase_ ssubphases_128K[] = {90 static subphase_t subphases_128K[] = { 143 91 { 144 92 .name = "Allocation", … … 179 127 }; 180 128 181 static subphase_ ssubphases_default[] = {129 static subphase_t subphases_default[] = { 182 130 { 183 131 .name = "Allocation", … … 217 165 } 218 166 }; 219 220 167 221 168 /* 222 169 * Phase definitions. 223 170 */ 224 static phase_ sphases[] = {171 static phase_t phases[] = { 225 172 { 226 173 .name = "32 B memory blocks", … … 257 204 }; 258 205 259 260 /* 261 * Global error flag. The flag is set if an error 262 * is encountered (overlapping blocks, inconsistent 263 * block data, etc.) 264 */ 265 static bool error_flag = false; 266 267 /* 268 * Memory accounting: the amount of allocated memory and the 269 * number and list of allocated blocks. 270 */ 271 static size_t mem_allocated; 272 static size_t mem_blocks_count; 273 274 static LIST_INITIALIZE(mem_blocks); 275 276 typedef struct { 277 /* Address of the start of the block */ 278 void *addr; 279 280 /* Size of the memory block */ 281 size_t size; 282 283 /* link to other blocks */ 284 link_t link; 285 } mem_block_s; 286 287 typedef mem_block_s *mem_block_t; 288 289 290 /** init_mem 291 * 292 * Initializes the memory accounting structures. 293 * 294 */ 295 static void init_mem(void) 206 static void do_subphase(phase_t *phase, subphase_t *subphase) 296 207 { 297 mem_allocated = 0; 298 mem_blocks_count = 0; 299 } 300 301 302 static bool overlap_match(link_t *entry, void *addr, size_t size) 303 { 304 mem_block_t mblk = list_get_instance(entry, mem_block_s, link); 305 306 /* Entry block control structure <mbeg, mend) */ 307 uint8_t *mbeg = (uint8_t *) mblk; 308 uint8_t *mend = (uint8_t *) mblk + sizeof(mem_block_s); 309 310 /* Entry block memory <bbeg, bend) */ 311 uint8_t *bbeg = (uint8_t *) mblk->addr; 312 uint8_t *bend = (uint8_t *) mblk->addr + mblk->size; 313 314 /* Data block <dbeg, dend) */ 315 uint8_t *dbeg = (uint8_t *) addr; 316 uint8_t *dend = (uint8_t *) addr + size; 317 318 /* Check for overlaps */ 319 if (((mbeg >= dbeg) && (mbeg < dend)) || 320 ((mend > dbeg) && (mend <= dend)) || 321 ((bbeg >= dbeg) && (bbeg < dend)) || 322 ((bend > dbeg) && (bend <= dend))) 323 return true; 324 325 return false; 326 } 327 328 329 /** test_overlap 330 * 331 * Test whether a block starting at @addr overlaps with another, previously 332 * allocated memory block or its control structure. 333 * 334 * @param addr Initial address of the block 335 * @param size Size of the block 336 * 337 * @return false if the block does not overlap. 338 * 339 */ 340 static int test_overlap(void *addr, size_t size) 341 { 342 link_t *entry; 343 bool fnd = false; 344 345 for (entry = mem_blocks.next; entry != &mem_blocks; entry = entry->next) { 346 if (overlap_match(entry, addr, size)) { 347 fnd = true; 348 break; 349 } 350 } 351 352 return fnd; 353 } 354 355 356 /** checked_malloc 357 * 358 * Allocate @size bytes of memory and check whether the chunk comes 359 * from the non-mapped memory region and whether the chunk overlaps 360 * with other, previously allocated, chunks. 361 * 362 * @param size Amount of memory to allocate 363 * 364 * @return NULL if the allocation failed. Sets the global error_flag to 365 * true if the allocation succeeded but is illegal. 366 * 367 */ 368 static void *checked_malloc(size_t size) 369 { 370 void *data; 371 372 /* Allocate the chunk of memory */ 373 data = malloc(size); 374 if (data == NULL) 375 return NULL; 376 377 /* Check for overlaps with other chunks */ 378 if (test_overlap(data, size)) { 379 TPRINTF("\nError: Allocated block overlaps with another " 380 "previously allocated block.\n"); 381 error_flag = true; 382 } 383 384 return data; 385 } 386 387 388 /** alloc_block 389 * 390 * Allocate a block of memory of @size bytes and add record about it into 391 * the mem_blocks list. Return a pointer to the block holder structure or 392 * NULL if the allocation failed. 393 * 394 * If the allocation is illegal (e.g. the memory does not come from the 395 * right region or some of the allocated blocks overlap with others), 396 * set the global error_flag. 397 * 398 * @param size Size of the memory block 399 * 400 */ 401 static mem_block_t alloc_block(size_t size) 402 { 403 /* Check for allocation limit */ 404 if (mem_allocated >= MAX_ALLOC) 405 return NULL; 406 407 /* Allocate the block holder */ 408 mem_block_t block = (mem_block_t) checked_malloc(sizeof(mem_block_s)); 409 if (block == NULL) 410 return NULL; 411 412 link_initialize(&block->link); 413 414 /* Allocate the block memory */ 415 block->addr = checked_malloc(size); 416 if (block->addr == NULL) { 417 free(block); 418 return NULL; 419 } 420 421 block->size = size; 422 423 /* Register the allocated block */ 424 list_append(&block->link, &mem_blocks); 425 mem_allocated += size + sizeof(mem_block_s); 426 mem_blocks_count++; 427 428 return block; 429 } 430 431 432 /** free_block 433 * 434 * Free the block of memory and the block control structure allocated by 435 * alloc_block. Set the global error_flag if an error occurs. 436 * 437 * @param block Block control structure 438 * 439 */ 440 static void free_block(mem_block_t block) 441 { 442 /* Unregister the block */ 443 list_remove(&block->link); 444 mem_allocated -= block->size + sizeof(mem_block_s); 445 mem_blocks_count--; 446 447 /* Free the memory */ 448 free(block->addr); 449 free(block); 450 } 451 452 453 /** expected_value 454 * 455 * Compute the expected value of a byte located at @pos in memory 456 * block described by @blk. 457 * 458 * @param blk Memory block control structure 459 * @param pos Position in the memory block data area 460 * 461 */ 462 static inline uint8_t expected_value(mem_block_t blk, uint8_t *pos) 463 { 464 return ((unsigned long) blk ^ (unsigned long) pos) & 0xff; 465 } 466 467 468 /** fill_block 469 * 470 * Fill the memory block controlled by @blk with data. 471 * 472 * @param blk Memory block control structure 473 * 474 */ 475 static void fill_block(mem_block_t blk) 476 { 477 uint8_t *pos; 478 uint8_t *end; 479 480 for (pos = blk->addr, end = pos + blk->size; pos < end; pos++) 481 *pos = expected_value(blk, pos); 482 } 483 484 485 /** check_block 486 * 487 * Check whether the block @blk contains the data it was filled with. 488 * Set global error_flag if an error occurs. 489 * 490 * @param blk Memory block control structure 491 * 492 */ 493 static void check_block(mem_block_t blk) 494 { 495 uint8_t *pos; 496 uint8_t *end; 497 498 for (pos = blk->addr, end = pos + blk->size; pos < end; pos++) { 499 if (*pos != expected_value (blk, pos)) { 500 TPRINTF("\nError: Corrupted content of a data block.\n"); 501 error_flag = true; 502 return; 503 } 504 } 505 } 506 507 508 static link_t *list_get_nth(link_t *list, unsigned int i) 509 { 510 unsigned int cnt = 0; 511 link_t *entry; 512 513 for (entry = list->next; entry != list; entry = entry->next) { 514 if (cnt == i) 515 return entry; 516 517 cnt++; 518 } 519 520 return NULL; 521 } 522 523 524 /** get_random_block 525 * 526 * Select a random memory block from the list of allocated blocks. 527 * 528 * @return Block control structure or NULL if the list is empty. 529 * 530 */ 531 static mem_block_t get_random_block(void) 532 { 533 if (mem_blocks_count == 0) 534 return NULL; 535 536 unsigned int blkidx = rand() % mem_blocks_count; 537 link_t *entry = list_get_nth(&mem_blocks, blkidx); 538 539 if (entry == NULL) { 540 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n"); 541 error_flag = true; 542 } 543 544 return list_get_instance(entry, mem_block_s, link); 545 } 546 547 548 #define RETURN_IF_ERROR \ 549 { \ 550 if (error_flag) \ 551 return; \ 552 } 553 554 555 static void do_subphase(phase_s *phase, subphase_s *subphase) 556 { 557 unsigned int cycles; 558 for (cycles = 0; /* always */; cycles++) { 559 560 if (subphase->cond.max_cycles && 561 cycles >= subphase->cond.max_cycles) { 208 for (unsigned int cycles = 0; /* always */; cycles++) { 209 210 if ((subphase->cond.max_cycles) && 211 (cycles >= subphase->cond.max_cycles)) { 562 212 /* 563 213 * We have performed the required number of … … 572 222 unsigned int rnd = rand() % 100; 573 223 if (rnd < subphase->prob.alloc) { 574 /* Compute a random number lying in interval <min_block_size, max_block_size> */ 224 /* 225 * Compute a random number lying in interval 226 * <min_block_size, max_block_size> 227 */ 575 228 int alloc = phase->alloc.min_block_size + 576 229 (rand() % (phase->alloc.max_block_size - phase->alloc.min_block_size + 1)); 577 230 578 mem_block_t blk = alloc_block(alloc);231 mem_block_t *blk = alloc_block(alloc); 579 232 RETURN_IF_ERROR; 580 233 … … 585 238 break; 586 239 } 587 588 240 } else { 589 241 TPRINTF("A"); 590 242 fill_block(blk); 243 RETURN_IF_ERROR; 591 244 } 592 245 593 246 } else if (rnd < subphase->prob.free) { 594 mem_block_t blk = get_random_block();247 mem_block_t *blk = get_random_block(); 595 248 if (blk == NULL) { 596 249 TPRINTF("F(R)"); … … 599 252 break; 600 253 } 601 602 254 } else { 603 255 TPRINTF("R"); … … 614 266 } 615 267 616 617 static void do_phase(phase_s *phase) 268 static void do_phase(phase_t *phase) 618 269 { 619 unsigned int subno; 620 621 for (subno = 0; subno < 3; subno++) { 622 subphase_s *subphase = & phase->subphases [subno]; 270 for (unsigned int subno = 0; subno < 3; subno++) { 271 subphase_t *subphase = &phase->subphases[subno]; 623 272 624 273 TPRINTF(".. Sub-phase %u (%s)\n", subno + 1, subphase->name); … … 632 281 init_mem(); 633 282 634 unsigned int phaseno;635 for (phaseno = 0; phaseno < sizeof_array(phases);phaseno++) {636 phase_ s*phase = &phases[phaseno];283 for (unsigned int phaseno = 0; phaseno < sizeof_array(phases); 284 phaseno++) { 285 phase_t *phase = &phases[phaseno]; 637 286 638 287 TPRINTF("Entering phase %u (%s)\n", phaseno + 1, phase->name); … … 645 294 } 646 295 296 TPRINTF("Cleaning up.\n"); 297 done_mem(); 647 298 if (error_flag) 648 299 return "Test failed"; -
uspace/app/tester/tester.c
r9bd5746 rcf5e86e 63 63 #include "mm/malloc1.def" 64 64 #include "mm/malloc2.def" 65 #include "mm/malloc3.def" 65 66 #include "hw/serial/serial1.def" 66 67 #include "hw/misc/virtchar1.def" 67 68 #include "libext2/libext2_1.def" 68 69 #include "devs/devman1.def" 70 #include "devs/devman2.def" 69 71 {NULL, NULL, NULL, false} 70 72 }; -
uspace/app/tester/tester.h
r9bd5746 rcf5e86e 38 38 #include <sys/types.h> 39 39 #include <bool.h> 40 #include <stacktrace.h> 40 41 41 42 #define IPC_TEST_SERVICE 10240 … … 46 47 extern char **test_argv; 47 48 49 /** 50 * sizeof_array 51 * @array array to determine the size of 52 * 53 * Returns the size of @array in array elements. 54 */ 55 #define sizeof_array(array) \ 56 (sizeof(array) / sizeof((array)[0])) 57 48 58 #define TPRINTF(format, ...) \ 49 { \59 do { \ 50 60 if (!test_quiet) { \ 51 fprintf(stderr, format, ##__VA_ARGS__); \61 fprintf(stderr, (format), ##__VA_ARGS__); \ 52 62 } \ 53 } 63 } while (0) 64 65 #define TSTACKTRACE() \ 66 do { \ 67 if (!test_quiet) { \ 68 stacktrace_print(); \ 69 } \ 70 } while (0) 54 71 55 72 typedef const char *(*test_entry_t)(void); … … 79 96 extern const char *test_malloc1(void); 80 97 extern const char *test_malloc2(void); 98 extern const char *test_malloc3(void); 81 99 extern const char *test_serial1(void); 82 100 extern const char *test_virtchar1(void); 83 101 extern const char *test_libext2_1(void); 84 102 extern const char *test_devman1(void); 103 extern const char *test_devman2(void); 85 104 86 105 extern test_t tests[]; -
uspace/drv/rootvirt/devices.def
r9bd5746 rcf5e86e 21 21 .match_id = "virtual&test1" 22 22 }, 23 { 24 .name = "test3", 25 .match_id = "virtual&test3" 26 }, 23 27 #endif -
uspace/lib/c/Makefile
r9bd5746 rcf5e86e 108 108 generic/adt/measured_strings.c \ 109 109 generic/adt/char_map.c \ 110 generic/adt/prodcons.c \ 110 111 generic/time.c \ 111 112 generic/stdlib.c \ -
uspace/lib/c/arch/ia32/Makefile.common
r9bd5746 rcf5e86e 28 28 29 29 CLANG_ARCH = i386 30 GCC_CFLAGS += -march=pentium 30 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer 31 31 32 32 ENDIANESS = LE -
uspace/lib/c/arch/ppc32/_link.ld.in
r9bd5746 rcf5e86e 10 10 #endif 11 11 data PT_LOAD FLAGS(6); 12 debug PT_NOTE; 12 13 } 13 14 … … 55 56 } :data 56 57 58 #ifdef CONFIG_LINE_DEBUG 59 .comment 0 : { *(.comment); } :debug 60 .debug_abbrev 0 : { *(.debug_abbrev); } :debug 61 .debug_aranges 0 : { *(.debug_aranges); } :debug 62 .debug_info 0 : { *(.debug_info); } :debug 63 .debug_line 0 : { *(.debug_line); } :debug 64 .debug_loc 0 : { *(.debug_loc); } :debug 65 .debug_pubnames 0 : { *(.debug_pubnames); } :debug 66 .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug 67 .debug_ranges 0 : { *(.debug_ranges); } :debug 68 .debug_str 0 : { *(.debug_str); } :debug 69 #endif 70 57 71 /DISCARD/ : { 58 72 *(*); -
uspace/lib/c/generic/adt/prodcons.c
r9bd5746 rcf5e86e 1 1 /* 2 * Copyright (c) 20 09Martin Decky2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #include <test.h> 29 /** @addtogroup libc 30 * @{ 31 */ 32 /** @file 33 */ 30 34 31 const char *test_fpu1(void) 35 #include <adt/prodcons.h> 36 #include <adt/list.h> 37 #include <fibril_synch.h> 38 39 void prodcons_initialize(prodcons_t *pc) 32 40 { 33 return NULL; 41 list_initialize(&pc->list); 42 fibril_mutex_initialize(&pc->mtx); 43 fibril_condvar_initialize(&pc->cv); 34 44 } 45 46 void prodcons_produce(prodcons_t *pc, link_t *item) 47 { 48 fibril_mutex_lock(&pc->mtx); 49 50 list_append(item, &pc->list); 51 fibril_condvar_signal(&pc->cv); 52 53 fibril_mutex_unlock(&pc->mtx); 54 } 55 56 link_t *prodcons_consume(prodcons_t *pc) 57 { 58 fibril_mutex_lock(&pc->mtx); 59 60 while (list_empty(&pc->list)) 61 fibril_condvar_wait(&pc->cv, &pc->mtx); 62 63 link_t *head = pc->list.next; 64 list_remove(head); 65 66 fibril_mutex_unlock(&pc->mtx); 67 68 return head; 69 } 70 71 /** @} 72 */ -
uspace/lib/c/generic/as.c
r9bd5746 rcf5e86e 51 51 * 52 52 */ 53 void *as_area_create(void *address, size_t size, int flags)53 void *as_area_create(void *address, size_t size, unsigned int flags) 54 54 { 55 55 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address, … … 67 67 * 68 68 */ 69 int as_area_resize(void *address, size_t size, int flags)69 int as_area_resize(void *address, size_t size, unsigned int flags) 70 70 { 71 71 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address, … … 95 95 * 96 96 */ 97 int as_area_change_flags(void *address, int flags)97 int as_area_change_flags(void *address, unsigned int flags) 98 98 { 99 99 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address, -
uspace/lib/c/generic/assert.c
r9bd5746 rcf5e86e 33 33 #include <assert.h> 34 34 #include <stdio.h> 35 #include <io/klog.h> 35 36 #include <stdlib.h> 37 #include <atomic.h> 36 38 #include <stacktrace.h> 39 #include <stdint.h> 40 41 static atomic_t failed_asserts = {0}; 37 42 38 43 void assert_abort(const char *cond, const char *file, unsigned int line) 39 44 { 45 /* 46 * Send the message safely to klog. Nested asserts should not occur. 47 */ 48 klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n", 49 cond, file, line); 50 51 /* 52 * Check if this is a nested or parallel assert. 53 */ 54 if (atomic_postinc(&failed_asserts)) 55 abort(); 56 57 /* 58 * Attempt to print the message to standard output and display 59 * the stack trace. These operations can theoretically trigger nested 60 * assertions. 61 */ 40 62 printf("Assertion failed (%s) in file \"%s\", line %u.\n", 41 63 cond, file, line); 42 64 stacktrace_print(); 65 43 66 abort(); 44 67 } -
uspace/lib/c/generic/event.c
r9bd5746 rcf5e86e 41 41 #include <kernel/ipc/event_types.h> 42 42 43 /** Subscribe forevent notifications.43 /** Subscribe event notifications. 44 44 * 45 * @param evno Event number.46 * @param method Use thismethod for notifying me.45 * @param evno Event type to subscribe. 46 * @param imethod Use this interface and method for notifying me. 47 47 * 48 48 * @return Value returned by the kernel. 49 * 49 50 */ 50 int event_subscribe(event_type_t e , sysarg_tmethod)51 int event_subscribe(event_type_t evno, sysarg_t imethod) 51 52 { 52 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) e, (sysarg_t) method); 53 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, 54 (sysarg_t) imethod); 55 } 56 57 /** Unmask event notifications. 58 * 59 * @param evno Event type to unmask. 60 * 61 * @return Value returned by the kernel. 62 * 63 */ 64 int event_unmask(event_type_t evno) 65 { 66 return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno); 53 67 } 54 68 -
uspace/lib/c/generic/io/klog.c
r9bd5746 rcf5e86e 38 38 #include <sys/types.h> 39 39 #include <unistd.h> 40 #include <errno.h> 40 41 #include <io/klog.h> 42 #include <io/printf_core.h> 41 43 42 44 size_t klog_write(const void *buf, size_t size) … … 55 57 } 56 58 59 /** Print formatted text to klog. 60 * 61 * @param fmt Format string 62 * 63 * \see For more details about format string see printf_core. 64 * 65 */ 66 int klog_printf(const char *fmt, ...) 67 { 68 va_list args; 69 va_start(args, fmt); 70 71 int ret = klog_vprintf(fmt, args); 72 73 va_end(args); 74 75 return ret; 76 } 77 78 static int klog_vprintf_str_write(const char *str, size_t size, void *data) 79 { 80 size_t wr = klog_write(str, size); 81 return str_nlength(str, wr); 82 } 83 84 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data) 85 { 86 size_t offset = 0; 87 size_t chars = 0; 88 89 while (offset < size) { 90 char buf[STR_BOUNDS(1)]; 91 size_t sz = 0; 92 93 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 94 klog_write(buf, sz); 95 96 chars++; 97 offset += sizeof(wchar_t); 98 } 99 100 return chars; 101 } 102 103 /** Print formatted text to klog. 104 * 105 * @param fmt Format string 106 * @param ap Format parameters 107 * 108 * \see For more details about format string see printf_core. 109 * 110 */ 111 int klog_vprintf(const char *fmt, va_list ap) 112 { 113 printf_spec_t ps = { 114 klog_vprintf_str_write, 115 klog_vprintf_wstr_write, 116 NULL 117 }; 118 119 return printf_core(fmt, &ps, ap); 120 } 121 57 122 /** @} 58 123 */ -
uspace/lib/c/generic/io/vprintf.c
r9bd5746 rcf5e86e 96 96 /** Print formatted text to stdout. 97 97 * 98 * @param file Output stream 99 * @param fmt Format string 100 * @param ap Format parameters 98 * @param fmt Format string 99 * @param ap Format parameters 101 100 * 102 101 * \see For more details about format string see printf_core. -
uspace/lib/c/generic/malloc.c
r9bd5746 rcf5e86e 65 65 #define BASE_ALIGN 16 66 66 67 /** Heap shrink granularity 68 * 69 * Try not to pump and stress the heap to much 70 * by shrinking and enlarging it too often. 71 * A heap area won't shrunk if it the released 72 * free block is smaller than this constant. 73 * 74 */ 75 #define SHRINK_GRANULARITY (64 * PAGE_SIZE) 76 67 77 /** Overhead of each heap block. */ 68 78 #define STRUCT_OVERHEAD \ 69 79 (sizeof(heap_block_head_t) + sizeof(heap_block_foot_t)) 70 80 81 /** Overhead of each area. */ 82 #define AREA_OVERHEAD(size) \ 83 (ALIGN_UP(size + sizeof(heap_area_t), BASE_ALIGN)) 84 71 85 /** Calculate real size of a heap block. 72 86 * … … 86 100 * 87 101 */ 88 #define AREA_FIRST_BLOCK (area) \102 #define AREA_FIRST_BLOCK_HEAD(area) \ 89 103 (ALIGN_UP(((uintptr_t) (area)) + sizeof(heap_area_t), BASE_ALIGN)) 104 105 /** Get last block in heap area. 106 * 107 */ 108 #define AREA_LAST_BLOCK_FOOT(area) \ 109 (((uintptr_t) (area)->end) - sizeof(heap_block_foot_t)) 110 111 /** Get header in heap block. 112 * 113 */ 114 #define BLOCK_HEAD(foot) \ 115 ((heap_block_head_t *) \ 116 (((uintptr_t) (foot)) + sizeof(heap_block_foot_t) - (foot)->size)) 90 117 91 118 /** Get footer in heap block. … … 94 121 #define BLOCK_FOOT(head) \ 95 122 ((heap_block_foot_t *) \ 96 (((uintptr_t) head) + head->size - sizeof(heap_block_foot_t)))123 (((uintptr_t) (head)) + (head)->size - sizeof(heap_block_foot_t))) 97 124 98 125 /** Heap area. … … 115 142 void *end; 116 143 144 /** Previous heap area */ 145 struct heap_area *prev; 146 117 147 /** Next heap area */ 118 148 struct heap_area *next; … … 157 187 158 188 /** Next heap block to examine (next fit algorithm) */ 159 static heap_block_head_t *next = NULL;189 static heap_block_head_t *next_fit = NULL; 160 190 161 191 /** Futex for thread-safe heap manipulation */ 162 192 static futex_t malloc_futex = FUTEX_INITIALIZER; 193 194 #ifndef NDEBUG 195 196 #define malloc_assert(expr) \ 197 do { \ 198 if (!(expr)) {\ 199 futex_up(&malloc_futex); \ 200 assert_abort(#expr, __FILE__, __LINE__); \ 201 } \ 202 } while (0) 203 204 #else /* NDEBUG */ 205 206 #define malloc_assert(expr) 207 208 #endif /* NDEBUG */ 163 209 164 210 /** Initialize a heap block … … 202 248 heap_block_head_t *head = (heap_block_head_t *) addr; 203 249 204 assert(head->magic == HEAP_BLOCK_HEAD_MAGIC);250 malloc_assert(head->magic == HEAP_BLOCK_HEAD_MAGIC); 205 251 206 252 heap_block_foot_t *foot = BLOCK_FOOT(head); 207 253 208 assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);209 assert(head->size == foot->size);254 malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC); 255 malloc_assert(head->size == foot->size); 210 256 } 211 257 212 258 /** Check a heap area structure 213 259 * 260 * Should be called only inside the critical section. 261 * 214 262 * @param addr Address of the heap area. 215 263 * … … 219 267 heap_area_t *area = (heap_area_t *) addr; 220 268 221 assert(area->magic == HEAP_AREA_MAGIC); 222 assert(area->start < area->end); 223 assert(((uintptr_t) area->start % PAGE_SIZE) == 0); 224 assert(((uintptr_t) area->end % PAGE_SIZE) == 0); 269 malloc_assert(area->magic == HEAP_AREA_MAGIC); 270 malloc_assert(addr == area->start); 271 malloc_assert(area->start < area->end); 272 malloc_assert(((uintptr_t) area->start % PAGE_SIZE) == 0); 273 malloc_assert(((uintptr_t) area->end % PAGE_SIZE) == 0); 225 274 } 226 275 227 276 /** Create new heap area 228 277 * 229 * @param start Preffered starting address of the new area. 230 * @param size Size of the area. 278 * Should be called only inside the critical section. 279 * 280 * @param size Size of the area. 231 281 * 232 282 */ … … 248 298 249 299 area->start = astart; 250 area->end = (void *) 251 ALIGN_DOWN((uintptr_t) astart + asize, BASE_ALIGN);300 area->end = (void *) ((uintptr_t) astart + asize); 301 area->prev = NULL; 252 302 area->next = NULL; 253 303 area->magic = HEAP_AREA_MAGIC; 254 304 255 void *block = (void *) AREA_FIRST_BLOCK (area);305 void *block = (void *) AREA_FIRST_BLOCK_HEAD(area); 256 306 size_t bsize = (size_t) (area->end - block); 257 307 … … 262 312 last_heap_area = area; 263 313 } else { 314 area->prev = last_heap_area; 264 315 last_heap_area->next = area; 265 316 last_heap_area = area; … … 271 322 /** Try to enlarge a heap area 272 323 * 324 * Should be called only inside the critical section. 325 * 273 326 * @param area Heap area to grow. 274 * @param size Gross size of item to allocate (bytes). 327 * @param size Gross size to grow (bytes). 328 * 329 * @return True if successful. 275 330 * 276 331 */ … … 282 337 area_check(area); 283 338 284 size_t asize = ALIGN_UP((size_t) (area->end - area->start) + size,285 PAGE_SIZE);286 287 339 /* New heap area size */ 288 void *end = (void *) 289 ALIGN_DOWN((uintptr_t) area->start + asize, BASE_ALIGN); 340 size_t gross_size = (size_t) (area->end - area->start) + size; 341 size_t asize = ALIGN_UP(gross_size, PAGE_SIZE); 342 void *end = (void *) ((uintptr_t) area->start + asize); 290 343 291 344 /* Check for overflow */ … … 299 352 300 353 /* Add new free block */ 301 block_init(area->end, (size_t) (end - area->end), true, area); 354 size_t net_size = (size_t) (end - area->end); 355 if (net_size > 0) 356 block_init(area->end, net_size, true, area); 302 357 303 358 /* Update heap area parameters */ … … 309 364 /** Try to enlarge any of the heap areas 310 365 * 366 * Should be called only inside the critical section. 367 * 311 368 * @param size Gross size of item to allocate (bytes). 312 369 * … … 318 375 319 376 /* First try to enlarge some existing area */ 320 heap_area_t *area;321 for (area = first_heap_area; area != NULL;area = area->next) {377 for (heap_area_t *area = first_heap_area; area != NULL; 378 area = area->next) { 322 379 if (area_grow(area, size)) 323 380 return true; … … 325 382 326 383 /* Eventually try to create a new area */ 327 return area_create(AREA_FIRST_BLOCK(size)); 328 } 329 330 /** Try to shrink heap space 331 * 384 return area_create(AREA_OVERHEAD(size)); 385 } 386 387 /** Try to shrink heap 388 * 389 * Should be called only inside the critical section. 332 390 * In all cases the next pointer is reset. 333 391 * 334 */ 335 static void heap_shrink(void) 336 { 337 next = NULL; 392 * @param area Last modified heap area. 393 * 394 */ 395 static void heap_shrink(heap_area_t *area) 396 { 397 area_check(area); 398 399 heap_block_foot_t *last_foot = 400 (heap_block_foot_t *) AREA_LAST_BLOCK_FOOT(area); 401 heap_block_head_t *last_head = BLOCK_HEAD(last_foot); 402 403 block_check((void *) last_head); 404 malloc_assert(last_head->area == area); 405 406 if (last_head->free) { 407 /* 408 * The last block of the heap area is 409 * unused. The area might be potentially 410 * shrunk. 411 */ 412 413 heap_block_head_t *first_head = 414 (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(area); 415 416 block_check((void *) first_head); 417 malloc_assert(first_head->area == area); 418 419 size_t shrink_size = ALIGN_DOWN(last_head->size, PAGE_SIZE); 420 421 if (first_head == last_head) { 422 /* 423 * The entire heap area consists of a single 424 * free heap block. This means we can get rid 425 * of it entirely. 426 */ 427 428 heap_area_t *prev = area->prev; 429 heap_area_t *next = area->next; 430 431 if (prev != NULL) { 432 area_check(prev); 433 prev->next = next; 434 } else 435 first_heap_area = next; 436 437 if (next != NULL) { 438 area_check(next); 439 next->prev = prev; 440 } else 441 last_heap_area = prev; 442 443 as_area_destroy(area->start); 444 } else if (shrink_size >= SHRINK_GRANULARITY) { 445 /* 446 * Make sure that we always shrink the area 447 * by a multiple of page size and update 448 * the block layout accordingly. 449 */ 450 451 size_t asize = (size_t) (area->end - area->start) - shrink_size; 452 void *end = (void *) ((uintptr_t) area->start + asize); 453 454 /* Resize the address space area */ 455 int ret = as_area_resize(area->start, asize, 0); 456 if (ret != EOK) 457 abort(); 458 459 /* Update heap area parameters */ 460 area->end = end; 461 size_t excess = ((size_t) area->end) - ((size_t) last_head); 462 463 if (excess > 0) { 464 if (excess >= STRUCT_OVERHEAD) { 465 /* 466 * The previous block cannot be free and there 467 * is enough free space left in the area to 468 * create a new free block. 469 */ 470 block_init((void *) last_head, excess, true, area); 471 } else { 472 /* 473 * The excess is small. Therefore just enlarge 474 * the previous block. 475 */ 476 heap_block_foot_t *prev_foot = (heap_block_foot_t *) 477 (((uintptr_t) last_head) - sizeof(heap_block_foot_t)); 478 heap_block_head_t *prev_head = BLOCK_HEAD(prev_foot); 479 480 block_check((void *) prev_head); 481 482 block_init(prev_head, prev_head->size + excess, 483 prev_head->free, area); 484 } 485 } 486 } 487 } 488 489 next_fit = NULL; 338 490 } 339 491 … … 362 514 static void split_mark(heap_block_head_t *cur, const size_t size) 363 515 { 364 assert(cur->size >= size);516 malloc_assert(cur->size >= size); 365 517 366 518 /* See if we should split the block. */ … … 398 550 { 399 551 area_check((void *) area); 400 assert((void *) first_block >= (void *) AREA_FIRST_BLOCK(area)); 401 assert((void *) first_block < area->end); 402 403 heap_block_head_t *cur; 404 for (cur = first_block; (void *) cur < area->end; 552 malloc_assert((void *) first_block >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 553 malloc_assert((void *) first_block < area->end); 554 555 for (heap_block_head_t *cur = first_block; (void *) cur < area->end; 405 556 cur = (heap_block_head_t *) (((void *) cur) + cur->size)) { 406 557 block_check(cur); … … 425 576 split_mark(cur, real_size); 426 577 427 next = cur;578 next_fit = cur; 428 579 return addr; 429 580 } else { … … 436 587 * data in (including alignment). 437 588 */ 438 if ((void *) cur > (void *) AREA_FIRST_BLOCK (area)) {589 if ((void *) cur > (void *) AREA_FIRST_BLOCK_HEAD(area)) { 439 590 /* 440 591 * There is a block before the current block. … … 477 628 split_mark(next_head, real_size); 478 629 479 next = next_head;630 next_fit = next_head; 480 631 return aligned; 481 632 } else { … … 496 647 size_t reduced_size = cur->size - excess; 497 648 cur = (heap_block_head_t *) 498 (AREA_FIRST_BLOCK (area) + excess);649 (AREA_FIRST_BLOCK_HEAD(area) + excess); 499 650 500 block_init((void *) AREA_FIRST_BLOCK (area), excess,501 true, area);651 block_init((void *) AREA_FIRST_BLOCK_HEAD(area), 652 excess, true, area); 502 653 block_init(cur, reduced_size, true, area); 503 654 split_mark(cur, real_size); 504 655 505 next = cur;656 next_fit = cur; 506 657 return aligned; 507 658 } … … 527 678 static void *malloc_internal(const size_t size, const size_t align) 528 679 { 529 assert(first_heap_area != NULL);680 malloc_assert(first_heap_area != NULL); 530 681 531 682 if (align == 0) … … 541 692 542 693 /* Try the next fit approach */ 543 split = next ;694 split = next_fit; 544 695 545 696 if (split != NULL) { … … 552 703 553 704 /* Search the entire heap */ 554 heap_area_t *area;555 for (area = first_heap_area; area != NULL;area = area->next) {705 for (heap_area_t *area = first_heap_area; area != NULL; 706 area = area->next) { 556 707 heap_block_head_t *first = (heap_block_head_t *) 557 AREA_FIRST_BLOCK (area);708 AREA_FIRST_BLOCK_HEAD(area); 558 709 559 710 void *addr = malloc_area(area, first, split, real_size, … … 652 803 653 804 block_check(head); 654 assert(!head->free);805 malloc_assert(!head->free); 655 806 656 807 heap_area_t *area = head->area; 657 808 658 809 area_check(area); 659 assert((void *) head >= (void *) AREA_FIRST_BLOCK(area));660 assert((void *) head < area->end);810 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 811 malloc_assert((void *) head < area->end); 661 812 662 813 void *ptr = NULL; … … 675 826 block_init((void *) head + real_size, 676 827 orig_size - real_size, true, area); 677 heap_shrink( );828 heap_shrink(area); 678 829 } 679 830 … … 697 848 698 849 ptr = ((void *) head) + sizeof(heap_block_head_t); 699 next = NULL;850 next_fit = NULL; 700 851 } else 701 852 reloc = true; … … 729 880 730 881 block_check(head); 731 assert(!head->free);882 malloc_assert(!head->free); 732 883 733 884 heap_area_t *area = head->area; 734 885 735 886 area_check(area); 736 assert((void *) head >= (void *) AREA_FIRST_BLOCK(area));737 assert((void *) head < area->end);887 malloc_assert((void *) head >= (void *) AREA_FIRST_BLOCK_HEAD(area)); 888 malloc_assert((void *) head < area->end); 738 889 739 890 /* Mark the block itself as free. */ … … 751 902 752 903 /* Look at the previous block. If it is free, merge the two. */ 753 if ((void *) head > (void *) AREA_FIRST_BLOCK (area)) {904 if ((void *) head > (void *) AREA_FIRST_BLOCK_HEAD(area)) { 754 905 heap_block_foot_t *prev_foot = 755 906 (heap_block_foot_t *) (((void *) head) - sizeof(heap_block_foot_t)); … … 765 916 } 766 917 767 heap_shrink( );918 heap_shrink(area); 768 919 769 920 futex_up(&malloc_futex); 770 921 } 771 922 923 void *heap_check(void) 924 { 925 futex_down(&malloc_futex); 926 927 if (first_heap_area == NULL) { 928 futex_up(&malloc_futex); 929 return (void *) -1; 930 } 931 932 /* Walk all heap areas */ 933 for (heap_area_t *area = first_heap_area; area != NULL; 934 area = area->next) { 935 936 /* Check heap area consistency */ 937 if ((area->magic != HEAP_AREA_MAGIC) || 938 ((void *) area != area->start) || 939 (area->start >= area->end) || 940 (((uintptr_t) area->start % PAGE_SIZE) != 0) || 941 (((uintptr_t) area->end % PAGE_SIZE) != 0)) { 942 futex_up(&malloc_futex); 943 return (void *) area; 944 } 945 946 /* Walk all heap blocks */ 947 for (heap_block_head_t *head = (heap_block_head_t *) 948 AREA_FIRST_BLOCK_HEAD(area); (void *) head < area->end; 949 head = (heap_block_head_t *) (((void *) head) + head->size)) { 950 951 /* Check heap block consistency */ 952 if (head->magic != HEAP_BLOCK_HEAD_MAGIC) { 953 futex_up(&malloc_futex); 954 return (void *) head; 955 } 956 957 heap_block_foot_t *foot = BLOCK_FOOT(head); 958 959 if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) || 960 (head->size != foot->size)) { 961 futex_up(&malloc_futex); 962 return (void *) foot; 963 } 964 } 965 } 966 967 futex_up(&malloc_futex); 968 969 return NULL; 970 } 971 772 972 /** @} 773 973 */ -
uspace/lib/c/generic/thread.c
r9bd5746 rcf5e86e 44 44 45 45 #ifndef THREAD_INITIAL_STACK_PAGES_NO 46 #define THREAD_INITIAL_STACK_PAGES_NO 146 #define THREAD_INITIAL_STACK_PAGES_NO 2 47 47 #endif 48 48 -
uspace/lib/c/include/adt/fifo.h
r9bd5746 rcf5e86e 51 51 typedef unsigned long fifo_index_t; 52 52 53 #define FIFO_CREATE_STATIC(name, t, itms) \54 struct { \55 t fifo[(itms)]; \56 fifo_count_t items; \57 fifo_index_t head; \58 fifo_index_t tail; \53 #define FIFO_CREATE_STATIC(name, t, itms) \ 54 struct { \ 55 t fifo[(itms)]; \ 56 fifo_count_t items; \ 57 fifo_index_t head; \ 58 fifo_index_t tail; \ 59 59 } name 60 60 -
uspace/lib/c/include/adt/list.h
r9bd5746 rcf5e86e 47 47 * 48 48 * @param name Name of the new statically allocated list. 49 */ 50 #define LIST_INITIALIZE(name) link_t name = { \ 51 .prev = &name, \ 52 .next = &name \ 53 } 49 * 50 */ 51 #define LIST_INITIALIZE(name) \ 52 link_t name = { \ 53 .prev = &name, \ 54 .next = &name \ 55 } 56 57 #define list_get_instance(link, type, member) \ 58 ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 59 60 #define list_foreach(list, iterator) \ 61 for (link_t *iterator = (list).next; \ 62 iterator != &(list); iterator = iterator->next) 54 63 55 64 /** Initialize doubly-linked circular list link … … 58 67 * 59 68 * @param link Pointer to link_t structure to be initialized. 69 * 60 70 */ 61 71 static inline void link_initialize(link_t *link) … … 69 79 * Initialize doubly-linked circular list. 70 80 * 71 * @param head Pointer to link_t structure representing head of the list. 72 */ 73 static inline void list_initialize(link_t *head) 74 { 75 head->prev = head; 76 head->next = head; 81 * @param list Pointer to link_t structure representing the list. 82 * 83 */ 84 static inline void list_initialize(link_t *list) 85 { 86 list->prev = list; 87 list->next = list; 77 88 } 78 89 … … 82 93 * 83 94 * @param link Pointer to link_t structure to be added. 84 * @param head Pointer to link_t structure representing head of the list. 85 */ 86 static inline void list_prepend(link_t *link, link_t *head) 87 { 88 link->next = head->next; 89 link->prev = head; 90 head->next->prev = link; 91 head->next = link; 95 * @param list Pointer to link_t structure representing the list. 96 * 97 */ 98 static inline void list_prepend(link_t *link, link_t *list) 99 { 100 link->next = list->next; 101 link->prev = list; 102 list->next->prev = link; 103 list->next = link; 92 104 } 93 105 … … 97 109 * 98 110 * @param link Pointer to link_t structure to be added. 99 * @param head Pointer to link_t structure representing head of the list. 100 */ 101 static inline void list_append(link_t *link, link_t *head) 102 { 103 link->prev = head->prev; 104 link->next = head; 105 head->prev->next = link; 106 head->prev = link; 107 } 108 109 /** Insert item before another item in doubly-linked circular list. */ 110 static inline void list_insert_before(link_t *l, link_t *r) 111 { 112 list_append(l, r); 113 } 114 115 /** Insert item after another item in doubly-linked circular list. */ 116 static inline void list_insert_after(link_t *r, link_t *l) 117 { 118 list_prepend(l, r); 111 * @param list Pointer to link_t structure representing the list. 112 * 113 */ 114 static inline void list_append(link_t *link, link_t *list) 115 { 116 link->prev = list->prev; 117 link->next = list; 118 list->prev->next = link; 119 list->prev = link; 120 } 121 122 /** Insert item before another item in doubly-linked circular list. 123 * 124 */ 125 static inline void list_insert_before(link_t *link, link_t *list) 126 { 127 list_append(link, list); 128 } 129 130 /** Insert item after another item in doubly-linked circular list. 131 * 132 */ 133 static inline void list_insert_after(link_t *link, link_t *list) 134 { 135 list_prepend(list, link); 119 136 } 120 137 … … 123 140 * Remove item from doubly-linked circular list. 124 141 * 125 * @param link Pointer to link_t structure to be removed from the list it is contained in. 142 * @param link Pointer to link_t structure to be removed from the list 143 * it is contained in. 144 * 126 145 */ 127 146 static inline void list_remove(link_t *link) … … 136 155 * Query emptiness of doubly-linked circular list. 137 156 * 138 * @param head Pointer to link_t structure representing head of the list. 139 */ 140 static inline int list_empty(link_t *head) 141 { 142 return ((head->next == head) ? 1 : 0); 143 } 144 157 * @param list Pointer to link_t structure representing the list. 158 * 159 */ 160 static inline int list_empty(link_t *list) 161 { 162 return (list->next == list); 163 } 164 165 /** Get head item of a list. 166 * 167 * @param list Pointer to link_t structure representing the list. 168 * 169 * @return Head item of the list. 170 * @return NULL if the list is empty. 171 * 172 */ 173 static inline link_t *list_head(link_t *list) 174 { 175 return ((list->next == list) ? NULL : list->next); 176 } 145 177 146 178 /** Split or concatenate headless doubly-linked circular list … … 151 183 * concatenates splitted lists and splits concatenated lists. 152 184 * 153 * @param part1 Pointer to link_t structure leading the first (half of the headless) list. 154 * @param part2 Pointer to link_t structure leading the second (half of the headless) list. 185 * @param part1 Pointer to link_t structure leading the first 186 * (half of the headless) list. 187 * @param part2 Pointer to link_t structure leading the second 188 * (half of the headless) list. 189 * 155 190 */ 156 191 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) … … 165 200 } 166 201 167 168 202 /** Split headless doubly-linked circular list 169 203 * 170 204 * Split headless doubly-linked circular list. 171 205 * 172 * @param part1 Pointer to link_t structure leading the first half of the headless list. 173 * @param part2 Pointer to link_t structure leading the second half of the headless list. 206 * @param part1 Pointer to link_t structure leading 207 * the first half of the headless list. 208 * @param part2 Pointer to link_t structure leading 209 * the second half of the headless list. 210 * 174 211 */ 175 212 static inline void headless_list_split(link_t *part1, link_t *part2) … … 182 219 * Concatenate two headless doubly-linked circular lists. 183 220 * 184 * @param part1 Pointer to link_t structure leading the first headless list. 185 * @param part2 Pointer to link_t structure leading the second headless list. 221 * @param part1 Pointer to link_t structure leading 222 * the first headless list. 223 * @param part2 Pointer to link_t structure leading 224 * the second headless list. 225 * 186 226 */ 187 227 static inline void headless_list_concat(link_t *part1, link_t *part2) … … 190 230 } 191 231 192 #define list_get_instance(link, type, member) ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member)))) 193 194 extern int list_member(const link_t *link, const link_t *head); 195 extern void list_concat(link_t *head1, link_t *head2); 196 extern unsigned int list_count(const link_t *link); 232 /** Get n-th item of a list. 233 * 234 * @param list Pointer to link_t structure representing the list. 235 * @param n Item number (indexed from zero). 236 * 237 * @return n-th item of the list. 238 * @return NULL if no n-th item found. 239 * 240 */ 241 static inline link_t *list_nth(link_t *list, unsigned int n) 242 { 243 unsigned int cnt = 0; 244 245 list_foreach(*list, link) { 246 if (cnt == n) 247 return link; 248 249 cnt++; 250 } 251 252 return NULL; 253 } 254 255 extern int list_member(const link_t *, const link_t *); 256 extern void list_concat(link_t *, link_t *); 257 extern unsigned int list_count(const link_t *); 197 258 198 259 #endif -
uspace/lib/c/include/adt/measured_strings.h
r9bd5746 rcf5e86e 61 61 extern measured_string_t *measured_string_create_bulk(const uint8_t *, size_t); 62 62 extern measured_string_t *measured_string_copy(measured_string_t *); 63 63 64 extern int measured_strings_receive(measured_string_t **, uint8_t **, size_t); 64 65 extern int measured_strings_reply(const measured_string_t *, size_t); -
uspace/lib/c/include/adt/prodcons.h
r9bd5746 rcf5e86e 1 1 /* 2 * Copyright (c) 20 09Martin Decky2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #include <test.h> 29 /** @addtogroup libc 30 * @{ 31 */ 32 /** @file 33 */ 30 34 31 const char *test_sse1(void) 32 { 33 return NULL; 34 } 35 #ifndef LIBC_PRODCONS_H_ 36 #define LIBC_PRODCONS_H_ 37 38 #include <adt/list.h> 39 #include <fibril_synch.h> 40 41 typedef struct { 42 fibril_mutex_t mtx; 43 fibril_condvar_t cv; 44 link_t list; 45 } prodcons_t; 46 47 extern void prodcons_initialize(prodcons_t *); 48 extern void prodcons_produce(prodcons_t *, link_t *); 49 extern link_t *prodcons_consume(prodcons_t *); 50 51 #endif 52 53 /** @} 54 */ -
uspace/lib/c/include/as.h
r9bd5746 rcf5e86e 54 54 } 55 55 56 extern void *as_area_create(void * address, size_t size, int flags);57 extern int as_area_resize(void * address, size_t size, int flags);58 extern int as_area_change_flags(void * address, int flags);59 extern int as_area_destroy(void * address);60 extern void *set_maxheapsize(size_t mhs);61 extern void * as_get_mappable_page(size_t sz);56 extern void *as_area_create(void *, size_t, unsigned int); 57 extern int as_area_resize(void *, size_t, unsigned int); 58 extern int as_area_change_flags(void *, unsigned int); 59 extern int as_area_destroy(void *); 60 extern void *set_maxheapsize(size_t); 61 extern void *as_get_mappable_page(size_t); 62 62 63 63 #endif -
uspace/lib/c/include/event.h
r9bd5746 rcf5e86e 39 39 40 40 extern int event_subscribe(event_type_t, sysarg_t); 41 extern int event_unmask(event_type_t); 41 42 42 43 #endif -
uspace/lib/c/include/fibril.h
r9bd5746 rcf5e86e 70 70 int (*func)(void *); 71 71 tcb_t *tcb; 72 72 73 73 struct fibril *clean_after_me; 74 74 int retval; 75 75 int flags; 76 76 77 77 fibril_owner_info_t *waits_for; 78 78 } fibril_t; -
uspace/lib/c/include/io/klog.h
r9bd5746 rcf5e86e 37 37 38 38 #include <sys/types.h> 39 #include <stdarg.h> 39 40 40 41 extern size_t klog_write(const void *, size_t); 41 42 extern void klog_update(void); 43 extern int klog_printf(const char *, ...); 44 extern int klog_vprintf(const char *, va_list); 42 45 43 46 #endif -
uspace/lib/c/include/malloc.h
r9bd5746 rcf5e86e 46 46 extern void *realloc(const void *addr, const size_t size); 47 47 extern void free(const void *addr); 48 extern void *heap_check(void); 48 49 49 50 #endif -
uspace/lib/net/il/ip_client.c
r9bd5746 rcf5e86e 181 181 /* Set the header */ 182 182 header = (ip_header_t *) data; 183 header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) +184 ipopt_length);183 SET_IP_HEADER_LENGTH(header, 184 (IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length))); 185 185 header->ttl = (ttl ? ttl : IPDEFTTL); 186 186 header->tos = tos; … … 188 188 189 189 if (dont_fragment) 190 header->flags = IPFLAG_DONT_FRAGMENT;190 SET_IP_HEADER_FLAGS(header, IPFLAG_DONT_FRAGMENT); 191 191 192 192 return EOK; … … 227 227 *tos = header->tos; 228 228 if (dont_fragment) 229 *dont_fragment = header->flags& IPFLAG_DONT_FRAGMENT;229 *dont_fragment = GET_IP_HEADER_FLAGS(header) & IPFLAG_DONT_FRAGMENT; 230 230 if (ipopt_length) { 231 231 *ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t); -
uspace/lib/net/include/ip_header.h
r9bd5746 rcf5e86e 64 64 */ 65 65 #define IP_FRAGMENT_OFFSET(header) \ 66 ((( (header)->fragment_offset_high<< 8) + \66 (((GET_IP_HEADER_FRAGMENT_OFFSET_HIGH(header) << 8) + \ 67 67 (header)->fragment_offset_low) * 8U) 68 68 … … 83 83 */ 84 84 #define IP_HEADER_LENGTH(header) \ 85 ( (header)->header_length* 4U)85 (GET_IP_HEADER_LENGTH(header) * 4U) 86 86 87 87 /** Returns the actual IP packet total length. … … 143 143 */ 144 144 struct ip_header { 145 #ifdef ARCH_IS_BIG_ENDIAN 146 uint8_t version : 4; 147 uint8_t header_length : 4; 148 #else 149 uint8_t header_length : 4; 150 uint8_t version : 4; 151 #endif 145 uint8_t vhl; /* version, header_length */ 146 147 #define GET_IP_HEADER_VERSION(header) \ 148 (((header)->vhl & 0xf0) >> 4) 149 #define SET_IP_HEADER_VERSION(header, version) \ 150 ((header)->vhl = \ 151 ((version & 0x0f) << 4) | ((header)->vhl & 0x0f)) 152 153 #define GET_IP_HEADER_LENGTH(header) \ 154 ((header)->vhl & 0x0f) 155 #define SET_IP_HEADER_LENGTH(header, length) \ 156 ((header)->vhl = \ 157 (length & 0x0f) | ((header)->vhl & 0xf0)) 152 158 153 159 uint8_t tos; … … 155 161 uint16_t identification; 156 162 157 #ifdef ARCH_IS_BIG_ENDIAN 158 uint8_t flags : 3; 159 uint8_t fragment_offset_high : 5; 160 #else 161 uint8_t fragment_offset_high : 5; 162 uint8_t flags : 3; 163 #endif 163 uint8_t ffoh; /* flags, fragment_offset_high */ 164 165 #define GET_IP_HEADER_FLAGS(header) \ 166 (((header)->ffoh & 0xe0) >> 5) 167 #define SET_IP_HEADER_FLAGS(header, flags) \ 168 ((header)->ffoh = \ 169 ((flags & 0x07) << 5) | ((header)->ffoh & 0x1f)) 170 171 #define GET_IP_HEADER_FRAGMENT_OFFSET_HIGH(header) \ 172 ((header)->ffoh & 0x1f) 173 #define SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(header, fragment_offset_high) \ 174 ((header)->ffoh = \ 175 (fragment_offset_high & 0x1f) | ((header)->ffoh & 0xe0)) 164 176 165 177 uint8_t fragment_offset_low; … … 181 193 uint8_t pointer; 182 194 183 #ifdef ARCH_IS_BIG_ENDIAN 184 uint8_t overflow : 4; 185 uint8_t flags : 4; 186 #else 187 uint8_t flags : 4; 188 uint8_t overflow : 4; 189 #endif 195 uint8_t of; /* overflow, flags */ 196 197 #define GET_IP_OPTION_OVERFLOW(option) \ 198 (((option)->of & 0xf0) >> 4) 199 #define SET_IP_OPTION_OVERFLOW(option, overflow) \ 200 ((option)->of = \ 201 ((overflow & 0x0f) << 4) | ((option)->of & 0x0f)) 202 203 #define GET_IP_OPTION_FLAGS(option) \ 204 ((option)->of & 0x0f) 205 #define SET_IP_OPTION_FLAGS(option, flags) \ 206 ((option)->of = \ 207 (flags & 0x0f) | ((option)->of & 0xf0)) 208 190 209 } __attribute__ ((packed)); 191 210 -
uspace/lib/softfloat/generic/add.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <add.h>37 #include <comparison.h>35 #include <sftypes.h> 36 #include <add.h> 37 #include <comparison.h> 38 38 39 39 /** Add two Float32 numbers with same signs … … 139 139 a.parts.exp = exp1; 140 140 141 /* Clear hidden bit and shift */141 /* Clear hidden bit and shift */ 142 142 a.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)) ; 143 143 return a; 144 144 } 145 146 145 147 146 /** Add two Float64 numbers with same signs … … 250 249 251 250 a.parts.exp = exp1; 252 /* Clear hidden bit and shift */251 /* Clear hidden bit and shift */ 253 252 a.parts.fraction = ( (frac1 >> 6 ) & (~FLOAT64_HIDDEN_BIT_MASK)); 254 253 -
uspace/lib/softfloat/generic/common.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <common.h>35 #include <sftypes.h> 36 #include <common.h> 37 37 38 38 /* Table for fast leading zeroes counting */ … … 213 213 /** @} 214 214 */ 215 -
uspace/lib/softfloat/generic/comparison.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <comparison.h>35 #include <sftypes.h> 36 #include <comparison.h> 37 37 38 inline int isFloat32NaN(float32 f) 39 { /* NaN : exp = 0xff and nonzero fraction */ 40 return ((f.parts.exp==0xFF)&&(f.parts.fraction)); 38 /* NaN : exp = 0xff and nonzero fraction */ 39 int isFloat32NaN(float32 f) 40 { 41 return ((f.parts.exp == 0xFF) && (f.parts.fraction)); 41 42 } 42 43 43 inline int isFloat64NaN(float64 d) 44 { /* NaN : exp = 0x7ff and nonzero fraction */ 45 return ((d.parts.exp==0x7FF)&&(d.parts.fraction)); 44 /* NaN : exp = 0x7ff and nonzero fraction */ 45 int isFloat64NaN(float64 d) 46 { 47 return ((d.parts.exp == 0x7FF) && (d.parts.fraction)); 46 48 } 47 49 48 inline int isFloat32SigNaN(float32 f) 49 { /* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 50 return ((f.parts.exp==0xFF)&&(f.parts.fraction<0x400000)&&(f.parts.fraction)); 50 /* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 51 int isFloat32SigNaN(float32 f) 52 { 53 return ((f.parts.exp == 0xFF) && (f.parts.fraction < 0x400000) && (f.parts.fraction)); 51 54 } 52 55 53 inline int isFloat64SigNaN(float64 d) 54 { /* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 55 return ((d.parts.exp==0x7FF)&&(d.parts.fraction)&&(d.parts.fraction<0x8000000000000ll)); 56 /* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */ 57 int isFloat64SigNaN(float64 d) 58 { 59 return ((d.parts.exp == 0x7FF) && (d.parts.fraction) && (d.parts.fraction < 0x8000000000000ll)); 56 60 } 57 61 58 in line int isFloat32Infinity(float32 f)62 int isFloat32Infinity(float32 f) 59 63 { 60 return ((f.parts.exp ==0xFF)&&(f.parts.fraction==0x0));64 return ((f.parts.exp == 0xFF) && (f.parts.fraction == 0x0)); 61 65 } 62 66 63 in line int isFloat64Infinity(float64 d)67 int isFloat64Infinity(float64 d) 64 68 { 65 return ((d.parts.exp ==0x7FF)&&(d.parts.fraction==0x0));69 return ((d.parts.exp == 0x7FF) && (d.parts.fraction == 0x0)); 66 70 } 67 71 68 in line int isFloat32Zero(float32 f)72 int isFloat32Zero(float32 f) 69 73 { 70 74 return (((f.binary) & 0x7FFFFFFF) == 0); 71 75 } 72 76 73 in line int isFloat64Zero(float64 d)77 int isFloat64Zero(float64 d) 74 78 { 75 79 return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0); … … 77 81 78 82 /** 79 * @return 1 , if both floats are equal - but NaNs are not recognized83 * @return 1 if both floats are equal - but NaNs are not recognized 80 84 */ 81 in line int isFloat32eq(float32 a, float32 b)85 int isFloat32eq(float32 a, float32 b) 82 86 { 83 return ((a.binary==b.binary)||(((a.binary| b.binary)&0x7FFFFFFF)==0)); /* a equals to b or both are zeros (with any sign) */ 87 /* a equals to b or both are zeros (with any sign) */ 88 return ((a.binary==b.binary) || (((a.binary | b.binary) & 0x7FFFFFFF) == 0)); 84 89 } 85 90 86 91 /** 87 * @return 1 , if a<b - but NaNs are not recognized92 * @return 1 if a < b - but NaNs are not recognized 88 93 */ 89 in line int isFloat32lt(float32 a, float32 b)94 int isFloat32lt(float32 a, float32 b) 90 95 { 91 if (((a.binary | b.binary)&0x7FFFFFFF)==0) {96 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) 92 97 return 0; /* +- zeroes */ 93 };94 98 95 if ((a.parts.sign)&&(b.parts.sign)) { 96 /*if both are negative, smaller is that with greater binary value*/ 97 return (a.binary>b.binary); 98 }; 99 if ((a.parts.sign) && (b.parts.sign)) 100 /* if both are negative, smaller is that with greater binary value */ 101 return (a.binary > b.binary); 99 102 100 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/ 101 a.parts.sign=!a.parts.sign; 102 b.parts.sign=!b.parts.sign; 103 return (a.binary<b.binary); 104 103 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */ 104 a.parts.sign = !a.parts.sign; 105 b.parts.sign = !b.parts.sign; 106 return (a.binary < b.binary); 105 107 } 106 108 107 109 /** 108 * @return 1 , if a>b - but NaNs are not recognized110 * @return 1 if a > b - but NaNs are not recognized 109 111 */ 110 in line int isFloat32gt(float32 a, float32 b)112 int isFloat32gt(float32 a, float32 b) 111 113 { 112 if (((a.binary | b.binary)&0x7FFFFFFF)==0) {114 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) 113 115 return 0; /* zeroes are equal with any sign */ 114 };115 116 116 if ((a.parts.sign)&&(b.parts.sign)) { 117 /*if both are negative, greater is that with smaller binary value*/ 118 return (a.binary<b.binary); 119 }; 117 if ((a.parts.sign) && (b.parts.sign)) 118 /* if both are negative, greater is that with smaller binary value */ 119 return (a.binary < b.binary); 120 120 121 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/ 122 a.parts.sign=!a.parts.sign; 123 b.parts.sign=!b.parts.sign; 124 return (a.binary>b.binary); 125 121 /* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison) */ 122 a.parts.sign = !a.parts.sign; 123 b.parts.sign = !b.parts.sign; 124 return (a.binary > b.binary); 126 125 } 127 126 -
uspace/lib/softfloat/generic/div.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include<sftypes.h> 36 #include<add.h> 37 #include<div.h> 38 #include<comparison.h> 39 #include<mul.h> 40 #include<common.h> 41 35 #include <sftypes.h> 36 #include <add.h> 37 #include <div.h> 38 #include <comparison.h> 39 #include <mul.h> 40 #include <common.h> 42 41 43 42 float32 divFloat32(float32 a, float32 b) -
uspace/lib/softfloat/generic/mul.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <mul.h>37 #include <comparison.h>38 #include <common.h>35 #include <sftypes.h> 36 #include <mul.h> 37 #include <comparison.h> 38 #include <common.h> 39 39 40 40 /** Multiply two 32 bit float numbers -
uspace/lib/softfloat/generic/other.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ -
uspace/lib/softfloat/generic/softfloat.c
r9bd5746 rcf5e86e 35 35 */ 36 36 37 #include <softfloat.h>38 #include <sftypes.h>39 40 #include <add.h>41 #include <sub.h>42 #include <mul.h>43 #include <div.h>44 45 #include <conversion.h>46 #include <comparison.h>47 #include <other.h>48 49 #include <functions.h>37 #include <softfloat.h> 38 #include <sftypes.h> 39 40 #include <add.h> 41 #include <sub.h> 42 #include <mul.h> 43 #include <div.h> 44 45 #include <conversion.h> 46 #include <comparison.h> 47 #include <other.h> 48 49 #include <functions.h> 50 50 51 51 /* Arithmetic functions */ … … 494 494 } 495 495 496 497 496 /** @} 498 497 */ 499 -
uspace/lib/softfloat/generic/sub.c
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #include <sftypes.h>36 #include <sub.h>37 #include <comparison.h>35 #include <sftypes.h> 36 #include <sub.h> 37 #include <comparison.h> 38 38 39 39 /** Subtract two float32 numbers with same signs … … 260 260 } 261 261 262 263 /** @} 264 */ 265 262 /** @} 263 */ -
uspace/lib/softfloat/include/add.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __ADD_H__ 37 37 38 float32 addFloat32(float32 a, float32 b); 39 40 float64 addFloat64(float64 a, float64 b); 38 extern float32 addFloat32(float32, float32); 39 extern float64 addFloat64(float64, float64); 41 40 42 41 #endif 43 42 44 45 /** @} 43 /** @} 46 44 */ 47 -
uspace/lib/softfloat/include/common.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __COMMON_H__ 37 37 38 #include <sftypes.h>38 #include <sftypes.h> 39 39 40 float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign);40 extern float64 finishFloat64(int32_t, uint64_t, char); 41 41 42 int countZeroes64(uint64_t i);43 int countZeroes32(uint32_t i);44 int countZeroes8(uint8_t i);42 extern int countZeroes64(uint64_t); 43 extern int countZeroes32(uint32_t); 44 extern int countZeroes8(uint8_t); 45 45 46 void roundFloat32(int32_t *exp, uint32_t *fraction);47 void roundFloat64(int32_t *exp, uint64_t *fraction);46 extern void roundFloat32(int32_t *, uint32_t *); 47 extern void roundFloat64(int32_t *, uint64_t *); 48 48 49 49 #endif 50 50 51 /** @}51 /** @} 52 52 */ 53 -
uspace/lib/softfloat/include/comparison.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __COMPARISON_H__ 37 37 38 inline int isFloat32NaN(float32 f);39 inline int isFloat32SigNaN(float32 f);38 extern int isFloat32NaN(float32); 39 extern int isFloat32SigNaN(float32); 40 40 41 inline int isFloat32Infinity(float32 f);42 inline int isFloat32Zero(float32 f);41 extern int isFloat32Infinity(float32); 42 extern int isFloat32Zero(float32); 43 43 44 inline int isFloat64NaN(float64 d);45 inline int isFloat64SigNaN(float64 d);44 extern int isFloat64NaN(float64); 45 extern int isFloat64SigNaN(float64); 46 46 47 inline int isFloat64Infinity(float64 d);48 inline int isFloat64Zero(float64 d);47 extern int isFloat64Infinity(float64); 48 extern int isFloat64Zero(float64); 49 49 50 inline int isFloat32eq(float32 a, float32 b);51 inline int isFloat32lt(float32 a, float32 b);52 inline int isFloat32gt(float32 a, float32 b);50 extern int isFloat32eq(float32, float32); 51 extern int isFloat32lt(float32, float32); 52 extern int isFloat32gt(float32, float32); 53 53 54 54 #endif 55 55 56 57 /** @} 56 /** @} 58 57 */ 59 -
uspace/lib/softfloat/include/conversion.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __CONVERSION_H__ 37 37 38 float64 convertFloat32ToFloat64(float32 a); 38 extern float64 convertFloat32ToFloat64(float32); 39 extern float32 convertFloat64ToFloat32(float64); 39 40 40 float32 convertFloat64ToFloat32(float64 a); 41 extern uint32_t float32_to_uint32(float32); 42 extern int32_t float32_to_int32(float32); 41 43 42 uint32_t float32_to_uint32(float32 a);43 int32_t float32_to_int32(float32 a);44 extern uint64_t float32_to_uint64(float32); 45 extern int64_t float32_to_int64(float32); 44 46 45 uint64_t float32_to_uint64(float32 a);46 int64_t float32_to_int64(float32 a);47 extern uint64_t float64_to_uint64(float64); 48 extern int64_t float64_to_int64(float64); 47 49 48 uint64_t float64_to_uint64(float64 a);49 int64_t float64_to_int64(float64 a);50 extern uint32_t float64_to_uint32(float64); 51 extern int32_t float64_to_int32(float64); 50 52 51 uint32_t float64_to_uint32(float64 a);52 int32_t float64_to_int32(float64 a);53 extern float32 uint32_to_float32(uint32_t); 54 extern float32 int32_to_float32(int32_t); 53 55 54 float32 uint32_to_float32(uint32_t i);55 float32 int32_to_float32(int32_t i);56 extern float32 uint64_to_float32(uint64_t); 57 extern float32 int64_to_float32(int64_t); 56 58 57 float32 uint64_to_float32(uint64_t i);58 float32 int64_to_float32(int64_t i);59 extern float64 uint32_to_float64(uint32_t); 60 extern float64 int32_to_float64(int32_t); 59 61 60 float64 uint32_to_float64(uint32_t i); 61 float64 int32_to_float64(int32_t i); 62 63 float64 uint64_to_float64(uint64_t i); 64 float64 int64_to_float64(int64_t i); 62 extern float64 uint64_to_float64(uint64_t); 63 extern float64 int64_to_float64(int64_t); 65 64 66 65 #endif 67 66 68 69 /** @} 67 /** @} 70 68 */ 71 -
uspace/lib/softfloat/include/div.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __DIV_H__ 37 37 38 float32 divFloat32(float32 a, float32 b);39 float64 divFloat64(float64 a, float64 b);38 extern float32 divFloat32(float32, float32); 39 extern float64 divFloat64(float64, float64); 40 40 41 uint64_t divFloat64estim(uint64_t a, uint64_t b);41 extern uint64_t divFloat64estim(uint64_t, uint64_t); 42 42 43 43 #endif 44 44 45 46 /** @} 45 /** @} 47 46 */ 48 -
uspace/lib/softfloat/include/mul.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __MUL_H__ 37 37 38 float32 mulFloat32(float32 a, float32 b); 38 extern float32 mulFloat32(float32, float32); 39 extern float64 mulFloat64(float64, float64); 39 40 40 float64 mulFloat64(float64 a, float64 b); 41 42 void mul64integers(uint64_t a,uint64_t b, uint64_t *lo, uint64_t *hi); 41 extern void mul64integers(uint64_t, uint64_t, uint64_t *, uint64_t *); 43 42 44 43 #endif 45 44 46 47 /** @} 45 /** @} 48 46 */ 49 -
uspace/lib/softfloat/include/other.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 38 38 #endif 39 39 40 41 /** @} 40 /** @} 42 41 */ 43 -
uspace/lib/softfloat/include/sftypes.h
r9bd5746 rcf5e86e 55 55 #error Unknown endianess 56 56 #endif 57 } parts __attribute__ ((packed));57 } parts __attribute__ ((packed)); 58 58 } float32; 59 59 … … 77 77 } float64; 78 78 79 #define FLOAT32_MAX 0x7f80000080 #define FLOAT32_MIN 0xff80000079 #define FLOAT32_MAX 0x7f800000 80 #define FLOAT32_MIN 0xff800000 81 81 #define FLOAT64_MAX 82 82 #define FLOAT64_MIN … … 86 86 * comparing with these constants is not sufficient. 87 87 */ 88 #define FLOAT32_NAN 0x7FC0000189 #define FLOAT32_SIGNAN 0x7F80000190 #define FLOAT32_INF 0x7F80000091 88 92 #define FLOAT 64_NAN 0x7FF8000000000001ll93 #define FLOAT 64_SIGNAN 0x7FF0000000000001ll94 #define FLOAT 64_INF 0x7FF0000000000000ll89 #define FLOAT32_NAN 0x7FC00001 90 #define FLOAT32_SIGNAN 0x7F800001 91 #define FLOAT32_INF 0x7F800000 95 92 96 #define FLOAT32_FRACTION_SIZE 23 97 #define FLOAT64_FRACTION_SIZE 52 93 #define FLOAT64_NAN 0x7FF8000000000001ll 94 #define FLOAT64_SIGNAN 0x7FF0000000000001ll 95 #define FLOAT64_INF 0x7FF0000000000000ll 98 96 99 #define FLOAT32_ HIDDEN_BIT_MASK 0x800000100 #define FLOAT64_ HIDDEN_BIT_MASK 0x10000000000000ll97 #define FLOAT32_FRACTION_SIZE 23 98 #define FLOAT64_FRACTION_SIZE 52 101 99 102 #define FLOAT32_ MAX_EXPONENT 0xFF103 #define FLOAT64_ MAX_EXPONENT 0x7FF100 #define FLOAT32_HIDDEN_BIT_MASK 0x800000 101 #define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll 104 102 105 #define FLOAT32_BIAS 0x7F 106 #define FLOAT64_BIAS 0x3FF 107 #define FLOAT80_BIAS 0x3FFF 103 #define FLOAT32_MAX_EXPONENT 0xFF 104 #define FLOAT64_MAX_EXPONENT 0x7FF 108 105 106 #define FLOAT32_BIAS 0x7F 107 #define FLOAT64_BIAS 0x3FF 108 #define FLOAT80_BIAS 0x3FFF 109 109 110 110 #endif -
uspace/lib/softfloat/include/softfloat.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __SOFTFLOAT_H__ 37 37 38 float __addsf3(float a, float b);39 double __adddf3(double a, double b);40 long double __addtf3(long double a, long double b);41 long double __addxf3(long double a, long double b);42 43 float __subsf3(float a, float b);44 double __subdf3(double a, double b);45 long double __subtf3(long double a, long double b);46 long double __subxf3(long double a, long double b);47 48 float __mulsf3(float a, float b);49 double __muldf3(double a, double b);50 long double __multf3(long double a, long double b);51 long double __mulxf3(long double a, long double b);52 53 float __divsf3(float a, float b);54 double __divdf3(double a, double b);55 long double __divtf3(long double a, long double b);56 long double __divxf3(long double a, long double b);57 58 float __negsf2(float a);59 double __negdf2(double a);60 long double __negtf2(long double a);61 long double __negxf2(long double a);62 63 double __extendsfdf2(float a);64 long double __extendsftf2(float a);65 long double __extendsfxf2(float a);66 long double __extenddftf2(double a);67 long double __extenddfxf2(double a);68 69 double __truncxfdf2(long double a);70 double __trunctfdf2(long double a);71 float __truncxfsf2(long double a);72 float __trunctfsf2(long double a);73 float __truncdfsf2(double a);74 75 int __fixsfsi(float a);76 int __fixdfsi(double a);77 int __fixtfsi(long double a);78 int __fixxfsi(long double a);79 80 long __fixsfdi(float a);81 long __fixdfdi(double a);82 long __fixtfdi(long double a);83 long __fixxfdi(long double a);84 85 long long __fixsfti(float a);86 long long __fixdfti(double a);87 long long __fixtfti(long double a);88 long long __fixxfti(long double a);89 90 unsigned int __fixunssfsi(float a);91 unsigned int __fixunsdfsi(double a);92 unsigned int __fixunstfsi(long double a);93 unsigned int __fixunsxfsi(long double a);94 95 unsigned long __fixunssfdi(float a);96 unsigned long __fixunsdfdi(double a);97 unsigned long __fixunstfdi(long double a);98 unsigned long __fixunsxfdi(long double a);99 100 unsigned long long __fixunssfti(float a);101 unsigned long long __fixunsdfti(double a);102 unsigned long long __fixunstfti(long double a);103 unsigned long long __fixunsxfti(long double a);104 105 float __floatsisf(int i);106 double __floatsidf(int i);107 long double __floatsitf(int i);108 long double __floatsixf(int i);109 110 float __floatdisf(long i);111 double __floatdidf(long i);112 long double __floatditf(long i);113 long double __floatdixf(long i);114 115 float __floattisf(long long i);116 double __floattidf(long long i);117 long double __floattitf(long long i);118 long double __floattixf(long long i);119 120 float __floatunsisf(unsigned int i);121 double __floatunsidf(unsigned int i);122 long double __floatunsitf(unsigned int i);123 long double __floatunsixf(unsigned int i);124 125 float __floatundisf(unsigned long i);126 double __floatundidf(unsigned long i);127 long double __floatunditf(unsigned long i);128 long double __floatundixf(unsigned long i);129 130 float __floatuntisf(unsigned long long i);131 double __floatuntidf(unsigned long long i);132 long double __floatuntitf(unsigned long long i);133 long double __floatuntixf(unsigned long long i);134 135 int __cmpsf2(float a, float b);136 int __cmpdf2(double a, double b);137 int __cmptf2(long double a, long double b);138 139 int __unordsf2(float a, float b);140 int __unorddf2(double a, double b);141 int __unordtf2(long double a, long double b);142 143 int __eqsf2(float a, float b);144 int __eqdf2(double a, double b);145 int __eqtf2(long double a, long double b);146 147 int __nesf2(float a, float b);148 int __nedf2(double a, double b);149 int __netf2(long double a, long double b);150 151 int __gesf2(float a, float b);152 int __gedf2(double a, double b);153 int __getf2(long double a, long double b);154 155 int __ltsf2(float a, float b);156 int __ltdf2(double a, double b);157 int __lttf2(long double a, long double b);158 int __lesf2(float a, float b);159 int __ledf2(double a, double b);160 int __letf2(long double a, long double b);161 162 int __gtsf2(float a, float b);163 int __gtdf2(double a, double b);164 int __gttf2(long double a, long double b);165 166 /* Not implemented yet */167 float __powisf2(float a, int b);38 extern float __addsf3(float, float); 39 extern double __adddf3(double, double); 40 extern long double __addtf3(long double, long double); 41 extern long double __addxf3(long double, long double); 42 43 extern float __subsf3(float, float); 44 extern double __subdf3(double, double); 45 extern long double __subtf3(long double, long double); 46 extern long double __subxf3(long double, long double); 47 48 extern float __mulsf3(float, float); 49 extern double __muldf3(double, double); 50 extern long double __multf3(long double, long double); 51 extern long double __mulxf3(long double, long double); 52 53 extern float __divsf3(float, float); 54 extern double __divdf3(double, double); 55 extern long double __divtf3(long double, long double); 56 extern long double __divxf3(long double, long double); 57 58 extern float __negsf2(float); 59 extern double __negdf2(double); 60 extern long double __negtf2(long double); 61 extern long double __negxf2(long double); 62 63 extern double __extendsfdf2(float); 64 extern long double __extendsftf2(float); 65 extern long double __extendsfxf2(float); 66 extern long double __extenddftf2(double); 67 extern long double __extenddfxf2(double); 68 69 extern double __truncxfdf2(long double); 70 extern double __trunctfdf2(long double); 71 extern float __truncxfsf2(long double); 72 extern float __trunctfsf2(long double); 73 extern float __truncdfsf2(double); 74 75 extern int __fixsfsi(float); 76 extern int __fixdfsi(double); 77 extern int __fixtfsi(long double); 78 extern int __fixxfsi(long double); 79 80 extern long __fixsfdi(float); 81 extern long __fixdfdi(double); 82 extern long __fixtfdi(long double); 83 extern long __fixxfdi(long double); 84 85 extern long long __fixsfti(float); 86 extern long long __fixdfti(double); 87 extern long long __fixtfti(long double); 88 extern long long __fixxfti(long double); 89 90 extern unsigned int __fixunssfsi(float); 91 extern unsigned int __fixunsdfsi(double); 92 extern unsigned int __fixunstfsi(long double); 93 extern unsigned int __fixunsxfsi(long double); 94 95 extern unsigned long __fixunssfdi(float); 96 extern unsigned long __fixunsdfdi(double); 97 extern unsigned long __fixunstfdi(long double); 98 extern unsigned long __fixunsxfdi(long double); 99 100 extern unsigned long long __fixunssfti(float); 101 extern unsigned long long __fixunsdfti(double); 102 extern unsigned long long __fixunstfti(long double); 103 extern unsigned long long __fixunsxfti(long double); 104 105 extern float __floatsisf(int); 106 extern double __floatsidf(int); 107 extern long double __floatsitf(int); 108 extern long double __floatsixf(int); 109 110 extern float __floatdisf(long); 111 extern double __floatdidf(long); 112 extern long double __floatditf(long); 113 extern long double __floatdixf(long); 114 115 extern float __floattisf(long long); 116 extern double __floattidf(long long); 117 extern long double __floattitf(long long); 118 extern long double __floattixf(long long); 119 120 extern float __floatunsisf(unsigned int); 121 extern double __floatunsidf(unsigned int); 122 extern long double __floatunsitf(unsigned int); 123 extern long double __floatunsixf(unsigned int); 124 125 extern float __floatundisf(unsigned long); 126 extern double __floatundidf(unsigned long); 127 extern long double __floatunditf(unsigned long); 128 extern long double __floatundixf(unsigned long); 129 130 extern float __floatuntisf(unsigned long long); 131 extern double __floatuntidf(unsigned long long); 132 extern long double __floatuntitf(unsigned long long); 133 extern long double __floatuntixf(unsigned long long); 134 135 extern int __cmpsf2(float, float); 136 extern int __cmpdf2(double, double); 137 extern int __cmptf2(long double, long double); 138 139 extern int __unordsf2(float, float); 140 extern int __unorddf2(double, double); 141 extern int __unordtf2(long double, long double); 142 143 extern int __eqsf2(float, float); 144 extern int __eqdf2(double, double); 145 extern int __eqtf2(long double, long double); 146 147 extern int __nesf2(float, float); 148 extern int __nedf2(double, double); 149 extern int __netf2(long double, long double); 150 151 extern int __gesf2(float, float); 152 extern int __gedf2(double, double); 153 extern int __getf2(long double, long double); 154 155 extern int __ltsf2(float, float); 156 extern int __ltdf2(double, double); 157 extern int __lttf2(long double, long double); 158 extern int __lesf2(float, float); 159 extern int __ledf2(double, double); 160 extern int __letf2(long double, long double); 161 162 extern int __gtsf2(float, float); 163 extern int __gtdf2(double, double); 164 extern int __gttf2(long double, long double); 165 166 /* Not implemented yet */ 167 extern float __powisf2(float, int); 168 168 169 169 #endif 170 170 171 172 /** @} 171 /** @} 173 172 */ 174 -
uspace/lib/softfloat/include/sub.h
r9bd5746 rcf5e86e 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 36 36 #define __SUB_H__ 37 37 38 float32 subFloat32(float32 a, float32 b); 39 40 float64 subFloat64(float64 a, float64 b); 38 extern float32 subFloat32(float32, float32); 39 extern float64 subFloat64(float64, float64); 41 40 42 41 #endif 43 42 44 45 /** @} 43 /** @} 46 44 */ 47 -
uspace/srv/net/il/ip/ip.c
r9bd5746 rcf5e86e 201 201 202 202 /* Set the destination address */ 203 switch ( header->version) {203 switch (GET_IP_HEADER_VERSION(header)) { 204 204 case IPVERSION: 205 205 addrlen = sizeof(dest_in); … … 635 635 636 636 /* Process all IP options */ 637 while (next < first->header_length) {637 while (next < GET_IP_HEADER_LENGTH(first)) { 638 638 option = (ip_option_t *) (((uint8_t *) first) + next); 639 639 /* Skip end or noop */ … … 656 656 if (length % 4) { 657 657 bzero(((uint8_t *) last) + length, 4 - (length % 4)); 658 last->header_length = length / 4 + 1;658 SET_IP_HEADER_LENGTH(last, (length / 4 + 1)); 659 659 } else { 660 last->header_length = length / 4;660 SET_IP_HEADER_LENGTH(last, (length / 4)); 661 661 } 662 662 … … 706 706 return rc; 707 707 708 header->version = IPV4;709 header->fragment_offset_high = 0;708 SET_IP_HEADER_VERSION(header, IPV4); 709 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(header, 0); 710 710 header->fragment_offset_low = 0; 711 711 header->header_checksum = 0; … … 735 735 memcpy(middle_header, last_header, 736 736 IP_HEADER_LENGTH(last_header)); 737 header->flags |= IPFLAG_MORE_FRAGMENTS; 737 SET_IP_HEADER_FLAGS(header, 738 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 738 739 middle_header->total_length = 739 740 htons(packet_get_data_length(next)); 740 middle_header->fragment_offset_high =741 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ;741 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(middle_header, 742 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length)); 742 743 middle_header->fragment_offset_low = 743 744 IP_COMPUTE_FRAGMENT_OFFSET_LOW(length); … … 768 769 middle_header->total_length = 769 770 htons(packet_get_data_length(next)); 770 middle_header->fragment_offset_high =771 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ;771 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(middle_header, 772 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length)); 772 773 middle_header->fragment_offset_low = 773 774 IP_COMPUTE_FRAGMENT_OFFSET_LOW(length); … … 785 786 length += packet_get_data_length(next); 786 787 free(last_header); 787 header->flags |= IPFLAG_MORE_FRAGMENTS; 788 SET_IP_HEADER_FLAGS(header, 789 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 788 790 } 789 791 … … 834 836 new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length); 835 837 offset = IP_FRAGMENT_OFFSET(header) + IP_HEADER_DATA_LENGTH(header); 836 new_header->fragment_offset_high =837 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(offset) ;838 SET_IP_HEADER_FRAGMENT_OFFSET_HIGH(new_header, 839 IP_COMPUTE_FRAGMENT_OFFSET_HIGH(offset)); 838 840 new_header->fragment_offset_low = 839 841 IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset); … … 865 867 return NULL; 866 868 memcpy(middle, last, IP_HEADER_LENGTH(last)); 867 middle->flags |= IPFLAG_MORE_FRAGMENTS; 869 SET_IP_HEADER_FLAGS(middle, 870 (GET_IP_HEADER_FLAGS(middle) | IPFLAG_MORE_FRAGMENTS)); 868 871 return middle; 869 872 } … … 922 925 923 926 /* Fragmentation forbidden? */ 924 if( header->flags& IPFLAG_DONT_FRAGMENT)927 if(GET_IP_HEADER_FLAGS(header) & IPFLAG_DONT_FRAGMENT) 925 928 return EPERM; 926 929 … … 958 961 959 962 /* Mark the first as fragmented */ 960 header->flags |= IPFLAG_MORE_FRAGMENTS; 963 SET_IP_HEADER_FLAGS(header, 964 (GET_IP_HEADER_FLAGS(header) | IPFLAG_MORE_FRAGMENTS)); 961 965 962 966 /* Create middle fragments */ … … 1319 1323 int rc; 1320 1324 1321 if (( header->flags& IPFLAG_MORE_FRAGMENTS) ||1325 if ((GET_IP_HEADER_FLAGS(header) & IPFLAG_MORE_FRAGMENTS) || 1322 1326 IP_FRAGMENT_OFFSET(header)) { 1323 1327 // TODO fragmented … … 1325 1329 } 1326 1330 1327 switch ( header->version) {1331 switch (GET_IP_HEADER_VERSION(header)) { 1328 1332 case IPVERSION: 1329 1333 addrlen = sizeof(src_in); … … 1447 1451 1448 1452 /* Set the destination address */ 1449 switch ( header->version) {1453 switch (GET_IP_HEADER_VERSION(header)) { 1450 1454 case IPVERSION: 1451 1455 addrlen = sizeof(addr_in); -
uspace/srv/net/tl/tcp/tcp.c
r9bd5746 rcf5e86e 476 476 old_incoming = socket_data->next_incoming; 477 477 478 if ( header->finalize) {478 if (GET_TCP_HEADER_FINALIZE(header)) { 479 479 socket_data->fin_incoming = new_sequence_number + 480 480 total_length - TCP_HEADER_LENGTH(header); … … 838 838 assert(packet); 839 839 840 if (! header->synchronize)840 if (!GET_TCP_HEADER_SYNCHRONIZE(header)) 841 841 return tcp_release_and_return(packet, EINVAL); 842 842 … … 903 903 assert(packet); 904 904 905 if (! header->synchronize)905 if (!GET_TCP_HEADER_SYNCHRONIZE(header)) 906 906 return tcp_release_and_return(packet, EINVAL); 907 907 … … 1057 1057 assert(packet); 1058 1058 1059 if (! header->acknowledge)1059 if (!GET_TCP_HEADER_ACKNOWLEDGE(header)) 1060 1060 return tcp_release_and_return(packet, EINVAL); 1061 1061 … … 1126 1126 assert(header); 1127 1127 1128 if (! header->acknowledge)1128 if (!GET_TCP_HEADER_ACKNOWLEDGE(header)) 1129 1129 return; 1130 1130 … … 1833 1833 1834 1834 /* Remember the outgoing FIN */ 1835 if ( header->finalize)1835 if (GET_TCP_HEADER_FINALIZE(header)) 1836 1836 socket_data->fin_outgoing = socket_data->next_outgoing; 1837 1837 … … 1952 1952 header->acknowledgement_number = 1953 1953 htonl(socket_data->next_incoming); 1954 header->acknowledge = 1;1954 SET_TCP_HEADER_ACKNOWLEDGE(header, 1); 1955 1955 } 1956 1956 header->window = htons(socket_data->window); … … 2024 2024 header->source_port = htons(socket->port); 2025 2025 header->source_port = htons(socket_data->dest_port); 2026 header->header_length = TCP_COMPUTE_HEADER_LENGTH(sizeof(*header)); 2027 header->synchronize = synchronize; 2028 header->finalize = finalize; 2026 SET_TCP_HEADER_LENGTH(header, 2027 TCP_COMPUTE_HEADER_LENGTH(sizeof(*header))); 2028 SET_TCP_HEADER_SYNCHRONIZE(header, synchronize); 2029 SET_TCP_HEADER_FINALIZE(header, finalize); 2029 2030 } 2030 2031 -
uspace/srv/net/tl/tcp/tcp_header.h
r9bd5746 rcf5e86e 47 47 * @param[in] header The TCP packet header. 48 48 */ 49 #define TCP_HEADER_LENGTH(header) ( (header)->header_length* 4U)49 #define TCP_HEADER_LENGTH(header) (GET_TCP_HEADER_LENGTH(header) * 4U) 50 50 51 51 /** Returns the TCP header length. … … 73 73 uint32_t sequence_number; 74 74 uint32_t acknowledgement_number; 75 76 #ifdef ARCH_IS_BIG_ENDIAN77 uint8_t header_length:4;78 uint8_t reserved1:4;79 #else80 uint8_t reserved1:4;81 uint8_t header_length:4;82 #endif83 75 84 #ifdef ARCH_IS_BIG_ENDIAN 85 uint8_t reserved2:2; 86 uint8_t urgent:1; 87 uint8_t acknowledge:1; 88 uint8_t push:1; 89 uint8_t reset:1; 90 uint8_t synchronize:1; 91 uint8_t finalize:1; 92 #else 93 uint8_t finalize:1; 94 uint8_t synchronize:1; 95 uint8_t reset:1; 96 uint8_t push:1; 97 uint8_t acknowledge:1; 98 uint8_t urgent:1; 99 uint8_t reserved2:2; 100 #endif 76 uint8_t hlr; /* header length, reserved1 */ 77 78 #define GET_TCP_HEADER_LENGTH(header) \ 79 (((header)->hlr & 0xf0) >> 4) 80 #define SET_TCP_HEADER_LENGTH(header, length) \ 81 ((header)->hlr = \ 82 ((length & 0x0f) << 4) | ((header)->hlr & 0x0f)) 83 84 #define GET_TCP_HEADER_RESERVED1(header) \ 85 ((header)->hlr & 0x0f) 86 #define SET_TCP_HEADER_RESERVED1(header, reserved1) \ 87 ((header)->hlr = \ 88 (reserved1 & 0x0f) | ((header)->hlr & 0xf0)) 89 90 /* reserved2, urgent, acknowledge, push, reset, synchronize, finalize */ 91 uint8_t ruaprsf; 92 93 #define GET_TCP_HEADER_RESERVED2(header) \ 94 (((header)->ruaprsf & 0xc0) >> 6) 95 #define SET_TCP_HEADER_RESERVED2(header, reserved2) \ 96 ((header)->ruaprsf = \ 97 ((reserved2 & 0x03) << 6) | ((header)->ruaprsf & 0x3f)) 98 99 #define GET_TCP_HEADER_URGENT(header) \ 100 (((header)->ruaprsf & 0x20) >> 5) 101 #define SET_TCP_HEADER_URGENT(header, urgent) \ 102 ((header)->ruaprsf = \ 103 ((urgent & 0x01) << 5) | ((header)->ruaprsf & 0xdf)) 104 105 #define GET_TCP_HEADER_ACKNOWLEDGE(header) \ 106 (((header)->ruaprsf & 0x10) >> 4) 107 #define SET_TCP_HEADER_ACKNOWLEDGE(header, acknowledge) \ 108 ((header)->ruaprsf = \ 109 ((acknowledge & 0x01) << 4) | ((header)->ruaprsf & 0xef)) 110 111 #define GET_TCP_HEADER_PUSH(header) \ 112 (((header)->ruaprsf & 0x08) >> 3) 113 #define SET_TCP_HEADER_PUSH(header, push) \ 114 ((header)->ruaprsf = \ 115 ((push & 0x01) << 3) | ((header)->ruaprsf & 0xf7)) 116 117 #define GET_TCP_HEADER_RESET(header) \ 118 (((header)->ruaprsf & 0x04) >> 2) 119 #define SET_TCP_HEADER_RESET(header, reset) \ 120 ((header)->ruaprsf = \ 121 ((reset & 0x01) << 2) | ((header)->ruaprsf & 0xfb)) 122 123 #define GET_TCP_HEADER_SYNCHRONIZE(header) \ 124 (((header)->ruaprsf & 0x02) >> 1) 125 #define SET_TCP_HEADER_SYNCHRONIZE(header, synchronize) \ 126 ((header)->ruaprsf = \ 127 ((synchronize & 0x01) << 1) | ((header)->ruaprsf & 0xfd)) 128 129 #define GET_TCP_HEADER_FINALIZE(header) \ 130 ((header)->ruaprsf & 0x01) 131 #define SET_TCP_HEADER_FINALIZE(header, finalize) \ 132 ((header)->ruaprsf = \ 133 (finalize & 0x01) | ((header)->ruaprsf & 0xfe)) 101 134 102 135 uint16_t window; -
uspace/srv/vfs/vfs.h
r9bd5746 rcf5e86e 176 176 vfs_pair_t *, ...); 177 177 extern int vfs_open_node_internal(vfs_lookup_res_t *); 178 extern int vfs_close_internal(vfs_file_t *);179 178 180 179 extern bool vfs_nodes_init(void); -
uspace/srv/vfs/vfs_file.c
r9bd5746 rcf5e86e 79 79 for (i = 0; i < MAX_OPEN_FILES; i++) { 80 80 if (FILES[i]) { 81 (void) vfs_close_internal(FILES[i]);82 81 (void) vfs_fd_free(i); 83 82 } … … 108 107 } 109 108 109 /** Close the file in the endpoint FS server. */ 110 static int vfs_file_close_remote(vfs_file_t *file) 111 { 112 ipc_call_t answer; 113 aid_t msg; 114 sysarg_t rc; 115 int phone; 116 117 assert(!file->refcnt); 118 119 phone = vfs_grab_phone(file->node->fs_handle); 120 msg = async_send_2(phone, VFS_OUT_CLOSE, file->node->devmap_handle, 121 file->node->index, &answer); 122 async_wait_for(msg, &rc); 123 vfs_release_phone(file->node->fs_handle, phone); 124 125 return IPC_GET_ARG1(answer); 126 } 127 128 110 129 /** Increment reference count of VFS file structure. 111 130 * … … 125 144 * decremented. 126 145 */ 127 static void vfs_file_delref(vfs_file_t *file) 128 { 146 static int vfs_file_delref(vfs_file_t *file) 147 { 148 int rc = EOK; 149 129 150 assert(fibril_mutex_is_locked(&VFS_DATA->lock)); 130 151 131 152 if (file->refcnt-- == 1) { 132 153 /* 133 * Lost the last reference to a file, need to drop our reference134 * to the underlying VFS node.154 * Lost the last reference to a file, need to close it in the 155 * endpoint FS and drop our reference to the underlying VFS node. 135 156 */ 157 rc = vfs_file_close_remote(file); 136 158 vfs_node_delref(file->node); 137 159 free(file); 138 160 } 161 162 return rc; 139 163 } 140 164 … … 201 225 int vfs_fd_free(int fd) 202 226 { 227 int rc; 228 203 229 if (!vfs_files_init()) 204 230 return ENOMEM; … … 210 236 } 211 237 212 vfs_file_delref(FILES[fd]);238 rc = vfs_file_delref(FILES[fd]); 213 239 FILES[fd] = NULL; 214 240 fibril_mutex_unlock(&VFS_DATA->lock); 215 241 216 return EOK;242 return rc; 217 243 } 218 244 -
uspace/srv/vfs/vfs_ops.c
r9bd5746 rcf5e86e 717 717 } 718 718 719 int vfs_close_internal(vfs_file_t *file)720 {721 /*722 * Lock the open file structure so that no other thread can manipulate723 * the same open file at a time.724 */725 fibril_mutex_lock(&file->lock);726 727 if (file->refcnt <= 1) {728 /* Only close the file on the destination FS server729 if there are no more file descriptors (except the730 present one) pointing to this file. */731 732 int fs_phone = vfs_grab_phone(file->node->fs_handle);733 734 /* Make a VFS_OUT_CLOSE request at the destination FS server. */735 aid_t msg;736 ipc_call_t answer;737 msg = async_send_2(fs_phone, VFS_OUT_CLOSE,738 file->node->devmap_handle, file->node->index, &answer);739 740 /* Wait for reply from the FS server. */741 sysarg_t rc;742 async_wait_for(msg, &rc);743 744 vfs_release_phone(file->node->fs_handle, fs_phone);745 fibril_mutex_unlock(&file->lock);746 747 return IPC_GET_ARG1(answer);748 }749 750 fibril_mutex_unlock(&file->lock);751 return EOK;752 }753 754 719 void vfs_close(ipc_callid_t rid, ipc_call_t *request) 755 720 { 756 721 int fd = IPC_GET_ARG1(*request); 757 758 /* Lookup the file structure corresponding to the file descriptor. */ 759 vfs_file_t *file = vfs_file_get(fd); 760 if (!file) { 761 async_answer_0(rid, ENOENT); 762 return; 763 } 764 765 int ret = vfs_close_internal(file); 766 if (ret != EOK) 767 async_answer_0(rid, ret); 768 769 vfs_file_put(file); 722 int ret; 723 770 724 ret = vfs_fd_free(fd); 771 725 async_answer_0(rid, ret); … … 1369 1323 fibril_mutex_lock(&oldfile->lock); 1370 1324 1371 /* Lookup an open file structure possibly corresponding to newfd. */ 1372 vfs_file_t *newfile = vfs_file_get(newfd); 1373 if (newfile) { 1374 /* Close the originally opened file. */ 1375 int ret = vfs_close_internal(newfile); 1376 if (ret != EOK) { 1377 fibril_mutex_unlock(&oldfile->lock); 1378 vfs_file_put(oldfile); 1379 vfs_file_put(newfile); 1380 async_answer_0(rid, ret); 1381 return; 1382 } 1383 1384 ret = vfs_fd_free(newfd); 1385 if (ret != EOK) { 1386 fibril_mutex_unlock(&oldfile->lock); 1387 vfs_file_put(oldfile); 1388 vfs_file_put(newfile); 1389 async_answer_0(rid, ret); 1390 return; 1391 } 1392 vfs_file_put(newfile); 1393 } 1325 /* Make sure newfd is closed. */ 1326 (void) vfs_fd_free(newfd); 1394 1327 1395 1328 /* Assign the old file to newfd. */
Note:
See TracChangeset
for help on using the changeset viewer.
