From 9faa0e600f64c0a45acbf3347e3c794385b43f2d Mon Sep 17 00:00:00 2001 From: mirsella Date: Tue, 26 Sep 2023 15:53:30 +0200 Subject: [PATCH] gamp --- src/free.c | 16 ++++++++++++++-- src/mmap.c | 5 +++-- test0 | Bin 0 -> 15776 bytes test0.c | 14 ++++++++++++++ test1 | Bin 0 -> 16080 bytes test1.c | 28 ++++++++++++++++++++++++++++ test2 | Bin 0 -> 16120 bytes test2.c | 24 ++++++++++++++++++++++++ test3 | Bin 0 -> 16160 bytes test3.c | 41 +++++++++++++++++++++++++++++++++++++++++ test4 | Bin 0 -> 15992 bytes test4.c | 26 ++++++++++++++++++++++++++ test5 | Bin 0 -> 16160 bytes test5.c | 34 ++++++++++++++++++++++++++++++++++ 14 files changed, 184 insertions(+), 4 deletions(-) create mode 100755 test0 create mode 100644 test0.c create mode 100755 test1 create mode 100644 test1.c create mode 100755 test2 create mode 100644 test2.c create mode 100755 test3 create mode 100644 test3.c create mode 100755 test4 create mode 100644 test4.c create mode 100755 test5 create mode 100644 test5.c diff --git a/src/free.c b/src/free.c index e6e4cd4..2372609 100644 --- a/src/free.c +++ b/src/free.c @@ -27,13 +27,25 @@ void _free(void *ptr) { map->prev->next = map->next; if (map->next) map->next->prev = map->prev; - if (map == g_mmap) - g_mmap = map->next; + // FIX: this cause page reclaims to skyrocket + /* if (map == g_mmap) */ + /* g_mmap = map->next; */ + t_mmap *gmmap = g_mmap; + (void)gmmap; + if (map == g_mmap) { + /* gmmap = map->next; */ + if (map->next) + g_mmap = map->next; + else + g_mmap = NULL; + } munmap(map, map->size + sizeof(t_mmap)); } } void free(void *ptr) { + (void)ptr; + /* return; */ if (LOGGING) { ft_dprintf(tmpfd(), "free(%p)\n", ptr); /* flog("free(): ", (size_t)ptr); */ diff --git a/src/mmap.c b/src/mmap.c index a9f1ea0..2e9137d 100644 --- a/src/mmap.c +++ b/src/mmap.c @@ -17,8 +17,9 @@ t_type get_mmap_type(size_t size) { } t_mmap *new_mmap(size_t size) { - t_mmap *map = mmap(NULL, get_mmap_size(size) + sizeof(t_mmap), - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + t_mmap *map = + mmap(NULL, get_mmap_size(size) + sizeof(t_mmap), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (!map) { errno = ENOMEM; return NULL; diff --git a/test0 b/test0 new file mode 100755 index 0000000000000000000000000000000000000000..7d3b6672c904c3b0175726d557cbebb6b367016a GIT binary patch literal 15776 zcmeHOZEPGz8J;^kiAxjPaT{Wi(5#?A39Z*>$2OrQerYbGrPA0ChlL0TPB+vxgs zwMT6xyE))=d0GRN>U1Ny9$SQOBILME&NRS1nx+o zo{#y7RfIfxhm1wkw}2Ru{S!4h?h-^qG~C*&8&?{W9pqbL!~v(~7F8F()#r z|`1$2I?+5I|{pJ|<;l%Y}im=UjZj*hq z9_J}1bDQwG`?EqoY;fWFI~tS?6K6Ew?G5;L&K&(Kl zK&(KlK&(KlK&${O@Os+=|FD*R-(o$p>1MZ5)~9P;(*K3EbhYK>Kp?;WIimmM@B0Qp z+up#Rtd|07M9261VeI1dC#{RWvX*|cd~!0=Q|tMOb?NXcRDr*vLY{w~G28ZjDyWb6 zuMlHh+Vlm6_pW$5sOb-Io|?YLzty()96P=&NdCFNzkiD1z^Zj|*}C$_Bi5CbCM$8x zy1we&PZjKw3R?VIGi`gRUx?@XJ9n6iRrR6M*3#i5XRV8`dRwh$4sRyo_5t7bZ)fRp zZPUN#sXK9oV%Nq0_9-glicVA9k280>R^w-1f04N}Bw1b0x`JF1 zr&xhlfmnf9fmnf9fmnf9fmnf9fmnf9fmnh6uLAu0S7LY5qx-2F{QJ?KW#4~-@L@uJ zVt*eYJx;5AulfF03HdinPKl={RAQk$v3u*5mS^b)Eav&Q`sF*m|1NeI*%JH$_8?{Z z==CD;0nyq%+S>V8+r3YJi|rB{`yu)HjT6fMvg()E{;q6d#NNa?e)y!M_p~Z?L(1QxX>~#H zUcpYm9fAM}Q#INDxJ3$5(h&Ml6P`AE1_|{&AU6E|>FfTIP64$lcCZPTeCe0r;C`SZ zJ*EcsvfR(##YVrR`u`nZfB1h{Ble{p9Ugwf*nfJeTJ)+$Ps;2!Q(ZmP!0b8O+iRx! z4ha398)QA2)oXs#i}g-W$!A3nLmciSY~;`5kyNc}Ugo2?D?|9p5&od?nBVXpqfA0| zs`j*IFkZaNIzj)vz6K7#t-lXYdWSNN_J40BK@2#B@I3*)Q>k=_r0jm; z+ttpxo+#}mz9ZSD@Oc5gU;Lx>36V_N1(@V_Z4DvLkn1ES7~{{i{D3;yRsg-gV9f1>`MBi=x82wxx`pQ#~Q zT_wIFNuOeod8k2)0c}3UEh!)}Y}5g7xPZ>fPqE3V~d7a;LIb@SG_^udHzn zxm=MBF3c;lSn^zRwpcai%cXg@>@9|(?`hQH4@^nE&^h` ziT=Y6c$VUM%>^6lE?`O;i}oLVxI`J&6!BOG0&C)k_M`XzWh&=;LV5jjTRy+B{*`Ki zwvcE18ok2thQtBItcSn`J{O5kNdXXkr~o$bTaoy*6aZTz1BN)%_q|9wzSn_xK7fC8 z{{B$n>uU}}JO!ivuz^34c#I#`IY2(A6;6l)_fyL7Eh0W;=n~);wOPMn{6YMZGOhH& z`W@>&oF|O>!v_AEV%tLTSZA(u5lIPt+FG;0^LmZv9@?+3|KxmVO~#MsKPSXt9KT5% zyC5FVMYV4BRw^A_*Di<$u24}pz8;X$F=z)hAP)8_Wtc+W!hnCjmu;iYK+ literal 0 HcmV?d00001 diff --git a/test0.c b/test0.c new file mode 100644 index 0000000..6a4739b --- /dev/null +++ b/test0.c @@ -0,0 +1,14 @@ +#include + +int main(void) +{ + int i; + char *addr; + + i = 0; + while (i < 1024) + { + i++; + } + return (0); +} diff --git a/test1 b/test1 new file mode 100755 index 0000000000000000000000000000000000000000..27838c71291f9c45a75310805846285d6bfcec1e GIT binary patch literal 16080 zcmeHOYit}>6~4P^5{EpzX%g}x@f2E=ws>PZaY#c=*0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3E{T0T+Oc@v6VxFR+5RJb$yh4(=pN63Y+(sA5N06EK$w9r17QZj41^g7GZ1DV z%)tL51K0EEE+Qnd={8ZzJz{@f zWQ;??|HlCPzk>mrgh+1`1B|@`2mhd#Vj=ak{qCQ-i_nuX$XQ;w)@VSHjdF{WVvQHQKQ&g$d|Jla% zV;yI?+HfBt+`(FLexdzWs^C1hplQo0`{)tnZSB9R@_B;(U8>aDhrNgrV!+9Vy;@J- z9toe4svAgOE6z63$JFXdp22Eo|L9VM?<44U&JySIS|3y6a((rGHbgok@q_)zlHNd2 zA3j6+rP0+2^Bbmd*7FF2Bwu6d1nFyy>t)i%X#T89AcBYe+CNq~FQfmKZE{nk>1cA)o*_wz5XMtTCJk=#d&X(ehmVj7q!2y;5Ntew42@T zOL z?mIuXyM0%82dU{?gq1YKYIg2Z*3O@+-?na(V+I`S24yt%+Bu7nn=oUQ7 zmz_c}ozGPX7TF3;#%6-lhBB^->u$!W8Xw4$$d#hgr{beQ5-O;a$BPAOJ#n$TIAr-9GW2Nii;MITN2?eI$Qd>htPV%EN>Gk%O- zyp{ofwsTzU%LVHfPx97-etz&g7yrNRFZkYrj(;cpeEd!W4LAx0`FxJ(Jz5K)|5z^q z(LUCT!T#IC=d~jESWi|^+T}iSp25euE=@XKT7ZxBDG=*Xa?yoj_{)*pK7118wXSMW0hJViD?|Bx7f@Iwg5z=;5VNDROx z5Cy>l{ye}xDF&d+o%0p&pgKzxfB&)G0ph+4{=v`BYr@C%SB7{BHi!ra^4}r@w-3Hy zc%HyVJ+bm0XTNa2iSw61f5^Za#I5)7aX&iI zNJ=X3^Q1d6^t>sU=PvHUuwKS_TAZ8Z&mR}?a2;PJ9giP;+>f5#$lgj}z2-@G_=q!) z$bP;`h-Z_BXeY>r% +#include +#include + +void print(char *s) +{ + write(1, s, strlen(s)); +} + +int main(void) +{ + int i; + char *addr; + + i = 0; + while (i < 1024) + { + addr = (char*)malloc(1024); + if (addr == NULL) + { + print("Failed to allocate memory\n"); + return (1); + } + addr[0] = 42; + i++; + } + return (0); +} diff --git a/test2 b/test2 new file mode 100755 index 0000000000000000000000000000000000000000..fd15d659af328f6519d7f5f0027c0fdca7692708 GIT binary patch literal 16120 zcmeHOYit}>6~4Q9xipD4FB&IJJU{|%iZ{0NAbpsuW3RIYCozcwK@`So@7Uh34|jK# z*cAzG4JB4;Dg2=b@x%Rrng|d^0+FJkI0VuZwJ7P2Dpe5*6#-iX>ZAb-h%Dc^bIxWw zT1Th?i63*N+3%jmckZ1tcXsdW-20_yTT3tyP*Ucpk1CQTLXIZFh8-W_3Lv6(s3rKU zR_oP5$n&+%u}2($)hSnkv$2Bp^MJ%#O_efuucKCi(nCVx%~dW@hfo9+p9k?4kbz|{ z?%{q4ioMjHL1Yv|f0ppWua9|NY<6f$klLVf;F_IyH|@1E&oFct<;6!FwGx!}J^>zITK2dz z$YtKo?ag%^IywJ>oL;p#mF(KSb#p3FlS*a^12qFXw%2Um8qR0K^}1o|mw|)E)b70p z6~auAj?<`uLyj!*$hMO0TG-oW84biU>K z^Ht~#uQTKTj`x?*E7R;Ah?_mhOgxo*+*0XyDwXY4M{-Hqf(=)*+sxbXoNcD#$&BjB zS(eJ%xs;VrWTOkaUF~jb-PL5)hqr7kRqMmsl-b&`$4po`t2ddqtz5^Rrc^d#b;P?; z6uLK^&2VVbaV_hJJ_m6%1NaQ;PpZ-R1l7Yp8LvP5+ShSe=cy>`3Tu+M+(Fe2nTmXm z$o)IE%+a6X?+MX&vc4kX*hMe$m7R{B#*lk_U3KYYER*M?OYe+3hd=GoOB-aFap`Hi zN;$*&MNrVSlrrJc(|sW2qD!y8zu9ofrKeba@iX9Oz|Vl60Y3wN2K)^88TijK@J{9W zf5e9WSP?t1;B`D3#J)0N2aA_t!#}S$uLBgfJqh)V;>KY>Wwj#zKC;}H`fagTJgH@x z$laK_T#{)*d1LBaNv4V9jj11qjA%!7v}UE_L9X%08$I$mkG#q)*Zrw=dIU5v`l3dnq>B@GrDlT=h;^shd6F%IYse#0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r)V}g2%w8 zxu(c6-xRFn#=QNPK8&J5ITgOle+4JlQQG&O|1-?r#eOoM7VLEKDQ8|j<%e=2@k_re z{QDx$85~CURqBM_!r|r{%oA*PJEP9#5LV)e+35WqVNsF@f3W-5lf$5 z{u{8k`JIO2D)@4V=~QI=i252TOL53^lRTfwK25K`$b#3wt#t9_`Snx{lqlloNVjFt z)8b$nyVAbQt7YGZ%-f8PEOzTiTT-Fy{c-&zNy z9f=@3kr#tZI%!|#hau*B{i!W?S;p*m1i?IN$_#Y#od=Z +#include +#include + +void print(char *s) { write(1, s, strlen(s)); } + +void test(void *p); +int main(void) { + int i; + char *addr; + + i = 0; + while (i < 1024) { + addr = (char *)malloc(1024); + if (addr == NULL) { + print("Failed to allocate memory\n"); + return (1); + } + addr[0] = 42; + free(addr); + i++; + } + return (0); +} diff --git a/test3 b/test3 new file mode 100755 index 0000000000000000000000000000000000000000..8ba2e253b72ec5e2631b8805f4d1b5a3b09a04b8 GIT binary patch literal 16160 zcmeHOYit}>6~4Q9Z4xKmv`OkDG})FyACWh9;-n$O%{qQ$40(|_LPeCx+B>!v?ZfQO z5<7k1DlNjK5kabGBpym7q^2qoK|-j2pic855`{!ikqCqgN{}s4>bSIW3(fMKx#vvA z!_L9ZX>=2)$xR>vBrVn4Sx$S8g!lHUpTJHdW}3n`2HG^-rj2wV6@c`vm+bFaK_l z)4YeFN#{!awf!46)NW{q7xVG8P8XktLk2+z!Pp6_hD(u?qZc;40a#nT8((AH&CA=(sAy*)R?N zz%=|b@?@|W}Y1@JhXSvHP+R1`#W|Qfh zD%ypNl~V;vn_2y7TagW&_zh~?_V%sK=Gyq$_}by9 zb5=*PGeb@EWb-+0!qlb}4bjyw&gu;O>2Hl8u+7lPcrGnZ&!thZgSqd2^=lXgVf7$n zDsrEZ>w9>S=8yAzMEF7GBMGe+UgXPLG*4rUaw}!T!+Xc&sE2p%v+OYL;n8uoOnP`4 z&r(h@Pq%TomPq%aho|dA%CLvm*Mrvl%)|3ff}^|4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(21JWG+P; z2-k9B5Ntxu`pF(b{31=gtNPWwlnxFuvtNpM!Og)ZcUiFg<@&| zIwMNOivw9Z*$K1@8hfRNgS85MDxS;RR=g)yiuV=reOAF9@KBwlG&b6#Q%p5&ZLg&P z=a}~3nXAU_w{0GD&jaT3^Oiai^PcRO3B)h*T+BT`F!{ z{Savc!aDDqxVY8JW3D%aXd>wtdhlrvsiUc6HjQA~9XVHVjQT7FbA=1;Kcr~hhD#d1 zMY{O+%gMZr)sC&y2|tJr&6UJ|x_x0}OGV~KT2hMk=Xm}7`@`t}^4=o%QQ_!!*Xu98 z`+_ksWc2%g68u}3Yf1lQJ}M~f%Y4+||0MirE-L;qUloi{a#5&{R26@jH>SbSR7Lzp zxPyYvL+33V&ZRzw8qFoeU*?a3OW9KTFLr{DK~Hm2k!5}=SjYbU{xhwPph8_1f0-`} z4zr=O??3)$*ncbA$^2VT=Ii87IrIBJ3yyLk@!j7U{=Jds5|}u}fBwG#*6SZ*Kf(Rl z&Ha|2F~R42{)4O#6gvqZvfxRd|4~*5?iNQz@e}-^&wqp!g75eSjQB}dX9*<)$)C)h z1m(F;?EU#W%k9hgS24C^+{~hY-~SaTsEgviIi@XL)S~HWmE2>!~X; zeuTb;%0hhPIZK{rWk09iUSz@R@U8av%RK*hEl3ox)6z{@cv>V(xtI23{w@1+WgjkG ze^kUz&f^Q<==jB7o_CL}A#0_2HMrm6FE|^{UVoKf(>jgPjsy@tk!fB}oU||V#VGsx z?WrwqS;XzLxvLWY)h?qe;_pQnJ6_WS2bBBp?NHLZTlypS-?`wV?_U3!1})Y4f=jz% UOVjB}{;l-GhO*q};1kt90N0(}zyJUM literal 0 HcmV?d00001 diff --git a/test3.c b/test3.c new file mode 100644 index 0000000..129e213 --- /dev/null +++ b/test3.c @@ -0,0 +1,41 @@ +#include +#include +#include + +#define M (1024 * 1024) + +void print(char *s) +{ + write(1, s, strlen(s)); +} + +int main() +{ + char *addr1; + char *addr2; + char *addr3; + + addr1 = (char*)malloc(16*M); + if (addr1 == NULL) + { + print("Failed to allocate memory\n"); + exit(1); + } + strcpy(addr1, "Hello world!\n"); + print(addr1); + addr2 = (char*)malloc(16*M); + if (addr2 == NULL) + { + print("Failed to allocate memory\n"); + exit(1); + } + addr3 = (char*)realloc(addr1, 128*M); + if (addr3 == NULL) + { + print("Failed to reallocate memory\n"); + exit(1); + } + addr3[127*M] = 42; + print(addr3); + return (0); +} diff --git a/test4 b/test4 new file mode 100755 index 0000000000000000000000000000000000000000..f92ac170cf7b734f3a949c4a4ff20568c738b7c4 GIT binary patch literal 15992 zcmeHOYiL}@6`ozc}0pMnC#PDGgTY)-;8bm=xN=? z_wBXQZqXgilsvcCx3@i8$h&>cK-N{ZJ)A4#?ULsdJ=<2=wWedv$z}_Ksx(qKVr$XP zxjCW_jyd*FChuf3k8?B{>p_W@b252F`jBTEG7UNFgFN)x)t;X2-R<@kYm2qbm$&j< zjnjzWkH;)Vmg9t&hvjvd#XOoXiR}k3e1nEBuD(M$7koe9b9s2VvA-#wf7laZuS=SG z*rA`@W$ZjRcuY}d0`}m1ss!vj|4=Rk?D~6CDy|0XJP%QRCU&;rGr)Bp2JB|Of)Qbq zfhYq}2BHi^8Hh3vWgyDHeW8VLKdC#VyHnlv zBAKsL?>RwG->BGsgln!`_^4W~KCg9NXkNK+20D3vTYGmX?N9olklr8ETmH~}?9As= z$9|hS`thX$eVr}SE$^p}@BBGMt*+Wio_`*)>KnhpttzrVN|w~|1-%USU-ec|*KcE) zy1uwNQ{Onjey0S9Iq^oyEU!geo~u zKk-g-vMPVMR;`}ob$I1>Eb+>_@)1kCp0E6xCBAd0e85tIrBf^=S$c=136|bwiI@46 z*R@0eE8o--1+2WFB??&ix|S$ljpQI^jLRB7wbm$ac zf}Sh>>|l?mL>Y)O5M?0BK$L+f15pN|3`7}-G7x1T%E13a2KYHuZ2i0ko2j$>oagpS z)oPlshwwSV#|Xbm_yl1Op?kSn{ShHQ%j6P!yjR7>8e;30EUJ5+?nK$n&+Ipn|EJ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BGY6fP0^s47-qg024rf=$z>>*p;M-nMH4kg^RL!t;S<<+ z-9sNO`i?gxd=3rk9;w#8kQwiy7q2zIpXWFAo-cpTWle z&w_mXKLsY>C>Z8{mh69}wF>%=^&AlGV?7t{ze9Xp%Yl#e9&noKxNsji&){R-l_481 z0l>%l5s397x#+?%g5`^(@LCLftiOQx8b$x%2Yib7ytadm^&PNT8VmOyec<&r=M;Rb zH-XdQi1x$R&*y-czgzsUeg&d^=5x-%{MX3FIYE5?|At&R*7f9~OL+XhMb;ocAv_@3 z7kW6ndLzU?Abg;xpx?ls4Dk;O0hsWaMnF8^J0bprQ~=)!O&IVH_GE~UbqNsnP4Exr z@2A4||2HSZQ!wlg9r%IpF@NTRC)i5$!2%v^zafDy5&RtqQv-a + +#define M (1024 * 1024) + +int main() +{ + malloc(1); + malloc(2); + malloc(4); + malloc(8); + malloc(16); + malloc(32); + malloc(64); + malloc(128); + malloc(256); + malloc(512); + malloc(1024); + malloc(1024 * 2); + malloc(1024 * 4); + malloc(1024 * 32); + malloc(M); + malloc(16*M); + malloc(128*M); + show_alloc_mem(); + return (0); +} diff --git a/test5 b/test5 new file mode 100755 index 0000000000000000000000000000000000000000..5f66d25811e738ec877619dd1016157d03839055 GIT binary patch literal 16160 zcmeHOdvFz389(=iM`(duTA%?0wiF%PPL>1$(nsXxal@wah#`#V6qilzCb@ba;oiNH zpwKw6okobJGmd7|Kj0r8)6R&a<5Z_kLs2Md9ngPZ{3kw`Nk%OpQccxz{l0U)Z`rK( z*82F*J(+ud=lgw+bN1VFch6?ec_y}_IUEWJE@k4w0;TbYVxput@FA)IM8#II2)@^f zHDVsfb0nwqQ3aq?=)dCgmm=u?;MHZaDG(q`g-1Yt>{J;m0QxEf~4IkAffO<-Ha@ z&27|Psq@f7`Ddi`iVev`$Cla+$#_*VkDlaru>r1?a6t3tVsL zdcnW%u_a&#<%EwPAig{*)q?F=zP3&AIL5r=Z`{N4SVzkV53k0h@}KhX&{4O{cz7Jo zT+R`XmvK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Y%w^*du` zY*&*B3+y`OC!**kHU-@q&1q_gt>jk?uPmu=I-X^J+XGPy}n^b%#`c?qrAdj zF6;Mi4RE!v{{P+9{L7sMuCWYd$1TSa@;GU4!7P1mHj#EPH(;gq3V<+sa74~oq4$RK>3O${1Y`r_3*L$;>UOVgbd#H|l0(RLX;zZRqv{d0} zljc2Eu1Dzc{xme9(8(&zXY6b)kx9=IOweWRq=gPt>rFaBm)+E%s&{8V#7fTY6uM*g zfr!HotTXZ?>2?ndxSlvfV@btOBTsp79h$OI2?(a#A?HGeA)kVgT;$jG?^8H$gP%0q zi&XLNm*aUGsiiH~5g&pN&Xw4|)V?sZ#lrI=B?++wDqes8{xJOiySMQ5k~zHZdj0vn z>q2K>w!2cQMTHJr0k1}%mG%ft6{#)RWb5Zu^`6^>MCKn3!5vzRsJa0?@hf@{y zAEyp7o&ue>P&k)52sNBbvOmus8JCkK_n++;kAfcOrY!UPl(Cxp{rx9e3_}IG%>F!I zW*j3!Zr^|WcppOl2D0P%HzUv2(I0c>_df|7=7i(B_Zhn1@N)^6$U^C5QG63>UVn}J z7!SCXs=~K1#?wCk0a7rs9fx6=@tn_pgcOXe>`2IdjNkY9kCTG&JH7$KejN5ypFhu& z82P!6?fv=tG5PcP7aCa-wvx!e=a1z#pn_dw|5ijwzdg&0x4^f;M|Li8wbzuBL09yojbMU+gd6>>Wqfc;or2+qiH`#fKa zkiXv^+wztr)IOQJD)xWWWmJXzy~tz7YZ|41d>vj5N}OMFfB5=~&x_o5uYYB&k{2vUj;vXc3yc7Tc literal 0 HcmV?d00001 diff --git a/test5.c b/test5.c new file mode 100644 index 0000000..01c2f63 --- /dev/null +++ b/test5.c @@ -0,0 +1,34 @@ +#include +#include +#include + +void print(char *s) +{ + write(1, s, strlen(s)); +} + +int main() +{ + int i; + int alignment; + char *addr; + + i = 1; + alignment = 2 * sizeof(size_t); + while (i <= 100) + { + addr = (char*)malloc(i); + if (addr == NULL) + { + print("Failed to allocate memory\n"); + exit(1); + } + if ((((unsigned long) (addr)) % alignment) != 0) + { + print("malloc returned a non aligned boundary\n"); + exit(1); + } + i++; + free(addr); + } +}