Differences From Artifact [4eb80f8cc9]:
- File src/amiga-library.m — part of check-in [27b401c7c2] at 2021-01-02 22:06:34 on branch amiga-library — Update copyright (user: js, size: 17228) [annotate] [blame] [check-ins using]
To Artifact [fdc1473cd0]:
- File
src/amiga-library.m
— part of check-in
[3c88df0ce4]
at
2021-05-09 14:45:19
on branch amiga-library
— Merge trunk into branch "amiga-library"
All necessary changes to adjust for the changes made in trunk are
included in the merge commit. (user: js, size: 12824) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 | #include <exec/libraries.h> #include <exec/nodes.h> #include <exec/resident.h> #include <proto/exec.h> #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFStdIOStream.h" #import "OFString.h" #import "amiga-library.h" #import "macros.h" | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <exec/libraries.h> #include <exec/nodes.h> #include <exec/resident.h> #include <proto/exec.h> #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFSocket.h" #import "OFStdIOStream.h" #import "OFString.h" #import "amiga-library.h" #import "macros.h" #define CONCAT_VERSION2(major, minor) #major "." #minor #define CONCAT_VERSION(major, minor) CONCAT_VERSION2(major, minor) #define VERSION_STRING CONCAT_VERSION(OBJFW_LIB_MAJOR, OBJFW_LIB_MINOR) #if defined(OF_AMIGAOS_M68K) # define DATA_OFFSET 0x7FFE |
︙ | ︙ | |||
62 63 64 65 66 67 68 | #ifdef OF_AMIGAOS_M68K extern uintptr_t __CTOR_LIST__[]; extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #ifdef OF_AMIGAOS_M68K extern uintptr_t __CTOR_LIST__[]; extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif #include "amiga-glue.h" #ifdef OF_AMIGAOS_M68K void __init_eh(void) { /* Taken care of by OFInit() */ } #endif #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; struct OFLibC libC; FILE **__sF; #if defined(OF_AMIGAOS_M68K) __asm__ ( ".text\n" ".globl ___restore_a4\n" ".align 1\n" |
︙ | ︙ | |||
215 216 217 218 219 220 221 | ); #endif return dataDataRelocs; } static struct Library * | | | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | ); #endif return dataDataRelocs; } static struct Library * libInit(struct ObjFWBase *base OF_M68K_REG(d0), void *segList OF_M68K_REG(a0), struct ExecBase *sysBase OF_M68K_REG(a6)) { #if defined(OF_AMIGAOS_M68K) __asm__ __volatile__ ( "move.l a6, _SysBase" :: "a"(sysBase) ); |
︙ | ︙ | |||
239 240 241 242 243 244 245 | base->parent = NULL; base->dataSeg = getDataSeg(); return &base->library; } struct Library *__saveds | | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | base->parent = NULL; base->dataSeg = getDataSeg(); return &base->library; } struct Library *__saveds libOpen(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) struct ObjFWBase *child; size_t dataSize, *dataDataRelocs; ptrdiff_t displacement; if (base->parent != NULL) return NULL; base->library.lib_OpenCnt++; base->library.lib_Flags &= ~LIBF_DELEXP; /* * We cannot use malloc here, as that depends on the libC passed from * the application. */ if ((child = AllocMem(base->library.lib_NegSize + base->library.lib_PosSize, MEMF_ANY)) == NULL) { base->library.lib_OpenCnt--; return NULL; } |
︙ | ︙ | |||
319 320 321 322 323 324 325 | base->library.lib_NegSize + base->library.lib_PosSize); return segList; #undef SysBase } static void *__saveds | | | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | base->library.lib_NegSize + base->library.lib_PosSize); return segList; #undef SysBase } static void *__saveds libExpunge(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) return expunge(base, SysBase); } static void *__saveds libClose(void) { /* * SysBase becomes invalid during this function, so we store it in * sysBase and add a define to make the inlines use the right one. */ struct ExecBase *sysBase = SysBase; #define SysBase sysBase OF_M68K_ARG(struct ObjFWBase *, base, a6) if (base->parent != NULL) { struct ObjFWBase *parent; #ifdef OF_AMIGAOS_M68K if (base->initialized) for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++) libC.__deregister_frame_info( (&_EH_FRAME_BEGINS__)[i]); #endif parent = base->parent; FreeMem(base->dataSeg - DATA_OFFSET, getDataSize()); FreeMem((char *)base - base->library.lib_NegSize, |
︙ | ︙ | |||
366 367 368 369 370 371 372 | return expunge(base, sysBase); return NULL; #undef SysBase } static void * | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | return expunge(base, sysBase); return NULL; #undef SysBase } static void * libNull(void) { return NULL; } bool __saveds OFInit(unsigned int version, struct OFLibC *libC_, FILE **sF) { #ifdef OF_AMIGAOS_M68K OF_M68K_ARG(struct ObjFWBase *, base, a6) #else register struct ObjFWBase *r12 __asm__("r12"); struct ObjFWBase *base = r12; #endif #ifdef OF_MORPHOS void *frame; #endif uintptr_t *iter, *iter0; if (version > 1) return false; if (base->initialized) return true; memcpy(&libC, libC_, sizeof(libC)); __sF = sF; #ifdef OF_AMIGAOS_M68K if ((size_t)_EH_FRAME_BEGINS__ != (size_t)_EH_FRAME_OBJECTS__) return false; for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++) libC.__register_frame_info((&_EH_FRAME_BEGINS__)[i], (&_EH_FRAME_OBJECTS__)[i]); iter0 = &__CTOR_LIST__[1]; #elif defined(OF_MORPHOS) __asm__ ( "lis %0, __EH_FRAME_BEGIN__@ha\n\t" "la %0, __EH_FRAME_BEGIN__@l(%0)\n\t" "lis %1, __CTOR_LIST__@ha\n\t" "la %1, __CTOR_LIST__@l(%1)\n\t" : "=r"(frame), "=r"(iter0) ); libC.__register_frame(frame); #endif for (iter = iter0; *iter != 0; iter++); while (iter > iter0) { void (*ctor)(void) = (void (*)(void))*--iter; ctor(); } base->initialized = true; return true; } void * malloc(size_t size) { return libC.malloc(size); } void * calloc(size_t count, size_t size) { return libC.calloc(count, size); } void * realloc(void *ptr, size_t size) { return libC.realloc(ptr, size); } void free(void *ptr) { libC.free(ptr); } int fprintf(FILE *restrict stream, const char *restrict fmt, ...) { int ret; va_list args; va_start(args, fmt); ret = libC.vfprintf(stream, fmt, args); va_end(args); return ret; } int vfprintf(FILE *restrict stream, const char *restrict fmt, va_list args) { return libC.vfprintf(stream, fmt, args); } int fflush(FILE *restrict stream) { return libC.fflush(stream); } void abort(void) { libC.abort(); OF_UNREACHABLE } #ifdef HAVE_SJLJ_EXCEPTIONS int _Unwind_SjLj_RaiseException(void *ex) { return libC._Unwind_SjLj_RaiseException(ex); } #else int _Unwind_RaiseException(void *ex) { return libC._Unwind_RaiseException(ex); } #endif void _Unwind_DeleteException(void *ex) { libC._Unwind_DeleteException(ex); } void * _Unwind_GetLanguageSpecificData(void *ctx) { return libC._Unwind_GetLanguageSpecificData(ctx); } uintptr_t _Unwind_GetRegionStart(void *ctx) { return libC._Unwind_GetRegionStart(ctx); } uintptr_t _Unwind_GetDataRelBase(void *ctx) { return libC._Unwind_GetDataRelBase(ctx); } uintptr_t _Unwind_GetTextRelBase(void *ctx) { return libC._Unwind_GetTextRelBase(ctx); } uintptr_t _Unwind_GetIP(void *ctx) { return libC._Unwind_GetIP(ctx); } uintptr_t _Unwind_GetGR(void *ctx, int gr) { return libC._Unwind_GetGR(ctx, gr); } void _Unwind_SetIP(void *ctx, uintptr_t ip) { libC._Unwind_SetIP(ctx, ip); } void _Unwind_SetGR(void *ctx, int gr, uintptr_t value) { libC._Unwind_SetGR(ctx, gr, value); } #ifdef HAVE_SJLJ_EXCEPTIONS void _Unwind_SjLj_Resume(void *ex) { libC._Unwind_SjLj_Resume(ex); } #else void _Unwind_Resume(void *ex) { libC._Unwind_Resume(ex); } #endif #ifdef OF_AMIGAOS_M68K void __register_frame_info(const void *begin, void *object) { libC.__register_frame_info(begin, object); } void *__deregister_frame_info(const void *begin) { return libC.__deregister_frame_info(begin); } #endif #ifdef OF_MORPHOS void __register_frame(void *frame) { libC.__register_frame(frame); } void __deregister_frame(void *frame) { libC.__deregister_frame(frame); } #endif int * OFErrNo(void) { return libC.errNo(); } int vsnprintf(char *restrict str, size_t size, const char *restrict fmt, va_list args) { return libC.vsnprintf(str, size, fmt, args); } #ifdef OF_AMIGAOS_M68K int sscanf(const char *restrict str, const char *restrict fmt, ...) { int ret; va_list args; va_start(args, fmt); ret = libC.vsscanf(str, fmt, args); va_end(args); return ret; } #endif void exit(int status) { libC.exit(status); OF_UNREACHABLE } int atexit(void (*function)(void)) { return libC.atexit(function); } OFSignalHandler signal(int sig, OFSignalHandler func) { return libC.signal(sig, func); } char * setlocale(int category, const char *locale) { return libC.setlocale(category, locale); } int _Unwind_Backtrace(int (*callback)(void *, void *), void *data) { return libC._Unwind_Backtrace(callback, data); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" static CONST_APTR functionTable[] = { #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_BEGIN, (CONST_APTR)FUNCARRAY_32BIT_NATIVE, #endif (CONST_APTR)libOpen, (CONST_APTR)libClose, (CONST_APTR)libExpunge, (CONST_APTR)libNull, #ifdef OF_MORPHOS (CONST_APTR)-1, (CONST_APTR)FUNCARRAY_32BIT_SYSTEMV, #endif #include "amiga-funcarray.inc" (CONST_APTR)-1, #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_END #endif }; #pragma GCC diagnostic pop static struct { ULONG dataSize; CONST_APTR *functionTable; ULONG *dataTable; struct Library *(*initFunc)( struct ObjFWBase *base OF_M68K_REG(d0), void *segList OF_M68K_REG(a0), struct ExecBase *execBase OF_M68K_REG(a6)); } init_table = { sizeof(struct ObjFWBase), functionTable, NULL, libInit }; struct Resident resident = { .rt_MatchWord = RTC_MATCHWORD, .rt_MatchTag = &resident, .rt_EndSkip = &resident + 1, .rt_Flags = RTF_AUTOINIT |
︙ | ︙ |